Initial support for C++ function pointers (#7788)

This change introduces a new inst kind `CppFunctionPointerType`, which
represents an imported C++ function pointer that can be invoked from
Carbon (support for forming such a pointer from a Carbon function is in
a follow-up PR). This is implemented by treating the operation of
invoking a function pointer in C++ as if it were a call to an `__invoke`
method on the function pointer type, and extending the existing
function-import logic to support importing this fictitious method.

---------

Co-authored-by: Nicholas Bishop <nbishop@nbishop.net>
This commit is contained in:
Geoff Romer
2026-09-30 00:06:06 +00:00
committed by GitHub
co-authored by Nicholas Bishop
parent f65572a1e6
commit 12e1afeb15
41 changed files with 2030 additions and 200 deletions
+18 -4
View File
@@ -2888,10 +2888,24 @@ static auto TryEvalCall(EvalContext& outer_eval_context, SemIR::LocId loc_id,
static auto GetReturnStorageParamIndexRange(EvalContext& eval_context,
const SemIR::Callee& callee)
-> std::pair<int, int> {
if (const auto* callee_function =
std::get_if<SemIR::CalleeFunction>(&callee)) {
const auto& function =
eval_context.functions().Get(callee_function->function_id);
auto function_id = SemIR::FunctionId::None;
CARBON_KIND_SWITCH(callee) {
case CARBON_KIND(SemIR::CalleeFunction callee_function): {
function_id = callee_function.function_id;
break;
}
case CARBON_KIND(SemIR::CalleeCppFunctionPointer callee_function_ptr): {
function_id = eval_context.context()
.clang_function_pointer_types()
.Get(callee_function_ptr.function_type_id)
.function_id;
break;
}
default:
break;
}
if (function_id.has_value()) {
const auto& function = eval_context.functions().Get(function_id);
return {function.call_param_ranges.return_begin().index,
function.call_param_ranges.return_end().index};
}