-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor asm ast #1736
Refactor asm ast #1736
Conversation
airgen/src/lib.rs
Outdated
.filter(|s| { | ||
matches!( | ||
s, | ||
PilStatement::EnumDeclaration(..) | PilStatement::LetStatement(..) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already envision spending quite some time trying to figure out why something is missing from the output. Is there a safer way to do this check so that we add variants here if the code is extended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using an exhaustive match instead
}) | ||
} | ||
|
||
pub fn get_machine(&self, ty: &AbsoluteSymbolPath) -> Option<&Machine> { | ||
let mut path = ty.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I the clone needed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes since modules are indexed by path and machines by name. To avoid this clone, we'd need slices of AbsoluteSymbolPath
which is not implemented in this PR.
ast/src/object/mod.rs
Outdated
@@ -41,7 +41,7 @@ pub struct PILGraph { | |||
pub main: Machine, | |||
pub entry_points: Vec<Operation>, | |||
pub objects: BTreeMap<Location, Object>, | |||
pub definitions: BTreeMap<AbsoluteSymbolPath, TypeOrExpression>, | |||
pub definitions: BTreeMap<AbsoluteSymbolPath, Vec<PilStatement>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the key here the module name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, comment added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should also rename this to statements
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
ModuleStatement::TraitImplementation(_) => None, | ||
ModuleStatement::SymbolDefinition(d) => Box::new(once(&d.name)), | ||
ModuleStatement::PilStatement(s) => { | ||
Box::new(s.symbol_definition_names().map(|(name, _)| name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should call symbol_definition_names_and_contained
here, but I'm not sure. .._and_contained
also returns the variants in an enum for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So... if we have
enum Foo {
Bar
}
Then the defined names should be ["Foo", "Bar"]
? Or ["Foo", "Foo::Bar"]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[("Foo", None), ("Foo", Some("Bar"))]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, what should this function return? Currently it returns all names defined in a given statement, as strings. Should the signature then change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least before your PR this was essentially only used by the call to local_names() inside check_machine to see if there is a name clash, so I think it's not needed to return the nested names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used only in the importer to prevent duplicates, and to detect the standard library. I think we do not need the nested names for that. Then the current code is correct?
@@ -97,7 +81,7 @@ pub enum SymbolValueRef<'a> { | |||
/// A module definition | |||
Module(ModuleRef<'a>), | |||
/// A generic symbol / function. | |||
Expression(&'a TypedExpression), | |||
Expression(&'a Option<Expression>, &'a Option<TypeScheme<Expression>>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not keep TypedExpression? Lifetime issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it's constructed from a reference over PilStatement::LetStatement
which is
LetStatement(
SourceRef,
String,
Option<TypeScheme<Expression>>,
Option<Expression>,
),
My understanding is that SymbolValueRef::Expression
also covers statements like let a: Type;
which seem to be allowed. TypedExpression
would not cover that.
importer/src/path_canonicalizer.rs
Outdated
} | ||
} | ||
PilStatement::TraitImplementation(_, trait_impl) => { | ||
for f in &mut trait_impl.functions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also call canonicalize_inside_type_scheme
for trait_impl.type_scheme
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted to https://github.com/powdr-labs/powdr/pull/1750/files because I'm not sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following discussion, removed the commit and instead used generics on the existing data structures
airgen/src/lib.rs
Outdated
PilStatement::Include(..) => false, | ||
PilStatement::Namespace(..) => false, | ||
PilStatement::PolynomialDefinition(..) => false, | ||
PilStatement::PublicDeclaration(..) => false, | ||
PilStatement::PolynomialConstantDeclaration(..) => false, | ||
PilStatement::PolynomialConstantDefinition(..) => false, | ||
PilStatement::PolynomialCommitDeclaration(..) => false, | ||
PilStatement::PlookupIdentity(..) => false, | ||
PilStatement::PermutationIdentity(..) => false, | ||
PilStatement::ConnectIdentity(..) => false, | ||
PilStatement::TraitImplementation(..) => false, | ||
PilStatement::TraitDeclaration(..) => false, | ||
PilStatement::Expression(..) => false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PilStatement::Include(..) => false, | |
PilStatement::Namespace(..) => false, | |
PilStatement::PolynomialDefinition(..) => false, | |
PilStatement::PublicDeclaration(..) => false, | |
PilStatement::PolynomialConstantDeclaration(..) => false, | |
PilStatement::PolynomialConstantDefinition(..) => false, | |
PilStatement::PolynomialCommitDeclaration(..) => false, | |
PilStatement::PlookupIdentity(..) => false, | |
PilStatement::PermutationIdentity(..) => false, | |
PilStatement::ConnectIdentity(..) => false, | |
PilStatement::TraitImplementation(..) => false, | |
PilStatement::TraitDeclaration(..) => false, | |
PilStatement::Expression(..) => false, | |
PilStatement::Include(..) | | |
PilStatement::Namespace(..) | | |
PilStatement::PolynomialDefinition(..) | | |
PilStatement::PublicDeclaration(..) | | |
PilStatement::PolynomialConstantDeclaration(..) | | |
PilStatement::PolynomialConstantDefinition(..) | | |
PilStatement::PolynomialCommitDeclaration(..) | | |
PilStatement::PlookupIdentity(..) | | |
PilStatement::PermutationIdentity(..) | | |
PilStatement::ConnectIdentity(..) | | |
PilStatement::TraitImplementation(..) | | |
PilStatement::TraitDeclaration(..) | | |
PilStatement::Expression(..) => false, |
5a50e2e
to
af73301
Compare
af73301
to
1928b49
Compare
c04d0d7
to
24550f5
Compare
|
||
/// A trait to operate the possible types for the array type lengths | ||
pub trait ArrayLength: std::fmt::Display + std::fmt::Debug { | ||
fn try_to_expression_mut(&mut self) -> Option<&mut Expression>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try_as_expression_mut?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
ast/src/parsed/types.rs
Outdated
} | ||
|
||
/// A trait to operate the possible types for the array type lengths | ||
pub trait ArrayLength: std::fmt::Display + std::fmt::Debug { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExpressionInArrayLength?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
No description provided.