Remove ref pattern from CppUnsafeDeref (#7293)

Since we can't currently iterate over ranges as references, the
`CppUnsafeDeref` interface can't require types that implement it to take
or return references.
This commit is contained in:
Christopher Di Bella
2026-06-03 01:22:07 +00:00
committed by GitHub
parent 057ef0d458
commit d578e4afe7
3 changed files with 24 additions and 18 deletions
+12 -7
View File
@@ -123,8 +123,8 @@ fn TestDerefFail(not_ptr: Cpp.NotAPtr) {
// CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
// CHECK:STDOUT: %CppUnsafeDeref.type: type = facet_type <@CppUnsafeDeref> [concrete]
// CHECK:STDOUT: %Self: %CppUnsafeDeref.type = symbolic_binding Self, 0 [symbolic]
// CHECK:STDOUT: %CppUnsafeDeref.WithSelf.Op.type.393: type = fn_type @CppUnsafeDeref.WithSelf.Op, @CppUnsafeDeref.WithSelf(%Self) [symbolic]
// CHECK:STDOUT: %Self.a61: %CppUnsafeDeref.type = symbolic_binding Self, 0 [symbolic]
// CHECK:STDOUT: %CppUnsafeDeref.WithSelf.Op.type.393: type = fn_type @CppUnsafeDeref.WithSelf.Op, @CppUnsafeDeref.WithSelf(%Self.a61) [symbolic]
// CHECK:STDOUT: %CppUnsafeDeref.WithSelf.Op.0fa: %CppUnsafeDeref.WithSelf.Op.type.393 = struct_value () [symbolic]
// CHECK:STDOUT: %CppUnsafeDeref.assoc_type: type = assoc_entity_type @CppUnsafeDeref [concrete]
// CHECK:STDOUT: %assoc1: %CppUnsafeDeref.assoc_type = assoc_entity element1, imports.%Core.import_ref.a48 [concrete]
@@ -134,6 +134,7 @@ fn TestDerefFail(not_ptr: Cpp.NotAPtr) {
// CHECK:STDOUT: %operator_Star__carbon_thunk: %operator_Star__carbon_thunk.type = struct_value () [concrete]
// CHECK:STDOUT: %ConstDeref.Op.type: type = fn_type @ConstDeref.Op [concrete]
// CHECK:STDOUT: %ConstDeref.Op: %ConstDeref.Op.type = struct_value () [concrete]
// CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
// CHECK:STDOUT: %custom_witness.000: <witness> = custom_witness (%i32, %ConstDeref.Op), @CppUnsafeDeref [concrete]
// CHECK:STDOUT: %CppUnsafeDeref.facet.909: %CppUnsafeDeref.type = facet_value %ConstDeref, (%custom_witness.000) [concrete]
// CHECK:STDOUT: %CppUnsafeDeref.WithSelf.Op.type.6a5: type = fn_type @CppUnsafeDeref.WithSelf.Op, @CppUnsafeDeref.WithSelf(%CppUnsafeDeref.facet.909) [concrete]
@@ -144,6 +145,7 @@ fn TestDerefFail(not_ptr: Cpp.NotAPtr) {
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
// CHECK:STDOUT: .Int = %Core.Int
// CHECK:STDOUT: .CppUnsafeDeref = %Core.CppUnsafeDeref
// CHECK:STDOUT: .Copy = %Core.Copy
// CHECK:STDOUT: import Core//prelude
// CHECK:STDOUT: import Core//prelude/...
// CHECK:STDOUT: }
@@ -161,6 +163,7 @@ fn TestDerefFail(not_ptr: Cpp.NotAPtr) {
// CHECK:STDOUT: } {
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: }
// CHECK:STDOUT: %Core.Copy: type = import_ref Core//prelude/copy, Copy, loaded [concrete = constants.%Copy.type]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @TestDerefPass(%int_ptr.param: ref %ConstDeref) -> ref %i32 {
@@ -169,13 +172,14 @@ fn TestDerefFail(not_ptr: Cpp.NotAPtr) {
// CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
// CHECK:STDOUT: %CppUnsafeDeref.ref: type = name_ref CppUnsafeDeref, imports.%Core.CppUnsafeDeref [concrete = constants.%CppUnsafeDeref.type]
// CHECK:STDOUT: %Op.ref.loc13_38: %CppUnsafeDeref.assoc_type = name_ref Op, imports.%Core.import_ref.05c [concrete = constants.%assoc1]
// CHECK:STDOUT: %impl_witness_assoc_constant: type = impl_witness_assoc_constant @ConstDeref.cpp_operator.%i32.2 [concrete = constants.%i32]
// CHECK:STDOUT: %impl_witness_assoc_constant: type = impl_witness_assoc_constant constants.%i32 [concrete = constants.%i32]
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: %impl.elem1: %.b71 = impl_witness_access constants.%custom_witness.000, element1 [concrete = constants.%ConstDeref.Op]
// CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_ptr.ref, %impl.elem1
// CHECK:STDOUT: %.loc13: %ConstDeref = acquire_value %int_ptr.ref
// CHECK:STDOUT: %Op.ref.loc13_43: %ConstDeref.cpp_operator.type = name_ref Op, imports.%ConstDeref.cpp_operator.decl [concrete = constants.%ConstDeref.cpp_operator]
// CHECK:STDOUT: %ConstDeref.cpp_operator.bound: <bound method> = bound_method %int_ptr.ref, %Op.ref.loc13_43
// CHECK:STDOUT: %operator_Star__carbon_thunk.call: ref %i32 = call imports.%operator_Star__carbon_thunk.decl(%int_ptr.ref)
// CHECK:STDOUT: %ConstDeref.cpp_operator.bound: <bound method> = bound_method %.loc13, %Op.ref.loc13_43
// CHECK:STDOUT: %operator_Star__carbon_thunk.call: ref %i32 = call imports.%operator_Star__carbon_thunk.decl(%.loc13)
// CHECK:STDOUT: return %operator_Star__carbon_thunk.call
// CHECK:STDOUT: }
// CHECK:STDOUT:
@@ -220,10 +224,11 @@ fn TestDerefFail(not_ptr: Cpp.NotAPtr) {
// CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
// CHECK:STDOUT: %CppUnsafeDeref.ref: type = name_ref CppUnsafeDeref, imports.%Core.CppUnsafeDeref [concrete = constants.%CppUnsafeDeref.type]
// CHECK:STDOUT: %Op.ref: %CppUnsafeDeref.assoc_type = name_ref Op, imports.%Core.import_ref.05c [concrete = constants.%assoc1]
// CHECK:STDOUT: %impl_witness_assoc_constant: type = impl_witness_assoc_constant @MutableDeref.cpp_operator.%i32.2 [concrete = constants.%i32]
// CHECK:STDOUT: %impl_witness_assoc_constant: type = impl_witness_assoc_constant constants.%i32 [concrete = constants.%i32]
// CHECK:STDOUT: %impl.elem1: %.a97 = impl_witness_access constants.%custom_witness.91c, element1 [concrete = constants.%MutableDeref.cpp_operator]
// CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_ptr.ref, %impl.elem1
// CHECK:STDOUT: %MutableDeref.cpp_operator.call: ref %i32 = call %bound_method(%int_ptr.ref)
// CHECK:STDOUT: %.loc13: %MutableDeref = acquire_value %int_ptr.ref
// CHECK:STDOUT: %MutableDeref.cpp_operator.call: ref %i32 = call %bound_method(%.loc13)
// CHECK:STDOUT: return %MutableDeref.cpp_operator.call
// CHECK:STDOUT: }
// CHECK:STDOUT: