Fix lowering logic of nested generics. #4091
Merged
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 #4048.
The issue exposed in #4048 is that our generics implementation does not support nested generics that introduce type constraints depending on another type parameter of the outer generic.
Specifically, this code wasn't allowed:
There isn't any fundamental reason that prevented us to handle this correctly. The main issue found is our IR lowering logic isn't correctly generating code that represent the type of a nesting generic inst. Fixing the bugs in the lowering logic allows everything to run correctly.
Note that a related issue is that in the future we we ever want to allow a where clause to specify depending generic params.
For example:
This means that this function will lower into the following IR:
Note that
%w_U
has type%wt
which is defined afterw_U
because in our IR all params must appear before any other insts.However this means that we are violating another rule that says all insts must dominate their uses, where %wt is not dominating
%w_U
.So in this PR we also try to relax our IR rule to allow all
IRParam
s to use things that are defined later in the same block to allow this generic to be legally represented. But this means that our IR cloning logic need to change accordingly to work with the relaxed rule.