Skip to content

add @available(*, noasync) attribute#4

Merged
lukaskollmer merged 1 commit intomainfrom
lukas/attributes
Jan 25, 2026
Merged

add @available(*, noasync) attribute#4
lukaskollmer merged 1 commit intomainfrom
lukas/attributes

Conversation

@lukaskollmer
Copy link
Member

@lukaskollmer lukaskollmer commented Jan 24, 2026

add @available(*, noasync) attribute

♻️ Current situation & Problem

changes the @ThreadLocal macro to annotate the get/set accessors it defines as @available(*, noasync).
the reason for this change is that the ThreadLocal mechanism completely does not work in async code, since any suspension point might result in the function switching to a different thread.
the reason why we weren't already doing this, is that i wasn't aware of the existence of this attribute.

⚙️ Release Notes

  • property accessors created via the @ThreadLocal macro now are marked as @available(*, noasync).

📚 Documentation

the fact that the mechanism shouldn't be used in async code already was explicitly documented

✅ Testing

no new tests; existing tests are adjusted
(i tried writing a test to check that a program that accesses an @ThreadLocal variable from an async function fails to compile, but as it turns out you can only test the output a macro will produce, but not for any downstream compilation errors...)

Code of Conduct & Contributing Guidelines

By creating and submitting this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

@lukaskollmer lukaskollmer self-assigned this Jan 24, 2026
@lukaskollmer lukaskollmer added the enhancement New feature or request label Jan 24, 2026
@codecov
Copy link

codecov bot commented Jan 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.88%. Comparing base (2600d76) to head (9e296f4).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main       #4   +/-   ##
=======================================
  Coverage   71.88%   71.88%           
=======================================
  Files           4        4           
  Lines          32       32           
=======================================
  Hits           23       23           
  Misses          9        9           
Files with missing lines Coverage Δ
Sources/ThreadLocal/ThreadLocal.swift 73.69% <ø> (ø)
Sources/ThreadLocalMacros/ThreadLocalMacro.swift 87.50% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2600d76...9e296f4. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lukaskollmer lukaskollmer merged commit 16704d1 into main Jan 25, 2026
14 of 15 checks passed
@lukaskollmer lukaskollmer deleted the lukas/attributes branch January 25, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments