Fix normalization overflow ICEs in monomorphization #146096
Open
+185
−1
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.
Fixes #92004
Fixes #92470
Fixes #95134
Fixes #105275
Fixes #105937
Fixes #117696-2
Fixes #118590
Fixes #122823
Fixes #131342
Fixes #139659
Analysis:
The causes of these issues are similar. They contain generic recursive functions that can be instantiated with different args infinitely at monomorphization stage.
Ideally this should be caught by the
check_recursion_limit
function. The reality is that normalization can reach recursion limit earlier than monomorphization's check because they calculate depths in different ways.Since normalization is called everywhere, ICEs appear in different locations.
Fix:
If we abort on overflow with
TypingMode::PostAnalysis
in the trait solver, it would also catch these errors.The main challenge is providing good diagnostics for them. So it's quite natural to put the check right before these normalization happening.
I first tried to the whole MIR body's normalization and
references_error
. (As elaborate_drop handles normalization failure by returningty::Error
.)It turns out that checking all
Local
s seems sufficient.These types are gonna be normalized anyway. So with cache, these checks shouldn't be expensive.
This fixes these ICEs for both the next and old solver, though I'm not sure the change I made to the old solver is proper. Its overflow handling looks convoluted thus I didn't try to fix it more "upstream".