Decouple PerformCallToFunction from ReturnTypeInfo (#6572)

`ReturnTypeInfo` is built around the assumption that a function call
results in exactly one initializing expression, but with `ref` returns
there may be zero, and in the future composite return forms will enable
there to be more than one. This change removes some usages of
`ReturnTypeInfo`, and restructures the calling code to be prepared for
multiple initializing returns.
This commit is contained in:
Geoff Romer
2026-01-09 23:04:54 +00:00
committed by GitHub
parent 9727c628c4
commit 87b4ca54e6
8 changed files with 65 additions and 55 deletions
+9 -5
View File
@@ -129,10 +129,13 @@ auto BuildReturnWithExpr(Context& context, SemIR::LocId loc_id,
const auto& function = GetCurrentFunctionForReturn(context);
auto returned_var_id = GetCurrentReturnedVar(context);
auto return_slot_id = SemIR::InstId::None;
auto return_info =
SemIR::ReturnTypeInfo::ForFunction(context.sem_ir(), function);
if (!return_info.type_id.has_value()) {
auto return_type_id = SemIR::TypeId::None;
if (function.return_type_inst_id.has_value()) {
return_type_id =
context.types().GetTypeIdForTypeInstId(function.return_type_inst_id);
}
if (!return_type_id.has_value()) {
CARBON_DIAGNOSTIC(
ReturnStatementDisallowExpr, Error,
"no return expression should be provided in this context");
@@ -148,8 +151,9 @@ auto BuildReturnWithExpr(Context& context, SemIR::LocId loc_id,
NoteReturnedVar(diag, returned_var_id);
diag.Emit();
expr_id = SemIR::ErrorInst::InstId;
} else if (!return_info.is_valid() ||
return_info.type_id == SemIR::ErrorInst::TypeId) {
} else if (!SemIR::InitRepr::ForType(context.sem_ir(), return_type_id)
.is_valid() ||
return_type_id == SemIR::ErrorInst::TypeId) {
// We already diagnosed that the return type is invalid. Don't try to
// convert to it.
expr_id = SemIR::ErrorInst::InstId;