Skip to content
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

Merged

Conversation

zygoloid
Copy link
Contributor

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.

@zygoloid
Copy link
Contributor Author

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.

@zygoloid
Copy link
Contributor Author

#4336 is blocked on this after merge because the check added in #4333 (landed in #4221) starts firing on one of the #4336 tests due to this bug.

@@ -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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

toolchain/sem_ir/ids.h Show resolved Hide resolved
toolchain/sem_ir/ids.h Show resolved Hide resolved
@geoffromer geoffromer added this pull request to the merge queue Sep 27, 2024
Merged via the queue into carbon-language:trunk with commit 42bda1e Sep 27, 2024
8 checks passed
@zygoloid zygoloid deleted the toolchain-no-subst-assoc-consts branch September 28, 2024 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants