Skip to content

Don't panic when const-folding an unfoldable const expression#1374

Merged
louisfd merged 2 commits into
tracel-ai:mainfrom
LucaCappelletti94:fix-const-fold-unwrap
Jun 9, 2026
Merged

Don't panic when const-folding an unfoldable const expression#1374
louisfd merged 2 commits into
tracel-ai:mainfrom
LucaCappelletti94:fix-const-fold-unwrap

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

As with #1372 and #1373, this turns a fuzzer-found panic in the #[cube] macro into correct behavior, on the way to differential fuzzing once the front end is stable (see #1364).

The binary and unary const-folding paths in parse/expression.rs call as_const(context).unwrap() after checking is_const(). That assumes every const expression can be rendered back as a const token stream, but some cannot: a compiler intrinsic such as vectorization_of reports is_const() as true while as_const() returns None, so the macro aborted the user's build with an opaque panic. The fix falls back to a runtime expression when folding is not possible.

Reproducer: vectorization_of(x) + vectorization_of(x).

image

@LucaCappelletti94 LucaCappelletti94 changed the title fix: don't panic when const-folding an unfoldable const expression Don't panic when const-folding an unfoldable const expression Jun 6, 2026

@nathanielsimard nathanielsimard left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just need to fix merge conflicts

@louisfd
louisfd merged commit 1724419 into tracel-ai:main Jun 9, 2026
6 checks passed
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