-
Notifications
You must be signed in to change notification settings - Fork 165
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
2688 labelled block #2689
2688 labelled block #2689
Conversation
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (AstBuilder::block): Add label arg to constructor call. * ast/rust-expr.h (class LoopLabel): Move before BlockExpr. (class BlockExpr): Add LoopLabel member. * expand/rust-derive-clone.cc (DeriveClone::clone_fn): Add label arg to constructor call. * parse/rust-parse-impl.h (Parser::parse_block_expr): Add label parameter. (Parser::parse_labelled_loop_expr): Add label arg to constructor call. * parse/rust-parse.h: Add label arg to constructor call. Signed-off-by: Jakub Dupak <[email protected]>
gcc/rust/ChangeLog: * hir/rust-ast-lower.cc (ASTLoweringBlock::visit): Call loop lowering and add it to constr. * hir/tree/rust-hir-expr.h (class LoopLabel): Move before BlockExpr and add to BlockExpr.
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Resolve using loop logic. Signed-off-by: Jakub Dupak <[email protected]>
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Add loop ctx. Signed-off-by: Jakub Dupak <[email protected]>
gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Bail on labelled block. Signed-off-by: Jakub Dupak <[email protected]>
2e226d6
to
9901240
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.
Small suggestion, otherwise LGTM
@@ -2121,6 +2149,7 @@ class BlockExpr : public ExprWithBlock, public WithInnerAttrs | |||
std::vector<std::unique_ptr<Stmt> > statements; | |||
std::unique_ptr<Expr> expr; | |||
bool tail_reachable; | |||
LoopLabel label; |
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.
Do we want to use tl::optional<LoopLabel>
instead of label.is_error()
? This would help enforce a label exists.
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.
Sounds good to me, but probably not in this PR - the same logic is used for loops (was taken from there) and it would make more sense to change it everywhere at once, otherwise it is more confusing. Agree @P-E-P ?
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.
You're right. Let's merge this then 👍
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.
this looks great. all my nitpicking is not specifically for this PR, but rather for the old classes that you moved - so they should be addressed in a separate PR and this one is good to merge IMO. thank you!
new BlockExpr (std::move (stmts), std::move (tail_expr), {}, {}, loc, loc)); | ||
return std::unique_ptr<Expr> (new BlockExpr (std::move (stmts), | ||
std::move (tail_expr), {}, {}, | ||
LoopLabel::error (), loc, loc)); |
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.
from an API point of view, I'm not sure if LoopLabel::error
here is very nice. something like empty
would probably be better? sorry for nitpicking haha
|
||
location_t get_locus () const { return locus; } | ||
|
||
Lifetime &get_lifetime () { return label; } |
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.
Lifetime &get_lifetime () { return label; } | |
Lifetime &get_label () { return label; } |
or
Lifetime &get_lifetime () { return label; } | |
Lifetime &get_name () { return label; } |
|
||
Analysis::NodeMapping &get_mappings () { return mappings; } | ||
|
||
Lifetime &get_lifetime () { return label; } |
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.
same here
{} | ||
|
||
// Returns whether the LoopLabel is in an error state. | ||
bool is_error () const { return label.is_error (); } |
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.
same here, should be is_empty()
IMO
!= AST::Lifetime::LifetimeType::NAMED) | ||
{ | ||
rust_error_at (label.get_locus (), | ||
"Labels must be a named lifetime value"); |
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.
"Labels must be a named lifetime value"); | |
"labels must be a named lifetime value"); |
for consistency :)
Adds suport for labelled blocks up to compile (where it bails). Resolves #2688