mirror of
https://github.com/apple/swift.git
synced 2025-12-25 12:15:36 +01:00
Similarly to how we've always handled parameter types, we now recursively expand tuples in result types and separately determine a result convention for each result. The most important code-generation change here is that indirect results are now returned separately from each other and from any direct results. It is generally far better, when receiving an indirect result, to receive it as an independent result; the caller is much more likely to be able to directly receive the result in the address they want to initialize, rather than having to receive it in temporary memory and then copy parts of it into the target. The most important conceptual change here that clients and producers of SIL must be aware of is the new distinction between a SILFunctionType's *parameters* and its *argument list*. The former is just the formal parameters, derived purely from the parameter types of the original function; indirect results are no longer in this list. The latter includes the indirect result arguments; as always, all the indirect results strictly precede the parameters. Apply instructions and entry block arguments follow the argument list, not the parameter list. A relatively minor change is that there can now be multiple direct results, each with its own result convention. This is a minor change because I've chosen to leave return instructions as taking a single operand and apply instructions as producing a single result; when the type describes multiple results, they are implicitly bound up in a tuple. It might make sense to split these up and allow e.g. return instructions to take a list of operands; however, it's not clear what to do on the caller side, and this would be a major change that can be separated out from this already over-large patch. Unsurprisingly, the most invasive changes here are in SILGen; this requires substantial reworking of both call emission and reabstraction. It also proved important to switch several SILGen operations over to work with RValue instead of ManagedValue, since otherwise they would be forced to spuriously "implode" buffers.
64 lines
2.1 KiB
Plaintext
64 lines
2.1 KiB
Plaintext
// Test module for the specialize_cg_update_crash.sil test.
|
|
|
|
sil_stage canonical
|
|
|
|
import Builtin
|
|
|
|
func genlibfunc<X>(x: X) -> X
|
|
|
|
func genlibfunc2<X>(x: X) -> X
|
|
|
|
func genlibfunc3<X>(x: X) -> X
|
|
|
|
class MyClass {
|
|
init()
|
|
func mymethod<X>(x: X) -> X
|
|
deinit
|
|
}
|
|
|
|
sil @_TFC7TestMod7MyClassD : $@convention(method) (@owned MyClass) -> ()
|
|
sil @_TFC7TestMod7MyClasscfMS0_FT_S0_ : $@convention(method) (@owned MyClass) -> @owned MyClass
|
|
|
|
sil @_TF7TestMod11genlibfunc3urFq_q_ : $@convention(thin) <X> (@in X) -> @out X {
|
|
bb0(%0 : $*X, %1 : $*X):
|
|
%4 = tuple ()
|
|
return %4 : $()
|
|
}
|
|
|
|
sil @_TF7TestMod11genlibfunc2urFq_q_ : $@convention(thin) <X> (@in X) -> @out X {
|
|
bb0(%0 : $*X, %1 : $*X):
|
|
%3 = function_ref @_TF7TestMod11genlibfunc3urFq_q_ : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out τ_0_0
|
|
%9 = tuple ()
|
|
return %9 : $()
|
|
}
|
|
|
|
sil @_TFC7TestMod7MyClass8mymethodurfS0_Fq_q_ : $@convention(method) <X> (@in X, @guaranteed MyClass) -> @out X {
|
|
bb0(%0 : $*X, %1 : $*X, %2 : $MyClass):
|
|
%5 = function_ref @_TF7TestMod11genlibfunc3urFq_q_ : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out τ_0_0
|
|
%11 = tuple ()
|
|
return %11 : $()
|
|
}
|
|
|
|
// This is the critical function.
|
|
sil @_TF7TestMod10genlibfuncurFq_q_ : $@convention(thin) <X> (@in X) -> @out X {
|
|
bb0(%0 : $*X, %1 : $*X):
|
|
|
|
// First reference the method, which lets the method be deserialized, but not processed.
|
|
%x0 = function_ref @_TFC7TestMod7MyClass8mymethodurfS0_Fq_q_ : $@convention(method) <X> (@in X, @guaranteed MyClass) -> @out X
|
|
|
|
// Then reference the metatype which reads the vtable and processes the method.
|
|
// The bug was that during reading the vtable (and processing the vtable functions),
|
|
// the callback (to update the CG) was lost.
|
|
%x4 = metatype $@thick MyClass.Type
|
|
|
|
%17 = tuple ()
|
|
return %17 : $()
|
|
}
|
|
|
|
sil_vtable MyClass {
|
|
#MyClass.init!initializer.1: _TFC7TestMod7MyClasscfMS0_FT_S0_ // TestMod.MyClass.init (TestMod.MyClass.Type)() -> TestMod.MyClass
|
|
#MyClass.mymethod!1: _TFC7TestMod7MyClass8mymethodurfS0_Fq_q_ // TestMod.MyClass.mymethod <A> (TestMod.MyClass)(A) -> A
|
|
#MyClass.deinit!deallocator: _TFC7TestMod7MyClassD // TestMod.MyClass.__deallocating_deinit
|
|
}
|
|
|