Fix optional constraints when used from another generic scope#9149
Fix optional constraints when used from another generic scope#9149juliusikkala wants to merge 3 commits intoshader-slang:masterfrom
Conversation
|
looks like the nonewitness does not have a sensible type, which might be fine now but that might be a source of problems in the future. |
|
I feel like the right fix should be to change the lowering logic, and create the witness table in its own generic, just like how any other ordinary witness tables are created. |
|
I agree on the types, so I started refactoring that part a bit. I'm not yet sure how to lower the witness tables as desired here. My understanding is that usually witness tables are generated from the InheritanceDecl: For NoneWitnesses, we can't really do that, because they are created when needed and there is no corresponding InheritanceDecl. |
|
This PR modifies IR instruction definition files. Please review if you need to update the following constants in
These version numbers help ensure compatibility between different versions of compiled modules. |
|
You create a fresh IRGenContext, then use that to call |
|
Thanks for the tip, unfortunately I wasn't able to make that work yet (or didn't understand the specifics here).
I wonder if it'd be better to somehow add a EDIT: I'm starting to feel like I want to do a larger rewrite to this feature. The initial implementation is too much of a hack, I don't like it at all anymore. The AST-level NoneWitness could probably stay, but I think on the IR side it could be easier to lower optional constraints as |
|
I'll close this now, as I plan to instead refactor the feature and there's not a whole lot I can reuse from here due to the major conflicts with #7968. |
The issue is that
NoneWitness(which is used to "satisfy" optional constraints when the constraint is not fulfilled byT) was getting lowered in-place in the outer generic after the return instruction has been emitted, causing IR looking like this:The generated witness table gets inserted after the terminator of block %6, and subsequently causes a variety of havoc inside the compiler, sometimes resulting in an internal error or segmentation fault. This PR ensures that it always gets hoisted into the global scope -
NoneWitnesscan (and IMO should) be shared across all uses.This is related to the feature with an open proposal in shader-slang/spec#25 and whose implementation was merged in #7422 (not exactly following proper proposal procedure 😬). In any case, the feature has already ended up in the compiler, and has a bug which is fixed by this PR.