[cfe-dev] Clang and Swift

David Chisnall via cfe-dev cfe-dev at lists.llvm.org
Sat Dec 5 04:14:58 PST 2015


On 3 Dec 2015, at 22:45, Douglas Gregor via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> * API Notes: This represents the bulk of the changes in the repository. API notes solve a not-uncommon problem: we invent some new Clang attribute that would be beneficial to add to some declarations in system headers (e.g., adding a ‘noreturn’ attribute to the C ‘exit’ function), but we can’t go around and fix all of the system headers everywhere. With API notes, we can write a separate YAML file that states that we want to add ‘noreturn’ to the ‘exit’ function: when we feed that YAML file into Clang as part of normal compilation (via a command-line option), Clang will add ‘noreturn’ to the ‘exit’ function when it parses the declaration of ‘exit’. Personally, I don’t like API notes—even with our optimizations, it’s inefficient in compile time and it takes the “truth” out of the headers—but I can see the wider use cases. If the Clang community wants this feature, I can prepare a proper proposal; if not, we’ll keep this code in the Swift clone of Clang and delete it if Swift ever stops needing it.

There are a few things that I’ve wanted to be able to put in some external store for language bridges (ownership semantics for pointers, array lengths).  It’s far easier to provide external metadata than to modify a third-party library’s sources.  Having some generic mechanism for doing this would be very useful.

More generally, I wonder if anyone on the Swift team would be interested in providing a stable external API for the bits of Clang’s CodeGen that you use?  This is something that would be very valuable to other languages.  

David




More information about the cfe-dev mailing list