File: external-keypath.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 (76 lines) | stat: -rw-r--r-- 3,575 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
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -enable-library-evolution -emit-module -o %t/ExternalKeyPaths.swiftmodule -module-name ExternalKeyPaths %S/Inputs/ExternalKeyPaths.swift
// RUN: %target-swift-emit-silgen -swift-version 5 -I %t %s | %FileCheck %s

import ExternalKeyPaths

struct Local {
  var x: Int
  var y: String
}

// CHECK-LABEL: sil hidden [ossa] @{{.*}}16externalKeyPaths
func externalKeyPaths<T: Hashable, U>(_ x: T, _ y: U, _ z: Int) {
  // CHECK: keypath $WritableKeyPath<External<Int>, Int>, (root $External<Int>; {{.*}} external #External.property<Int>)
  _ = \External<Int>.property

  // CHECK: keypath $WritableKeyPath<External<Int>, Int>, (root $External<Int>; {{.*}} external #External.intProperty<Int>)
  _ = \External<Int>.intProperty

  // CHECK: keypath $WritableKeyPath<External<T>, T>, <τ_0_0, τ_0_1 where τ_0_0 : Hashable> (root $External<τ_0_0>; {{.*}} external #External.property<T>) <T, U> 
  _ = \External<T>.property

  // CHECK: keypath $WritableKeyPath<External<T>, Int>, <τ_0_0, τ_0_1 where τ_0_0 : Hashable> (root $External<τ_0_0>; {{.*}} external #External.intProperty<T>) <T, U>
  _ = \External<T>.intProperty

  // CHECK: keypath $WritableKeyPath<External<U>, U>, <τ_0_0, τ_0_1 where τ_0_0 : Hashable> (root $External<τ_0_1>; {{.*}} external #External.property<U>) <T, U>
  _ = \External<U>.property

  // CHECK: keypath $WritableKeyPath<External<U>, Int>, <τ_0_0, τ_0_1 where τ_0_0 : Hashable> (root $External<τ_0_1>; {{.*}} external #External.intProperty<U>) <T, U>
  _ = \External<U>.intProperty

  // CHECK: keypath $KeyPath<External<Int>, Int>, (root $External<Int>; {{.*}} external #External.subscript<Int, Int>) (%2)
  _ = \External<Int>.[z]

  // CHECK: keypath $KeyPath<External<T>, T>, <τ_0_0, τ_0_1 where τ_0_0 : Hashable> (root $External<τ_0_0>; {{.*}} external #External.subscript<T, T>) <T, U> ({{.*}})
  _ = \External<T>.[x]

  // CHECK: keypath $KeyPath<External<U>, U>, <τ_0_0, τ_0_1 where τ_0_0 : Hashable> (root $External<τ_0_1>; {{.*}} external #External.subscript<U, T>) <T, U> ({{.*}})
  _ = \External<U>.[x]

  // CHECK: keypath $KeyPath<External<Local>, Int>, <τ_0_0, τ_0_1 where τ_0_0 : Hashable> (
  // CHECK-SAME: root $External<Local>;
  // CHECK-SAME: external #External.subscript<Local, T>
  // CHECK-SAME: stored_property #Local.x : $Int) <T, U> ({{.*}})
  _ = \External<Local>.[x].x

  // CHECK: keypath $KeyPath<External<Local>, String>, <τ_0_0, τ_0_1 where τ_0_0 : Hashable> (
  // CHECK-SAME: root $External<Local>;
  // CHECK-SAME: external #External.subscript<Local, T>
  // CHECK-SAME: stored_property #Local.y : $String) <T, U> ({{.*}})
  _ = \External<Local>.[x].y

  // CHECK: keypath $KeyPath<ExternalEmptySubscript, Int>, (
  // CHECK-SAME: root $ExternalEmptySubscript;
  // CHECK-SAME: external #ExternalEmptySubscript.subscript
  _ = \ExternalEmptySubscript.[]

  // CHECK: keypath $KeyPath<External<Int>, Int>, (
  // CHECK-SAME: root $External<Int>;
  // CHECK-SAME: gettable_property
  // CHECK-SAME: external #External.privateSetProperty
  _ = \External<Int>.privateSetProperty

  // CHECK: keypath $KeyPath<External<Int>, Int>, (
  // CHECK-SAME: root $External<Int>;
  // CHECK-SAME: gettable_property
  // CHECK-SAME: external #External.subscript
  _ = \External<Int>.[privateSet: 0]
}

// CHECK-LABEL: sil hidden [ossa] @{{.*}}testProtocolRequirement
func testProtocolRequirement<T: ExternalProto>(_: T.Type) {
  // CHECK: keypath $WritableKeyPath<T, Int>,
  // CHECK-NOT: external #ExternalProto.protoReqt
  _ = \T.protoReqt
}