Track and resolve the specific callee in a call to a generic function (#4395)

Add a new `specific_function` instruction that represents a generic
function plus its deduced argument list as a callee in a function call.
The new instruction can only appear as the immediate operand of a call
instruction, so we give it a builtin placeholder type.

At the end of each file, require definitions for all specific functions
used in that file. Resolve the generic with the argument list to produce
those specific function definitions as needed, and diagnose if the
generic doesn't have a definition available.

A few tests are updated in cases where they declared and used generic
functions but didn't previously provide a function definition.
This commit is contained in:
Richard Smith
2024-10-10 20:52:46 +00:00
committed by GitHub
parent bb874f21f7
commit 1a1bfd2eb2
35 changed files with 1761 additions and 528 deletions
+9 -2
View File
@@ -12,10 +12,17 @@ namespace Carbon::SemIR {
auto GetCalleeFunction(const File& sem_ir, InstId callee_id) -> CalleeFunction {
CalleeFunction result = {.function_id = FunctionId::Invalid,
.specific_id = SpecificId::Invalid,
.enclosing_specific_id = SpecificId::Invalid,
.resolved_specific_id = SpecificId::Invalid,
.self_id = InstId::Invalid,
.is_error = false};
if (auto specific_function =
sem_ir.insts().TryGetAs<SpecificFunction>(callee_id)) {
result.resolved_specific_id = specific_function->specific_id;
callee_id = specific_function->callee_id;
}
if (auto bound_method = sem_ir.insts().TryGetAs<BoundMethod>(callee_id)) {
result.self_id = bound_method->object_id;
callee_id = bound_method->function_id;
@@ -38,7 +45,7 @@ auto GetCalleeFunction(const File& sem_ir, InstId callee_id) -> CalleeFunction {
}
result.function_id = fn_type->function_id;
result.specific_id = fn_type->specific_id;
result.enclosing_specific_id = fn_type->specific_id;
return result;
}