diff --git a/toolchain/check/decl_name_stack.h b/toolchain/check/decl_name_stack.h index f1a09ffac19a..5e2cb2e3dc5c 100644 --- a/toolchain/check/decl_name_stack.h +++ b/toolchain/check/decl_name_stack.h @@ -106,7 +106,6 @@ class DeclNameStack { .pattern_block_id = name.pattern_block_id, .implicit_param_patterns_id = name.implicit_param_patterns_id, .param_patterns_id = name.param_patterns_id, - .call_params_id = name.call_params_id, .is_extern = is_extern, .extern_library_id = extern_library, .non_owning_decl_id = diff --git a/toolchain/check/global_init.cpp b/toolchain/check/global_init.cpp index a85a36f98190..f96403be2fc6 100644 --- a/toolchain/check/global_init.cpp +++ b/toolchain/check/global_init.cpp @@ -44,12 +44,12 @@ auto GlobalInit::Finalize() -> void { .pattern_block_id = SemIR::InstBlockId::Empty, .implicit_param_patterns_id = SemIR::InstBlockId::None, .param_patterns_id = SemIR::InstBlockId::Empty, - .call_params_id = SemIR::InstBlockId::Empty, .is_extern = false, .extern_library_id = SemIR::LibraryNameId::None, .non_owning_decl_id = SemIR::InstId::None, .first_owning_decl_id = SemIR::InstId::None}, - {.return_slot_pattern_id = SemIR::InstId::None, + {.call_params_id = SemIR::InstBlockId::Empty, + .return_slot_pattern_id = SemIR::InstId::None, .body_block_ids = {SemIR::InstBlockId::GlobalInit}}})); } diff --git a/toolchain/check/handle_function.cpp b/toolchain/check/handle_function.cpp index cf623c7979fe..ed5cb998ba64 100644 --- a/toolchain/check/handle_function.cpp +++ b/toolchain/check/handle_function.cpp @@ -178,6 +178,7 @@ static auto MergeFunctionRedecl(Context& context, // Track the signature from the definition, so that IDs in the body // match IDs in the signature. prev_function.MergeDefinition(new_function); + prev_function.call_params_id = new_function.call_params_id; prev_function.return_slot_pattern_id = new_function.return_slot_pattern_id; prev_function.self_param_id = new_function.self_param_id; } @@ -473,7 +474,8 @@ static auto BuildFunctionDecl(Context& context, auto function_info = SemIR::Function{name_context.MakeEntityWithParamsBase( name, decl_id, is_extern, introducer.extern_library), - {.return_slot_pattern_id = name.return_slot_pattern_id, + {.call_params_id = name.call_params_id, + .return_slot_pattern_id = name.return_slot_pattern_id, .virtual_modifier = virtual_modifier, .self_param_id = self_param_id}}; if (is_definition) { diff --git a/toolchain/check/import_cpp.cpp b/toolchain/check/import_cpp.cpp index fced18373eaa..83c833769a88 100644 --- a/toolchain/check/import_cpp.cpp +++ b/toolchain/check/import_cpp.cpp @@ -235,13 +235,13 @@ static auto ImportFunctionDecl(Context& context, SemIR::LocId loc_id, .pattern_block_id = SemIR::InstBlockId::Empty, .implicit_param_patterns_id = SemIR::InstBlockId::Empty, .param_patterns_id = SemIR::InstBlockId::Empty, - .call_params_id = SemIR::InstBlockId::Empty, .is_extern = false, .extern_library_id = SemIR::LibraryNameId::None, .non_owning_decl_id = SemIR::InstId::None, .first_owning_decl_id = decl_id, .definition_id = SemIR::InstId::None}, - {.return_slot_pattern_id = SemIR::InstId::None, + {.call_params_id = SemIR::InstBlockId::Empty, + .return_slot_pattern_id = SemIR::InstId::None, .virtual_modifier = SemIR::FunctionFields::VirtualModifier::None, .self_param_id = SemIR::InstId::None, .cpp_decl = clang_decl}}; diff --git a/toolchain/check/import_ref.cpp b/toolchain/check/import_ref.cpp index ebaab8a5388b..2e77045ab047 100644 --- a/toolchain/check/import_ref.cpp +++ b/toolchain/check/import_ref.cpp @@ -1230,7 +1230,6 @@ static auto GetIncompleteLocalEntityBase( .param_patterns_id = import_base.param_patterns_id.has_value() ? SemIR::InstBlockId::Empty : SemIR::InstBlockId::None, - .call_params_id = SemIR::InstBlockId::None, .is_extern = import_base.is_extern, .extern_library_id = extern_library_id, .non_owning_decl_id = import_base.non_owning_decl_id.has_value() @@ -1910,7 +1909,8 @@ static auto MakeFunctionDecl(ImportContext& context, // Start with an incomplete function. function_decl.function_id = context.local_functions().Add( {GetIncompleteLocalEntityBase(context, function_decl_id, import_function), - {.return_slot_pattern_id = SemIR::InstId::None, + {.call_params_id = SemIR::InstBlockId::None, + .return_slot_pattern_id = SemIR::InstId::None, .builtin_function_kind = import_function.builtin_function_kind}}); function_decl.type_id = GetFunctionType( diff --git a/toolchain/driver/testdata/compile/multifile_raw_and_textual_ir.carbon b/toolchain/driver/testdata/compile/multifile_raw_and_textual_ir.carbon index e390d3df58b6..95ec9d74eeba 100644 --- a/toolchain/driver/testdata/compile/multifile_raw_and_textual_ir.carbon +++ b/toolchain/driver/testdata/compile/multifile_raw_and_textual_ir.carbon @@ -36,7 +36,7 @@ fn B() { // CHECK:STDOUT: name_scope0: {inst: inst12, parent_scope: name_scope, has_error: false, extended_scopes: [], names: {name0: inst13}} // CHECK:STDOUT: entity_names: {} // CHECK:STDOUT: functions: -// CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, body: [inst_block5]} +// CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, call_params_id: inst_block_empty, body: [inst_block5]} // CHECK:STDOUT: classes: {} // CHECK:STDOUT: generics: {} // CHECK:STDOUT: specifics: {} @@ -117,7 +117,7 @@ fn B() { // CHECK:STDOUT: entity_names: // CHECK:STDOUT: entity_name0: {name: name1, parent_scope: name_scope1, index: -1, is_template: 0} // CHECK:STDOUT: functions: -// CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, body: [inst_block5]} +// CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, call_params_id: inst_block_empty, body: [inst_block5]} // CHECK:STDOUT: function1: {name: name1, parent_scope: name_scope1} // CHECK:STDOUT: classes: {} // CHECK:STDOUT: generics: {} diff --git a/toolchain/driver/testdata/compile/multifile_raw_ir.carbon b/toolchain/driver/testdata/compile/multifile_raw_ir.carbon index 8b74020f139a..7aab69b81ac4 100644 --- a/toolchain/driver/testdata/compile/multifile_raw_ir.carbon +++ b/toolchain/driver/testdata/compile/multifile_raw_ir.carbon @@ -36,7 +36,7 @@ fn B() { // CHECK:STDOUT: name_scope0: {inst: inst12, parent_scope: name_scope, has_error: false, extended_scopes: [], names: {name0: inst13}} // CHECK:STDOUT: entity_names: {} // CHECK:STDOUT: functions: -// CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, body: [inst_block5]} +// CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, call_params_id: inst_block_empty, body: [inst_block5]} // CHECK:STDOUT: classes: {} // CHECK:STDOUT: generics: {} // CHECK:STDOUT: specifics: {} @@ -97,7 +97,7 @@ fn B() { // CHECK:STDOUT: entity_names: // CHECK:STDOUT: entity_name0: {name: name1, parent_scope: name_scope1, index: -1, is_template: 0} // CHECK:STDOUT: functions: -// CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, body: [inst_block5]} +// CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, call_params_id: inst_block_empty, body: [inst_block5]} // CHECK:STDOUT: function1: {name: name1, parent_scope: name_scope1} // CHECK:STDOUT: classes: {} // CHECK:STDOUT: generics: {} diff --git a/toolchain/driver/testdata/compile/raw_and_textual_ir.carbon b/toolchain/driver/testdata/compile/raw_and_textual_ir.carbon index 44c4ee6f87cc..84d33bde4472 100644 --- a/toolchain/driver/testdata/compile/raw_and_textual_ir.carbon +++ b/toolchain/driver/testdata/compile/raw_and_textual_ir.carbon @@ -27,7 +27,7 @@ fn Foo(n: ()) -> ((), ()) { // CHECK:STDOUT: entity_names: // CHECK:STDOUT: entity_name0: {name: name1, parent_scope: name_scope, index: -1, is_template: 0} // CHECK:STDOUT: functions: -// CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, return_slot_pattern: inst27, body: [inst_block10]} +// CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, call_params_id: inst_block7, return_slot_pattern: inst27, body: [inst_block10]} // CHECK:STDOUT: classes: {} // CHECK:STDOUT: generics: {} // CHECK:STDOUT: specifics: {} diff --git a/toolchain/driver/testdata/compile/raw_ir.carbon b/toolchain/driver/testdata/compile/raw_ir.carbon index d54a2080fe08..118b0901e879 100644 --- a/toolchain/driver/testdata/compile/raw_ir.carbon +++ b/toolchain/driver/testdata/compile/raw_ir.carbon @@ -28,7 +28,7 @@ fn Foo[T:! type](n: T) -> (T, ()) { // CHECK:STDOUT: entity_name0: {name: name1, parent_scope: name_scope, index: 0, is_template: 0} // CHECK:STDOUT: entity_name1: {name: name2, parent_scope: name_scope, index: -1, is_template: 0} // CHECK:STDOUT: functions: -// CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, return_slot_pattern: inst30, body: [inst_block16]} +// CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, call_params_id: inst_block9, return_slot_pattern: inst30, body: [inst_block16]} // CHECK:STDOUT: classes: {} // CHECK:STDOUT: generics: // CHECK:STDOUT: generic0: {decl: inst34, bindings: inst_block12} diff --git a/toolchain/sem_ir/entity_with_params_base.h b/toolchain/sem_ir/entity_with_params_base.h index 162c00d0f4f6..8e25e9a9484a 100644 --- a/toolchain/sem_ir/entity_with_params_base.h +++ b/toolchain/sem_ir/entity_with_params_base.h @@ -47,7 +47,6 @@ struct EntityWithParamsBase { pattern_block_id = definition.pattern_block_id; implicit_param_patterns_id = definition.implicit_param_patterns_id; param_patterns_id = definition.param_patterns_id; - call_params_id = definition.call_params_id; definition_id = definition.definition_id; } @@ -112,21 +111,6 @@ struct EntityWithParamsBase { // pattern, a reference to the root pattern inst for that element. InstBlockId param_patterns_id; - // If this entity is a function, this block consists of references to the - // `AnyParam` insts that represent the function's `Call` parameters. The - // "`Call` parameters" are the parameters corresponding to the arguments that - // are passed to a `Call` inst, so they do not include compile-time - // parameters, but they do include the return slot. - // - // The parameters appear in declaration order: `self` (if present), then the - // explicit runtime parameters, then the return slot (which is "declared" by - // the function's return type declaration). This is not populated on imported - // functions, because it is relevant only for a function definition. - // - // TODO: Can this be moved to `Function`, since it is not applicable to other - // kinds of entities? - InstBlockId call_params_id; - // True if declarations are `extern`. bool is_extern; diff --git a/toolchain/sem_ir/function.h b/toolchain/sem_ir/function.h index 8ec7e558af10..99007207a105 100644 --- a/toolchain/sem_ir/function.h +++ b/toolchain/sem_ir/function.h @@ -21,6 +21,18 @@ struct FunctionFields { // The following members always have values, and do not change throughout the // lifetime of the function. + // This block consists of references to the `AnyParam` insts that represent + // the function's `Call` parameters. The "`Call` parameters" are the + // parameters corresponding to the arguments that are passed to a `Call` + // inst, so they do not include compile-time parameters, but they do include + // the return slot. + // + // The parameters appear in declaration order: `self` (if present), then the + // explicit runtime parameters, then the return slot (which is "declared" by + // the function's return type declaration). This is not populated on imported + // functions, because it is relevant only for a function definition. + InstBlockId call_params_id; + // A reference to the instruction in the entity's pattern block that depends // on all other pattern insts pertaining to the return slot pattern. This may // or may not be used by the function, depending on whether the return type @@ -72,6 +84,9 @@ struct Function : public EntityWithParamsBase, auto Print(llvm::raw_ostream& out) const -> void { out << "{"; PrintBaseFields(out); + if (call_params_id.has_value()) { + out << ", call_params_id: " << call_params_id; + } if (return_slot_pattern_id.has_value()) { out << ", return_slot_pattern: " << return_slot_pattern_id; }