forked from swiftlang/swift
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitwise-borrowable-generics.swift
44 lines (36 loc) · 1.01 KB
/
bitwise-borrowable-generics.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// RUN: %target-run-simple-swift(-enable-experimental-feature RawLayout)
// REQUIRES: executable_test
// REQUIRES: swift_feature_RawLayout
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime
// UNSUPPORTED: CPU=arm64e
import Synchronization
structNC<T>:~Copyable {varx:T}
@_rawLayout(like: T, movesAsLike)
structTest<T>:~Copyable {}
func isBitwiseBorrowable(_ type:any(~Copyable.Type))->Bool{
letmetadataPtr=unsafeBitCast(type,
to: UnsafePointer<UnsafePointer<UInt>>.self)
letflags=metadataPtr[-1][10]
return flags &0x0110_0000==0
}
func test(_ type:any(~Copyable.Type)){
print("\(isBitwiseBorrowable(type))")
}
protocol P:~Copyable {}
// CHECK: begin
print("begin")
// CHECK-NEXT: true
test(Int.self)
// CHECK-NEXT: true
test(Any.self)
// CHECK-NEXT: true
test(P.self)
// CHECK-NEXT: true
test(NC<Int>.self)
// CHECK-NEXT: true
test(NC<Any>.self)
// CHECK-NEXT: false
test(Test<Int>.self)
// CHECK-NEXT: false
test(Test<Any>.self)