Commits

Slava Pestov committed e1f0f024808
SILGen: Three-parameter re-abstraction thunks Right now, re-abstraction thunks are set up to convert values as follows, where L is type lowering: - OrigToSubst: L(origType, substType) -> L(substType) - SubstToOrig: L(substType) -> L(origType, substType) This assumes there's no AST-level type conversion, because when we visit a type in contravariant position, we flip the direction of the transform but we're still converting *to* substType -- which will now equal to the type of the input, not the type of the expected result! This caused several problems: - VTable thunk generation had a bunch of special logic to compute a substOverrideType, and wrap the thunk result in an optional, duplicating work done in the transform - Witness thunk generation similarly had to handle the case of upcasting to a base class to call the witness, and casting the result of materializeForSet back to the right type for properties defined on the base. Now the materializeForSet cast sequence is a bit longer, we unpack the returned tuple and do a convert_function on the function, then pack it again -- before we would unchecked_ref_cast the tuple, which is technically incorrect since the tuple is not a ref, but IRGen didn't seem to care... To handle the conversions correctly, we add a third AST type parameter to a transform, named inputType. Now, transforms perform these conversions: - OrigToSubst: L(origType, inputType) -> L(substType) - SubstToOrig: L(inputType) -> L(origType, substType) When we flip the direction of the transform while visiting types in contravariant position, we also swap substType with inputType. Note that this is similar to how bridging thunks work, for the same reason -- bridging thunks convert between AST types. This is mostly just a nice cleanup that fixes some obscure corner cases for now, but this functionality will be used in a subsequent patch. Swift SVN r31486