[swift-evolution] [Planning][Request] "constexpr" for Swift 5
Alejandro Martinez
alexito4 at gmail.com
Mon Sep 4 13:31:42 CDT 2017
Sorry for jumping late into this,
about the topic of compile time execution, I raised it pretty much in
the beginning of Swift being open sourced and it stills pops in my
mind everytime I see Jonathan Blow use it in his language.
So for my own curiosity, how feasible it is for Swift to do it with
the current compiler pipeline (SIL, LLVM....)? And by that I mean
actually marking some function/file and letting it run at compile
time. Would it be posible for the compiler to interpret arbitrary
Swift code? It probably won't be easy but I just want to know if it's
closer to "it can be done" or "no way". From Blow's streams I know
that this probably would have to work by compiling everything it can
before interpreting the compile-time code which I don't know how Swift
would deal with it.
But ignoring that, I would be pretty happy if we could have things
like the ones mentioned (including a be able to do what Sourcery and
what the compiler with equatable/etc do in plain Swift).
Thanks
On Thu, Aug 10, 2017 at 1:10 PM, Tino Heth via swift-evolution
<swift-evolution at swift.org> wrote:
> 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
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
--
Alejandro Martinez
http://alejandromp.com
More information about the swift-evolution
mailing list