Skip to content

[WIP] Raw storage and locks/atomics prototype #67425

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

Merged
merged 1 commit into from
Jul 26, 2023

Conversation

jckarter
Copy link
Contributor

Strawman implementation of a @_rawLayout attribute that gives a noncopyable struct a layout consisting of inline raw memory it can mostly do as it pleases with. As a proof of concept, show how this can be used to implement a safe wrapper over os_unfair_lock that can be stored inline within a class or other move-only type without an additional allocation.

@jckarter jckarter force-pushed the raw-storage branch 2 times, most recently from bd03417 to 68ad1d5 Compare July 22, 2023 02:19
@jckarter
Copy link
Contributor Author

@swift-ci Please test

This attribute can be attached to a noncopyable struct to specify that its
storage is raw, meaning the type definition is (with some limitations)
able to do as it pleases with the storage. This provides a basis for
implementing types for things like atomics, locks, and data structures
that use inline storage to store conditionally-initialized values.
The example in `test/Prototypes/UnfairLock.swift` demonstrates the use
of a raw layout type to wrap Darwin's `os_unfair_lock` APIs, allowing
a lock value to be stored inside of classes or other types without
needing a separate allocation, and using the borrow model to enforce
safe access to lock-guarded storage.
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@xedin xedin removed their request for review July 25, 2023 22:48
@jckarter jckarter merged commit 705e317 into swiftlang:main Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants