Skip to content

Conversation

@danakj
Copy link
Contributor

@danakj danakj commented Dec 10, 2025

Instead of burying operations to pop the generic stack in GetOrAddImpl, we move them up to handle_impl.cpp in BuildImplDecl, which puts them at the same level as other operations on the generic stack, like StartGenericDecl or FinishGenericDefinition.

To do so, we split GetOrAddImpl into a few pieces:

  • FindImplId finds an existing Impl that matches the declaration, or returns a LookupBucketRef and whether an error was diagnosed instead.
  • AddImpl takes a fully built Impl, makes an ImplId for it, and does additional steps for a new Impl verifying it and applying extend.
  • AddImplWitnessForDeclaration constructs the Impl's witness, which must be done between two generic steps in order to use the generic's self specific but also add the witness instruction to the generic.

We group the logic to build the initial table in the definition and to complete it in the definition together in impl.cpp. And we save a lookup into the ImplStore by passing Impl by reference to FinishImplWitness, as we now do for other similar functions in impl.h.

This is based on #6470.

@danakj danakj requested a review from zygoloid December 10, 2025 20:37
@danakj danakj requested a review from a team as a code owner December 10, 2025 20:37
@danakj danakj added the dependent Depends on another issue/PR label Dec 10, 2025
@danakj danakj force-pushed the less-completing-impl-as-chain-8 branch from ffd26af to 423c53e Compare December 10, 2025 20:37
Copy link
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG, thanks!

@danakj danakj enabled auto-merge December 16, 2025 14:56
@danakj danakj added this pull request to the merge queue Dec 16, 2025
Merged via the queue into carbon-language:trunk with commit efec4e4 Dec 16, 2025
8 checks passed
@danakj danakj deleted the less-completing-impl-as-chain-8 branch December 16, 2025 16:10
github-merge-queue bot pushed a commit that referenced this pull request Dec 17, 2025
The impl's body block has to end before we make its ImplDecl
instruction, and the witness instructions come later, so they don't end
up in the body block. Currently they just end up in the enclosing (file,
typically, or class) scope block.

Add a new InstBlockId to Impl for holding witness instructions, and
explicitly insert them into that block. Then include those instructions
into the scope of the Impl for naming, and format them into the Impl
right after the body block.

This is based on #6484
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependent Depends on another issue/PR toolchain

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants