Don't panic when const-folding an unfoldable const expression#1374
Merged
Conversation
nathanielsimard
approved these changes
Jun 8, 2026
nathanielsimard
left a comment
Member
There was a problem hiding this comment.
Just need to fix merge conflicts
LucaCappelletti94
force-pushed
the
fix-const-fold-unwrap
branch
from
June 8, 2026 15:21
ab3b4cf to
eacf8ed
Compare
marcantoinem
pushed a commit
to marcantoinem/cubecl
that referenced
this pull request
Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-foldingpaths in parse/expression.rs callas_const(context).unwrap()after checkingis_const(). That assumes every const expression can be rendered back as aconsttoken stream, but some cannot: a compiler intrinsic such asvectorization_ofreportsis_const()astruewhileas_const()returnsNone, 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).