mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-01 22:02:45 +01:00
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.