apple / apple/swift-atomics

Add support for `@_noLocks` and `@_noAllocation` Swift attributes

Open
#63 5 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Swift
Stars
1.2k
Forks
63
PR merge metrics
No merged PRs in 30d

Description

### Description
For real time programming the `@_noLocks` and `@_noAllocation` Swift attributes provide programmers with a convenient way of ensuring the safety of their code in a real time environment. Currently, when using these attributes with Swift Atomics, the following error message is generated.

Called function is not available in this module and can have unpredictable performance

### Steps to Reproduce
```
import Atomics

public struct WrappedInt {

private let wrappedInt = UnsafeAtomic.create(0)

@_noLocks
@_noAllocation
public func value() -> Int {
// ERROR: Called function is not available in this module and can have unpredictable performance
wrappedInt.load(ordering: .relaxed)
}
}
```

### Expected behavior
The `@_noLocks` and `@_noAllocation` attributes generate no errors indicating code is free from locks and allocations and may be suitable for execution within a real time environment.

### Actual behavior
The `@_noLocks` and `@_noAllocation` attributes generate errors indicating the code may contain locks or allocations and may be unsafe for execution within a real time environment.

### Environment
Swift 5.8 Dev Snapshot 2022-12-29

Contributor guide

Open the contributing guide

Research direction

Start with the Swift Atomics reproduction in the issue and verify the diagnostic under the stated Swift 5.8 development snapshot. Trace the atomic load used by the example and determine the project entry points involved in attribute checking. Done means both @_noLocks and @_noAllocation no longer report the shown errors for this usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.