[swift-evolution] [Planning][Request] "constexpr" for Swift 5

Tino Heth 2th at gmx.de
Thu Aug 10 07:10:03 CDT 2017


Imho this topic was much better than that other one ;-) — and I just realised that of metaprogramming build on top of reflection wasn't discussed in its own thread yet…
I fear "constexpr" is already burned, because people associate it with things like calculating Fibonacci numbers at compile time (which is kind of cool, but doesn't have much merit for most of us).

Right now, there is SE-185, which allows to synthesise Equatable and Hashable.
To do so, nearly 1500 lines of C++ are needed, and even if we assume that two thirds are comments and whitespace, it's still a big piece of code that could only be written by someone with deep knowledge about C++ and the Swift compiler.
Compile time metaprogramming could do the same, but in probably less than twenty lines of Swift that could be written rather easily by anyone who knows the language…

So to update my list of things that might be added, there are also some points that are already there and whose implementation could have been simplified drastically:
> - Forwarding of protocol conformance (Kotlin, for example, has this: When a member conforms to a protocol, you don't have to write a bunch of methods that just say "let my member do this")
> - init with reduced boilerplate
> - Subtyping for non-class types, including a "newtype" option
> - Property behaviours
- Equatable, Hashabable
- Encoding/Decoding

I still wonder that virtually no one else seems to be thrilled about the power of the idea… @gor.f.gyolchanyan would you like join an attempt to raise the attention?

- Tino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170810/2fb4c093/attachment.html>


More information about the swift-evolution mailing list