Hi! I’m really excited to see Swift moving in this direction! I hope this is just the beginning and we endup getting more powerful metaprogramming capabilties. Some questions and comments ahead (be aware I’m not an expert on this topic, just a big fan of it ^^):
-
Usage of metaprogramming: One concern I have is the thinking that this is not gonna be widely used. Even if that may seem true now I think that if the system is good enough it will open new possibilites for Swift developers. Examples of this is how Sourcery opened a new world of code generation in Swift; or if you follow J. Blow streams you can see how even his team is discovering new uses of metaprogramming on their projects thanks to Jai capabilities. (thanks @Tino for the link with Jai information)
-
Does the current idea of the directive imply that the function is ONLY used at compile time?. Because it may be really useful to just allow the same code to run at compile and/or run time.
-
The attribute: is there any reason to not flip the behaviour so the checks of compile time execution happen at the call site? Like Jai does with the #run directive. I agree that for cross module boundaries a directive is needed but I wonder if we can reduce the burden of annotating code in your same module.
-
Reading the last alternative (Fully compile the expressions and evaluate them on the machine) I understand why that exact alternative is not desirable but I don’t fully understand the current direction.
Is the goal to have a full Swift interpreter? If that’s not the case I'm worried that the usage of this feature is gonna be weird with the usage of a strange derivate of Swift.
How hard would be to keep it in sync with future language evolution proposals? Is there anything stoping Swift to copy the mentioned feature from Jai and run any Swift code at compile time? (obviously in practice it may not be easy, just wondering if that’s the future plan)
Wouldn’t a full Swift interpreter also help in other dynamic scenarios like JIT or just as a plain interpreter? -
The proposal mentions a future direction with Values in generics and improvements in Static Strings. But what about other metaprogramming features like rust-like macros, or directly being able to create/manipulate/generate code via AST nodes or textual strings. Are these features in any way related to this piece of work or completely unrelated, or are they even feasible in Swift?
Sorry for the long post, I've been thinking about this for a long time now (wow my first post is old! Run Swift code at compile time) and I'm really excited to see some movement around this ^^