-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't substitute into the targeted instructions of an associated constant. #4342
Don't substitute into the targeted instructions of an associated constant. #4342
Conversation
I've split this PR into three commits: the first adds the test and shows the old behavior (with the CHECK disabled), the second fixes the bug, and the third updates the test to show new new behavior (and re-enables the CHECK). This should hopefully give a better idea of what this PR is fixing. |
toolchain/sem_ir/ids.h
Outdated
@@ -86,6 +86,20 @@ constexpr InstId InstId::Invalid = InstId(InvalidIndex); | |||
InstId::ForBuiltin(BuiltinInstKind::Name); | |||
#include "toolchain/sem_ir/builtin_inst_kind.def" | |||
|
|||
// An ID of an instruction that is referenced absolutely within a typed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The phrasing of this comment makes it sound kind of like "absoluteness" is a property of the inst itself, but based on the code, I gather it's actually a property of the ID. In other words, in principle you could have an AbsoluteInstId
and an InstId
that refer to the same inst. Is that right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's right. I've updated the comment to try to make this clearer.
When an instruction makes an absolute reference to another instruction, such as when
assoc_const
refers to the declaration of the associated constant in an interface, substitution into that instruction should not substitute into the referenced instruction.Mark the corresponding
InstId
fields in the typed instructions as being absolute by giving them a distinct ID type thatSubst
doesn't substitute into. This formation of unnecessarily complicated SemIR that could in some cases lead to a CHECK failure when printing formatted SemIR because the same instruction ends up in multiple scopes.