Skip to content

gccrs: Add initial compilation support for IdentifierPattern's subpatterns #3814

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

Merged
merged 2 commits into from
Jun 11, 2025

Conversation

Polygonalr
Copy link
Contributor

@Polygonalr Polygonalr commented Jun 9, 2025

Adds initial support for compilation of IdentifierPattern's subpattern. For now, tested and works with simple LiteralPattern subpatterns; more complex subpatterns require further testing.

Reviewers: 1st commit contains the actual changes, 2nd commit only contains variable renaming.

gcc/rust/ChangeLog:

	* backend/rust-compile-pattern.cc: Add CheckExpr compilation for
		IdentifierPattern with subpattern.
	* backend/rust-compile-pattern.h: Modify IdentifierPattern's
		visit func to support the above.
	* typecheck/rust-hir-type-check-pattern.cc: Add typechecking
		support for the changes above.

Signed-off-by: Yap Zhi Heng <[email protected]>
gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc: Rename to_bind to subpattern.
	* ast/rust-ast-visitor.cc: Ditto.
	* ast/rust-pattern.cc: Ditto.
	* ast/rust-pattern.h: Ditto.
	* backend/rust-compile-pattern.cc: Ditto.
	* expand/rust-cfg-strip.cc: Ditto.
	* hir/rust-ast-lower-pattern.cc: Ditto.
	* hir/rust-hir-dump.cc: Ditto.
	* hir/tree/rust-hir-pattern.h: Ditto.
	* hir/tree/rust-hir.cc: Ditto.
	* typecheck/rust-hir-type-check-pattern.cc: Ditto.

Signed-off-by: Yap Zhi Heng <[email protected]>
@Polygonalr Polygonalr force-pushed the identifierpattern-clean branch from 1f5fb1d to 37a5e70 Compare June 9, 2025 12:44
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.

good job @Polygonalr!! this PR looks really nice and the test cases are really good.

Comment on lines +429 to +438
{
if (pattern.has_subpattern ())
{
check_expr = CompilePatternCheckExpr::Compile (pattern.get_subpattern (),
match_scrutinee_expr, ctx);
}
else
{
check_expr = boolean_true_node;
}
Copy link
Member

Choose a reason for hiding this comment

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

well done!

Comment on lines +48 to -53
void visit (HIR::IdentifierPattern &) override;

// Always succeeds
void visit (HIR::IdentifierPattern &) override
{
check_expr = boolean_true_node;
}
Copy link
Member

Choose a reason for hiding this comment

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

good job, this is always a good cleanup - we try prioritizing implementations in .cc files rather than .h files

Comment on lines +542 to +544
{
TypeCheckPattern::Resolve (pattern.get_subpattern (), parent);
}
Copy link
Member

Choose a reason for hiding this comment

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

GCC style is to avoid braces for one-line if blocks, but this is a nitpick - feel free to disregard

Suggested change
{
TypeCheckPattern::Resolve (pattern.get_subpattern (), parent);
}
TypeCheckPattern::Resolve (pattern.get_subpattern (), parent);

@powerboat9
Copy link
Collaborator

Looks like you might be missing some changes to CompilePatternBindings -- otherwise, looks good

@CohenArthur CohenArthur added this pull request to the merge queue Jun 11, 2025
Merged via the queue into Rust-GCC:master with commit 0dbcc83 Jun 11, 2025
12 checks passed
@Polygonalr Polygonalr deleted the identifierpattern-clean branch August 2, 2025 06:53
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