[swift-dev] PR-9995: enable exclusivity runtime checks.

Andrew Trick atrick at apple.com
Thu Jun 1 18:47:45 CDT 2017

Hi swift-dev,

PR-9995 enables exclusivity runtime checks:

These checks catch violations of exclusivity that can't be discovered statically [0], printing the message:

"Simultaneous accesses to 0x*, but modification requires exclusive access."

The error message is followed by a backtrace and details on the source locations of the two conflicting accesses.

In Swift 3 mode, this runtime diagnostic is a warning. In Swift 4 mode it is an error, meaning the program aborts immediately after reporting the first failure.

To disable the runtime checks, use -enforce-exclusivity=unchecked, which enables static
checks only.

This feature is explained in the Swift evolution proposal: Enforce Exclusive Access to Memory:

Note that exclusivity is not yet fully enforced for noescape closures. The current checks are conservative in this respect. Enforcement will be strengthened to handle this case in the near future, pending review of the proposal ammendment: "Restrictions on recursive uses of non-escaping closures".

[0] dynamic exclusivity violation

struct MyStruct {
  var i: Int = 0

  mutating func mutateS(_ f: ()->Int) {
    i += f()

class MyClass {
  var s: MyStruct
  init() { s = MyStruct() }

func foo(_ o: MyClass) {
  o.s.mutateS({ o.s.i })


More information about the swift-dev mailing list