-
Notifications
You must be signed in to change notification settings - Fork 661
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
[Feat] Add network.id
and self.address
opcodes
#27917
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## mainnet #27917 +/- ##
===========================================
- Coverage 76.59% 76.57% -0.02%
===========================================
Files 208 209 +1
Lines 7215 7244 +29
Branches 7215 7244 +29
===========================================
+ Hits 5526 5547 +21
- Misses 1689 1697 +8 ☔ View full report in Codecov by Sentry. |
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.
The overall approach looks good! Left some comments. Additionally, would you be able to port the network.id
execution test from snarkVM over?
Expression::Identifier(identifier) if identifier.name == sym::network => match access.name.name { | ||
sym::id => { | ||
// Check that the operation is not invoked outside a `finalize` block. | ||
if self.scope_state.variant != Some(Variant::AsyncFunction) { | ||
self.handler.emit_err(TypeCheckerError::invalid_operation_outside_finalize( | ||
"network.id", | ||
access.name.span(), | ||
)) | ||
} | ||
return Some(Type::Integer(IntegerType::U16)); | ||
} | ||
_ => { | ||
self.emit_err(TypeCheckerError::invalid_block_access(access.name.span())); | ||
} | ||
}, |
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 there a way we we can de-dup this pattern with the block above? Ditto for the first two blocks.
@@ -273,7 +273,9 @@ impl StatementReconstructor for Flattener<'_> { | |||
let guard = self.construct_guard(); | |||
|
|||
match input.expression { | |||
Expression::Unit(_) | Expression::Identifier(_) => self.returns.push((guard, input)), | |||
Expression::Unit(_) | Expression::Identifier(_) | Expression::Access(_) => { |
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.
Are accesses required to be added here? Shouldn't SSA create unique assignment statements for access expressions?
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 added it because there was a compiler panic when a return statement contained an access expression. Looks like it might not be processed in SSA to ensure proper CG. https://github.com/AleoHQ/leo/blob/e6ba5069dc115837b1df361099db3db265f75676/compiler/passes/src/static_single_assignment/rename_statement.rs#L359
} else { | ||
// Parse instances of `self.address`. | ||
if let Expression::Identifier(id) = expr { |
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 would be more "proper" to do the swap in a later pass. That way the parsed AST accurately reflects the input program. A canonicalization pass would be good for this. At the very least, we should add a comment to move this to canonicalization.
@d0cd Something unexpected about adding the |
The test runner requires a few blocks initially to set up the test. Updating it to a later number should work. |
network.id
and self.address
opcodes
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.
LGTM! Great work!
Resolves #27912. Additionally, program name references are valid addresses. Example
let a: address = hello.aleo
.