mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-15 23:58:10 +00:00
Support calls to generic functions with deduced return types. (#7981)
When a deduced return type depends on the function's generic parameters, it's computed by the definition's eval block, so resolve the specific's definition at the call. Calling a specific during its own instantiation, before the point where its return type is deduced, is diagnosed like any other use of the function before its return type is known. Also allow exporting such functions to C++. Resolving such a specific from within a checked generic can perform template actions with symbolic arguments. Perform delayed actions in a discarded generic region so the instructions they create aren't attached to the generic being checked, and check that evaluating a specific doesn't add anything to an enclosing generic region. Assisted-by: Claude via Antigravity
This commit is contained in:
1 parent
6d80ceb58e
commit
0d3b606a56
14 files changed
+1679
-36
No files matched your search
@@ -1513,6 +1513,10 @@ auto ExportFunctionSpecializationToCpp(
|
||||
if (specific_id == SemIR::SpecificId::None) {
|
||||
return false;
|
||||
}
|
||||
if (!ResolveReturnTypeInSpecific(context, loc_id, target.function,
|
||||
specific_id)) {
|
||||
return false;
|
||||
}
|
||||
// This name is appended to the thunk name to disambiguate between
|
||||
// specializations.
|
||||
SemIR::Mangler m(context.sem_ir(), context.total_ir_count(),
|
||||
@@ -1576,10 +1580,11 @@ static auto ExportGenericFunctionToCpp(Context& context, SemIR::LocId loc_id,
|
||||
static auto ExportFunctionToCpp(Context& context, SemIR::LocId loc_id,
|
||||
SemIR::FunctionId callee_function_id)
|
||||
-> clang::NamedDecl* {
|
||||
if (const auto& callee = context.functions().Get(callee_function_id);
|
||||
callee.has_pending_deduced_return_type() ||
|
||||
(callee.has_deduced_return_type() && callee.generic_id.has_value())) {
|
||||
context.TODO(loc_id, "export of function with deduced return type");
|
||||
if (context.functions()
|
||||
.Get(callee_function_id)
|
||||
.has_pending_deduced_return_type()) {
|
||||
context.TODO(loc_id,
|
||||
"export of function before its return type is deduced");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user