Design Priorities for the Swift 6 Language Mode

I've noticed previously that -enable-actor-data-race-checks is very blunt - it appears to add a preamble to literally every actor-isolated partial function, even when actor isolation should be able to be proven statically.

Will the implementation be improved to limit runtime checks, or is the plan to enable it as it currently is?

Example. Calling one @MainActor function from another @MainActor function:

Godbolt

@MainActor
func funcOne() async -> Int {
  funcTwo()
}

@MainActor
func funcTwo() -> Int {
  return 42
}

// Compiling with -O (no data race checks)

(1) suspend resume partial function for output.funcOne() async -> Swift.Int:
        push    rax
        mov     rdi, qword ptr [r14 + 16]
        call    swift_release@PLT
        mov     rax, qword ptr [r14 + 8]
        mov     edi, 42                     ; <-- The result
        pop     rcx
        jmp     rax

// Compiling with -O -enable-actor-data-race-checks

(1) suspend resume partial function for output.funcOne() async -> Swift.Int:
        push    r15
        push    rbx
        push    rax
        mov     rbx, qword ptr [r14 + 16]
        mov     r15, qword ptr [r14 + 32]
        mov     r13, rbx
        call    ($sScM6sharedScMvgZ)@PLT               ; static Swift.MainActor.shared.getter
        mov     r13, rax
        mov     rdi, rbx
        mov     rsi, r15
        call    ($sScA15unownedExecutorScevgTj)@PLT    ; dispatch thunk of Swift.Actor.unownedExecutor.getter
        mov     rbx, rax
        mov     r15, rdx
        mov     rdi, rax
        mov     rsi, rdx
        call    swift_task_isCurrentExecutor@PLT       ; runtime call
        test    al, 1
        jne     .LBB2_2
        lea     rdi, [rip + ".L.str.20.output/example.swift"]
        mov     esi, 20
        mov     ecx, 7
        mov     edx, 1
        mov     r8, rbx
        mov     r9, r15
        call    swift_task_reportUnexpectedExecutor@PLT
.LBB2_2:
        mov     rbx, qword ptr [r14 + 24]
        mov     rdi, r13
        call    swift_release@PLT
        mov     rdi, rbx
        call    swift_release@PLT
        mov     rax, qword ptr [r14 + 8]
        mov     edi, 42                     ; <-- The result
        add     rsp, 8
        pop     rbx
        pop     r15
        jmp     rax

I'd like to mention one thing that would help us develop a package ecosystem that is more robust: non-exhaustive enums. Even if just an option.

We also have a problem with packages that use non-standard language features (e.g. @_exported import, _modify, @inline(__always)). I hope that is also on the list of things to address when it comes to the long-term health of the package ecosystem.

7 Likes