Skip to content
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

Merged
merged 6 commits into from
Nov 22, 2022
Merged

Mut redux #777

merged 6 commits into from
Nov 22, 2022

Conversation

sbillig
Copy link
Collaborator

@sbillig sbillig commented Aug 4, 2022

This adds the concept of mutability to the language. Anything not marked mut isn't mutable.

The analyzer's Type::Mut is mapped to MIR's Type::MPtr for all non-primitive types. This works, but maybe isn't ideal. Perhaps mut parameters could be of type MutRef 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 mutless status.

Subsumes #768; the rebasing required to keep that separate became a pain.

To-Do

  • OPTIONAL: Update Spec if applicable
  • Add entry to the release notes (may forgo for trivial changes)
  • Clean up commit history

Followup issues:
#810
#811
#812
#814

Copy link
Collaborator

@cburgdorf cburgdorf left a 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));
Copy link
Collaborator

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.
Copy link
Collaborator

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() {
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

Copy link
Member

@Y-Nak Y-Nak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@cburgdorf cburgdorf merged commit 3b84dbd into ethereum:master Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants