Skip to content

Commit 7b80dee

Browse files
authored
Prepare for rust update (#1523)
* run clippy and update code after rust update * run cargo check on tests * run cargo clippy fix on tests * accept changes in xml tests because of the diagnostic box wrapper * update rust to 1.90, set the version by parameter
1 parent 2f406d9 commit 7b80dee

File tree

42 files changed

+757
-621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+757
-621
lines changed

.devcontainer/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# FROM mcr.microsoft.com/vscode/devcontainers/rust:latest
2-
FROM ghcr.io/plc-lang/rust-llvm:latest
1+
ARG RUST_LLVM_VERSION=latest
2+
FROM ghcr.io/plc-lang/rust-llvm:${RUST_LLVM_VERSION}
33

44
# Avoid warnings by switching to noninteractive
55
ENV DEBIAN_FRONTEND=noninteractive

.github/workflows/windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
name: Windows Build
1515
runs-on: windows-2022
1616
env:
17-
toolchain-version: 1.83.0
17+
toolchain-version: 1.90.0
1818
llvm-version: 14.0.6
1919
steps:
2020

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ghcr.io/plc-lang/rust-llvm:latest
1+
ARG RUST_LLVM_VERSION=latest
2+
FROM ghcr.io/plc-lang/rust-llvm:${RUST_LLVM_VERSION}
23

34
# Allow invoking `plc` from anywhere
45
ENV PLCLOC="/opt/rusty"

compiler/plc_ast/src/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ impl Variable {
584584
#[derive(Clone, PartialEq)]
585585
pub enum DataTypeDeclaration {
586586
Reference { referenced_type: String, location: SourceLocation },
587-
Definition { data_type: DataType, location: SourceLocation, scope: Option<String> },
587+
Definition { data_type: Box<DataType>, location: SourceLocation, scope: Option<String> },
588588
Aggregate { referenced_type: String, location: SourceLocation },
589589
}
590590

@@ -637,7 +637,7 @@ impl DataTypeDeclaration {
637637
DataTypeDeclaration::Reference { .. } => Some(self.clone()),
638638

639639
DataTypeDeclaration::Definition { data_type, .. } => {
640-
if let DataType::PointerType { referenced_type, .. } = data_type {
640+
if let DataType::PointerType { referenced_type, .. } = data_type.as_ref() {
641641
return referenced_type.get_inner_pointer_ty();
642642
}
643643

compiler/plc_ast/src/pre_processor.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ pub fn pre_process(unit: &mut CompilationUnit, mut id_provider: IdProvider) {
6161
if let DataTypeDeclaration::Definition { mut data_type, location, scope } = *datatype {
6262
data_type.set_name(type_name);
6363
add_nested_datatypes(name, &mut data_type, &mut new_types, &location);
64-
let data_type = UserTypeDeclaration { data_type, initializer: None, location, scope };
64+
let data_type =
65+
UserTypeDeclaration { data_type: *data_type, initializer: None, location, scope };
6566
new_types.push(data_type);
6667
}
6768
}
@@ -311,11 +312,12 @@ fn preprocess_return_type(pou: &mut Pou, types: &mut Vec<UserTypeDeclaration>) {
311312
referenced_type: type_name.clone(),
312313
location: return_type.get_location(),
313314
};
314-
let datatype = std::mem::replace(&mut pou.return_type, Some(type_ref));
315+
let datatype = pou.return_type.replace(type_ref);
315316
if let Some(DataTypeDeclaration::Definition { mut data_type, location, scope }) = datatype {
316317
data_type.set_name(type_name);
317318
add_nested_datatypes(pou.name.as_str(), &mut data_type, types, &location);
318-
let data_type = UserTypeDeclaration { data_type, initializer: None, location, scope };
319+
let data_type =
320+
UserTypeDeclaration { data_type: *data_type, initializer: None, location, scope };
319321
types.push(data_type);
320322
}
321323
}
@@ -325,7 +327,11 @@ fn preprocess_return_type(pou: &mut Pou, types: &mut Vec<UserTypeDeclaration>) {
325327
fn should_generate_implicit(datatype: &DataTypeDeclaration) -> bool {
326328
match datatype {
327329
DataTypeDeclaration::Reference { .. } | DataTypeDeclaration::Aggregate { .. } => false,
328-
DataTypeDeclaration::Definition { data_type: DataType::VarArgs { .. }, .. } => false,
330+
DataTypeDeclaration::Definition { data_type, .. }
331+
if matches!(data_type.as_ref(), DataType::VarArgs { .. }) =>
332+
{
333+
false
334+
}
329335
DataTypeDeclaration::Definition { .. } => true,
330336
}
331337
}
@@ -346,7 +352,7 @@ fn pre_process_variable_data_type(
346352
// create index entry
347353
add_nested_datatypes(new_type_name.as_str(), &mut data_type, types, &location);
348354
data_type.set_name(new_type_name);
349-
types.push(UserTypeDeclaration { data_type, initializer: None, location, scope });
355+
types.push(UserTypeDeclaration { data_type: *data_type, initializer: None, location, scope });
350356
}
351357
//make sure it gets generated
352358
}
@@ -370,13 +376,18 @@ fn add_nested_datatypes(
370376
{
371377
data_type.set_name(new_type_name.clone());
372378
add_nested_datatypes(new_type_name.as_str(), &mut data_type, types, &inner_location);
373-
types.push(UserTypeDeclaration { data_type, initializer: None, location: location.clone(), scope });
379+
types.push(UserTypeDeclaration {
380+
data_type: *data_type,
381+
initializer: None,
382+
location: location.clone(),
383+
scope,
384+
});
374385
}
375386
}
376387

377388
fn replace_generic_type_name(dt: &mut DataTypeDeclaration, generics: &FxHashMap<String, String>) {
378389
match dt {
379-
DataTypeDeclaration::Definition { data_type, .. } => match data_type {
390+
DataTypeDeclaration::Definition { data_type, .. } => match data_type.as_mut() {
380391
DataType::ArrayType { referenced_type, .. }
381392
| DataType::PointerType { referenced_type, .. }
382393
| DataType::VarArgs { referenced_type: Some(referenced_type), .. } => {

compiler/plc_diagnostics/src/diagnostics.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::fmt::Display;
1+
use std::{
2+
fmt::Display,
3+
ops::{Deref, DerefMut},
4+
};
25

36
use serde::{Deserialize, Serialize};
47

@@ -29,6 +32,11 @@ pub enum Severity {
2932
/// Diagnostic severity can be overridden when being reported.
3033
#[derive(Debug)]
3134
pub struct Diagnostic {
35+
pub inner: Box<DiagnosticsInner>,
36+
}
37+
38+
#[derive(Debug)]
39+
pub struct DiagnosticsInner {
3240
/// The Description of the error being reported.
3341
pub message: String,
3442
/// Primary location where the diagnostic occurred
@@ -43,6 +51,20 @@ pub struct Diagnostic {
4351
pub internal_error: Option<anyhow::Error>,
4452
}
4553

54+
impl Deref for Diagnostic {
55+
type Target = DiagnosticsInner;
56+
57+
fn deref(&self) -> &Self::Target {
58+
&self.inner
59+
}
60+
}
61+
62+
impl DerefMut for Diagnostic {
63+
fn deref_mut(&mut self) -> &mut Self::Target {
64+
&mut self.inner
65+
}
66+
}
67+
4668
impl std::error::Error for Diagnostic {
4769
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
4870
self.internal_error.as_ref().and_then(|it| it.source())
@@ -58,14 +80,15 @@ impl From<std::io::Error> for Diagnostic {
5880
/// Builder for Diagnostics
5981
impl Diagnostic {
6082
pub fn new(message: impl Into<String>) -> Self {
61-
Diagnostic {
83+
let inner = DiagnosticsInner {
6284
message: message.into(),
6385
primary_location: SourceLocation::undefined(),
6486
secondary_locations: Default::default(),
6587
error_code: "E001", //Default error if none specified
6688
sub_diagnostics: Default::default(),
6789
internal_error: Default::default(),
68-
}
90+
};
91+
Self { inner: Box::new(inner) }
6992
}
7093

7194
pub fn with_location<T>(mut self, location: T) -> Self

compiler/plc_xml/src/model/snapshots/plc_xml__model__fbd__tests__recursive_sink_source_connections_are_an_error.snap

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,51 @@ expression: err
44
---
55
[
66
Diagnostic {
7-
message: "Sink is connected to itself. Found the following recursion: connection2 -> connection1 -> connection2",
8-
primary_location: SourceLocation {
9-
span: Block {
10-
local_id: 6,
11-
execution_order: None,
12-
inner_range: None,
7+
inner: DiagnosticsInner {
8+
message: "Sink is connected to itself. Found the following recursion: connection2 -> connection1 -> connection2",
9+
primary_location: SourceLocation {
10+
span: Block {
11+
local_id: 6,
12+
execution_order: None,
13+
inner_range: None,
14+
},
1315
},
16+
secondary_locations: None,
17+
error_code: "E085",
18+
sub_diagnostics: [],
19+
internal_error: None,
1420
},
15-
secondary_locations: None,
16-
error_code: "E085",
17-
sub_diagnostics: [],
18-
internal_error: None,
1921
},
2022
Diagnostic {
21-
message: "Sink is connected to itself. Found the following recursion: connection2 -> connection1 -> connection2",
22-
primary_location: SourceLocation {
23-
span: Block {
24-
local_id: 6,
25-
execution_order: None,
26-
inner_range: None,
23+
inner: DiagnosticsInner {
24+
message: "Sink is connected to itself. Found the following recursion: connection2 -> connection1 -> connection2",
25+
primary_location: SourceLocation {
26+
span: Block {
27+
local_id: 6,
28+
execution_order: None,
29+
inner_range: None,
30+
},
2731
},
32+
secondary_locations: None,
33+
error_code: "E085",
34+
sub_diagnostics: [],
35+
internal_error: None,
2836
},
29-
secondary_locations: None,
30-
error_code: "E085",
31-
sub_diagnostics: [],
32-
internal_error: None,
3337
},
3438
Diagnostic {
35-
message: "Sink is connected to itself. Found the following recursion: connection1 -> connection2 -> connection1",
36-
primary_location: SourceLocation {
37-
span: Block {
38-
local_id: 5,
39-
execution_order: None,
40-
inner_range: None,
39+
inner: DiagnosticsInner {
40+
message: "Sink is connected to itself. Found the following recursion: connection1 -> connection2 -> connection1",
41+
primary_location: SourceLocation {
42+
span: Block {
43+
local_id: 5,
44+
execution_order: None,
45+
inner_range: None,
46+
},
4147
},
48+
secondary_locations: None,
49+
error_code: "E085",
50+
sub_diagnostics: [],
51+
internal_error: None,
4252
},
43-
secondary_locations: None,
44-
error_code: "E085",
45-
sub_diagnostics: [],
46-
internal_error: None,
4753
},
4854
]

compiler/plc_xml/src/model/snapshots/plc_xml__model__fbd__tests__unassociated_sink_removed_from_model_with_error.snap

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ expression: err
44
---
55
[
66
Diagnostic {
7-
message: "Expected a corresponding source-connection mark for sink 'connection1', but could not find one.",
8-
primary_location: SourceLocation {
9-
span: Block {
10-
local_id: 3,
11-
execution_order: None,
12-
inner_range: None,
7+
inner: DiagnosticsInner {
8+
message: "Expected a corresponding source-connection mark for sink 'connection1', but could not find one.",
9+
primary_location: SourceLocation {
10+
span: Block {
11+
local_id: 3,
12+
execution_order: None,
13+
inner_range: None,
14+
},
1315
},
16+
secondary_locations: None,
17+
error_code: "E086",
18+
sub_diagnostics: [],
19+
internal_error: None,
1420
},
15-
secondary_locations: None,
16-
error_code: "E086",
17-
sub_diagnostics: [],
18-
internal_error: None,
1921
},
2022
]

compiler/plc_xml/src/model/snapshots/plc_xml__model__fbd__tests__unconnected_source_has_no_effect.snap

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ expression: err
44
---
55
[
66
Diagnostic {
7-
message: "Source 'connection1' is not connected.",
8-
primary_location: SourceLocation {
9-
span: Block {
10-
local_id: 3,
11-
execution_order: None,
12-
inner_range: None,
7+
inner: DiagnosticsInner {
8+
message: "Source 'connection1' is not connected.",
9+
primary_location: SourceLocation {
10+
span: Block {
11+
local_id: 3,
12+
execution_order: None,
13+
inner_range: None,
14+
},
1315
},
16+
secondary_locations: None,
17+
error_code: "E084",
18+
sub_diagnostics: [],
19+
internal_error: None,
1420
},
15-
secondary_locations: None,
16-
error_code: "E084",
17-
sub_diagnostics: [],
18-
internal_error: None,
1921
},
2022
]

compiler/plc_xml/src/xml_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ where
4848
fn visit(reader: &mut Reader, tag: Option<BytesStart>) -> Result<Self, Error>;
4949
}
5050

51-
pub(crate) fn visit(content: &str) -> Result<Project, Error> {
51+
pub(crate) fn visit(content: &str) -> Result<Project<'_>, Error> {
5252
let mut reader = Reader::new(content);
5353
reader.trim_text(true).expand_empty_elements(true);
5454
let mut project = Project::default();

0 commit comments

Comments
 (0)