[swift-evolution] Proposal: allow arbitrary compile-time code execution

Steve Richey srichey at gowithfloat.com
Mon Feb 8 14:54:22 CST 2016


Based on the response, it seems like there's some interest, but the team wouldn't get to it until after Swift 3 at the earliest. Should I open a pull request to the swift-evolution repo to allow feedback and prevent duplicate proposals?

- Steve

From: <clattner at apple.com<mailto:clattner at apple.com>> on behalf of Chris Lattner <clattner at apple.com<mailto:clattner at apple.com>>
Date: Monday, February 8, 2016 at 1:13 PM
To: Steve Richey <srichey at gowithfloat.com<mailto:srichey at gowithfloat.com>>
Cc: "swift-evolution at swift.org<mailto:swift-evolution at swift.org>" <swift-evolution at swift.org<mailto:swift-evolution at swift.org>>
Subject: Re: [swift-evolution] Proposal: allow arbitrary compile-time code execution


On Feb 7, 2016, at 8:29 PM, Steve Richey via swift-evolution <swift-evolution at swift.org<mailto:swift-evolution at swift.org>> wrote:

It is not uncommon to want to run code at build time. Xcode solves this need by allowing "Build Phases", which are often shell scripts which handle compile-time tasks.

It may be beneficial to Swift developers, especially those who are not programming on platforms supported by Xcode, to handle compile-time tasks in a powerful and expressive language with which they are already familiar: Swift!

In short, I propose the addition of a `#run` expression that allows the execution of code at compile time. This syntax and concept are borrowed from the programming language Jai (https://sites.google.com/site/jailanguageprimer/#TOC-Arbitrary-Compile-Time-Code-Execution) but the syntax fits nicely with other special expression syntax in Swift such as `#available`, `#selector`, `#file`, and so on.

Something like this would definitely be interesting to build out.  We should investigate it post-Swift 3 in the context of a hygienic macro system.

-Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160208/7c27070b/attachment.html>


More information about the swift-evolution mailing list