Avoid symbolic witnesses for .Self in an impl decl (#7564)

Point symbolic witnesses into `.Self` written inside an impl decl at the
impl that is being declared. This is tricky because the impl does not
yet exist. So we use a new instruction `ImplSelfWitness` which _will_ be
replaced by the `ImplWitness` once it becomes available. The
`ImplSelfWitness` acts like a symbolic witness, except it does not
perform lookup, since we know which impl we will get a witness from.

This prevents us from finding other impls when performing lookups into
`.Self` in an impl decl, which produces incorrect/incoherent results.
This commit is contained in:
Dana Jansens
2026-07-29 16:25:23 +00:00
committed by GitHub
parent 2ac425e591
commit f51c075f8b
94 changed files with 3221 additions and 2797 deletions
@@ -39,14 +39,14 @@ fn TestOp(a: C) -> C {
// CHECK:STDOUT: %C.as.BitComplement.impl.Op.type: type = fn_type @C.as.BitComplement.impl.Op [concrete]
// CHECK:STDOUT: %C.as.BitComplement.impl.Op: %C.as.BitComplement.impl.Op.type = struct_value () [concrete]
// CHECK:STDOUT: %BitComplement.facet: %BitComplement.type = facet_value %C, (%BitComplement.impl_witness) [concrete]
// CHECK:STDOUT: %BitComplement.WithSelf.Op.type.697: type = fn_type @BitComplement.WithSelf.Op, @BitComplement.WithSelf(%BitComplement.facet) [concrete]
// CHECK:STDOUT: %.6c8: type = fn_type_with_self_type %BitComplement.WithSelf.Op.type.697, %BitComplement.facet [concrete]
// CHECK:STDOUT: %BitComplement.WithSelf.Op.type.904: type = fn_type @BitComplement.WithSelf.Op, @BitComplement.WithSelf(%BitComplement.facet) [concrete]
// CHECK:STDOUT: %.95e: type = fn_type_with_self_type %BitComplement.WithSelf.Op.type.904, %BitComplement.facet [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @TestOp(%a.param: %C) -> out %return.param: %C {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %a.ref: %C = name_ref a, %a
// CHECK:STDOUT: %impl.elem1: %.6c8 = impl_witness_access constants.%BitComplement.impl_witness, element1 [concrete = constants.%C.as.BitComplement.impl.Op]
// CHECK:STDOUT: %impl.elem1: %.95e = impl_witness_access constants.%BitComplement.impl_witness, element1 [concrete = constants.%C.as.BitComplement.impl.Op]
// CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem1
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: %C.as.BitComplement.impl.Op.call: init %C to %.loc27_20.1 = call %bound_method(%a.ref)