mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-23 11:32:37 +00:00
Add support for -> auto deduced return types. (#7931)
The return type is deduced from the function's `return` statements (currently required to all have the same type), or from its first `returned var`. Calls to generic functions with deduced return types are not yet supported. When a function has a deduced return type, we defer the return type portion of the callee pattern match until deduction, and during deduction we extend the decl block and the pattern block with the return-related instructions. Conversions for `return expr;` statements are deferred until the return type has been deduced. The design requires that we take the common type of the returned types as the deduced return type, so we can't in general perform any conversions for returned expressions until we reach the end of the function. This is accomplished by inserting a `splice_block` where the conversions will go, and later updating that instruction to contain the conversion. Assisted-by: Claude Opus 5.5 via Antigravity
This commit is contained in:
1 parent
1c69fe3447
commit
bf5d2a2ace
41 files changed
+2631
-214
No files matched your search
@@ -9,8 +9,9 @@
|
||||
|
||||
namespace Carbon::Check {
|
||||
|
||||
auto PopNameComponent(Context& context, SemIR::InstId return_pattern_id)
|
||||
-> NameComponent {
|
||||
auto PopNameComponent(Context& context, SemIR::InstId return_pattern_id,
|
||||
bool has_return_specifier) -> NameComponent {
|
||||
CARBON_CHECK(has_return_specifier || !return_pattern_id.has_value());
|
||||
Parse::NodeId first_param_node_id = Parse::NoneNodeId();
|
||||
Parse::NodeId last_param_node_id = Parse::NoneNodeId();
|
||||
|
||||
@@ -49,8 +50,7 @@ auto PopNameComponent(Context& context, SemIR::InstId return_pattern_id)
|
||||
auto param_ranges = SemIR::Function::CallParamIndexRanges::Empty;
|
||||
auto pattern_block_id = SemIR::InstBlockId::None;
|
||||
if (param_patterns_id->has_value() ||
|
||||
implicit_param_patterns_id->has_value() ||
|
||||
return_pattern_id.has_value()) {
|
||||
implicit_param_patterns_id->has_value() || has_return_specifier) {
|
||||
auto results = CalleePatternMatch(context, *implicit_param_patterns_id,
|
||||
*param_patterns_id, return_pattern_id);
|
||||
call_param_patterns_id = results.call_param_patterns_id;
|
||||
|
||||
Reference in new issue
Block a user