-
Notifications
You must be signed in to change notification settings - Fork 187
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
Mut redux #777
Mut redux #777
Conversation
0433251
to
2532bbf
Compare
e4c6af7
to
6c1694f
Compare
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.
Great work!
@@ -73,7 +73,7 @@ pub trait AnalyzerContext { | |||
/// # Panics | |||
/// | |||
/// Panics if an entry does not already exist for the node id. | |||
fn update_expression(&self, node: &Node<ast::Expr>, attributes: ExpressionAttributes); | |||
fn update_expression(&self, node: &Node<ast::Expr>, f: &dyn Fn(&mut ExpressionAttributes)); |
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.
Nitpick: Imho single letter variables should be avoided at most times (except in some established math formulars etc). Maybe this could be fn
.
@@ -379,35 +384,6 @@ impl AnalyzerContext for TempContext { | |||
} | |||
} | |||
|
|||
/// Indicates where an expression is stored. |
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 served us well but great to see it go now!
@@ -123,12 +136,6 @@ pub fn function_signature( | |||
arg.span, | |||
"instances of `Context` must be named `ctx`", | |||
); | |||
} else if !function.parent(db).is_contract() { |
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.
Curious why this was removed
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.
@cburgdorf This was a driveby change that should have been its own tiny PR; it's just an arbitrary restriction that shouldn't exist. There's no reason to prevent someone from writing a utility or library function that uses the context object.
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.
Great!
This adds the concept of
mut
ability to the language. Anything not markedmut
isn't mutable.The analyzer's
Type::Mut
is mapped to MIR'sType::MPtr
for all non-primitive types. This works, but maybe isn't ideal. Perhapsmut
parameters could be of typeMutRef
or something, and mut vars wouldn't need a type wrapper at all in MIR. The ExpressionAttributes struct now contains a vec of "type adjustments", which are the implicit coercions that were performed to transform the expression into the expected type. This feels a bit fragile to me; perhaps better would be to introduce an HIR form, in which fe's implicit coercions would be "desugared" into explicit type coercions.Much of this PR feels like it could be better with more work, but I've reworked this enough times and let it stagnate for way too long, and I'm satisfied that this is at least an improvement over the current
mut
less status.Subsumes #768; the rebasing required to keep that separate became a pain.
To-Do
Followup issues:
#810
#811
#812
#814