[swift-dev] Value-result ABI for small trivial inouts
John McCall
rjmccall at apple.com
Fri Dec 18 11:35:56 CST 2015
> On Dec 17, 2015, at 11:09 PM, Slava Pestov via swift-dev <swift-dev at swift.org> wrote:
>> On Dec 17, 2015, at 3:34 PM, Joe Groff via swift-dev <swift-dev at swift.org> wrote:
>>
>> We currently always pass inout parameters indirectly, but it seems to me that for inout parameters that are of small trivial types like Int or CGSize, a value-result calling convention might always be preferable, and we might want to codify that in the stable ABI. Values of these types are likely to be SSAed, and the indirect convention forces memory traffic that would otherwise be unnecessary. On ARMv7 and ARM64, the argument and return register sets are the same, so a value-result convention is likely to be able to compile down to in-place operations on those registers, so it's a potential code size win too.
>>
>> (Value-result is not a clear win for nontrivial types, since it forces a load and retain onto the outermost caller that inouts a value in memory, since we can't invalidate the memory during the inout call. The extra retain would potentially defeat COW optimization. We have primitives like `isUniquelyReferenced` that depend on mutable references being in memory too.)
>
> This makes me wonder, are stores to inouts ever visible if a function throws?
I believe we do all writebacks right now on the throwing path because they’re just set up as cleanups. I think this is more-or-less a language guarantee, because if we were going to discard them, we’d need to at least explain *when* we do that, and I’m not sure there’s a user-meaningful criterion for that. Notably, we always have to call the callback for materializeForSet because otherwise we might leak or leave something pinned, which is clearly unacceptable.
We’re definitely not going to go all the way and formalize a model where a throw “reverses the transaction” by discarding all writes to inout variables.
John.
More information about the swift-dev
mailing list