forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexistential_metatypes.swift
49 lines (40 loc) · 1.82 KB
/
existential_metatypes.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
45
46
47
48
49
// RUN: %target-swift-frontend -emit-ir -o - -primary-file %s | FileCheck %s
// REQUIRES: CPU=x86_64
// Currently, this can't be a SIL file because we don't parse
// conformances correctly.
protocol Kindable {
var kind: Int { get }
}
extension Int: Kindable {
var kind: Int { return 0 }
}
extension Float: Kindable {
var kind: Int { return 1 }
}
// CHECK: define hidden void @_TF21existential_metatypes5test0FT_T_()
// CHECK: [[V:%.*]] = alloca { %swift.type*, i8** }, align 8
func test0() {
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds { %swift.type*, i8** }, { %swift.type*, i8** }* [[V]], i32 0, i32 0
// CHECK-NEXT: store %swift.type* @_TMSi, %swift.type** [[T0]], align 8
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds { %swift.type*, i8** }, { %swift.type*, i8** }* [[V]], i32 0, i32 1
// CHECK-NEXT: store i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @_TWPSi21existential_metatypes8KindableS_, i32 0, i32 0), i8*** [[T0]], align 8
var v: Kindable.Type = Int.self
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds { %swift.type*, i8** }, { %swift.type*, i8** }* [[V]], i32 0, i32 0
// CHECK-NEXT: store %swift.type* @_TMSf, %swift.type** [[T0]], align 8
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds { %swift.type*, i8** }, { %swift.type*, i8** }* [[V]], i32 0, i32 1
// CHECK-NEXT: store i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @_TWPSf21existential_metatypes8KindableS_, i32 0, i32 0), i8*** [[T0]], align 8
v = Float.self
// CHECK-NEXT: ret void
}
// CHECK: define hidden void @_TF21existential_metatypes5test1FGSqPMPS_8Kindable__T_(i64, i64)
// CHECK: [[TYPE:%.*]] = inttoptr i64 %0 to %swift.type*
// CHECK: [[WITNESS:%.*]] = inttoptr i64 %1 to i8**
func use(t: Kindable.Type) {}
func test1(opt: Kindable.Type?) {
switch opt {
case .Some(let t):
use(t)
case .None:
break
}
}