Use specific_constant when referring to name in enclosing generic (#7936)

When unqualified lookup finds a name from an enclosing generic, create a
`specific_constant` if it's a constant, or a `specific_inst` otherwise,
to refer to that name from the inner generic. This allows consumers of
generic instructions to always use a specific of the current scope's
generic when accessing the constant value or type of a dependent
instruction.

Fixes crashes in dominance and in `GetExprCategory` caused by using
specifics for the wrong generic.

Assisted-by: Gemini via Antigravity
This commit is contained in:
Richard Smith authored and GitHub committed 2026-10-15 02:00:24 +00:00
1 parent 893cce070f
commit e1c8c1f855
46 files changed
+1229 -551

No files matched your search

@@ -381,8 +381,9 @@ var arr: array(i32, (1 as i32) + (2 as i32)) = (3, 4, (3 as i32) + (4 as i32));
// CHECK:STDOUT: %return.param_patt.loc14_23.1: @As.WithSelf.Convert.%pattern_type.loc14_23 (%pattern_type.51d) = out_param_pattern [symbolic = %return.param_patt.loc14_23.2 (constants.%return.param_patt.41d)]
// CHECK:STDOUT: %return.patt.loc14_20.1: @As.WithSelf.Convert.%pattern_type.loc14_23 (%pattern_type.51d) = return_slot_pattern %return.param_patt.loc14_23.1, %T.ref [symbolic = %return.patt.loc14_20.2 (constants.%return.patt.b39)]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %T.ref: type = name_ref T, @As.%T.loc13_15.2 [symbolic = %T (constants.%T)]
// CHECK:STDOUT: %.loc14_23.2: Core.Form = init_form %T.ref [symbolic = %.loc14_23.1 (constants.%.184)]
// CHECK:STDOUT: %.loc14_23.2: type = specific_constant @As.%T.loc13_15.2, @As(constants.%T) [symbolic = %T (constants.%T)]
// CHECK:STDOUT: %T.ref: type = name_ref T, %.loc14_23.2 [symbolic = %T (constants.%T)]
// CHECK:STDOUT: %.loc14_23.3: Core.Form = init_form %T.ref [symbolic = %.loc14_23.1 (constants.%.184)]
// CHECK:STDOUT: %self.param: @As.WithSelf.Convert.%Self.as_type.loc14_14.1 (%Self.as_type.5c1) = value_param call_param0
// CHECK:STDOUT: %.loc14_14.1: type = splice_block %.loc14_14.3 [symbolic = %Self.as_type.loc14_14.1 (constants.%Self.as_type.5c1)] {
// CHECK:STDOUT: %.loc14_14.2: @As.WithSelf.Convert.%As.type (%As.type.12c) = specific_constant @As.%Self.loc13_23.1, @As(constants.%T) [symbolic = %Self (constants.%Self.b18)]
@@ -426,8 +427,9 @@ var arr: array(i32, (1 as i32) + (2 as i32)) = (3, 4, (3 as i32) + (4 as i32));
// CHECK:STDOUT: %return.param_patt.loc18_23.1: @ImplicitAs.WithSelf.Convert.%pattern_type.loc18_23 (%pattern_type.51d) = out_param_pattern [symbolic = %return.param_patt.loc18_23.2 (constants.%return.param_patt.41d)]
// CHECK:STDOUT: %return.patt.loc18_20.1: @ImplicitAs.WithSelf.Convert.%pattern_type.loc18_23 (%pattern_type.51d) = return_slot_pattern %return.param_patt.loc18_23.1, %T.ref [symbolic = %return.patt.loc18_20.2 (constants.%return.patt.b39)]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %T.ref: type = name_ref T, @ImplicitAs.%T.loc17_23.2 [symbolic = %T (constants.%T)]
// CHECK:STDOUT: %.loc18_23.2: Core.Form = init_form %T.ref [symbolic = %.loc18_23.1 (constants.%.184)]
// CHECK:STDOUT: %.loc18_23.2: type = specific_constant @ImplicitAs.%T.loc17_23.2, @ImplicitAs(constants.%T) [symbolic = %T (constants.%T)]
// CHECK:STDOUT: %T.ref: type = name_ref T, %.loc18_23.2 [symbolic = %T (constants.%T)]
// CHECK:STDOUT: %.loc18_23.3: Core.Form = init_form %T.ref [symbolic = %.loc18_23.1 (constants.%.184)]
// CHECK:STDOUT: %self.param: @ImplicitAs.WithSelf.Convert.%Self.as_type.loc18_14.1 (%Self.as_type.0dd) = value_param call_param0
// CHECK:STDOUT: %.loc18_14.1: type = splice_block %.loc18_14.3 [symbolic = %Self.as_type.loc18_14.1 (constants.%Self.as_type.0dd)] {
// CHECK:STDOUT: %.loc18_14.2: @ImplicitAs.WithSelf.Convert.%ImplicitAs.type (%ImplicitAs.type.b02) = specific_constant @ImplicitAs.%Self.loc17_31.1, @ImplicitAs(constants.%T) [symbolic = %Self (constants.%Self.757)]
@@ -356,8 +356,9 @@ fn G() {
// CHECK:STDOUT: %return.param_patt.loc16_16.1: @Wrap.Make.%pattern_type (%pattern_type.51d) = out_param_pattern [symbolic = %return.param_patt.loc16_16.2 (constants.%return.param_patt.41d)]
// CHECK:STDOUT: %return.patt.loc16_13.1: @Wrap.Make.%pattern_type (%pattern_type.51d) = return_slot_pattern %return.param_patt.loc16_16.1, %T.ref [symbolic = %return.patt.loc16_13.2 (constants.%return.patt.b39)]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %T.ref: type = name_ref T, @Wrap.%T.loc15_13.2 [symbolic = %T (constants.%T)]
// CHECK:STDOUT: %.loc16_16.3: Core.Form = init_form %T.ref [symbolic = %.loc16_16.2 (constants.%.184)]
// CHECK:STDOUT: %.loc16_16.3: type = specific_constant @Wrap.%T.loc15_13.2, @Wrap(constants.%T) [symbolic = %T (constants.%T)]
// CHECK:STDOUT: %T.ref: type = name_ref T, %.loc16_16.3 [symbolic = %T (constants.%T)]
// CHECK:STDOUT: %.loc16_16.4: Core.Form = init_form %T.ref [symbolic = %.loc16_16.2 (constants.%.184)]
// CHECK:STDOUT: %return.param: ref @Wrap.Make.%T (%T) = out_param call_param0
// CHECK:STDOUT: %return: ref @Wrap.Make.%T (%T) = return_slot %return.param
// CHECK:STDOUT: }