Fix generic witness table SequentialIDDecorations #6129
+7
−52
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 (hopefully) #5407, although I couldn't get OPs code compiling with the current master branch version of Slang. At least this PR fixes the two similar cases from the comments. This is likely not the correct way to do it, but it's probably easiest to discuss this in a PR since I want to fix this in any case.
The problem appears to be that witness tables for generic structs don't get
SequentialIDDecoration
s. This is becauseensureWitnessTableSequentialIDs
checks for LinkageDecoration, which those generic witness tables don't have (but should they?). WhenaddLinkageDecoration
is called for witness tables invisitInheritanceDecl
(slang-lower-to-ir.cpp
), it starts by finding the outermost generic and attaches the decoration to that, which in this case is not the witness table itself.I tried adding a new flag to
addLinkageDecoration
to skip that outermost-generic-search, skipping it only invisitInheritanceDecl
, but that broke some tests, so it's probably not that simple.So the overkill approach in this PR is to give
SequentialIDDecoration
to every single witness table for whichensureWitnessTableSequentialIDs
is called. It doesn't seem to break any tests and fixes the code examples from that issue, but I guess there must be some negative consequences since clearly some effort was seen to only add the IDs in a very specific corner case.