File: existential_shape_metadata.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (88 lines) | stat: -rw-r--r-- 4,235 bytes parent folder | download
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// RUN: %target-swift-frontend -emit-ir %s -swift-version 5 -disable-availability-checking | %IRGenFileCheck %s

// CHECK-LABEL: @"$sl26existential_shape_metadata2Q0_px1TRts_XPXGMq" = linkonce_odr hidden constant
// CHECK-SAME:  { i32 {{.*}}sub ([[INT]] ptrtoint (ptr @{{[0-9]+}} to [[INT]])
// CHECK-SAME:    i32 6400,
// CHECK-SAME:    i32 {{.*}} @"flat unique 26existential_shape_metadata2Q0_px1TAaBPRts_XP"
// CHECK-SAME:    i16 2, i16 2, i16 3, i16 0,
// CHECK-SAME:    i16 1, i16 0, i16 1, i16 0, i32 1,

// CHECK-LABEL: @"$sl26existential_shape_metadata2R033_881A0B6978EB4286E7CFF1E27030ACACLL_px1TRts_XPXG" = internal constant
// CHECK-SAME:  { i32 6400,
//   This could use a symbolic reference because this doesn't have to be uniqued.
// CHECK-SAME:    i32 {{.*}} @"flat unique 26existential_shape_metadata2R033_881A0B6978EB4286E7CFF1E27030ACACLL_px1TAabCLLPRts_XP"
// CHECK-SAME:    i16 2, i16 2, i16 3, i16 0,
// CHECK-SAME:    i16 1, i16 0, i16 1, i16 0, i32 1,

public protocol P0 {}
public protocol P1 {}

public protocol Q0<T> {
  associatedtype T
}
public protocol Q1<A> {
  associatedtype A
}
public protocol Q2<A, B>: Q1 {
  associatedtype A
  associatedtype B
}

private protocol R0<T> {
  associatedtype T
}

public struct B<T> {}
private struct C {}

// CHECK-LABEL: define{{.*}} @"$s26existential_shape_metadata12testConcrete
public func testConcrete() -> Any.Type {
  // CHECK: [[METADATA:%.*]] = call ptr @__swift_instantiateConcreteTypeFromMangledName(ptr @"$s26existential_shape_metadata2Q0_pSi1TAaBPRts_XPMD")
  // CHECK: ret ptr [[METADATA]]
  return (any Q0<Int>).self
}

//   Still the same shape with an application of a dependent type.
// CHECK-LABEL: define{{.*}} @"$s26existential_shape_metadata13testDependent
public func testDependent<T>(t: T.Type) -> Any.Type {
  // CHECK: [[ARGS:%.*]] = alloca [1 x ptr], align
  // CHECK: [[T0:%.*]] = getelementptr inbounds [1 x ptr], ptr [[ARGS]], i32 0, i32 0
  // CHECK: store ptr %T, ptr [[T0]], align
  // CHECK: [[METADATA:%.*]] = call ptr @swift_getExtendedExistentialTypeMetadata(ptr @"$sl26existential_shape_metadata2Q0_px1TRts_XPXGMq{{(\.ptrauth)?}}", ptr [[ARGS]])
  // CHECK: ret ptr [[METADATA]]
  return (any Q0<T>).self
}

//   Still the same shape with an application of a complex type.
// CHECK-LABEL: define{{.*}} @"$s26existential_shape_metadata22testComplexApplication
public func testComplexApplication<T>(t: T.Type) -> Any.Type {
  // CHECK: [[ARGS:%.*]] = alloca [1 x ptr], align
  // CHECK: [[T0:%.*]] = call swiftcc %swift.metadata_response @"$s26existential_shape_metadata1BVMa"([[INT]] 255, ptr %T)
  // CHECK: [[B_T:%.*]] = extractvalue %swift.metadata_response [[T0]], 0
  // CHECK: [[T0:%.*]] = getelementptr inbounds [1 x ptr], ptr [[ARGS]], i32 0, i32 0
  // CHECK: store ptr [[B_T]], ptr [[T0]], align
  // CHECK: [[METADATA:%.*]] = call ptr @swift_getExtendedExistentialTypeMetadata(ptr @"$sl26existential_shape_metadata2Q0_px1TRts_XPXGMq{{(\.ptrauth)?}}", ptr [[ARGS]])
  // CHECK: ret ptr [[METADATA]]
  return (any Q0<B<T>>).self
}

//   Private protocols make the shape private and unique.
// CHECK-LABEL: define{{.*}} @"$s26existential_shape_metadata12test_private
public func test_private<T>(t: T.Type) -> Any.Type {
  // CHECK: [[ARGS:%.*]] = alloca [1 x ptr], align
  // CHECK: [[T0:%.*]] = getelementptr inbounds [1 x ptr], ptr [[ARGS]], i32 0, i32 0
  // CHECK: store ptr %T, ptr [[T0]], align
  //   FIXME: this should be unique?
  // CHECK: [[METADATA:%.*]] = call ptr @swift_getExtendedExistentialTypeMetadata_unique(ptr @"$sl26existential_shape_metadata2R033_881A0B6978EB4286E7CFF1E27030ACACLL_px1TRts_XPXG{{(\.ptrauth)?}}", ptr [[ARGS]])
  // CHECK: ret ptr [[METADATA]]
  return (any R0<T>).self
}

//   Applying private arguments to a public protocol does not
//   change anything: the shape is still public.
// CHECK-LABEL: define{{.*}} @"$s26existential_shape_metadata23test_privateApplication
public func test_privateApplication<T>(t: T.Type) -> Any.Type {
  // CHECK: [[METADATA:%.*]] = call ptr @__swift_instantiateConcreteTypeFromMangledName(ptr @"$s26existential_shape_metadata2Q0_pAA1C33_881A0B6978EB4286E7CFF1E27030ACACLLV1TAaBPRts_XPMD")
  // CHECK: ret ptr [[METADATA]]
  return (any Q0<C>).self
}