Files
swift-mirror/test/Serialization/attr-rawlayout.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

19 lines
855 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -enable-experimental-feature RawLayout -emit-module-path %t/a.swiftmodule -module-name a %s
// RUN: llvm-bcanalyzer -dump %t/a.swiftmodule | %FileCheck --check-prefix BC-CHECK --implicit-check-not UnknownCode %s
// RUN: %target-swift-ide-test -print-module -module-to-print a -source-filename x -I %t | %FileCheck --check-prefix MODULE-CHECK %s
// BC-CHECK: <RawLayout_DECL_ATTR
// MODULE-CHECK: @_rawLayout(size: 5, alignment: 4) struct A_ExplicitSizeAlign
@_rawLayout(size: 5, alignment: 4)
struct A_ExplicitSizeAlign: ~Copyable {}
// MODULE-CHECK: @_rawLayout(like: T) struct B_Cell
@_rawLayout(like: T)
struct B_Cell<T>: ~Copyable {}
// MODULE-CHECK: @_rawLayout(likeArrayOf: T, count: 8) struct C_SmallVector
@_rawLayout(likeArrayOf: T, count: 8)
struct C_SmallVector<T>: ~Copyable {}