swift-llvm and swift-clang

When Apple released the apple/swift repository on GitHub, they also released apple/swift-llvm and apple/swift-clang. Why?


Apple's Swift fork of LLVM has only three sets of minor changes:

$3+ patron-only content

Details of swift-llvm's three major sets of changes.

I am a patronBecome a patron

All of these changes seem like they could be merged back into LLVM trunk. However, two of the three changes are related to APINotes and, as discussed below, it's not clear those will be pushed upstream.


Apple's Swift fork of Clang includes a much broader set of changes than the Swift fork of LLVM. Doug Gregor outlines these changes in an email to Clang's mailing list. Here's what I found:

1. APINotes

$3+ patron-only content

Details of what "APINotes" are, as well as where they're implemented in swift-clang.

I am a patronBecome a patron

2. Additional attributes

$3+ patron-only content

A list of additional Clang attributes defined in swift-clang.

I am a patronBecome a patron

3. Module shadowing…?

My first encounter with variable "shadowing" was from Python:

def foo():   # Defines function 'foo'
    return "foo"

foo = "bar"  # Function definition shadowed by variable
print(foo)   # => "bar"

In this case, the second definition of foo shadows the first.

Swift's Clang fork adds the ability to shadow Clang modules. Unlike Python definition shadowing, the first definition of a Clang module shadows the second.

In cases where implicit module imports end up importing two modules with the same name, this change allows you to specify -fmodule-map-file, in order to choose which specific copy of a module is imported.

So, why is this part of Swift's fork of Clang? I… actually have no idea. If you know, hit me up.

Further reading

If you're interested in the challenges involved in "living downstream" from a large project like LLVM, watch this session from last year's LLVM Developers' Meeting. You can see some ideas from that talk in action on Apple's LLVM and Clang forks. For example, an Automerger bot propogates changes from upstream LLVM into a staging branch, called upstream-with-swift.