From ae5d1efd13da8c7d1a1aa6cc6fc9b377990ff897 Mon Sep 17 00:00:00 2001 From: Geoff Romer Date: Mon, 5 Oct 2026 20:40:16 +0000 Subject: [PATCH] Rename CalleeFunctionInfo to clarify its narrow applicability (#7899) As requested in the review of #7834. --- toolchain/check/cpp/import.cpp | 22 +++++++++---------- toolchain/check/cpp/thunk.cpp | 40 +++++++++++++++++----------------- toolchain/check/cpp/thunk.h | 16 +++++++------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/toolchain/check/cpp/import.cpp b/toolchain/check/cpp/import.cpp index d1de4b4e7334..bfb74616827f 100644 --- a/toolchain/check/cpp/import.cpp +++ b/toolchain/check/cpp/import.cpp @@ -1591,7 +1591,7 @@ static auto MakeParamPattern( // TODO: Consider refactoring to extract and reuse more logic from // `HandleAnyBindingPattern()`. static auto MakeParamPatternsBlockId(Context& context, SemIR::LocId loc_id, - const CalleeFunctionInfo& function_info) + const CppCalleeFunctionInfo& function_info) -> SemIR::InstBlockId { // The `self` parameter of a method is the first entry in the explicit // parameter list. Build it (if any) first, then the remaining explicit @@ -1682,7 +1682,7 @@ static auto MakeParamPatternsBlockId(Context& context, SemIR::LocId loc_id, // are treated as returning a class instance. // TODO: Support more return types. static auto GetReturnTypeExpr(Context& context, SemIR::LocId loc_id, - const CalleeFunctionInfo& function_info) + const CppCalleeFunctionInfo& function_info) -> Context::FormExpr { auto make_init_form = [&](SemIR::TypeInstId type_component_inst_id) { SemIR::InitForm inst = {.type_id = SemIR::FormType::TypeId, @@ -1749,7 +1749,7 @@ struct ReturnInfo { // and the returned return_type_inst_id will be `SemIR::ErrorInst::InstId`. // Constructors are treated as returning a class instance. static auto GetReturnInfo(Context& context, SemIR::LocId loc_id, - const CalleeFunctionInfo& function_info) + const CppCalleeFunctionInfo& function_info) -> ReturnInfo { auto [form_inst_id, type_inst_id, type_id] = GetReturnTypeExpr(context, loc_id, function_info); @@ -1825,7 +1825,7 @@ struct FunctionSignatureInsts { // signature to the Carbon function signature. static auto CreateFunctionSignatureInsts( Context& context, SemIR::LocId loc_id, - const CalleeFunctionInfo& function_info) + const CppCalleeFunctionInfo& function_info) -> std::optional { context.full_pattern_stack().StartExplicitParamList(); auto param_patterns_id = @@ -1859,7 +1859,7 @@ static auto CreateFunctionSignatureInsts( // Returns the Carbon function name for the given function. static auto GetFunctionName(Context& context, - const CalleeFunctionInfo& function_info) + const CppCalleeFunctionInfo& function_info) -> SemIR::NameId { clang::DeclarationName decl_name = function_info.decl_name; switch (decl_name.getNameKind()) { @@ -1899,7 +1899,7 @@ static auto GetFunctionName(Context& context, // * Have not been imported before. // * Be of supported type (ignoring parameters). static auto ImportFunction(Context& context, SemIR::LocId loc_id, - const CalleeFunctionInfo& function_info) + const CppCalleeFunctionInfo& function_info) -> std::optional { StartFunctionSignature(context); @@ -1991,7 +1991,7 @@ static auto ImportFunction(Context& context, SemIR::LocId loc_id, // `ImportFunction`), this builds a simple-ABI thunk that invokes the callee, // and defines the imported function as calling it. static auto DefineAsThunkCall(Context& context, SemIR::LocId loc_id, - const CalleeFunctionInfo& callee_info, + const CppCalleeFunctionInfo& callee_info, SemIR::Function& function) -> void { clang::FunctionDecl* thunk_clang_decl = BuildCppThunk(context, callee_info); if (thunk_clang_decl == nullptr) { @@ -2007,8 +2007,8 @@ static auto DefineAsThunkCall(Context& context, SemIR::LocId loc_id, SemIR::ClangDeclSignatureId thunk_signature_id = context.clang_decl_signatures().Add(std::move(thunk_signature)); - CalleeFunctionInfo thunk_callee_info(context, thunk_clang_decl, - thunk_signature_id); + CppCalleeFunctionInfo thunk_callee_info(context, thunk_clang_decl, + thunk_signature_id); auto thunk_decl_id = ImportFunction(context, loc_id, thunk_callee_info); if (thunk_decl_id == std::nullopt) { return; @@ -2056,7 +2056,7 @@ static auto ImportFunctionDecl(Context& context, SemIR::LocId loc_id, CARBON_CHECK(clang_decl->getFunctionType()->isFunctionProtoType(), "Not Prototype function (non-C++ code)"); - CalleeFunctionInfo callee_info(context, clang_decl, key.signature_id); + CppCalleeFunctionInfo callee_info(context, clang_decl, key.signature_id); auto function_decl_id = ImportFunction(context, loc_id, callee_info); if (!function_decl_id) { MarkFailedDecl(context, key); @@ -2143,7 +2143,7 @@ auto ImportFunctionPointerInvoke( builder.Note(loc_id, InCppFunctionPointerThunk); }); - CalleeFunctionInfo callee_info(context, info.clang_type); + CppCalleeFunctionInfo callee_info(context, info.clang_type); SemIR::ClangFunctionPointerTypeInfo result = { .clang_type = info.clang_type, .decl_id = SemIR::ErrorInst::InstId, diff --git a/toolchain/check/cpp/thunk.cpp b/toolchain/check/cpp/thunk.cpp index a21c00dc9b11..43060a2265cc 100644 --- a/toolchain/check/cpp/thunk.cpp +++ b/toolchain/check/cpp/thunk.cpp @@ -165,9 +165,9 @@ static auto IsSimpleAbiType(clang::ASTContext& ast_context, return false; } -CalleeFunctionInfo::CalleeFunctionInfo(Context& context, - clang::FunctionDecl* decl, - SemIR::ClangDeclSignatureId signature_id) +CppCalleeFunctionInfo::CppCalleeFunctionInfo( + Context& context, clang::FunctionDecl* decl, + SemIR::ClangDeclSignatureId signature_id) : decl(decl), decl_name(decl->getDeclName()), clang_loc(decl->getLocation()), @@ -197,8 +197,8 @@ CalleeFunctionInfo::CalleeFunctionInfo(Context& context, /*for_parameter=*/false); } -CalleeFunctionInfo::CalleeFunctionInfo(Context& context, - const clang::Type* function_pointer_type) +CppCalleeFunctionInfo::CppCalleeFunctionInfo( + Context& context, const clang::Type* function_pointer_type) : self_param_kind(SelfParamKind::FunctionPointer), decl(nullptr), decl_name(&context.ast_context().Idents.get("__invoke")), @@ -228,7 +228,7 @@ CalleeFunctionInfo::CalleeFunctionInfo(Context& context, signature = &context.clang_decl_signatures().Get(signature_id); } -auto CalleeFunctionInfo::GetCalleeParamIdentifier(int i) const +auto CppCalleeFunctionInfo::GetCalleeParamIdentifier(int i) const -> clang::IdentifierInfo* { switch (self_param_kind) { case SelfParamKind::FunctionPointer: @@ -238,7 +238,7 @@ auto CalleeFunctionInfo::GetCalleeParamIdentifier(int i) const } } -auto CalleeFunctionInfo::GetCalleeParamLocation(int i) const +auto CppCalleeFunctionInfo::GetCalleeParamLocation(int i) const -> clang::SourceLocation { switch (self_param_kind) { case SelfParamKind::FunctionPointer: @@ -248,8 +248,8 @@ auto CalleeFunctionInfo::GetCalleeParamLocation(int i) const } } -auto IsCppThunkRequired(Context& context, const CalleeFunctionInfo& callee_info) - -> bool { +auto IsCppThunkRequired(Context& context, + const CppCalleeFunctionInfo& callee_info) -> bool { auto* decl = cast(callee_info.decl); if (callee_info.signature->kind != SemIR::ClangDeclSignature::Normal || callee_info.signature->num_params != @@ -316,7 +316,7 @@ static auto GetThunkParameterType(clang::ASTContext& ast_context, // Creates the thunk parameter types given the callee function. static auto BuildThunkParameterTypes(clang::ASTContext& ast_context, - CalleeFunctionInfo callee_info) + CppCalleeFunctionInfo callee_info) -> llvm::SmallVector { llvm::SmallVector thunk_param_types; thunk_param_types.reserve(callee_info.num_thunk_params()); @@ -340,7 +340,7 @@ static auto BuildThunkParameterTypes(clang::ASTContext& ast_context, // Returns the thunk parameters using the callee function parameter identifiers. static auto BuildThunkParameters(clang::ASTContext& ast_context, - CalleeFunctionInfo callee_info, + CppCalleeFunctionInfo callee_info, clang::SourceLocation clang_loc, clang::FunctionDecl* thunk_function_decl) -> llvm::SmallVector { @@ -427,7 +427,7 @@ static auto GetDeclNameForThunk(clang::ASTContext& ast_context, // Returns the thunk function declaration given the callee function and the // thunk parameter types. static auto CreateThunkFunctionDecl( - Context& context, CalleeFunctionInfo callee_info, + Context& context, CppCalleeFunctionInfo callee_info, clang::SourceLocation clang_loc, llvm::ArrayRef thunk_param_types) -> clang::FunctionDecl* { clang::ASTContext& ast_context = context.ast_context(); @@ -506,7 +506,7 @@ static auto BuildThunkParamRef( // given callee parameter index. static auto BuildParamRefForCalleeArg(clang::Sema& sema, clang::FunctionDecl* thunk_function_decl, - CalleeFunctionInfo callee_info, + CppCalleeFunctionInfo callee_info, unsigned callee_index) -> clang::Expr* { unsigned thunk_index = callee_index + callee_info.callee_param_to_carbon_param_offset(); @@ -520,7 +520,7 @@ static auto BuildParamRefForCalleeArg(clang::Sema& sema, // the corresponding thunk parameters. static auto BuildCalleeArgs(clang::Sema& sema, clang::FunctionDecl* thunk_function_decl, - CalleeFunctionInfo callee_info) + CppCalleeFunctionInfo callee_info) -> llvm::SmallVector { llvm::SmallVector call_args; call_args.reserve(callee_info.num_callee_params - @@ -540,7 +540,7 @@ static auto BuildCalleeArgs(clang::Sema& sema, static auto BuildThunkBody(CppContext& cpp_context, clang::Sema& sema, clang::SourceLocation clang_loc, clang::FunctionDecl* thunk_function_decl, - CalleeFunctionInfo callee_info) + CppCalleeFunctionInfo callee_info) -> clang::StmtResult { // TODO: Consider building a CompoundStmt holding our created statement to // make our result more closely resemble a real C++ function. @@ -549,8 +549,8 @@ static auto BuildThunkBody(CppContext& cpp_context, clang::Sema& sema, // the callee. Otherwise, build a regular reference to the function. clang::ExprResult callee; switch (callee_info.self_param_kind) { - case CalleeFunctionInfo::SelfParamKind::ExplicitObjectParam: - case CalleeFunctionInfo::SelfParamKind::ImplicitObjectParam: { + case CppCalleeFunctionInfo::SelfParamKind::ExplicitObjectParam: + case CppCalleeFunctionInfo::SelfParamKind::ImplicitObjectParam: { clang::QualType object_param_type = cast(callee_info.decl) ->getFunctionObjectParameterReferenceType(); @@ -574,12 +574,12 @@ static auto BuildThunkBody(CppContext& cpp_context, clang::Sema& sema, clang::OK_Ordinary); break; } - case CalleeFunctionInfo::SelfParamKind::FunctionPointer: + case CppCalleeFunctionInfo::SelfParamKind::FunctionPointer: callee = BuildThunkParamRef(sema, thunk_function_decl, 0, callee_info.signature->self_passing_mode, callee_info.self_param_type); break; - case CalleeFunctionInfo::SelfParamKind::None: + case CppCalleeFunctionInfo::SelfParamKind::None: if (isa(callee_info.decl)) { break; } @@ -657,7 +657,7 @@ static auto BuildThunkBody(CppContext& cpp_context, clang::Sema& sema, return sema.ActOnExprStmt(placement_new, /*DiscardedValue=*/true); } -auto BuildCppThunk(Context& context, const CalleeFunctionInfo& callee_info) +auto BuildCppThunk(Context& context, const CppCalleeFunctionInfo& callee_info) -> clang::FunctionDecl* { // Build the thunk function declaration. auto thunk_param_types = diff --git a/toolchain/check/cpp/thunk.h b/toolchain/check/cpp/thunk.h index adaafbd0bb8e..cfde765ad377 100644 --- a/toolchain/check/cpp/thunk.h +++ b/toolchain/check/cpp/thunk.h @@ -22,11 +22,11 @@ namespace Carbon::Check { // Carbon. // - The Carbon function that is actually called by user code, and maps its // parameters to the simple ABI. -struct CalleeFunctionInfo { +struct CppCalleeFunctionInfo { // Constructs a CalleeFunctionInfo that represents the given C++ function with // the given signature. - explicit CalleeFunctionInfo(Context& context, clang::FunctionDecl* decl, - SemIR::ClangDeclSignatureId signature_id); + explicit CppCalleeFunctionInfo(Context& context, clang::FunctionDecl* decl, + SemIR::ClangDeclSignatureId signature_id); // Constructs a CalleeFunctionInfo that represents a C++ function pointer. // We treat function pointer types as having an `__invoke` method, with the @@ -36,8 +36,8 @@ struct CalleeFunctionInfo { // return types already have simple ABIs). The Carbon counterpart of this // method is real, however, and takes the pointer value as its `self` // parameter. - explicit CalleeFunctionInfo(Context& context, - const clang::Type* function_pointer_type); + explicit CppCalleeFunctionInfo(Context& context, + const clang::Type* function_pointer_type); // Returns the offset I such that callee parameter N corresponds to // parameter N+I of the imported Carbon function. @@ -167,13 +167,13 @@ struct CalleeFunctionInfo { // used to call it. A C++ thunk is required for functions whose ABI uses any // type except void, pointer and reference types, and signed 32-bit and 64-bit // integers. -auto IsCppThunkRequired(Context& context, const CalleeFunctionInfo& callee_info) - -> bool; +auto IsCppThunkRequired(Context& context, + const CppCalleeFunctionInfo& callee_info) -> bool; // Builds a C++ thunk with simple ABI (pointers, i32 and i64 types) that calls // the specified callee. Assumes `IsCppThunkRequired()` return true for // `callee_info`. Returns `nullptr` on failure. -auto BuildCppThunk(Context& context, const CalleeFunctionInfo& callee_info) +auto BuildCppThunk(Context& context, const CppCalleeFunctionInfo& callee_info) -> clang::FunctionDecl*; // Builds a call to a thunk function that forwards a call argument list built