mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
When making a direct call to a thunk, inline the call in SemIR. (#5642)
This preserves the constant values of the arguments to the thunk, which is important if the thunk requires conversion of an `IntLiteral` to some other type. This should become unnecessary once we have form support, but avoiding the indirection through a thunk function seems valuable even once that support is in place. To support this, track whether a function is a thunk on the Function object, and if so, what the callee of the thunk is. This information is also included in formatted SemIR when dumping the thunk.
This commit is contained in:
@@ -1841,9 +1841,7 @@ static auto MakeFunctionDecl(ImportContext& context,
|
||||
function_decl.function_id = context.local_functions().Add(
|
||||
{GetIncompleteLocalEntityBase(context, function_decl_id, import_function),
|
||||
{.call_params_id = SemIR::InstBlockId::None,
|
||||
.return_slot_pattern_id = SemIR::InstId::None,
|
||||
.special_function_kind = import_function.special_function_kind,
|
||||
.builtin_function_kind = import_function.builtin_function_kind}});
|
||||
.return_slot_pattern_id = SemIR::InstId::None}});
|
||||
|
||||
function_decl.type_id = GetFunctionType(
|
||||
context.local_context(), function_decl.function_id, specific_id);
|
||||
@@ -1928,6 +1926,24 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
|
||||
new_function.definition_id = new_function.first_owning_decl_id;
|
||||
}
|
||||
|
||||
switch (import_function.special_function_kind) {
|
||||
case SemIR::Function::SpecialFunctionKind::None: {
|
||||
break;
|
||||
}
|
||||
case SemIR::Function::SpecialFunctionKind::Builtin: {
|
||||
new_function.SetBuiltinFunction(import_function.builtin_function_kind());
|
||||
break;
|
||||
}
|
||||
case SemIR::Function::SpecialFunctionKind::Thunk: {
|
||||
auto entity_name_id = resolver.local_entity_names().AddCanonical(
|
||||
{.name_id = new_function.name_id,
|
||||
.parent_scope_id = new_function.parent_scope_id});
|
||||
new_function.SetThunk(AddImportRef(
|
||||
resolver, import_function.thunk_decl_id(), entity_name_id));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ResolveResult::Done(function_const_id, new_function.first_decl_id());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user