Skip to content

transpile: Improve case translation#1776

Draft
Rua wants to merge 15 commits into
immunant:masterfrom
Rua:pattern-conversion
Draft

transpile: Improve case translation#1776
Rua wants to merge 15 commits into
immunant:masterfrom
Rua:pattern-conversion

Conversation

@Rua
Copy link
Copy Markdown
Contributor

@Rua Rua commented May 4, 2026

Translating case statements is currently a very ad-hoc affair, so this is an attempt to make it a bit more generic and flexible. expr_to_pat now converts expressions to equivalent patterns, preserving the semantics and returning None if an expression with no equivalent is encountered.

Translation functions can now use is_pattern to detect if they are translating an expression that's meant to appear inside a Rust pattern, and adjust accordingly. That will help towards getting #1775 to work. Currently, all expressions that cannot (conservatively) be translated in pattern context return a translation error. That will then trigger fallback to directly using the ConstIntExpr value that's provided inside the Case value.

Additionally, it seems that it fixes a missing macro expansion in macrocase.c, so that's a bonus!

@Rua Rua force-pushed the pattern-conversion branch 6 times, most recently from 9211786 to cc22e77 Compare May 4, 2026 17:26
@Rua Rua force-pushed the pattern-conversion branch 2 times, most recently from e63622e to 8eca20d Compare May 5, 2026 12:25
@Rua Rua changed the title transpile: Add is_pattern to ExprContext for customized case translation transpile: Improve case translation May 5, 2026
@Rua Rua force-pushed the pattern-conversion branch 2 times, most recently from 6251ffa to e437818 Compare May 5, 2026 13:35
@Rua Rua force-pushed the pattern-conversion branch from e437818 to a0d125a Compare May 5, 2026 13:59
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.

1 participant