File: keypaths_objc.sil

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 (61 lines) | stat: -rw-r--r-- 2,216 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

// RUN: %empty-directory(%t)
// RUN: %{python} %utils/chex.py < %s > %t/keypaths_objc.sil
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-ir %t/keypaths_objc.sil | %FileCheck %t/keypaths_objc.sil --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
// REQUIRES: objc_interop

import Swift
import Foundation

class C: NSObject {
  @objc dynamic var x: NSString { get }
  @_hasStorage final var stored: Int
  override init()
}

sil_vtable C {}

sil @x_get : $@convention(keypath_accessor_getter) (@in_guaranteed C) -> @out NSString

// CHECK: [[KEYPATH_A:@keypath(\..*)?]] = private global
// --             computed, get-only, function-instantiated identifier
// CHECK-SAME: <i32 0x0200_0001>,
// CHECK-SAME: ptr [[SELECTOR_FN:@[A-Za-z0-9_.]+]] to

// CHECK: [[KEYPATH_B:@keypath(\..*)?]] = private global
// --             class mutable stored property with indirect offset
// CHECK-SAME: <i32 0x03fffffd>,
// CHECK-SAME: @"$s13keypaths_objc1CC6storedSivpWvd"

// CHECK-LABEL: define swiftcc void @objc_only_property()
sil @objc_only_property : $@convention(thin) () -> () {
entry:
  // CHECK: call ptr @swift_getKeyPath({{.*}} [[KEYPATH_A]]
  %a = keypath $KeyPath<C, NSString>, (objc "x"; root $C; gettable_property $NSString, id #C.x!getter.foreign, getter @x_get : $@convention(keypath_accessor_getter) (@in_guaranteed C) -> @out NSString)
  strong_retain %a : $KeyPath<C, NSString>
  unreachable
}

sil hidden @$s13keypaths_objc1CC1xSo8NSStringCvgTo : $@convention(objc_method) (@guaranteed C) -> NSString {
entry(%0 : $C):
  unreachable
}

sil hidden @$s13keypaths_objc1CCACycfcTo : $@convention(objc_method) (@objc_metatype C.Type) -> @owned C {
entry(%0 : $@objc_metatype C.Type):
  unreachable
}

// CHECK: define linkonce_odr hidden ptr [[SELECTOR_FN]]
// CHECK-NEXT: entry:
// CHECK-NEXT:   %1 = load {{.*}}selector(x)
// CHECK-NEXT:   ret ptr %1

// CHECK-LABEL: define swiftcc void @objc_stored_property()
sil @objc_stored_property : $@convention(thin) () -> () {
entry:
  // CHECK: call ptr @swift_getKeyPath({{.*}} [[KEYPATH_B]]
  %b = keypath $KeyPath<C, Int>, (objc "stored"; root $C; stored_property #C.stored : $Int)
  strong_retain %b : $KeyPath<C, Int>
  unreachable
}