Remove redundant deduced specifics (#5107)

When deduction has to substitute binding parameters into further generic
parameters, we do conversion of the argument to the substituted type.
Then we replace the argument instruction id with that Converted
instruction. This causes a redundant specific to be created for the
Converted instruction which is not needed. What we want is the specific
for its constant value.

So when we replace the argument instruction id, replace it with the
instruction from the constant value of the converted argument.

This was raised in [discord
#toolchain](https://discord.com/channels/655572317891461132/655578254970716160/1349067541070217306).
This commit is contained in:
Dana Jansens
2025-03-11 19:16:32 +00:00
committed by GitHub
parent 201a4dc1c6
commit 82fe19ee99
5 changed files with 16 additions and 65 deletions
@@ -273,7 +273,7 @@ fn G() {
// CHECK:STDOUT: %ImplsGeneric.ref: type = name_ref ImplsGeneric, file.%ImplsGeneric.decl [concrete = constants.%ImplsGeneric]
// CHECK:STDOUT: %Generic.facet: %Generic.type.769 = facet_value constants.%ImplsGeneric, (constants.%impl_witness.b42) [concrete = constants.%Generic.facet.8bd]
// CHECK:STDOUT: %.loc34: %Generic.type.769 = converted constants.%ImplsGeneric, %Generic.facet [concrete = constants.%Generic.facet.8bd]
// CHECK:STDOUT: %CallGenericMethod.specific_fn: <specific function> = specific_function %CallGenericMethod.ref, @CallGenericMethod(constants.%GenericParam, %.loc34) [concrete = constants.%CallGenericMethod.specific_fn]
// CHECK:STDOUT: %CallGenericMethod.specific_fn: <specific function> = specific_function %CallGenericMethod.ref, @CallGenericMethod(constants.%GenericParam, constants.%Generic.facet.8bd) [concrete = constants.%CallGenericMethod.specific_fn]
// CHECK:STDOUT: %CallGenericMethod.call: init %empty_tuple.type = call %CallGenericMethod.specific_fn()
// CHECK:STDOUT: return
// CHECK:STDOUT: }
@@ -333,7 +333,7 @@ fn G() {
// CHECK:STDOUT:
// CHECK:STDOUT: specific @F.1(@CallGenericMethod.%T.loc29_22.2, @CallGenericMethod.%Generic.facet) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @CallGenericMethod(constants.%GenericParam, @G.3.%.loc34) {
// CHECK:STDOUT: specific @CallGenericMethod(constants.%GenericParam, constants.%Generic.facet.8bd) {
// CHECK:STDOUT: %T.loc29_22.2 => constants.%GenericParam
// CHECK:STDOUT: %T.patt.loc29_22.2 => constants.%GenericParam
// CHECK:STDOUT: %Generic.type.loc29_45.2 => constants.%Generic.type.769
@@ -353,11 +353,3 @@ fn G() {
// CHECK:STDOUT: %specific_fn.loc30_4.2 => constants.%F.specific_fn
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @CallGenericMethod(constants.%GenericParam, constants.%Generic.facet.8bd) {
// CHECK:STDOUT: %T.loc29_22.2 => constants.%GenericParam
// CHECK:STDOUT: %T.patt.loc29_22.2 => constants.%GenericParam
// CHECK:STDOUT: %Generic.type.loc29_45.2 => constants.%Generic.type.769
// CHECK:STDOUT: %U.loc29_32.2 => constants.%Generic.facet.8bd
// CHECK:STDOUT: %U.patt.loc29_32.2 => constants.%Generic.facet.8bd
// CHECK:STDOUT: }
// CHECK:STDOUT: