-
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
Implement support for break statement #125
Conversation
Codecov Report
@@ Coverage Diff @@
## master #125 +/- ##
=======================================
Coverage 84.38% 84.39%
=======================================
Files 40 40
Lines 2556 2596 +40
=======================================
+ Hits 2157 2191 +34
- Misses 399 405 +6
Continue to review full report at Codecov.
|
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.
👍
let block_scope_2 = BlockScope::from_block_scope( | ||
Span::new(0, 0), | ||
BlockScopeType::IfElse, | ||
block_scope_1.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 had been using Rc::clone(&scope)
, since that's what's used in the API docs for Rc: https://doc.rust-lang.org/std/rc/struct.Rc.html.
Both of these do the same thing, of course, and I don't have a strong opinion about which method we should use to call clone
, but I think we should be consistent.
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.
Thanks for bringing this up. I wasn't aware that there was a good reason for the the more verbose syntax. I looked it up and RC::clone(&ptr)
is indeed the preferred syntax. The reason for that is to make it clear what the clone
is about since clone
is a very vaguely defined action in Rust. In this case it is just increasing the reference counter whereas e.g. cloning a Vec<T>
can cause quite a bit of memory getting copied.
References:
https://github.com/nical/rfcs/blob/rc-newref-clone/text/0000-rc-newref-clone.md
rust-lang/rust#42137 (comment)
I'm going to merge this as is and send a follow up PR to rewrite all occurrences with the idiomatic syntax.
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.
Updated all usage in this PR #126
What was wrong?
We don't support
break
statements yet.How was it fixed?
BlockScopeType
toBlockScope
that can be one ofFunction
,IfElse
orLoop
.pub fn inherits_type(&self, typ: BlockScopeType) -> bool
toBlockScope
to be able to tell if certain statements (e.g.break
,continue
) can be used within the current scope or not.inherits_type
if placement is ok and returnsSemanticError::BreakWithoutLoop
if notbreak
to YUL