Skip to content

Commit

Permalink
Do not resolve the declaration when forming a specific for use in an …
Browse files Browse the repository at this point in the history
…eval block (#4692)

When substituting into a generic in order to form a generic eval block,
we form `SpecificId`s to track the list of arguments that should
eventually be used to form a specific referenced by the eval block.
Values within that specific are not needed and won't ever be used, so
it's safe to skip forming them in the first place.

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
  • Loading branch information
josh11b and josh11b authored Dec 17, 2024
1 parent 76055de commit b25117b
Show file tree
Hide file tree
Showing 53 changed files with 238 additions and 991 deletions.
10 changes: 3 additions & 7 deletions toolchain/check/subst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,10 @@ static auto PopOperand(Context& context, Worklist& worklist, SemIR::IdKind kind,
return arg;
}
auto& specific = context.specifics().Get(specific_id);
auto args_id =
auto args_id = SemIR::InstBlockId(
PopOperand(context, worklist, SemIR::IdKind::For<SemIR::InstBlockId>,
specific.args_id.index);
// TODO: Provide a location here.
SemIRLoc loc = SemIR::InstId::Invalid;
return MakeSpecific(context, loc, specific.generic_id,
SemIR::InstBlockId(args_id))
.index;
specific.args_id.index));
return context.specifics().GetOrAdd(specific.generic_id, args_id).index;
}
case SemIR::IdKind::For<SemIR::FacetTypeId>: {
const auto& old_facet_type_info =
Expand Down
10 changes: 2 additions & 8 deletions toolchain/check/testdata/class/fail_generic_method.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,14 @@ fn Class(N:! i32).F[self: Self](n: T) {}
// CHECK:STDOUT: %T.patt.loc11_13.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Class(@F.%T) {
// CHECK:STDOUT: %T.loc11_13.2 => constants.%T
// CHECK:STDOUT: %T.patt.loc11_13.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Class(@F.%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @F(constants.%T) {
// CHECK:STDOUT: %T => constants.%T
// CHECK:STDOUT: %Class => constants.%Class
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Class(%T.loc11_13.2) {
// CHECK:STDOUT: %T.loc11_13.2 => constants.%T
// CHECK:STDOUT: %T.patt.loc11_13.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Class(%T.loc11_13.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @.1(constants.%N.2) {
// CHECK:STDOUT: %N.loc32_10.2 => constants.%N.2
Expand Down
25 changes: 5 additions & 20 deletions toolchain/check/testdata/class/generic/adapt.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,7 @@ fn ImportedConvertLocal(a: Adapter(C)) -> i32 {
// CHECK:STDOUT: %T.patt.loc4_9.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @C(%T.loc4_9.2) {
// CHECK:STDOUT: %T.loc4_9.2 => constants.%T
// CHECK:STDOUT: %T.patt.loc4_9.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @C(%T.loc4_9.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @C(constants.%i32) {
// CHECK:STDOUT: %T.loc4_9.2 => constants.%i32
Expand Down Expand Up @@ -382,10 +379,7 @@ fn ImportedConvertLocal(a: Adapter(C)) -> i32 {
// CHECK:STDOUT: %complete_type => constants.%complete_type.3
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @C(%T) {
// CHECK:STDOUT: %T => constants.%T
// CHECK:STDOUT: %T.patt => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @C(%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: --- fail_todo_extend_adapt_specific_type.carbon
// CHECK:STDOUT:
Expand Down Expand Up @@ -504,10 +498,7 @@ fn ImportedConvertLocal(a: Adapter(C)) -> i32 {
// CHECK:STDOUT: %T.patt.loc4_9.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @C(%T.loc4_9.2) {
// CHECK:STDOUT: %T.loc4_9.2 => constants.%T
// CHECK:STDOUT: %T.patt.loc4_9.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @C(%T.loc4_9.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @C(constants.%i32) {
// CHECK:STDOUT: %T.loc4_9.2 => constants.%i32
Expand Down Expand Up @@ -611,10 +602,7 @@ fn ImportedConvertLocal(a: Adapter(C)) -> i32 {
// CHECK:STDOUT: %T.patt.loc7_9.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @C(%T.loc7_9.2) {
// CHECK:STDOUT: %T.loc7_9.2 => constants.%T
// CHECK:STDOUT: %T.patt.loc7_9.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @C(%T.loc7_9.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @C(constants.%i32) {
// CHECK:STDOUT: %T.loc7_9.2 => constants.%i32
Expand Down Expand Up @@ -745,10 +733,7 @@ fn ImportedConvertLocal(a: Adapter(C)) -> i32 {
// CHECK:STDOUT: %complete_type => constants.%complete_type.3
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @C(%T) {
// CHECK:STDOUT: %T => constants.%T
// CHECK:STDOUT: %T.patt => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @C(%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: --- adapt_generic_type.carbon
// CHECK:STDOUT:
Expand Down
58 changes: 12 additions & 46 deletions toolchain/check/testdata/class/generic/base_is_generic.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,7 @@ fn H() {
// CHECK:STDOUT: %T.patt.loc4_17.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Base(%T.loc4_17.2) {
// CHECK:STDOUT: %T.loc4_17.2 => constants.%T
// CHECK:STDOUT: %T.patt.loc4_17.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Base(%T.loc4_17.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Base(constants.%Param) {
// CHECK:STDOUT: %T.loc4_17.2 => constants.%Param
Expand Down Expand Up @@ -380,10 +377,7 @@ fn H() {
// CHECK:STDOUT: %complete_type => constants.%complete_type.5
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Base(%T) {
// CHECK:STDOUT: %T => constants.%T
// CHECK:STDOUT: %T.patt => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Base(%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: --- fail_todo_extend_symbolic_base.carbon
// CHECK:STDOUT:
Expand Down Expand Up @@ -673,19 +667,11 @@ fn H() {
// CHECK:STDOUT: %G.specific_fn.loc5_24.2 => constants.%G.specific_fn.1
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @X(%U.loc4_14.2) {
// CHECK:STDOUT: %U.loc4_14.2 => constants.%U
// CHECK:STDOUT: %U.patt.loc4_14.2 => constants.%U
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @X(%U.loc4_14.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @X(@G.%U) {
// CHECK:STDOUT: %U.loc4_14.2 => constants.%U
// CHECK:STDOUT: %U.patt.loc4_14.2 => constants.%U
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @X(@G.%U) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @G(%U) {
// CHECK:STDOUT: %U => constants.%U
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @G(%U) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @C(constants.%T) {
// CHECK:STDOUT: %T.loc8_9.2 => constants.%T
Expand All @@ -701,15 +687,9 @@ fn H() {
// CHECK:STDOUT: %G => constants.%G.2
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @X(@C.%T.loc8_9.2) {
// CHECK:STDOUT: %U.loc4_14.2 => constants.%T
// CHECK:STDOUT: %U.patt.loc4_14.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @X(@C.%T.loc8_9.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @C(%T.loc8_9.2) {
// CHECK:STDOUT: %T.loc8_9.2 => constants.%T
// CHECK:STDOUT: %T.patt.loc8_9.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @C(%T.loc8_9.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @C(constants.%i32) {
// CHECK:STDOUT: %T.loc8_9.2 => constants.%i32
Expand Down Expand Up @@ -903,20 +883,11 @@ fn H() {
// CHECK:STDOUT: %T.patt => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @X(%U) {
// CHECK:STDOUT: %U => constants.%U
// CHECK:STDOUT: %U.patt => constants.%U
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @X(%U) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @X(@C.%T) {
// CHECK:STDOUT: %U => constants.%T
// CHECK:STDOUT: %U.patt => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @X(@C.%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @C(%T) {
// CHECK:STDOUT: %T => constants.%T
// CHECK:STDOUT: %T.patt => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @C(%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @G(constants.%U) {
// CHECK:STDOUT: %U => constants.%U
Expand All @@ -928,14 +899,9 @@ fn H() {
// CHECK:STDOUT: %G.specific_fn => constants.%G.specific_fn.1
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @X(@G.%U) {
// CHECK:STDOUT: %U => constants.%U
// CHECK:STDOUT: %U.patt => constants.%U
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @X(@G.%U) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @G(%U) {
// CHECK:STDOUT: %U => constants.%U
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @G(%U) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @C(constants.%i32) {
// CHECK:STDOUT: %T => constants.%i32
Expand Down
15 changes: 3 additions & 12 deletions toolchain/check/testdata/class/generic/basic.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,7 @@ class Declaration(T:! type);
// CHECK:STDOUT: %complete_type.loc22_1.2 => constants.%complete_type
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Class(@GetAddr.%T) {
// CHECK:STDOUT: %T.loc11_13.2 => constants.%T
// CHECK:STDOUT: %T.patt.loc11_13.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Class(@GetAddr.%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @GetAddr(constants.%T) {
// CHECK:STDOUT: %T => constants.%T
Expand All @@ -215,20 +212,14 @@ class Declaration(T:! type);
// CHECK:STDOUT: %ptr.loc12_38.1 => constants.%ptr.2
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Class(@GetValue.%T) {
// CHECK:STDOUT: %T.loc11_13.2 => constants.%T
// CHECK:STDOUT: %T.patt.loc11_13.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Class(@GetValue.%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @GetValue(constants.%T) {
// CHECK:STDOUT: %T => constants.%T
// CHECK:STDOUT: %Class => constants.%Class
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Class(%T.loc11_13.2) {
// CHECK:STDOUT: %T.loc11_13.2 => constants.%T
// CHECK:STDOUT: %T.patt.loc11_13.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Class(%T.loc11_13.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Declaration(constants.%T) {
// CHECK:STDOUT: %T.loc24_19.2 => constants.%T
Expand Down
40 changes: 8 additions & 32 deletions toolchain/check/testdata/class/generic/call.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,7 @@ class Outer(T:! type) {
// CHECK:STDOUT: %D => constants.%D.1
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Outer(@A.%T) {
// CHECK:STDOUT: %T.loc2_13.2 => constants.%T
// CHECK:STDOUT: %T.patt.loc2_13.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Outer(@A.%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @A(constants.%T, constants.%U) {
// CHECK:STDOUT: %T => constants.%T
Expand All @@ -736,10 +733,7 @@ class Outer(T:! type) {
// CHECK:STDOUT: %Inner.generic => constants.%Inner.generic.2
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Outer(@B.%U) {
// CHECK:STDOUT: %T.loc2_13.2 => constants.%U
// CHECK:STDOUT: %T.patt.loc2_13.2 => constants.%U
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Outer(@B.%U) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @B(constants.%T, constants.%U) {
// CHECK:STDOUT: %U => constants.%U
Expand All @@ -762,15 +756,9 @@ class Outer(T:! type) {
// CHECK:STDOUT: %D => constants.%D.2
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Outer(@C.%T) {
// CHECK:STDOUT: %T.loc2_13.2 => constants.%T
// CHECK:STDOUT: %T.patt.loc2_13.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Outer(@C.%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Inner(@C.%T, @C.%T) {
// CHECK:STDOUT: %U.loc3_15.2 => constants.%T
// CHECK:STDOUT: %U.patt.loc3_15.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Inner(@C.%T, @C.%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @C(constants.%T, constants.%U) {
// CHECK:STDOUT: %T => constants.%T
Expand All @@ -779,15 +767,9 @@ class Outer(T:! type) {
// CHECK:STDOUT: %Inner.loc10_22.1 => constants.%Inner.2
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Outer(@D.%T) {
// CHECK:STDOUT: %T.loc2_13.2 => constants.%T
// CHECK:STDOUT: %T.patt.loc2_13.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Outer(@D.%T) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Inner(@D.%T, @D.%U) {
// CHECK:STDOUT: %U.loc3_15.2 => constants.%U
// CHECK:STDOUT: %U.patt.loc3_15.2 => constants.%U
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Inner(@D.%T, @D.%U) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @D(constants.%T, constants.%U) {
// CHECK:STDOUT: %T => constants.%T
Expand All @@ -797,13 +779,7 @@ class Outer(T:! type) {
// CHECK:STDOUT: %Inner.loc13_22.1 => constants.%Inner.1
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Inner(%T, %U.loc3_15.2) {
// CHECK:STDOUT: %U.loc3_15.2 => constants.%U
// CHECK:STDOUT: %U.patt.loc3_15.2 => constants.%U
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Inner(%T, %U.loc3_15.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Outer(%T.loc2_13.2) {
// CHECK:STDOUT: %T.loc2_13.2 => constants.%T
// CHECK:STDOUT: %T.patt.loc2_13.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Outer(%T.loc2_13.2) {}
// CHECK:STDOUT:
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,7 @@ fn F(a: A(0)*) {
// CHECK:STDOUT: %N.patt.loc6_9.2 => constants.%N.2
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @A(%N.loc6_9.2) {
// CHECK:STDOUT: %N.loc6_9.2 => constants.%N.2
// CHECK:STDOUT: %N.patt.loc6_9.2 => constants.%N.2
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @A(%N.loc6_9.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @A(constants.%int_0.2) {
// CHECK:STDOUT: %N.loc6_9.2 => constants.%int_0.2
Expand Down
15 changes: 3 additions & 12 deletions toolchain/check/testdata/class/generic/field.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,7 @@ fn H(U:! type, c: Class(U)) -> U {
// CHECK:STDOUT: %complete_type.loc13_1.2 => constants.%complete_type.1
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Class(%T.loc11_13.2) {
// CHECK:STDOUT: %T.loc11_13.2 => constants.%T
// CHECK:STDOUT: %T.patt.loc11_13.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Class(%T.loc11_13.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Class(constants.%i32) {
// CHECK:STDOUT: %T.loc11_13.2 => constants.%i32
Expand All @@ -243,10 +240,7 @@ fn H(U:! type, c: Class(U)) -> U {
// CHECK:STDOUT: %complete_type.loc13_1.2 => constants.%complete_type.4
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Class(@G.%T.loc19_6.2) {
// CHECK:STDOUT: %T.loc11_13.2 => constants.%T
// CHECK:STDOUT: %T.patt.loc11_13.2 => constants.%T
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Class(@G.%T.loc19_6.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @G(constants.%T) {
// CHECK:STDOUT: %T.loc19_6.2 => constants.%T
Expand All @@ -266,10 +260,7 @@ fn H(U:! type, c: Class(U)) -> U {
// CHECK:STDOUT: %complete_type.loc13_1.2 => constants.%complete_type.5
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Class(@H.%U.loc23_6.2) {
// CHECK:STDOUT: %T.loc11_13.2 => constants.%U
// CHECK:STDOUT: %T.patt.loc11_13.2 => constants.%U
// CHECK:STDOUT: }
// CHECK:STDOUT: specific @Class(@H.%U.loc23_6.2) {}
// CHECK:STDOUT:
// CHECK:STDOUT: specific @H(constants.%U) {
// CHECK:STDOUT: %U.loc23_6.2 => constants.%U
Expand Down
Loading

0 comments on commit b25117b

Please sign in to comment.