Reverse nesting of BoundMethod and SpecificFunction. (#5079)

During SemIR, when identifying a specific in a specific context, we'd
have to either look through a specific or through a bound method.
Canonicalize which one to look through first, by having the BoundMethod
created around a SpecificFunction instead.
This changes a lot of check tests.

TODO: As the SemIr does not currently allow removal (access to insts()
is intentionally const), the bound instruction created prior to finding
the specific is not removed from the instructions.
Options: (1) leave as is, (2) add a way to remove the previous bound,
(3) rethink how/when the BoundMethod inst is created.
This commit is contained in:
Alina Sbirlea
2025-03-08 01:34:06 +00:00
committed by GitHub
parent 820ace95e8
commit 7fd54eded0
165 changed files with 2795 additions and 1958 deletions
+19 -14
View File
@@ -39,13 +39,14 @@ fn G() -> i32 {
// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, %impl_witness.d39 [concrete]
// CHECK:STDOUT: %.a0b: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
// CHECK:STDOUT: %Convert.bound.ab5: <bound method> = bound_method %int_1.5b8, %Convert.956 [concrete]
// CHECK:STDOUT: %Convert.specific_fn.70c: <specific function> = specific_function %Convert.bound.ab5, @Convert.2(%int_32) [concrete]
// CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
// CHECK:STDOUT: %bound_method.9a1: <bound method> = bound_method %int_1.5b8, %Convert.specific_fn [concrete]
// CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete]
// CHECK:STDOUT: %Convert.bound.ef9: <bound method> = bound_method %int_2.ecc, %Convert.956 [concrete]
// CHECK:STDOUT: %Convert.specific_fn.787: <specific function> = specific_function %Convert.bound.ef9, @Convert.2(%int_32) [concrete]
// CHECK:STDOUT: %bound_method.b92: <bound method> = bound_method %int_2.ecc, %Convert.specific_fn [concrete]
// CHECK:STDOUT: %int_2.ef8: %i32 = int_value 2 [concrete]
// CHECK:STDOUT: %Convert.bound.b30: <bound method> = bound_method %int_3.1ba, %Convert.956 [concrete]
// CHECK:STDOUT: %Convert.specific_fn.b42: <specific function> = specific_function %Convert.bound.b30, @Convert.2(%int_32) [concrete]
// CHECK:STDOUT: %bound_method.047: <bound method> = bound_method %int_3.1ba, %Convert.specific_fn [concrete]
// CHECK:STDOUT: %int_3.822: %i32 = int_value 3 [concrete]
// CHECK:STDOUT: %array: %array_type = tuple_value (%int_1.5d2, %int_2.ef8, %int_3.822) [concrete]
// CHECK:STDOUT: }
@@ -126,25 +127,28 @@ fn G() -> i32 {
// CHECK:STDOUT: %int_1.loc16_23: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
// CHECK:STDOUT: %impl.elem0.loc16_20.1: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [concrete = constants.%Convert.956]
// CHECK:STDOUT: %bound_method.loc16_20.1: <bound method> = bound_method %int_1.loc16_13, %impl.elem0.loc16_20.1 [concrete = constants.%Convert.bound.ab5]
// CHECK:STDOUT: %specific_fn.loc16_20.1: <specific function> = specific_function %bound_method.loc16_20.1, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn.70c]
// CHECK:STDOUT: %int.convert_checked.loc16_20.1: init %i32 = call %specific_fn.loc16_20.1(%int_1.loc16_13) [concrete = constants.%int_1.5d2]
// CHECK:STDOUT: %specific_fn.loc16_20.1: <specific function> = specific_function %impl.elem0.loc16_20.1, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
// CHECK:STDOUT: %bound_method.loc16_20.2: <bound method> = bound_method %int_1.loc16_13, %specific_fn.loc16_20.1 [concrete = constants.%bound_method.9a1]
// CHECK:STDOUT: %int.convert_checked.loc16_20.1: init %i32 = call %bound_method.loc16_20.2(%int_1.loc16_13) [concrete = constants.%int_1.5d2]
// CHECK:STDOUT: %.loc16_20.2: init %i32 = converted %int_1.loc16_13, %int.convert_checked.loc16_20.1 [concrete = constants.%int_1.5d2]
// CHECK:STDOUT: %.loc16_20.3: ref %array_type = temporary_storage
// CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
// CHECK:STDOUT: %.loc16_20.4: ref %i32 = array_index %.loc16_20.3, %int_0
// CHECK:STDOUT: %.loc16_20.5: init %i32 = initialize_from %.loc16_20.2 to %.loc16_20.4 [concrete = constants.%int_1.5d2]
// CHECK:STDOUT: %impl.elem0.loc16_20.2: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [concrete = constants.%Convert.956]
// CHECK:STDOUT: %bound_method.loc16_20.2: <bound method> = bound_method %int_2.loc16_16, %impl.elem0.loc16_20.2 [concrete = constants.%Convert.bound.ef9]
// CHECK:STDOUT: %specific_fn.loc16_20.2: <specific function> = specific_function %bound_method.loc16_20.2, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn.787]
// CHECK:STDOUT: %int.convert_checked.loc16_20.2: init %i32 = call %specific_fn.loc16_20.2(%int_2.loc16_16) [concrete = constants.%int_2.ef8]
// CHECK:STDOUT: %bound_method.loc16_20.3: <bound method> = bound_method %int_2.loc16_16, %impl.elem0.loc16_20.2 [concrete = constants.%Convert.bound.ef9]
// CHECK:STDOUT: %specific_fn.loc16_20.2: <specific function> = specific_function %impl.elem0.loc16_20.2, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
// CHECK:STDOUT: %bound_method.loc16_20.4: <bound method> = bound_method %int_2.loc16_16, %specific_fn.loc16_20.2 [concrete = constants.%bound_method.b92]
// CHECK:STDOUT: %int.convert_checked.loc16_20.2: init %i32 = call %bound_method.loc16_20.4(%int_2.loc16_16) [concrete = constants.%int_2.ef8]
// CHECK:STDOUT: %.loc16_20.6: init %i32 = converted %int_2.loc16_16, %int.convert_checked.loc16_20.2 [concrete = constants.%int_2.ef8]
// CHECK:STDOUT: %int_1.loc16_20: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
// CHECK:STDOUT: %.loc16_20.7: ref %i32 = array_index %.loc16_20.3, %int_1.loc16_20
// CHECK:STDOUT: %.loc16_20.8: init %i32 = initialize_from %.loc16_20.6 to %.loc16_20.7 [concrete = constants.%int_2.ef8]
// CHECK:STDOUT: %impl.elem0.loc16_20.3: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [concrete = constants.%Convert.956]
// CHECK:STDOUT: %bound_method.loc16_20.3: <bound method> = bound_method %int_3, %impl.elem0.loc16_20.3 [concrete = constants.%Convert.bound.b30]
// CHECK:STDOUT: %specific_fn.loc16_20.3: <specific function> = specific_function %bound_method.loc16_20.3, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn.b42]
// CHECK:STDOUT: %int.convert_checked.loc16_20.3: init %i32 = call %specific_fn.loc16_20.3(%int_3) [concrete = constants.%int_3.822]
// CHECK:STDOUT: %bound_method.loc16_20.5: <bound method> = bound_method %int_3, %impl.elem0.loc16_20.3 [concrete = constants.%Convert.bound.b30]
// CHECK:STDOUT: %specific_fn.loc16_20.3: <specific function> = specific_function %impl.elem0.loc16_20.3, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
// CHECK:STDOUT: %bound_method.loc16_20.6: <bound method> = bound_method %int_3, %specific_fn.loc16_20.3 [concrete = constants.%bound_method.047]
// CHECK:STDOUT: %int.convert_checked.loc16_20.3: init %i32 = call %bound_method.loc16_20.6(%int_3) [concrete = constants.%int_3.822]
// CHECK:STDOUT: %.loc16_20.9: init %i32 = converted %int_3, %int.convert_checked.loc16_20.3 [concrete = constants.%int_3.822]
// CHECK:STDOUT: %int_2.loc16_20: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc]
// CHECK:STDOUT: %.loc16_20.10: ref %i32 = array_index %.loc16_20.3, %int_2.loc16_20
@@ -154,9 +158,10 @@ fn G() -> i32 {
// CHECK:STDOUT: %.loc16_20.14: ref %array_type = temporary %.loc16_20.3, %.loc16_20.13
// CHECK:STDOUT: %.loc16_20.15: %array_type = bind_value %.loc16_20.14
// CHECK:STDOUT: %impl.elem0.loc16_23: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [concrete = constants.%Convert.956]
// CHECK:STDOUT: %bound_method.loc16_23: <bound method> = bound_method %int_1.loc16_23, %impl.elem0.loc16_23 [concrete = constants.%Convert.bound.ab5]
// CHECK:STDOUT: %specific_fn.loc16_23: <specific function> = specific_function %bound_method.loc16_23, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn.70c]
// CHECK:STDOUT: %int.convert_checked.loc16_23: init %i32 = call %specific_fn.loc16_23(%int_1.loc16_23) [concrete = constants.%int_1.5d2]
// CHECK:STDOUT: %bound_method.loc16_23.1: <bound method> = bound_method %int_1.loc16_23, %impl.elem0.loc16_23 [concrete = constants.%Convert.bound.ab5]
// CHECK:STDOUT: %specific_fn.loc16_23: <specific function> = specific_function %impl.elem0.loc16_23, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
// CHECK:STDOUT: %bound_method.loc16_23.2: <bound method> = bound_method %int_1.loc16_23, %specific_fn.loc16_23 [concrete = constants.%bound_method.9a1]
// CHECK:STDOUT: %int.convert_checked.loc16_23: init %i32 = call %bound_method.loc16_23.2(%int_1.loc16_23) [concrete = constants.%int_1.5d2]
// CHECK:STDOUT: %.loc16_23.1: %i32 = value_of_initializer %int.convert_checked.loc16_23 [concrete = constants.%int_1.5d2]
// CHECK:STDOUT: %.loc16_23.2: %i32 = converted %int_1.loc16_23, %.loc16_23.1 [concrete = constants.%int_1.5d2]
// CHECK:STDOUT: %F.call: init %i32 = call %F.ref(%.loc16_20.15, %.loc16_23.2)