File: SILDeclRef.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 (70 lines) | stat: -rw-r--r-- 3,086 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
// RUN: %target-swift-emit-sil %s | %FileCheck %s
// RUN: %target-swift-emit-sil %s | %target-sil-opt -parse-serialized-sil -enable-sil-verify-all -module-name="SILDeclRef"  - | %FileCheck %s

// Check that all SILDeclRefs are represented in the text form with a signature.
// This allows to avoid ambiguities which sometimes arise e.g. when a
// vtable or witness table contain multiple entries for a function with the same
// name but different signatures (like "foo" in the examples below).
//
// Check that SILParser can parse the new SIL syntax for SILDeclRefs by first
// producing the new syntax and then parsing it using sil-opt.

public protocol P {
  func foo() -> Int32
  func foo(n: Int32)
}

extension P {
  func boo() -> Int32 {
    return 1
  }
}

public class Base : P {
  public func foo() -> Int32 { return 2 }
  public func foo(n: Int32) {}
  public func foo(f: Float) -> Int32 { return 3 }
}

public class Derived1: Base {
  override public func foo() -> Int32 { return 4 }
  override public func foo(n: Int32) {}
  override public func foo(f: Float) -> Int32 { return 5 }
}

public class Derived2: Base {
  override public func foo() -> Int32 { return 6 }
  override public func foo(n: Int32) {}
  override public func foo(f: Float) -> Int32 { return 7 }
}

// CHECK-LABEL: sil @$s10SILDeclRef5testP1ps5Int32VAA1P_p_tF
// Check that witness_method contains SILDeclRefs with a signature.
// CHECK: witness_method $@opened({{.*}}, any P) Self, #P.foo : <Self where Self : P> (Self) -> () -> Int32, %{{.*}} : $*@opened({{.*}}, any P) Self : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int32
public func testP(p: P) -> Int32 {
  return p.foo()
}

// Check that class_method contains SILDeclRefs with a signature.
// CHECK-LABEL:sil @$s10SILDeclRef8testBase1bs5Int32VAA0D0C_tF
// CHECK: class_method %{{.*}} : $Base, #Base.foo : (Base) -> (Float) -> Int32, $@convention(method) (Float, @guaranteed Base) -> Int32
public func testBase(b: Base) -> Int32 {
  return b.foo(f: 10)
}

// Check that vtables and witness tables contain SILDeclRefs with signatures.

// CHECK: sil_vtable Base {
// CHECK-NEXT:  #Base.foo: (Base) -> () -> Int32 : @$s10SILDeclRef4BaseC3foos5Int32VyF	// Base.foo()
// CHECK-NEXT:  #Base.foo: (Base) -> (Int32) -> () : @$s10SILDeclRef4BaseC3foo1nys5Int32V_tF	// Base.foo(n:)
// CHECK-NEXT:  #Base.foo: (Base) -> (Float) -> Int32 : @$s10SILDeclRef4BaseC3foo1fs5Int32VSf_tF	// Base.foo(f:)
// CHECK-NEXT:  #Base.init!allocator: (Base.Type) -> () -> Base : @$s10SILDeclRef4BaseCACycfC
// CHECK-NEXT:  #Base.deinit!deallocator: @$s10SILDeclRef4BaseCfD	// Base.__deallocating_deinit
// CHECK-NEXT: }

// CHECK:sil_witness_table Base: P module SILDeclRef {
// CHECK-NEXT: method #P.foo: <Self where Self : P> (Self) -> () -> Int32 : @$s10SILDeclRef4BaseCAA1PA2aDP3foos5Int32VyFTW	// protocol witness for P.foo()
// CHECK-NEXT: method #P.foo: <Self where Self : P> (Self) -> (Int32) -> () : @$s10SILDeclRef4BaseCAA1PA2aDP3foo1nys5Int32V_tFTW	// protocol witness for P.foo(n:) in conformance Base
// CHECK-NEXT: }