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

2688 labelled block #2689

Merged
merged 5 commits into from
Oct 20, 2023
Merged

2688 labelled block #2689

merged 5 commits into from
Oct 20, 2023

Conversation

jdupak
Copy link
Contributor

@jdupak jdupak commented Oct 16, 2023

Adds suport for labelled blocks up to compile (where it bails). Resolves #2688

@jdupak jdupak changed the title 2688 labeled block 2688 labelled block Oct 16, 2023
@jdupak jdupak changed the title 2688 labelled block WIP: 2688 labelled block Oct 16, 2023
@jdupak
Copy link
Contributor Author

jdupak commented Oct 16, 2023

@P-E-P

@P-E-P P-E-P self-requested a review October 16, 2023 15:53
@P-E-P P-E-P added this to the GCC 14.1 release milestone Oct 16, 2023
@jdupak jdupak changed the title WIP: 2688 labelled block 2688 labelled block Oct 18, 2023
@jdupak jdupak mentioned this pull request Oct 19, 2023
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]>
@jdupak jdupak force-pushed the 2688-labeled-block branch from 2e226d6 to 9901240 Compare October 19, 2023 13:38
Copy link
Member

@P-E-P P-E-P left a 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;
Copy link
Member

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.

Copy link
Contributor Author

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 ?

Copy link
Member

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 👍

@P-E-P P-E-P added this pull request to the merge queue Oct 20, 2023
Copy link
Member

@CohenArthur CohenArthur left a 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));
Copy link
Member

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; }
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Lifetime &get_lifetime () { return label; }
Lifetime &get_label () { return label; }

or

Suggested change
Lifetime &get_lifetime () { return label; }
Lifetime &get_name () { return label; }


Analysis::NodeMapping &get_mappings () { return mappings; }

Lifetime &get_lifetime () { return label; }
Copy link
Member

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 (); }
Copy link
Member

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");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Labels must be a named lifetime value");
"labels must be a named lifetime value");

for consistency :)

Merged via the queue into Rust-GCC:master with commit 9a53cb5 Oct 20, 2023
9 checks passed
@jdupak jdupak mentioned this pull request Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Cannot parse labelled block
3 participants