Skip to content

Commit

Permalink
cargo: Make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
volsa committed Jan 22, 2025
1 parent 39ec182 commit 6dbe543
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 68 deletions.
7 changes: 2 additions & 5 deletions compiler/plc_driver/src/pipelines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,9 @@ impl<T: SourceContainer> Pipeline for BuildPipeline<T> {

fn index(&mut self, project: ParsedProject) -> Result<IndexedProject, Diagnostic> {
self.participants.iter().for_each(|p| {
p.pre_index(&project, &mut self.diagnostician);
p.pre_index(&project);
});
let project = self
.mutable_participants
.iter_mut()
.fold(project, |project, p| p.pre_index(project, &mut self.diagnostician));
let project = self.mutable_participants.iter_mut().fold(project, |project, p| p.pre_index(project));
let indexed_project = project.index(self.context.provider());
self.participants.iter().for_each(|p| {
p.post_index(&indexed_project);
Expand Down
61 changes: 7 additions & 54 deletions compiler/plc_driver/src/pipelines/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ use plc::{
resolver::{AnnotationMap, StatementAnnotation},
ConfigFormat, OnlineChange, Target,
};
use plc_diagnostics::{diagnostician::Diagnostician, diagnostics::Diagnostic};
use plc_index::GlobalContext;
use plc_diagnostics::diagnostics::Diagnostic;
use project::{object::Object, project::LibraryInformation};
use source_code::{source_location::SourceLocation, SourceContainer};

Expand All @@ -36,7 +35,7 @@ use super::{AnnotatedProject, GeneratedProject, IndexedProject, ParsedProject};
pub trait PipelineParticipant: Sync + Send {
/// Implement this to access the project before it gets indexed
/// This happens directly after parsing
fn pre_index(&self, _parsed_project: &ParsedProject, diagnostician: &mut Diagnostician) {}
fn pre_index(&self, _parsed_project: &ParsedProject) {}
/// Implement this to access the project after it got indexed
/// This happens directly after the index returns
fn post_index(&self, _indexed_project: &IndexedProject) {}
Expand Down Expand Up @@ -71,11 +70,7 @@ pub trait PipelineParticipant: Sync + Send {
pub trait PipelineParticipantMut {
/// Implement this to access the project before it gets indexed
/// This happens directly after parsing
fn pre_index(
&mut self,
parsed_project: ParsedProject,
_diagnostician: &mut Diagnostician,
) -> ParsedProject {
fn pre_index(&mut self, parsed_project: ParsedProject) -> ParsedProject {
parsed_project
}

Expand Down Expand Up @@ -227,11 +222,7 @@ impl<T: SourceContainer + Send> PipelineParticipant for CodegenParticipant<T> {
pub struct LoweringParticipant;

impl PipelineParticipantMut for LoweringParticipant {
fn pre_index(
&mut self,
parsed_project: ParsedProject,
diagnostician: &mut Diagnostician,
) -> ParsedProject {
fn pre_index(&mut self, parsed_project: ParsedProject) -> ParsedProject {
parsed_project
}

Expand Down Expand Up @@ -262,11 +253,7 @@ impl PipelineParticipantMut for InitParticipant {
}

impl PipelineParticipantMut for PropertyDesugar {
fn pre_index(
&mut self,
parsed_project: ParsedProject,
diagnostician: &mut Diagnostician,
) -> ParsedProject {
fn pre_index(&mut self, parsed_project: ParsedProject) -> ParsedProject {
let ParsedProject { mut units, .. } = parsed_project;
PropertyDesugar::validate_units(&units);

Expand Down Expand Up @@ -299,7 +286,7 @@ impl PipelineParticipantMut for PropertyDesugar {
// dbg!(annotations.get(&left));
// dbg!(annotations.get(&right));

if annotations.get(&right).is_some_and(StatementAnnotation::is_property) {
if annotations.get(right).is_some_and(StatementAnnotation::is_property) {
insert_get_prefix("get_", right);

let mut call = AstFactory::create_call_statement(
Expand All @@ -310,7 +297,7 @@ impl PipelineParticipantMut for PropertyDesugar {
);

std::mem::swap(right.as_mut(), &mut call);
} else if annotations.get(&left).is_some_and(StatementAnnotation::is_property) {
} else if annotations.get(left).is_some_and(StatementAnnotation::is_property) {
insert_get_prefix("set_", left);
let mut call = AstFactory::create_call_statement(
left.as_ref().clone(),
Expand Down Expand Up @@ -340,37 +327,3 @@ fn insert_get_prefix(prefix: &str, node: &mut AstNode) {

name.insert_str(0, prefix);
}

impl PipelineParticipant for PropertyDesugar {
fn pre_index(&self, parsed_project: &ParsedProject, diagnostician: &mut Diagnostician) {
let ParsedProject { units } = parsed_project;

for unit in units {
for property in &unit.properties {
dbg!(&property);
if property.implementations.is_empty() {
let diagnostic = Diagnostic::new("test")
.with_location(property.name_location.clone())
.with_error_code("E001");

dbg!(&diagnostic);

diagnostician.handle(&[diagnostic]);
}
}
}
}
}

pub struct Validator2 {
context: Arc<GlobalContext>,
diagnostics: Vec<Diagnostic>,
}

impl Validator2 {
pub fn new(context: Arc<GlobalContext>) -> Validator2 {
Validator2 { context, diagnostics: Vec::new() }
}
}

impl PipelineParticipantMut for Validator2 {}
6 changes: 3 additions & 3 deletions src/lowering/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use plc_ast::{
};
use plc_diagnostics::diagnostics::Diagnostic;
use plc_source::source_location::SourceLocation;
use rustc_hash::{FxHashMap, FxHashSet};
use rustc_hash::FxHashMap;

pub struct PropertyDesugar {
pub parents: HashMap<String, Vec<String>>,
Expand Down Expand Up @@ -111,7 +111,7 @@ impl PropertyDesugar {

fn validate_block_type(
diagnostics: &mut Vec<Diagnostic>,
variables: &Vec<VariableBlock>,
variables: &[VariableBlock],
location: &SourceLocation,
) {
if variables.is_empty() {
Expand Down Expand Up @@ -156,7 +156,7 @@ impl AstVisitorMut for PropertyDesugar {
),
AstFactory::create_member_reference(
AstFactory::create_identifier(
&name,
name,
SourceLocation::undefined(),
self.id_provider.next_id(),
),
Expand Down
3 changes: 1 addition & 2 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ pub mod tests {
let mut reporter = Diagnostician::buffered();
reporter.register_file("<internal>".to_string(), src.to_string());

let (mut unit, mut diagnostics) = parse(src);
// assert!(diagnostics.is_empty(), "fixme, these should also be reported");
let (unit, mut diagnostics) = parse(src);

let mut units = vec![unit];

Expand Down
4 changes: 2 additions & 2 deletions src/validation/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ fn validate_reference<T: AnnotationMap>(
&& context
.qualifier
.and_then(|qualifier| context.index.find_pou(qualifier))
.map(|pou| (pou.get_name(), pou.get_container())) // get the container pou (for actions this is the program/fb)
.map_or(false, |(pou, container)| {
.map(|pou| (pou.get_name(), pou.get_container()))
.is_some_and(|(pou, container)| {
!qualified_name.starts_with(pou)
&& !qualified_name.starts_with(container)
&& !context.index.is_init_function(pou)
Expand Down
2 changes: 1 addition & 1 deletion src/validation/tests/duplicates_validation_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
index::{indexer, Index},
lexer, parser,
resolver::TypeAnnotator,
test_utils::tests::{parse_and_validate_buffered, temp_make_me_generic_but_for_now_validate_property},
test_utils::tests::parse_and_validate_buffered,
typesystem,
validation::Validator,
};
Expand Down
2 changes: 1 addition & 1 deletion src/validation/tests/pou_validation_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::test_utils::tests::{
parse_and_validate_buffered, temp_make_me_generic_but_for_now_validate_property,
};
use insta::{assert_debug_snapshot, assert_snapshot};
use insta::assert_snapshot;

#[test]
fn actions_container_no_name() {
Expand Down

0 comments on commit 6dbe543

Please sign in to comment.