Skip to content

gccrs: Implement compilation support for TuplePatternItems::RANGED #3863

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Polygonalr
Copy link
Contributor

This is part of implementing support for RestPatterns, RestPattern support for slices will be next.

Includes a fix to my little oopsie made in my type-checking code, and test updates to ensure that the mistake will not repeat.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-pattern.cc (visit(TuplePattern)): Fix
		incorrect logic for field size checking.

gcc/testsuite/ChangeLog:

	* rust/compile/tuple_mismatch.rs: Include RestPattern in test.

Signed-off-by: Yap Zhi Heng <[email protected]>
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

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

Looks great but just minor comment on the test case and we need to see what the gimple is being generated here would help the review.

Example GIMPLE output of the match statement for match-restpattern-tuple-1.rs:

...
RUSTTMP.2 = x;
_1 = RUSTTMP.2.__0;
_2 = _1 == 1;
_3 = RUSTTMP.2.__3;
_4 = _3 == 4;
_5 = _2 & _4;
if (_5 != 0) goto <D.109>; else goto <D.110>;
<D.109>:
{
    {

    }
    goto <D.104>;
}
<D.110>:
if (1 != 0) goto <D.111>; else goto <D.112>;
<D.111>:
{
    {

    }
    goto <D.104>;
}
<D.112>:
<D.104>:
...

gcc/rust/ChangeLog:

	* backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit(TuplePattern)):
		Implement check expression compilation for TuplePatternItems::RANGED.

Signed-off-by: Yap Zhi Heng <[email protected]>
@Polygonalr Polygonalr force-pushed the restpattern-tuple-compile branch from e5d7765 to 3bb39a7 Compare July 1, 2025 15:05
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.

2 participants