Files
swift-mirror/test/Sema/raw_layout_parse.swift
Joe Groff aee071bf4e Introduce an experimental @_rawLayout attribute.
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.
2023-07-24 14:28:19 -07:00

30 lines
970 B
Swift

// RUN: %target-swift-frontend -enable-experimental-feature RawLayout -parse -verify %s
@_rawLayout(size: 4, alignment: 4)
struct Lock: ~Copyable {}
@_rawLayout(like: Int)
struct Lock2: ~Copyable {}
@_rawLayout(like: Optional<Int>)
struct Lock3: ~Copyable {}
@_rawLayout(like: T)
struct MyUnmanaged<T>: ~Copyable {}
@_rawLayout(likeArrayOf: T, count: 8)
struct SmallVectorBuf<T>: ~Copyable {}
@_rawLayout // expected-error{{expected '('}}
struct NoLayoutSpecified: ~Copyable {}
@_rawLayout() // expected-error{{expected 'size', 'like', or 'likeArrayOf' argument to @_rawLayout attribute}}
struct NoParamsSpecified: ~Copyable {}
@_rawLayout(size: 4) // expected-error{{expected alignment argument after size argument in @_rawLayout attribute}}
struct SizeWithoutAlignment: ~Copyable {}
@_rawLayout(likeArrayOf: Optional<Int>) // expected-error{{expected count argument after likeArrayOf argument in @_rawLayout attribute}}
struct ArrayWithoutSize: ~Copyable {}