Implement correctly overriding dependent virtual functions (#5804)

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
David Blaikie
2025-07-17 16:14:50 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent 9f67fa4b0f
commit 3bf98e9bc2
5 changed files with 1295 additions and 33 deletions
+25
View File
@@ -64,6 +64,31 @@ auto GetCalleeFunction(const File& sem_ir, InstId callee_id,
return result;
}
auto DecomposeVirtualFunction(const File& sem_ir, InstId fn_decl_id,
SpecificId base_class_specific_id)
-> DecomposedVirtualFunction {
// Remap the base's vtable entry to the appropriate constant usable in
// the context of the derived class (for the specific for the base
// class, for instance).
fn_decl_id = sem_ir.constant_values().GetInstId(
GetConstantValueInSpecific(sem_ir, base_class_specific_id, fn_decl_id));
auto specific_id = SemIR::SpecificId::None;
auto callee_id = fn_decl_id;
if (auto specific_function =
sem_ir.insts().TryGetAs<SemIR::SpecificFunction>(fn_decl_id)) {
specific_id = specific_function->specific_id;
callee_id = specific_function->callee_id;
}
// Identify the function we're calling by its type.
auto fn_type_inst =
sem_ir.types().GetAsInst(sem_ir.insts().Get(callee_id).type_id());
return {.fn_decl_id = fn_decl_id,
.function_id = fn_type_inst.As<FunctionType>().function_id,
.specific_id = specific_id};
}
auto Function::GetParamPatternInfoFromPatternId(const File& sem_ir,
InstId pattern_id)
-> std::optional<ParamPatternInfo> {