Uh oh!
There was an error while loading. Please reload this page.
rustc_monomorphize: Skip vtable alloc collection in the pre-optimisation MentionedItems mode - #152462
rustc_monomorphize: Skip vtable alloc collection in the pre-optimisation MentionedItems mode#152462jakubadamw wants to merge 2 commits into
MentionedItems mode#152462Conversation
… mode When collecting mentioned items during monomorphization, the routine was recursively walking vtable allocations, which could lead to infinite recursion if a vtable method's body contained a const embedding another vtable. We can skip the recursive walk when we're only gathering mentioned items. Vtable methods are only relevant during actual codegen, so this should be safe.
rustbot
commented
Feb 11, 2026
r? @fmease rustbot has assigned @fmease. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Mark-Simulacrum
commented
Feb 11, 2026
Can you elaborate on "safe"? Are we reaching the mentioned items only brought in via vtables in some other way already? Can this change behavior of existing programs (e.g., make more things compile in check mode)? |
| @@ -0,0 +1,16 @@ | |||
| //@ run-pass | |||
There was a problem hiding this comment.
The problem resurfaces when compiling without optimizations -Zmir-opt-level=0. The motivation behind "mentioned" collection mode is to ensure consistency across optimization levels. In that sense the existing implementation is working as intended (putting aside the glaring issue of ICE itself).
tmiasko
commented
Feb 11, 2026
ICE will be turned into an error in #152120. I don't think collection process needs any changes (except perhaps to improve the diagnostic to indicate a source location that gives rise to the error). |
jakubadamw
commented
Feb 12, 2026
@Mark-Simulacrum, these are very helpful questions! You're right that this attempt may be preventing some invalid programs from being rejected, and I'll try to come up with a test case that demonstrates it. @tmiasko, thank you for your feedback as well! |
tmiasko
commented
Feb 12, 2026
To be clear, the test case you have already included should fail to compile. This is because evaluating The only issue is that this results in an ICE instead of an error. |
jakubadamw
commented
Apr 4, 2026
#141911 has been fixed, closing this. |
When collecting mentioned items during monomorphization, the
collect_alloc()routine was recursively walking vtable allocations, which could lead to infinite recursion if a vtable method's body contained a const embedding another vtable. We can skip the recursive walk when we're only gathering mentioned items. Vtable methods are only relevant during actual codegen, so this should be safe.Closes#141911.