Build generic eval blocks incrementally (#5313)

Instead of building an eval block as a separate pass at the end of a
generic, build the eval block incrementally.

The larger change here is that asking for the type or constant value of
an instruction now always returns an unattached type or constant value,
in order to preserve the behavior that we previously achieved by doing
the rewrite to attached types and constant values at the end of handling
the generic.

This also incidentally fixes some subtle issues where attached types and
constant values would leak out into check and cause it to get confused
about differences between attached and unattached values. Check should
no longer see attached values except where it explicitly asks for them.

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
This commit is contained in:
Richard Smith
2025-05-01 20:24:15 +00:00
committed by GitHub
co-authored by Dana Jansens
parent 797b14eb8e
commit 4f5d11a28b
138 changed files with 1067 additions and 2109 deletions
@@ -499,10 +499,6 @@ var arr: array(i32, (1 as i32) + (2 as i32)) = (3, 4, (3 as i32) + (4 as i32));
// CHECK:STDOUT: %pattern_type.loc12_28 => constants.%pattern_type.7dc
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @As(@Convert.1.%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @As(%T.loc11_14.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @ImplicitAs(constants.%T) {
// CHECK:STDOUT: %T.loc15_22.2 => constants.%T
// CHECK:STDOUT: }
@@ -516,10 +512,6 @@ var arr: array(i32, (1 as i32) + (2 as i32)) = (3, 4, (3 as i32) + (4 as i32));
// CHECK:STDOUT: %pattern_type.loc16_28 => constants.%pattern_type.7dc
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @ImplicitAs(@Convert.2.%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @ImplicitAs(%T.loc15_22.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Op.1(constants.%Add.facet) {
// CHECK:STDOUT: %Self => constants.%Add.facet
// CHECK:STDOUT: %Self.as_type.loc8_15.1 => constants.%i32.builtin
@@ -702,11 +694,11 @@ var arr: array(i32, (1 as i32) + (2 as i32)) = (3, 4, (3 as i32) + (4 as i32));
// CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//default, Int, loaded [concrete = constants.%Int]
// CHECK:STDOUT: %Core.As: %As.type.90f = import_ref Core//default, As, loaded [concrete = constants.%As.generic]
// CHECK:STDOUT: %Core.import_ref.5ab3ec.1: type = import_ref Core//default, loc11_14, loaded [symbolic = @As.%T (constants.%T)]
// CHECK:STDOUT: %Core.import_ref.a7c = import_ref Core//default, inst87 [no loc], unloaded
// CHECK:STDOUT: %Core.import_ref.a7c = import_ref Core//default, inst88 [no loc], unloaded
// CHECK:STDOUT: %Core.import_ref.5e1: @As.%As.assoc_type (%As.assoc_type.760) = import_ref Core//default, loc12_32, loaded [symbolic = @As.%assoc0 (constants.%assoc0.97d)]
// CHECK:STDOUT: %Core.Convert.313 = import_ref Core//default, Convert, unloaded
// CHECK:STDOUT: %Core.import_ref.5ab3ec.2: type = import_ref Core//default, loc11_14, loaded [symbolic = @As.%T (constants.%T)]
// CHECK:STDOUT: %Core.import_ref.996: @As.%As.type (%As.type.eed) = import_ref Core//default, inst87 [no loc], loaded [symbolic = @As.%Self (constants.%Self.65a)]
// CHECK:STDOUT: %Core.import_ref.996: @As.%As.type (%As.type.eed) = import_ref Core//default, inst88 [no loc], loaded [symbolic = @As.%Self (constants.%Self.65a)]
// CHECK:STDOUT: %Core.import_ref.708: @As.%Convert.type (%Convert.type.843) = import_ref Core//default, loc12_32, loaded [symbolic = @As.%Convert (constants.%Convert.95f)]
// CHECK:STDOUT: %Core.import_ref.4e8 = import_ref Core//default, loc12_32, unloaded
// CHECK:STDOUT: %Core.import_ref.07c = import_ref Core//default, inst43 [no loc], unloaded
@@ -719,14 +711,14 @@ var arr: array(i32, (1 as i32) + (2 as i32)) = (3, 4, (3 as i32) + (4 as i32));
// CHECK:STDOUT: %Core.import_ref.8721d7.1: type = import_ref Core//default, loc23_17, loaded [concrete = Core.IntLiteral]
// CHECK:STDOUT: %Core.import_ref.1e5: type = import_ref Core//default, loc23_28, loaded [concrete = constants.%As.type.a6d]
// CHECK:STDOUT: %Core.import_ref.5ab3ec.3: type = import_ref Core//default, loc15_22, loaded [symbolic = @ImplicitAs.%T (constants.%T)]
// CHECK:STDOUT: %Core.import_ref.ff5 = import_ref Core//default, inst131 [no loc], unloaded
// CHECK:STDOUT: %Core.import_ref.ff5 = import_ref Core//default, inst132 [no loc], unloaded
// CHECK:STDOUT: %Core.import_ref.492: @ImplicitAs.%ImplicitAs.assoc_type (%ImplicitAs.assoc_type.ca0) = import_ref Core//default, loc16_32, loaded [symbolic = @ImplicitAs.%assoc0 (constants.%assoc0.dc001e.2)]
// CHECK:STDOUT: %Core.Convert.e69 = import_ref Core//default, Convert, unloaded
// CHECK:STDOUT: %Core.import_ref.c62: <witness> = import_ref Core//default, loc27_38, loaded [concrete = constants.%ImplicitAs.impl_witness.07a]
// CHECK:STDOUT: %Core.import_ref.8721d7.2: type = import_ref Core//default, loc27_17, loaded [concrete = Core.IntLiteral]
// CHECK:STDOUT: %Core.import_ref.4d9: type = import_ref Core//default, loc27_36, loaded [concrete = constants.%ImplicitAs.type.61e]
// CHECK:STDOUT: %Core.import_ref.5ab3ec.4: type = import_ref Core//default, loc15_22, loaded [symbolic = @ImplicitAs.%T (constants.%T)]
// CHECK:STDOUT: %Core.import_ref.ce1: @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.d62) = import_ref Core//default, inst131 [no loc], loaded [symbolic = @ImplicitAs.%Self (constants.%Self.519)]
// CHECK:STDOUT: %Core.import_ref.ce1: @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.d62) = import_ref Core//default, inst132 [no loc], loaded [symbolic = @ImplicitAs.%Self (constants.%Self.519)]
// CHECK:STDOUT: %Core.import_ref.207961.1 = import_ref Core//default, loc16_32, unloaded
// CHECK:STDOUT: %Core.import_ref.1c752f.1: @ImplicitAs.%Convert.type (%Convert.type.275) = import_ref Core//default, loc16_32, loaded [symbolic = @ImplicitAs.%Convert (constants.%Convert.42e)]
// CHECK:STDOUT: %Core.import_ref.c5f: <witness> = import_ref Core//default, loc31_38, loaded [concrete = constants.%ImplicitAs.impl_witness.9c5]
@@ -959,10 +951,6 @@ var arr: array(i32, (1 as i32) + (2 as i32)) = (3, 4, (3 as i32) + (4 as i32));
// CHECK:STDOUT: %T => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @As(%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @As(@Convert.1.%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Convert.1(constants.%T, constants.%Self.65a) {
// CHECK:STDOUT: %T => constants.%T
// CHECK:STDOUT: %As.type => constants.%As.type.eed
@@ -1000,10 +988,6 @@ var arr: array(i32, (1 as i32) + (2 as i32)) = (3, 4, (3 as i32) + (4 as i32));
// CHECK:STDOUT: %assoc0 => constants.%assoc0.6fd
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @ImplicitAs(%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @ImplicitAs(@Convert.2.%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Convert.2(constants.%T, constants.%Self.519) {
// CHECK:STDOUT: %T => constants.%T
// CHECK:STDOUT: %ImplicitAs.type => constants.%ImplicitAs.type.d62
@@ -87,7 +87,7 @@ fn Class(F:! type).Inner.G() -> i32 { return F(); }
// CHECK:STDOUT: } {
// CHECK:STDOUT: %F.loc5_13.1: type = bind_symbolic_name F, 0 [symbolic = %F.loc5_13.2 (constants.%F.8b3)]
// CHECK:STDOUT: }
// CHECK:STDOUT: %G.decl: @Inner.%G.type (%G.type) = fn_decl @G [symbolic = constants.%G] {
// CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [symbolic = constants.%G] {
// CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
// CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param0 [concrete]
// CHECK:STDOUT: } {
@@ -213,11 +213,3 @@ fn Class(F:! type).Inner.G() -> i32 { return F(); }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @G(constants.%F.8b3) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Inner(%F.loc8_19.1) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Inner(@Class.%F.loc5_13.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Inner(@G.%F.loc13_46.1) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @F(@G.%F.loc13_46.1) {}
// CHECK:STDOUT:
@@ -286,8 +286,6 @@ fn G() {
// CHECK:STDOUT:
// CHECK:STDOUT: specific @F.1(constants.%Scalar, constants.%Self.dee8d8.1) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Generic(%Scalar.loc11_19.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Generic(constants.%GenericParam) {
// CHECK:STDOUT: %Scalar.loc11_19.2 => constants.%GenericParam
// CHECK:STDOUT:
@@ -325,12 +323,8 @@ fn G() {
// CHECK:STDOUT: %pattern_type => constants.%pattern_type.80f
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Generic(@CallGenericMethod.%T.loc29_22.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @F.1(constants.%T, constants.%Generic.facet.680) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @F.1(@CallGenericMethod.%T.loc29_22.2, @CallGenericMethod.%Generic.facet) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @CallGenericMethod(constants.%GenericParam, constants.%Generic.facet.8ff) {
// CHECK:STDOUT: %T.loc29_22.2 => constants.%GenericParam
// CHECK:STDOUT: %Generic.type.loc29_45.2 => constants.%Generic.type.769
-26
View File
@@ -382,8 +382,6 @@ fn F() {
// CHECK:STDOUT: %ExplicitGenericParam.specific_fn.loc4_50.2 => constants.%ExplicitGenericParam.specific_fn.c0a
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @ExplicitGenericParam(%T.loc4_25.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @ExplicitGenericParam(constants.%i32) {
// CHECK:STDOUT: %T.loc4_25.2 => constants.%i32
// CHECK:STDOUT: %ptr.loc4_39.2 => constants.%ptr.235
@@ -411,8 +409,6 @@ fn F() {
// CHECK:STDOUT: %ExplicitGenericParam.specific_fn.loc4_50.2 => constants.%ExplicitGenericParam.specific_fn.6ad
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @ExplicitGenericParam(@CallExplicitGenericParamWithGenericArg.%struct_type.a.loc10_62.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: --- fail_deduce_explicit_non_constant.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
@@ -526,14 +522,10 @@ fn F() {
// CHECK:STDOUT: %ExplicitGenericParam.specific_fn.loc4_50.2 => constants.%ExplicitGenericParam.specific_fn
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @ExplicitGenericParam(%T.loc4_25.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @CallExplicitGenericParamConst(constants.%T) {
// CHECK:STDOUT: %T.loc6_34.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @ExplicitGenericParam(@CallExplicitGenericParamConst.%T.loc6_34.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: --- explicit_vs_deduced.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
@@ -665,8 +657,6 @@ fn F() {
// CHECK:STDOUT: %ExplicitAndAlsoDeduced.specific_fn.loc7_10.2 => constants.%ExplicitAndAlsoDeduced.specific_fn.41d
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @ExplicitAndAlsoDeduced(%T.loc6_27.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @ExplicitAndAlsoDeduced(constants.%A) {
// CHECK:STDOUT: %T.loc6_27.2 => constants.%A
// CHECK:STDOUT: %pattern_type.loc6_37 => constants.%pattern_type.c10
@@ -805,8 +795,6 @@ fn F() {
// CHECK:STDOUT: %ImplicitGenericParam.specific_fn.loc4_56.2 => constants.%ImplicitGenericParam.specific_fn.fc1
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @ImplicitGenericParam(%T.loc4_25.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @ImplicitGenericParam(constants.%i32) {
// CHECK:STDOUT: %T.loc4_25.2 => constants.%i32
// CHECK:STDOUT: %pattern_type.loc4_35 => constants.%pattern_type.7ce
@@ -1773,10 +1761,6 @@ fn F() {
// CHECK:STDOUT: !definition:
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @DD(@impl.266.%E.loc9_14.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @impl.266(%E.loc9_14.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @CC(constants.%D) {
// CHECK:STDOUT: %D.loc11_10.2 => constants.%D
// CHECK:STDOUT: }
@@ -1794,12 +1778,6 @@ fn F() {
// CHECK:STDOUT: %Z.impl_witness => constants.%Z.impl_witness.b58
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @DD(@impl.497.%E.loc12_14.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @CC(@impl.497.%Z.facet.loc12_32.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @impl.497(%E.loc12_14.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @DD(constants.%EE) {
// CHECK:STDOUT: %E.loc8_10.2 => constants.%EE
// CHECK:STDOUT: }
@@ -2047,10 +2025,6 @@ fn F() {
// CHECK:STDOUT: %Z.impl_witness => constants.%Z.impl_witness.741
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @CC(@impl.562.%Y.facet.loc19_29.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @impl.562(%E.loc19_14.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @CC(constants.%Y.facet.268) {
// CHECK:STDOUT: %D.loc12_10.2 => constants.%Y.facet.268
// CHECK:STDOUT: }
@@ -254,8 +254,6 @@ fn CallSpecific(x: C) -> C {
// CHECK:STDOUT: %pattern_type => constants.%pattern_type.7dc
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Function(@CallGeneric.%T.loc8_16.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @CallGenericPtr(constants.%T) {
// CHECK:STDOUT: %T.loc12_19.2 => constants.%T
// CHECK:STDOUT: %ptr.loc12_33.2 => constants.%ptr.79f
@@ -270,8 +268,6 @@ fn CallSpecific(x: C) -> C {
// CHECK:STDOUT: %require_complete => constants.%require_complete.6e5
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Function(@CallGenericPtr.%ptr.loc12_33.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Function(constants.%C) {
// CHECK:STDOUT: %T.loc4_13.2 => constants.%C
// CHECK:STDOUT: %pattern_type => constants.%pattern_type.c48
@@ -475,8 +471,6 @@ fn CallSpecific(x: C) -> C {
// CHECK:STDOUT: %pattern_type => constants.%pattern_type.7dc
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Function(@CallGeneric.%T.loc8_16.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @CallGenericPtr(constants.%T) {
// CHECK:STDOUT: %T.loc12_19.2 => constants.%T
// CHECK:STDOUT: %ptr.loc12_33.2 => constants.%ptr.79f
@@ -491,8 +485,6 @@ fn CallSpecific(x: C) -> C {
// CHECK:STDOUT: %require_complete => constants.%require_complete.6e5
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Function(@CallGenericPtr.%ptr.loc12_33.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Function(constants.%C) {
// CHECK:STDOUT: %T.loc4_13.2 => constants.%C
// CHECK:STDOUT: %pattern_type => constants.%pattern_type.c48
@@ -101,8 +101,6 @@ fn H() {
// CHECK:STDOUT: %T.loc7_6.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @F(@G.%T.loc7_6.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: --- user.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
@@ -196,8 +194,6 @@ fn H() {
// CHECK:STDOUT: %T => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @F(@G.%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @G(constants.%C) {
// CHECK:STDOUT: %T => constants.%C
// CHECK:STDOUT:
@@ -171,8 +171,6 @@ fn F(U:! type, T:! type) -> U* {
// CHECK:STDOUT: %F.specific_fn.loc7_10.2 => constants.%F.specific_fn
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @F(%T.loc4_6.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: --- fail_different_return_type.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
@@ -236,12 +236,6 @@ fn G() {
// CHECK:STDOUT: %Make.specific_fn.loc12_27.2 => constants.%Make.specific_fn.bf1
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Wrap(%T.loc11_12.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Wrap(@Make.%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Make(%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Wrap(constants.%i32) {
// CHECK:STDOUT: %T.loc11_12.2 => constants.%i32
// CHECK:STDOUT: