File: vtables_objc.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 (91 lines) | stat: -rw-r--r-- 2,655 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
89
90
91

// RUN: %target-swift-emit-silgen -module-name vtables_objc -sdk %S/Inputs -I %S/Inputs -enable-source-import %s -disable-objc-attr-requires-foundation-module | %FileCheck %s

// REQUIRES: objc_interop

import gizmo

// Test ObjC base class

class Hoozit : Gizmo {
  // Overrides Gizmo.frob
  override func frob() {}

  // Overrides Gizmo.funge
  override func funge() {}

  // Overrides Gizmo.foo
  final override func foo() {}

  func anse() {}
  func incorrige() {}
}

// CHECK-LABEL: sil hidden [ossa] @$s12vtables_objc10callHoozityyAA0D0CF : $@convention(thin) (@guaranteed Hoozit) -> ()
func callHoozit(_ h: Hoozit) {
  // CHECK: objc_method {{.*}} : $Hoozit, #Hoozit.frob!foreign
  h.frob()
  // CHECK: function_ref @$s12vtables_objc6HoozitC3fooyyF
  h.foo()
  // CHECK: class_method {{.*}} : $Hoozit, #Hoozit.anse :
  h.anse()
  // CHECK: return
}

class Wotsit : Hoozit {
  // Overrides Gizmo.funge
  override func funge() {}

  // Overrides Hoozit.incorrige
  override func incorrige() {}

  // Overrides Gizmo.frob
  final override func frob() {}
}

// CHECK-LABEL: sil hidden [ossa] @$s12vtables_objc10callWotsityyAA0D0CF : $@convention(thin) (@guaranteed Wotsit) -> ()
func callWotsit(_ w: Wotsit) {
  // CHECK: objc_method {{.*}} : $Wotsit, #Wotsit.funge!foreign
  w.funge()
  // CHECK: class_method {{.*}} : $Wotsit, #Wotsit.incorrige :
  w.incorrige()
  // CHECK: function_ref @$s12vtables_objc6WotsitC4frobyyF
  w.frob()
  // CHECK: return
}

// Entries only exist for native Swift methods

// CHECK: sil_vtable Hoozit {
// CHECK-NEXT:   #Hoozit.anse: {{.*}} : @$s12vtables_objc6HoozitC4anse{{[_0-9a-zA-Z]*}}F
// CHECK-NEXT:   #Hoozit.incorrige: {{.*}} : @$s12vtables_objc6HoozitC9incorrige{{[_0-9a-zA-Z]*}}F
// CHECK-NEXT:   #Hoozit.deinit!deallocator: @$s12vtables_objc6HoozitCfD
// CHECK-NEXT: }

// CHECK: sil_vtable Wotsit {
// CHECK-NEXT:   #Hoozit.anse: {{.*}} : @$s12vtables_objc6HoozitC4anse{{[_0-9a-zA-Z]*}}F
// CHECK-NEXT:   #Hoozit.incorrige: {{.*}} : @$s12vtables_objc6WotsitC9incorrige{{[_0-9a-zA-Z]*}}F
// CHECK-NEXT:   #Wotsit.deinit!deallocator: @$s12vtables_objc6WotsitCfD
// CHECK-NEXT: }

// <rdar://problem/15282548>
// CHECK: sil_vtable Base {
// CHECK:   #Base.init!allocator: {{.*}} : @$s12vtables_objc4BaseC{{[_0-9a-zA-Z]*}}fC
// CHECK: }
// CHECK: sil_vtable Derived {
// CHECK:   #Base.init!allocator: {{.*}} : @$s12vtables_objc7DerivedC{{[_0-9a-zA-Z]*}}fC
// CHECK: }
@objc class Base {}

extension Base {
  // note: does not have a vtable slot, because it is from an extension
  @objc func identify() -> Int {
    return 0
  }
}

class Derived : Base {
  override func identify() -> Int {
    return 1
  }
}