[swift-evolution] [Planning][Request] "constexpr" for Swift 5
gor.f.gyolchanyan at icloud.com
Mon Jul 31 04:25:02 CDT 2017
> On Jul 31, 2017, at 12:16 PM, Tino Heth <2th at gmx.de> wrote:
>> OTOH, if the compiler can prove that a local array is never resized, why *shouldn't* it get all the benefits of a fixed-sized array without having to use a special syntax? Put another way, why shouldn't fixed-size be one of those optional attributes for arrays, like ownership will be for variables, that users can opt into for more performance but is otherwise automatically worked out by the compiler?
> I think it's a good idea in general, but I don't think I'd notice if this feature would exist, so just to save some work for the compiler (and Core), I'd prefer to first get the feature itself, and improve it later.
> So from my high-level perspective, I think the order should be
> 0) Add support for value literals as generic parameters
Value literals would be limited to the ones accepted by ExpressibleBy*Literal, which would be very limiting for anything that isn't an Int or a Float. This might solve the specific case of fixed-size arrays, but otherwise would be nearly useless.
> 1) Add Array<T, size: UInt>
> 2) Add support for generic parameters that are evaluated at compile time
> 3) Make everything fast ;-)
> n) Add useful additions like detecting arrays that aren't declared as fixed length, but could
> I think the alternative to macros (don't care much how hygienic they are ;-) could be even more beneficial, but it's a topic that stands on its own (not sure wether this thread is more for fixed size arrays or metaprogramming… ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution