Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for @_noLocks and @_noAllocation Swift attributes #63

Open
tcldr opened this issue Jan 5, 2023 · 4 comments
Open

Add support for @_noLocks and @_noAllocation Swift attributes #63

tcldr opened this issue Jan 5, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@tcldr
Copy link

tcldr commented Jan 5, 2023

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<Int>.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

@tcldr tcldr added the bug Something isn't working label Jan 5, 2023
@lorentey
Copy link
Member

It looks like these attributes have been present since 5.6, so we can safely add them once #67 lands.

@tcldr
Copy link
Author

tcldr commented Mar 17, 2023

Great, thanks, @lorentey !

@lorentey
Copy link
Member

Ah, @_noLocks and @_noAllocation require the -experimental-performance-annotations compiler flag. Unfortunately the package manager considers such flags "unsafe", so this package cannot use them. 😞

@tcldr
Copy link
Author

tcldr commented Mar 18, 2023

Of course - yes, forgot about that. Fingers-crossed they’ll lose their underscores soon. Will be a powerful tool for real-time stuff. Thanks for investigating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants