[swift-evolution] Add wrappers for allocWithTailElems_{n} routines

Alexey Komnin interfere.work at gmail.com
Tue Dec 13 04:46:24 CST 2016

Hi everyone!

I really don't know whether you have discussed it before. So, here is the deal.

Currently, Builtin routines like allocWithTailElems_{n} not available
outside of stdlib. On the other hand, those routines are widely used
in implementation of containers: Array, Set, Dictionary and others.

On the other hand, some Builtin routines are wrapped by publicly
available operators and functions like unsafeBitCast, (==).
ManagedBuffer.create(minimumCapacity:) class method is just a wrapper
around call to allocWithTailElems_1 builtin function. So, it is
possible to implement some containers, like Deque or linked-list using
ManagedBuffer, but it's not enough if developer is going to implement
advanced data structures like OrderedSet, LRU-cache or something more

Instead, the developers are forced to use complex pointer arithmetic
with UnsafeRawPtr. My point is: I think the language must provide all
the available tools to build algorithms and data structures. First of
all, it should provide the tools used for stdlib implementation.

Could we make some ManagedBuffer-alike wrappers around
allocWithTailElems_{n} routines?

Alexey Komnin.

More information about the swift-evolution mailing list