Remove caching of return slot usage. (#4163)

The caching isn't buying us much, and is adding complexity and
divergence between the codepaths for generic and non-generic functions.

This means we no longer suppress diagnostics for the second or
subsequent time we call a function with an incomplete return type. If we
want to add that back, it might be worth considering moving the
suppression to `TryToCompleteType` and only diagnosing that a type is
incomplete once, regardless of why we're requiring it to be complete.
This commit is contained in:
Richard Smith
2024-07-25 20:29:59 +00:00
committed by GitHub
parent bf1106fc34
commit a9e835f3dc
14 changed files with 183 additions and 192 deletions
+16
View File
@@ -51,4 +51,20 @@ auto Function::GetDeclaredReturnType(const File& file,
file.insts().Get(return_storage_id).type_id());
}
auto ReturnInfo::ForType(const File& file, TypeId type_id) -> ReturnInfo {
if (!type_id.is_valid()) {
// Implicit `-> ()` has no return slot.
return {.type_id = type_id, .return_slot = ReturnSlot::Absent};
}
if (!file.types().IsComplete(type_id)) {
return {.type_id = type_id, .return_slot = ReturnSlot::Incomplete};
}
return {.type_id = type_id,
.return_slot = GetInitRepr(file, type_id).has_return_slot()
? SemIR::ReturnSlot::Present
: SemIR::ReturnSlot::Absent};
}
} // namespace Carbon::SemIR