mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add CallAction to allow deferring calls (#7682)
Calls with template callee or args can now be deferred via an
InstAction. This allows code like this to check:
```carbon
import Cpp inline '''
template<typename T>
struct C {};
''';
fn F(generic T: type) {
let unused c: Cpp.C(T) = Cpp.C(T).C();
}
```
This commit is contained in:
+59
-45
@@ -46,18 +46,21 @@ library "[[@TEST_NAME]]";
|
||||
// TODO: This should be valid.
|
||||
fn G(template N: i32) {
|
||||
//@dump-sem-ir-begin
|
||||
// CHECK:STDERR: fail_todo_init_template_dependent_bound.carbon:[[@LINE+8]]:35: error: cannot initialize array with dependent bound from a list of initializers [ArrayInitDependentBound]
|
||||
// CHECK:STDERR: fail_todo_init_template_dependent_bound.carbon:[[@LINE+4]]:35: error: cannot initialize array with dependent bound from a list of initializers [ArrayInitDependentBound]
|
||||
// CHECK:STDERR: var unused arr: array(i32, N) = (1, 2, 3);
|
||||
// CHECK:STDERR: ^~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_todo_init_template_dependent_bound.carbon:[[@LINE+4]]:3: error: value of type `<dependent type>` is not callable [CallToNonCallable]
|
||||
// CHECK:STDERR: var unused arr: array(i32, N) = (1, 2, 3);
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
var unused arr: array(i32, N) = (1, 2, 3);
|
||||
//@dump-sem-ir-end
|
||||
}
|
||||
|
||||
// CHECK:STDERR: fail_todo_init_template_dependent_bound.carbon:[[@LINE+7]]:10: error: unable to monomorphize specific `G(3)` [ResolvingSpecificHere]
|
||||
// CHECK:STDERR: fn H() { G(3); }
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR: fail_todo_init_template_dependent_bound.carbon:[[@LINE-7]]:3: note: value of type `<bound method>` is not callable [CallToNonCallable]
|
||||
// CHECK:STDERR: var unused arr: array(i32, N) = (1, 2, 3);
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
fn H() { G(3); }
|
||||
|
||||
|
||||
@@ -180,7 +183,7 @@ fn H() { G(3); }
|
||||
// CHECK:STDOUT: %N.patt.38a: %pattern_type.6b6 = symbolic_binding_pattern N, 0, template [template]
|
||||
// CHECK:STDOUT: %N.37f: %i32 = symbolic_binding N, 0, template [template]
|
||||
// CHECK:STDOUT: %i32.builtin: type = int_type signed, %int_32 [concrete]
|
||||
// CHECK:STDOUT: %.233: Core.IntLiteral = splice_inst @G.%.loc15_30.2 [template]
|
||||
// CHECK:STDOUT: %.233: Core.IntLiteral = splice_inst @G.%.loc11_30.2 [template]
|
||||
// CHECK:STDOUT: %array_type.3cc: type = array_type %.233, %i32 [template]
|
||||
// CHECK:STDOUT: %require_complete.2bf: <witness> = require_complete_type %array_type.3cc [template]
|
||||
// CHECK:STDOUT: %pattern_type.ed3: type = pattern_type %array_type.3cc [template]
|
||||
@@ -197,8 +200,9 @@ fn H() { G(3); }
|
||||
// CHECK:STDOUT: %Destroy.WithSelf.Op.42b: %Destroy.WithSelf.Op.type.d3e = struct_value () [symbolic]
|
||||
// CHECK:STDOUT: %Destroy.assoc_type: type = assoc_entity_type @Destroy [concrete]
|
||||
// CHECK:STDOUT: %assoc0.ae8: %Destroy.assoc_type = assoc_entity element0, imports.%Core.import_ref.918 [concrete]
|
||||
// CHECK:STDOUT: %.a09: %array_type.3cc = splice_inst @G.%.loc15_3.3 [template]
|
||||
// CHECK:STDOUT: %.b71: @G.%.loc15_3.6 (@G.%.loc15_3.6) = splice_inst @G.%.loc15_3.5 [template]
|
||||
// CHECK:STDOUT: %.a09: %array_type.3cc = splice_inst @G.%.loc11_3.4 [template]
|
||||
// CHECK:STDOUT: %.b71: @G.%.loc11_3.7 (@G.%.loc11_3.7) = splice_inst @G.%.loc11_3.6 [template]
|
||||
// CHECK:STDOUT: %.098: @G.%.loc11_3.10 (@G.%.loc11_3.10) = splice_inst @G.%.loc11_3.9 [template]
|
||||
// CHECK:STDOUT: %From: Core.IntLiteral = symbolic_binding From, 0 [symbolic]
|
||||
// CHECK:STDOUT: %ImplicitAs.type.7cb: type = facet_type <@ImplicitAs, @ImplicitAs(Core.IntLiteral)> [concrete]
|
||||
// CHECK:STDOUT: %Int.as.ImplicitAs.impl.Convert.type.48d: type = fn_type @Int.as.ImplicitAs.impl.Convert, @Int.as.ImplicitAs.impl(%From) [symbolic]
|
||||
@@ -231,7 +235,7 @@ fn H() { G(3); }
|
||||
// CHECK:STDOUT: %inst.as_compatible: <instruction> = inst_value [concrete] {
|
||||
// CHECK:STDOUT: %.723: ref %array_type.dc7 = as_compatible @G.%arr.var
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %Destroy.Op.type.1d8f74.3: type = fn_type @Destroy.Op.loc15_3.3 [concrete]
|
||||
// CHECK:STDOUT: %Destroy.Op.type.1d8f74.3: type = fn_type @Destroy.Op.loc11_3.3 [concrete]
|
||||
// CHECK:STDOUT: %Destroy.Op.1a2547.3: %Destroy.Op.type.1d8f74.3 = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %custom_witness.df9cc1.3: <witness> = custom_witness (%Destroy.Op.1a2547.3), @Destroy [concrete]
|
||||
// CHECK:STDOUT: %Destroy.facet.9a9: %Destroy.type = facet_value %array_type.dc7, (%custom_witness.df9cc1.3) [concrete]
|
||||
@@ -243,6 +247,9 @@ fn H() { G(3); }
|
||||
// CHECK:STDOUT: %bound_method.69b: <bound method> = bound_method %.723, %impl.elem0.ef2
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %inst.splice_block.edd: <instruction> = inst_value [concrete] {
|
||||
// CHECK:STDOUT: %.432: <error> = splice_block <error> [concrete = <error>] {}
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
@@ -255,52 +262,56 @@ fn H() { G(3); }
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !definition:
|
||||
// CHECK:STDOUT: %.loc15_30.2: <instruction> = convert_to_value_action %N.ref, Core.IntLiteral [template]
|
||||
// CHECK:STDOUT: %.loc15_30.3: Core.IntLiteral = splice_inst %.loc15_30.2 [template = %.loc15_30.3 (constants.%.233)]
|
||||
// CHECK:STDOUT: %array_type.loc15_31.2: type = array_type %.loc15_30.3, constants.%i32 [template = %array_type.loc15_31.2 (constants.%array_type.3cc)]
|
||||
// CHECK:STDOUT: %require_complete: <witness> = require_complete_type %array_type.loc15_31.2 [template = %require_complete (constants.%require_complete.2bf)]
|
||||
// CHECK:STDOUT: %pattern_type: type = pattern_type %array_type.loc15_31.2 [template = %pattern_type (constants.%pattern_type.ed3)]
|
||||
// CHECK:STDOUT: %arr.patt.loc15_17.2: @G.%pattern_type (%pattern_type.ed3) = ref_binding_pattern arr [template = %arr.patt.loc15_17.2 (constants.%arr.patt.515)]
|
||||
// CHECK:STDOUT: %arr.var_patt.loc15_3.2: @G.%pattern_type (%pattern_type.ed3) = var_pattern %arr.patt.loc15_17.2 [template = %arr.var_patt.loc15_3.2 (constants.%arr.var_patt.821)]
|
||||
// CHECK:STDOUT: %.loc15_3.3: <instruction> = refine_type_action %arr.var, %array_type.loc15_31.2 [template]
|
||||
// CHECK:STDOUT: %.loc15_3.4: @G.%array_type.loc15_31.2 (%array_type.3cc) = splice_inst %.loc15_3.3 [template = %.loc15_3.4 (constants.%.a09)]
|
||||
// CHECK:STDOUT: %.loc15_3.5: <instruction> = compound_member_access_action %.loc15_3.1, constants.%assoc0.ae8 [template]
|
||||
// CHECK:STDOUT: %.loc15_3.6: type = type_of_inst %.loc15_3.5 [template]
|
||||
// CHECK:STDOUT: %.loc15_3.7: @G.%.loc15_3.6 (@G.%.loc15_3.6) = splice_inst %.loc15_3.5 [template = %.loc15_3.7 (constants.%.b71)]
|
||||
// CHECK:STDOUT: %.loc11_30.2: <instruction> = convert_to_value_action %N.ref, Core.IntLiteral [template]
|
||||
// CHECK:STDOUT: %.loc11_30.3: Core.IntLiteral = splice_inst %.loc11_30.2 [template = %.loc11_30.3 (constants.%.233)]
|
||||
// CHECK:STDOUT: %array_type.loc11_31.2: type = array_type %.loc11_30.3, constants.%i32 [template = %array_type.loc11_31.2 (constants.%array_type.3cc)]
|
||||
// CHECK:STDOUT: %require_complete: <witness> = require_complete_type %array_type.loc11_31.2 [template = %require_complete (constants.%require_complete.2bf)]
|
||||
// CHECK:STDOUT: %pattern_type: type = pattern_type %array_type.loc11_31.2 [template = %pattern_type (constants.%pattern_type.ed3)]
|
||||
// CHECK:STDOUT: %arr.patt.loc11_17.2: @G.%pattern_type (%pattern_type.ed3) = ref_binding_pattern arr [template = %arr.patt.loc11_17.2 (constants.%arr.patt.515)]
|
||||
// CHECK:STDOUT: %arr.var_patt.loc11_3.2: @G.%pattern_type (%pattern_type.ed3) = var_pattern %arr.patt.loc11_17.2 [template = %arr.var_patt.loc11_3.2 (constants.%arr.var_patt.821)]
|
||||
// CHECK:STDOUT: %.loc11_3.4: <instruction> = refine_type_action %arr.var, %array_type.loc11_31.2 [template]
|
||||
// CHECK:STDOUT: %.loc11_3.5: @G.%array_type.loc11_31.2 (%array_type.3cc) = splice_inst %.loc11_3.4 [template = %.loc11_3.5 (constants.%.a09)]
|
||||
// CHECK:STDOUT: %.loc11_3.6: <instruction> = compound_member_access_action %.loc11_3.1, constants.%assoc0.ae8 [template]
|
||||
// CHECK:STDOUT: %.loc11_3.7: type = type_of_inst %.loc11_3.6 [template]
|
||||
// CHECK:STDOUT: %.loc11_3.8: @G.%.loc11_3.7 (@G.%.loc11_3.7) = splice_inst %.loc11_3.6 [template = %.loc11_3.8 (constants.%.b71)]
|
||||
// CHECK:STDOUT: %.loc11_3.9: <instruction> = call_action (%.loc11_3.2), true [template]
|
||||
// CHECK:STDOUT: %.loc11_3.10: type = type_of_inst %.loc11_3.9 [template]
|
||||
// CHECK:STDOUT: %.loc11_3.11: @G.%.loc11_3.10 (@G.%.loc11_3.10) = splice_inst %.loc11_3.9 [template = %.loc11_3.11 (constants.%.098)]
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: %arr.var: ref @G.%array_type.loc15_31.2 (%array_type.3cc) = var_storage %arr.var_patt.loc15_3.1
|
||||
// CHECK:STDOUT: %arr.var: ref @G.%array_type.loc11_31.2 (%array_type.3cc) = var_storage %arr.var_patt.loc11_3.1
|
||||
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
|
||||
// CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [concrete = constants.%int_2]
|
||||
// CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [concrete = constants.%int_3.1ba]
|
||||
// CHECK:STDOUT: %.loc15_43: %tuple.type = tuple_literal (%int_1, %int_2, %int_3) [concrete = constants.%tuple]
|
||||
// CHECK:STDOUT: %.loc11_43: %tuple.type = tuple_literal (%int_1, %int_2, %int_3) [concrete = constants.%tuple]
|
||||
// CHECK:STDOUT: assign %arr.var, <error>
|
||||
// CHECK:STDOUT: %.loc15_31: type = splice_block %array_type.loc15_31.1 [template = %array_type.loc15_31.2 (constants.%array_type.3cc)] {
|
||||
// CHECK:STDOUT: %i32.loc15: type = type_literal constants.%i32 [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %.loc11_31: type = splice_block %array_type.loc11_31.1 [template = %array_type.loc11_31.2 (constants.%array_type.3cc)] {
|
||||
// CHECK:STDOUT: %i32.loc11: type = type_literal constants.%i32 [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %N.ref: %i32 = name_ref N, %N.loc5_16.2 [template = %N.loc5_16.1 (constants.%N.37f)]
|
||||
// CHECK:STDOUT: %.loc15_30.1: Core.IntLiteral = splice_inst %.loc15_30.2 [template = %.loc15_30.3 (constants.%.233)]
|
||||
// CHECK:STDOUT: %array_type.loc15_31.1: type = array_type %.loc15_30.1, %i32.loc15 [template = %array_type.loc15_31.2 (constants.%array_type.3cc)]
|
||||
// CHECK:STDOUT: %.loc11_30.1: Core.IntLiteral = splice_inst %.loc11_30.2 [template = %.loc11_30.3 (constants.%.233)]
|
||||
// CHECK:STDOUT: %array_type.loc11_31.1: type = array_type %.loc11_30.1, %i32.loc11 [template = %array_type.loc11_31.2 (constants.%array_type.3cc)]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %arr: ref @G.%array_type.loc15_31.2 (%array_type.3cc) = wrapper_binding arr, %arr.var
|
||||
// CHECK:STDOUT: %arr: ref @G.%array_type.loc11_31.2 (%array_type.3cc) = wrapper_binding arr, %arr.var
|
||||
// CHECK:STDOUT: name_binding_decl {
|
||||
// CHECK:STDOUT: %arr.patt.loc15_17.1: @G.%pattern_type (%pattern_type.ed3) = ref_binding_pattern arr [template = %arr.patt.loc15_17.2 (constants.%arr.patt.515)]
|
||||
// CHECK:STDOUT: %arr.var_patt.loc15_3.1: @G.%pattern_type (%pattern_type.ed3) = var_pattern %arr.patt.loc15_17.1 [template = %arr.var_patt.loc15_3.2 (constants.%arr.var_patt.821)]
|
||||
// CHECK:STDOUT: %arr.patt.loc11_17.1: @G.%pattern_type (%pattern_type.ed3) = ref_binding_pattern arr [template = %arr.patt.loc11_17.2 (constants.%arr.patt.515)]
|
||||
// CHECK:STDOUT: %arr.var_patt.loc11_3.1: @G.%pattern_type (%pattern_type.ed3) = var_pattern %arr.patt.loc11_17.1 [template = %arr.var_patt.loc11_3.2 (constants.%arr.var_patt.821)]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %.loc15_3.1: @G.%array_type.loc15_31.2 (%array_type.3cc) = splice_inst %.loc15_3.3 [template = %.loc15_3.4 (constants.%.a09)]
|
||||
// CHECK:STDOUT: %.loc15_3.2: @G.%.loc15_3.6 (@G.%.loc15_3.6) = splice_inst %.loc15_3.5 [template = %.loc15_3.7 (constants.%.b71)]
|
||||
// CHECK:STDOUT: %.loc11_3.1: @G.%array_type.loc11_31.2 (%array_type.3cc) = splice_inst %.loc11_3.4 [template = %.loc11_3.5 (constants.%.a09)]
|
||||
// CHECK:STDOUT: %.loc11_3.2: @G.%.loc11_3.7 (@G.%.loc11_3.7) = splice_inst %.loc11_3.6 [template = %.loc11_3.8 (constants.%.b71)]
|
||||
// CHECK:STDOUT: %.loc11_3.3: @G.%.loc11_3.10 (@G.%.loc11_3.10) = splice_inst %.loc11_3.9 [template = %.loc11_3.11 (constants.%.098)]
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @Destroy.Op.loc15_3.1(%self.param: ref %i32.builtin) = "no_op";
|
||||
// CHECK:STDOUT: fn @Destroy.Op.loc11_3.1(%self.param: ref %i32.builtin) = "no_op";
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @Destroy.Op.loc15_3.2(%self.param: ref %i32) {
|
||||
// CHECK:STDOUT: fn @Destroy.Op.loc11_3.2(%self.param: ref %i32) {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @Destroy.Op.loc15_3.3(%self.param: ref %array_type.dc7) {
|
||||
// CHECK:STDOUT: fn @Destroy.Op.loc11_3.3(%self.param: ref %array_type.dc7) {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
@@ -315,17 +326,20 @@ fn H() { G(3); }
|
||||
// CHECK:STDOUT: %N.loc5_16.1 => constants.%int_3.410
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !definition:
|
||||
// CHECK:STDOUT: %.loc15_30.2 => constants.%inst.splice_block.ca0
|
||||
// CHECK:STDOUT: %.loc15_30.3 => constants.%int_3.1ba
|
||||
// CHECK:STDOUT: %array_type.loc15_31.2 => constants.%array_type.dc7
|
||||
// CHECK:STDOUT: %.loc11_30.2 => constants.%inst.splice_block.ca0
|
||||
// CHECK:STDOUT: %.loc11_30.3 => constants.%int_3.1ba
|
||||
// CHECK:STDOUT: %array_type.loc11_31.2 => constants.%array_type.dc7
|
||||
// CHECK:STDOUT: %require_complete => constants.%complete_type.b77
|
||||
// CHECK:STDOUT: %pattern_type => constants.%pattern_type.771
|
||||
// CHECK:STDOUT: %arr.patt.loc15_17.2 => constants.%arr.patt.316
|
||||
// CHECK:STDOUT: %arr.var_patt.loc15_3.2 => constants.%arr.var_patt.c63
|
||||
// CHECK:STDOUT: %.loc15_3.3 => constants.%inst.as_compatible
|
||||
// CHECK:STDOUT: %.loc15_3.4 => invalid
|
||||
// CHECK:STDOUT: %.loc15_3.5 => constants.%inst.splice_block.adf
|
||||
// CHECK:STDOUT: %.loc15_3.6 => <bound method>
|
||||
// CHECK:STDOUT: %.loc15_3.7 => invalid
|
||||
// CHECK:STDOUT: %arr.patt.loc11_17.2 => constants.%arr.patt.316
|
||||
// CHECK:STDOUT: %arr.var_patt.loc11_3.2 => constants.%arr.var_patt.c63
|
||||
// CHECK:STDOUT: %.loc11_3.4 => constants.%inst.as_compatible
|
||||
// CHECK:STDOUT: %.loc11_3.5 => invalid
|
||||
// CHECK:STDOUT: %.loc11_3.6 => constants.%inst.splice_block.adf
|
||||
// CHECK:STDOUT: %.loc11_3.7 => <bound method>
|
||||
// CHECK:STDOUT: %.loc11_3.8 => invalid
|
||||
// CHECK:STDOUT: %.loc11_3.9 => constants.%inst.splice_block.edd
|
||||
// CHECK:STDOUT: %.loc11_3.10 => <error>
|
||||
// CHECK:STDOUT: %.loc11_3.11 => <error>
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
|
||||
Reference in New Issue
Block a user