This question is somewhere between swift-dev and swift-users, not sure where 
best to post this.  

I’m working on a project that wants to get very low-abstraction penalty array 
operations, particularly with varargs.  Given the currently language 
limitations (no fixed size arrays), the best I’ve been able to come up with is 
something like this, where “lowlevelAPI” contains the heavy lifting (and is 
assumed to be opaque), and the “safeAPI” wrappers exist merely to provide a 
convenient safe wrapper for clients:

Attachment: array_abstraction.swift
Description: Binary data


Given whole module optimization of the program, we should in principle, be able 
to optimize this down to the equivalent of an LLVM array alloca in the clients, 
a few stores to it, then passing the pointers to the LLVM alloca into 
lowlevelAPI.  However, Swift is not doing this, not even with:

$ swiftc array_abstraction.swift -emit-sil -o - -O 

In this trivial case (with constant initializers) it does do the “array 
outlining” optimization, but this is no where near the abstraction level it 
could be.

Is there a better way to achieve this, and if not, is there any planned work 
(perhaps aligned with the ABI stability efforts) to improve vararg array 
performance to be able to avoid heap abstractions?  Any individual call to a 
vararg array is a known length, so it is a perfect candidate for a stack 
allocation.

-Chris


_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

Reply via email to