Don't substitute into the targeted instructions of an associated constant. (#4342)

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 that `Subst` 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.
This commit is contained in:
Richard Smith
2024-09-27 17:41:05 +00:00
committed by GitHub
parent 73c6f67378
commit 42bda1e38f
5 changed files with 195 additions and 7 deletions
+4
View File
@@ -1030,6 +1030,10 @@ class FormatterImpl {
out_ << inst_namer_->GetNameFor(scope_, id);
}
auto FormatName(AbsoluteInstId id) -> void {
FormatName(static_cast<InstId>(id));
}
auto FormatName(SpecificId id) -> void {
const auto& specific = sem_ir_.specifics().Get(id);
FormatName(specific.generic_id);