Skip to content

@_noLocks doesn't work with Builtin.atomicload_{} #74407

@jcavar

Description

@jcavar

Description

The new Atomic type cannot be used with @_noLocks since a simple usage reports a violation. It seems that the issue is in the implementation of Atomic load and the use Builtin.atomicload_{} family of functions.

A simplified code sample is available below. Required settings:

swiftSettings: [
    .unsafeFlags(["-disable-availability-checking"]),
    .enableExperimentalFeature("StaticExclusiveOnly"),
    .enableExperimentalFeature("RawLayout"),
    .enableExperimentalFeature("BuiltinModule")
]

Reproduction

import Builtin

public struct MyAtomic: ~Copyable {
  var rawAddress: Builtin.RawPointer {
    Builtin.unprotectedAddressOfBorrow(self)
  }
}

extension MyAtomic {
  @_noLocks
  public func load(ordering: AtomicLoadOrdering) -> Int {
    let result = Builtin.atomicload_monotonic_Int64(rawAddress) // error: this code pattern can cause locking
    return 1
  }
}

Expected behavior

Atomic load doesn't cause locking and performance annotation doesn't report violation.

Environment

Apple Swift version 6.0-dev (LLVM 57177aa1b91540b, Swift 3889ede)
Target: arm64-apple-macosx14.0

Additional information

cc @eeckstein @Azoy

Metadata

Metadata

Assignees

No one assigned

    Labels

    @_noLocksFeature → attributes: The @_noLocks attributeSILattributesFeature: Declaration and type attributesbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfperformanceswift 6.0unexpected errorBug: Unexpected error

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions