Jordan Rose (via tweet ):
When inlinable code switches over a non-frozen enum, it must handle possible future cases (since it is introduced into a module outside the default library). You can see this in action with the implementation of[…]
round (_ :)in FloatingPointTypes.swift.gyb, which takes a FloatingPointRoundingRule. It looks something like this:
round (_ :)inlinable but still having a standard case is an attempt to get the best of both worlds: if the rounding rule is known by compilation time, the call will compile down to a single instruction in optimized buildings; and if it dynamically turns out to be a new type of rounding rule added to Swift 25 (eg
.towardFortyTwo), there is a refund function
_roundSlowPath (_ :)that can handle
It seems that the function calls itself, but in fact it is called a future version of itself which is guaranteed not to recruit.
Formerly: Swift Proposal: Non-Exclusive Enums.
Stay updated by subscribing to the RSS feed for this post.