Initial support for return forms (#6556)

The main changes here are:
- Introducing `InitForm` and `RefForm` to represent initializing and
reference forms (the two return forms currently supported by the
parser).
- Introducing the `FormType` singleton inst to represent their type
(i.e. `Core.Form`).
- Emitting an inst representing a function's declared return form as
part of handling the function signature.

The return form inst is currently ignored. Subsequent PRs will expose it
in `SemIR::Function` and use it to determine the form of call
expressions.
This commit is contained in:
Geoff Romer
2026-01-07 00:54:18 +00:00
committed by GitHub
parent 444c18dfa3
commit 505b1c86b9
225 changed files with 4164 additions and 2583 deletions
@@ -75,6 +75,7 @@ fn G() -> str {
// CHECK:STDOUT: %ptr.85f: type = ptr_type %str.ee0 [concrete]
// CHECK:STDOUT: %Consume__carbon_thunk.type: type = fn_type @Consume__carbon_thunk [concrete]
// CHECK:STDOUT: %Consume__carbon_thunk: %Consume__carbon_thunk.type = struct_value () [concrete]
// CHECK:STDOUT: %.a70: form = init_form %str.ee0, call_param0 [concrete]
// CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
// CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
// CHECK:STDOUT: %Produce.cpp_overload_set.type: type = cpp_overload_set_type @Produce.cpp_overload_set [concrete]
@@ -109,6 +110,7 @@ fn G() -> str {
// CHECK:STDOUT: %return.patt: %pattern_type.461 = return_slot_pattern [concrete]
// CHECK:STDOUT: %return.param_patt: %pattern_type.461 = out_param_pattern %return.patt, call_param0 [concrete]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %.loc13_11: form = init_form constants.%str.ee0, call_param0 [concrete = constants.%.a70]
// CHECK:STDOUT: %return.param: ref %str.ee0 = out_param call_param0
// CHECK:STDOUT: %return: ref %str.ee0 = return_slot %return.param
// CHECK:STDOUT: }
@@ -131,10 +133,10 @@ fn G() -> str {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
// CHECK:STDOUT: %Produce.ref: %Produce.cpp_overload_set.type = name_ref Produce, imports.%Produce.cpp_overload_set.value [concrete = constants.%Produce.cpp_overload_set.value]
// CHECK:STDOUT: %.loc13: ref %str.ee0 = splice_block %return {}
// CHECK:STDOUT: %addr: %ptr.85f = addr_of %.loc13
// CHECK:STDOUT: %.loc13_8: ref %str.ee0 = splice_block %return {}
// CHECK:STDOUT: %addr: %ptr.85f = addr_of %.loc13_8
// CHECK:STDOUT: %Produce__carbon_thunk.call: init %empty_tuple.type = call imports.%Produce__carbon_thunk.decl(%addr)
// CHECK:STDOUT: %.loc14: init %str.ee0 = in_place_init %Produce__carbon_thunk.call, %.loc13
// CHECK:STDOUT: %.loc14: init %str.ee0 = in_place_init %Produce__carbon_thunk.call, %.loc13_8
// CHECK:STDOUT: return %.loc14 to %return
// CHECK:STDOUT: }
// CHECK:STDOUT: