Don't keep insts in eval block from failed deduce #5601
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.
Deduction does
SubstConstant()
to apply enclosing specifics, and deduced arguments, to the arguments. This process creates new instructions with the applied substitutions, which may includeLookupImplWitness
. If the conversion fails, those instructions will not be used, but they have been added to the enclosing generic when there is one. This leaves behind aLookupImplWitness
instruction with a runtime constant value as a dependent instruction and in the eval block. When the generic's eval block is re-evaluated later, theLookupImplWitness
instruction fails to produce a constant value (again), which violates its contract and we crash.To avoid this, we scope the SubstConstant and Convert steps in deduce with a "commit" for the generic stack. If the conversion fails, we drop all instructions created by SubstConstant and Convert from the enclosing generic context. Such instructions must not be referred to again, but they will not be as they are not stored anywhere or returned if Convert failed.
This fixes the crash demonstrated in https://carbon.godbolt.org/z/1EjMroT6e