Don't treat dependent types as having a copy value representation. (#6055)

Add `Dependent` value and initializing representations for types whose
representations are unknown because they are dependent. When generating
SemIR in such cases, use a worst-case initializing representation that
both provides a destination address and also propagates a potential
result value.

Use this to fix incorrect lowering and lowering crashes for specific
functions involving generic types that don't use a copy value
representation.

In lowering, be careful to distinguish between whether the initializing
representation for the generic return type uses a return slot (which
affects whether the SemIR declaration and call have one) and whether the
initializing representation for the specific return type uses a return
slot (which affects whether the LLVM IR declaration and call have one).
This commit is contained in:
Richard Smith
2025-09-15 23:59:00 +00:00
committed by GitHub
parent ca40e9d693
commit b44ba47cf3
53 changed files with 1375 additions and 670 deletions
+12 -8
View File
@@ -169,14 +169,15 @@ fn CallSpecific(x: C*) -> C* {
// CHECK:STDOUT: %impl.elem0.loc6_10.2: @Function.%.loc6_10.2 (%.c50) = impl_witness_access %Copy.lookup_impl_witness, element0 [symbolic = %impl.elem0.loc6_10.2 (constants.%impl.elem0.792)]
// CHECK:STDOUT: %specific_impl_fn.loc6_10.2: <specific function> = specific_impl_function %impl.elem0.loc6_10.2, @Copy.Op(%Copy.facet) [symbolic = %specific_impl_fn.loc6_10.2 (constants.%specific_impl_fn.547)]
// CHECK:STDOUT:
// CHECK:STDOUT: fn(%x.param: @Function.%T.as_type.loc5_31.1 (%T.as_type)) -> @Function.%T.as_type.loc5_31.1 (%T.as_type) {
// CHECK:STDOUT: fn(%x.param: @Function.%T.as_type.loc5_31.1 (%T.as_type)) -> %return.param: @Function.%T.as_type.loc5_31.1 (%T.as_type) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %x.ref: @Function.%T.as_type.loc5_31.1 (%T.as_type) = name_ref x, %x
// CHECK:STDOUT: %impl.elem0.loc6_10.1: @Function.%.loc6_10.2 (%.c50) = impl_witness_access constants.%Copy.lookup_impl_witness.e15, element0 [symbolic = %impl.elem0.loc6_10.2 (constants.%impl.elem0.792)]
// CHECK:STDOUT: %bound_method.loc6_10.1: <bound method> = bound_method %x.ref, %impl.elem0.loc6_10.1
// CHECK:STDOUT: %specific_impl_fn.loc6_10.1: <specific function> = specific_impl_function %impl.elem0.loc6_10.1, @Copy.Op(constants.%Copy.facet.021) [symbolic = %specific_impl_fn.loc6_10.2 (constants.%specific_impl_fn.547)]
// CHECK:STDOUT: %bound_method.loc6_10.2: <bound method> = bound_method %x.ref, %specific_impl_fn.loc6_10.1
// CHECK:STDOUT: %.loc6_10.1: init @Function.%T.as_type.loc5_31.1 (%T.as_type) = call %bound_method.loc6_10.2(%x.ref)
// CHECK:STDOUT: %.loc5_34: ref @Function.%T.as_type.loc5_31.1 (%T.as_type) = splice_block %return {}
// CHECK:STDOUT: %.loc6_10.1: init @Function.%T.as_type.loc5_31.1 (%T.as_type) = call %bound_method.loc6_10.2(%x.ref) to %.loc5_34
// CHECK:STDOUT: return %.loc6_10.1 to %return
// CHECK:STDOUT: }
// CHECK:STDOUT: }
@@ -188,7 +189,7 @@ fn CallSpecific(x: C*) -> C* {
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: %Function.specific_fn.loc12_10.2: <specific function> = specific_function constants.%Function, @Function(%T.loc10_16.1) [symbolic = %Function.specific_fn.loc12_10.2 (constants.%Function.specific_fn.8cd)]
// CHECK:STDOUT:
// CHECK:STDOUT: fn(%x.param: @CallGeneric.%T.as_type.loc10_34.1 (%T.as_type)) -> @CallGeneric.%T.as_type.loc10_34.1 (%T.as_type) {
// CHECK:STDOUT: fn(%x.param: @CallGeneric.%T.as_type.loc10_34.1 (%T.as_type)) -> %return.param: @CallGeneric.%T.as_type.loc10_34.1 (%T.as_type) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %Function.ref: %Function.type = name_ref Function, file.%Function.decl [concrete = constants.%Function]
// CHECK:STDOUT: %T.ref.loc12: %Copy.type = name_ref T, %T.loc10_16.2 [symbolic = %T.loc10_16.1 (constants.%T.be8)]
@@ -196,7 +197,8 @@ fn CallSpecific(x: C*) -> C* {
// CHECK:STDOUT: %.loc12_23.1: %Copy.type = converted constants.%T.as_type, constants.%T.be8 [symbolic = %T.loc10_16.1 (constants.%T.be8)]
// CHECK:STDOUT: %.loc12_23.2: %Copy.type = converted constants.%T.as_type, constants.%T.be8 [symbolic = %T.loc10_16.1 (constants.%T.be8)]
// CHECK:STDOUT: %Function.specific_fn.loc12_10.1: <specific function> = specific_function %Function.ref, @Function(constants.%T.be8) [symbolic = %Function.specific_fn.loc12_10.2 (constants.%Function.specific_fn.8cd)]
// CHECK:STDOUT: %Function.call: init @CallGeneric.%T.as_type.loc10_34.1 (%T.as_type) = call %Function.specific_fn.loc12_10.1(%x.ref)
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: %Function.call: init @CallGeneric.%T.as_type.loc10_34.1 (%T.as_type) = call %Function.specific_fn.loc12_10.1(%x.ref) to %.loc10_37
// CHECK:STDOUT: return %Function.call to %return
// CHECK:STDOUT: }
// CHECK:STDOUT: }
@@ -398,14 +400,15 @@ fn CallSpecific(x: C*) -> C* {
// CHECK:STDOUT: %impl.elem0.loc6_10.2: @Function.%.loc6_10.2 (%.c50) = impl_witness_access %Copy.lookup_impl_witness, element0 [symbolic = %impl.elem0.loc6_10.2 (constants.%impl.elem0.792)]
// CHECK:STDOUT: %specific_impl_fn.loc6_10.2: <specific function> = specific_impl_function %impl.elem0.loc6_10.2, @Copy.Op(%Copy.facet) [symbolic = %specific_impl_fn.loc6_10.2 (constants.%specific_impl_fn.547)]
// CHECK:STDOUT:
// CHECK:STDOUT: fn(%x.param: @Function.%T.as_type.loc5_31.1 (%T.as_type)) -> @Function.%T.as_type.loc5_31.1 (%T.as_type) {
// CHECK:STDOUT: fn(%x.param: @Function.%T.as_type.loc5_31.1 (%T.as_type)) -> %return.param: @Function.%T.as_type.loc5_31.1 (%T.as_type) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %x.ref: @Function.%T.as_type.loc5_31.1 (%T.as_type) = name_ref x, %x
// CHECK:STDOUT: %impl.elem0.loc6_10.1: @Function.%.loc6_10.2 (%.c50) = impl_witness_access constants.%Copy.lookup_impl_witness.e15, element0 [symbolic = %impl.elem0.loc6_10.2 (constants.%impl.elem0.792)]
// CHECK:STDOUT: %bound_method.loc6_10.1: <bound method> = bound_method %x.ref, %impl.elem0.loc6_10.1
// CHECK:STDOUT: %specific_impl_fn.loc6_10.1: <specific function> = specific_impl_function %impl.elem0.loc6_10.1, @Copy.Op(constants.%Copy.facet.021) [symbolic = %specific_impl_fn.loc6_10.2 (constants.%specific_impl_fn.547)]
// CHECK:STDOUT: %bound_method.loc6_10.2: <bound method> = bound_method %x.ref, %specific_impl_fn.loc6_10.1
// CHECK:STDOUT: %.loc6_10.1: init @Function.%T.as_type.loc5_31.1 (%T.as_type) = call %bound_method.loc6_10.2(%x.ref)
// CHECK:STDOUT: %.loc5_34: ref @Function.%T.as_type.loc5_31.1 (%T.as_type) = splice_block %return {}
// CHECK:STDOUT: %.loc6_10.1: init @Function.%T.as_type.loc5_31.1 (%T.as_type) = call %bound_method.loc6_10.2(%x.ref) to %.loc5_34
// CHECK:STDOUT: return %.loc6_10.1 to %return
// CHECK:STDOUT: }
// CHECK:STDOUT: }
@@ -417,14 +420,15 @@ fn CallSpecific(x: C*) -> C* {
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: %Function.specific_fn.loc12_10.2: <specific function> = specific_function constants.%Function, @Function(%T.loc10_16.1) [symbolic = %Function.specific_fn.loc12_10.2 (constants.%Function.specific_fn.8cd)]
// CHECK:STDOUT:
// CHECK:STDOUT: fn(%x.param: @CallGeneric.%T.as_type.loc10_34.1 (%T.as_type)) -> @CallGeneric.%T.as_type.loc10_34.1 (%T.as_type) {
// CHECK:STDOUT: fn(%x.param: @CallGeneric.%T.as_type.loc10_34.1 (%T.as_type)) -> %return.param: @CallGeneric.%T.as_type.loc10_34.1 (%T.as_type) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %Function.ref: %Function.type = name_ref Function, file.%Function.decl [concrete = constants.%Function]
// CHECK:STDOUT: %x.ref: @CallGeneric.%T.as_type.loc10_34.1 (%T.as_type) = name_ref x, %x
// CHECK:STDOUT: %.loc12_20.1: %Copy.type = converted constants.%T.as_type, constants.%T.be8 [symbolic = %T.loc10_16.1 (constants.%T.be8)]
// CHECK:STDOUT: %.loc12_20.2: %Copy.type = converted constants.%T.as_type, constants.%T.be8 [symbolic = %T.loc10_16.1 (constants.%T.be8)]
// CHECK:STDOUT: %Function.specific_fn.loc12_10.1: <specific function> = specific_function %Function.ref, @Function(constants.%T.be8) [symbolic = %Function.specific_fn.loc12_10.2 (constants.%Function.specific_fn.8cd)]
// CHECK:STDOUT: %Function.call: init @CallGeneric.%T.as_type.loc10_34.1 (%T.as_type) = call %Function.specific_fn.loc12_10.1(%x.ref)
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: %Function.call: init @CallGeneric.%T.as_type.loc10_34.1 (%T.as_type) = call %Function.specific_fn.loc12_10.1(%x.ref) to %.loc10_37
// CHECK:STDOUT: return %Function.call to %return
// CHECK:STDOUT: }
// CHECK:STDOUT: }
@@ -226,12 +226,13 @@ fn G() {
// CHECK:STDOUT: %Wrap.Make: @Wrap.Make.%Wrap.Make.type (%Wrap.Make.type.652) = struct_value () [symbolic = %Wrap.Make (constants.%Wrap.Make.eb2)]
// CHECK:STDOUT: %Wrap.Make.specific_fn.loc16_27.2: <specific function> = specific_function %Wrap.Make, @Wrap.Make(%T) [symbolic = %Wrap.Make.specific_fn.loc16_27.2 (constants.%Wrap.Make.specific_fn.bf1)]
// CHECK:STDOUT:
// CHECK:STDOUT: fn() -> @Wrap.Make.%T (%T) {
// CHECK:STDOUT: fn() -> %return.param: @Wrap.Make.%T (%T) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %.loc16: @Wrap.Make.%Wrap.Make.type (%Wrap.Make.type.652) = specific_constant @Wrap.%Wrap.Make.decl, @Wrap(constants.%T) [symbolic = %Wrap.Make (constants.%Wrap.Make.eb2)]
// CHECK:STDOUT: %Make.ref: @Wrap.Make.%Wrap.Make.type (%Wrap.Make.type.652) = name_ref Make, %.loc16 [symbolic = %Wrap.Make (constants.%Wrap.Make.eb2)]
// CHECK:STDOUT: %.loc16_27: @Wrap.Make.%Wrap.Make.type (%Wrap.Make.type.652) = specific_constant @Wrap.%Wrap.Make.decl, @Wrap(constants.%T) [symbolic = %Wrap.Make (constants.%Wrap.Make.eb2)]
// CHECK:STDOUT: %Make.ref: @Wrap.Make.%Wrap.Make.type (%Wrap.Make.type.652) = name_ref Make, %.loc16_27 [symbolic = %Wrap.Make (constants.%Wrap.Make.eb2)]
// CHECK:STDOUT: %Wrap.Make.specific_fn.loc16_27.1: <specific function> = specific_function %Make.ref, @Wrap.Make(constants.%T) [symbolic = %Wrap.Make.specific_fn.loc16_27.2 (constants.%Wrap.Make.specific_fn.bf1)]
// CHECK:STDOUT: %Wrap.Make.call: init @Wrap.Make.%T (%T) = call %Wrap.Make.specific_fn.loc16_27.1()
// CHECK:STDOUT: %.loc16_13: ref @Wrap.Make.%T (%T) = splice_block %return {}
// CHECK:STDOUT: %Wrap.Make.call: init @Wrap.Make.%T (%T) = call %Wrap.Make.specific_fn.loc16_27.1() to %.loc16_13
// CHECK:STDOUT: return %Wrap.Make.call to %return
// CHECK:STDOUT: }
// CHECK:STDOUT: }