File: devirt_default_witness_method.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 (101 lines) | stat: -rw-r--r-- 5,397 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
92
93
94
95
96
97
98
99
100
101
// RUN: %target-sil-opt -enable-sil-verify-all %s -devirtualizer -sil-combine -enable-library-evolution | %FileCheck %s
sil_stage canonical

import Builtin
import Swift
import SwiftShims

public protocol P { }
public protocol Q : P { }
extension Int : P, Q { }

public protocol ResilientProtocol {
  func defaultA()
}

sil @defaultA : $@convention(witness_method: ResilientProtocol) <Self where Self : ResilientProtocol> (@in_guaranteed Self) -> () {
bb0(%0 : $*Self):
  %result = tuple ()
  return %result : $()
}

sil_default_witness_table ResilientProtocol {
  method #ResilientProtocol.defaultA: @defaultA
}

struct ConformingStruct : ResilientProtocol {
  func defaultA()
}

sil_witness_table ConformingStruct : ResilientProtocol module protocol_resilience {
  method #ResilientProtocol.defaultA: @defaultA
}

struct ConformingGenericStruct<T> : ResilientProtocol {
  func defaultA()
}

sil_witness_table <T> ConformingGenericStruct<T> : ResilientProtocol module protocol_resilience {
  method #ResilientProtocol.defaultA: @defaultA
}

public protocol ResilientProtocolWithGeneric {
  func defaultB<T: Q>(_: T)
}

sil @defaultB : $@convention(witness_method: ResilientProtocolWithGeneric) <Self where Self : ResilientProtocolWithGeneric><T where T : Q> (@in T, @in_guaranteed Self) -> () {
bb0(%0 : $*T, %1 : $*Self):
  %result = tuple ()
  return %result : $()
}

sil_default_witness_table ResilientProtocolWithGeneric {
  method #ResilientProtocolWithGeneric.defaultB: @defaultB
}

extension ConformingGenericStruct : ResilientProtocolWithGeneric {
  func defaultB<T>(_: T)
}

sil_witness_table <T> ConformingGenericStruct<T> : ResilientProtocolWithGeneric module protocol_resilience {
  method #ResilientProtocolWithGeneric.defaultB: @defaultB
}

// CHECK-LABEL: sil hidden @test_devirt_of_default_witness_method : $@convention(thin) (@in_guaranteed ConformingStruct) -> ()
// CHECK:       bb0(%0 : $*ConformingStruct):
// CHECK:         [[FN:%.*]] = function_ref @defaultA : $@convention(witness_method: ResilientProtocol) <τ_0_0 where τ_0_0 : ResilientProtocol> (@in_guaranteed τ_0_0) -> ()
// CHECK-NEXT:    [[RESULT:%.*]] = apply [[FN]]<ConformingStruct>(%0) : $@convention(witness_method: ResilientProtocol) <τ_0_0 where τ_0_0 : ResilientProtocol> (@in_guaranteed τ_0_0)
// CHECK-NEXT:    return [[RESULT]] : $()

sil hidden @test_devirt_of_default_witness_method : $@convention(thin) (@in_guaranteed ConformingStruct) -> () {
bb0(%0 : $*ConformingStruct):
  %fn = witness_method $ConformingStruct, #ResilientProtocol.defaultA : $@convention(witness_method: ResilientProtocol) <T where T : ResilientProtocol> (@in_guaranteed T) -> ()
  %result = apply %fn<ConformingStruct>(%0) : $@convention(witness_method: ResilientProtocol) <T where T : ResilientProtocol> (@in_guaranteed T) -> ()
  return %result : $()
}

// CHECK-LABEL: sil hidden @test_devirt_of_generic_default_witness_method : $@convention(thin) (@in_guaranteed ConformingGenericStruct<Int>) -> ()
// CHECK:       bb0(%0 : $*ConformingGenericStruct<Int>):
// CHECK:         [[FN:%.*]] = function_ref @defaultA : $@convention(witness_method: ResilientProtocol) <τ_0_0 where τ_0_0 : ResilientProtocol> (@in_guaranteed τ_0_0) -> ()
// CHECK-NEXT:    [[RESULT:%.*]] = apply [[FN]]<ConformingGenericStruct<Int>>(%0) : $@convention(witness_method: ResilientProtocol) <τ_0_0 where τ_0_0 : ResilientProtocol> (@in_guaranteed τ_0_0)
// CHECK-NEXT:    return [[RESULT]] : $()

sil hidden @test_devirt_of_generic_default_witness_method : $@convention(thin) (@in_guaranteed ConformingGenericStruct<Int>) -> () {
bb0(%0 : $*ConformingGenericStruct<Int>):
  %fn = witness_method $ConformingGenericStruct<Int>, #ResilientProtocol.defaultA : $@convention(witness_method: ResilientProtocol) <T where T : ResilientProtocol> (@in_guaranteed T) -> ()
  %result = apply %fn<ConformingGenericStruct<Int>>(%0) : $@convention(witness_method: ResilientProtocol) <T where T : ResilientProtocol> (@in_guaranteed T) -> ()
  return %result : $()
}

// CHECK-LABEL: test_devirt_of_inner_generic_default_witness_method
// CHECK:       bb0(%0 : $*ConformingGenericStruct<Int>, %1 : $*Int):
// CHECK:       [[FN:%[0-9]+]] = function_ref @defaultB : $@convention(witness_method: ResilientProtocolWithGeneric) <τ_0_0 where τ_0_0 : ResilientProtocolWithGeneric><τ_1_0 where τ_1_0 : Q> (@in τ_1_0, @in_guaranteed τ_0_0) -> ()
// CHECK:       [[RESULT:%[0-9]+]] = apply [[FN]]<ConformingGenericStruct<Int>, Int>(%1, %0) : $@convention(witness_method: ResilientProtocolWithGeneric) <τ_0_0 where τ_0_0 : ResilientProtocolWithGeneric><τ_1_0 where τ_1_0 : Q> (@in τ_1_0, @in_guaranteed τ_0_0) -> ()
// CHECK:       return [[RESULT]] : $()
// CHECK:     }
sil hidden @test_devirt_of_inner_generic_default_witness_method : $@convention(thin) (@in_guaranteed ConformingGenericStruct<Int>, @in Int) -> () {
bb0(%0 : $*ConformingGenericStruct<Int>, %1 : $*Int):
  %fn = witness_method $ConformingGenericStruct<Int>, #ResilientProtocolWithGeneric.defaultB : $@convention(witness_method: ResilientProtocolWithGeneric) <T where T : ResilientProtocolWithGeneric><U where U : Q> (@in U, @in_guaranteed T) -> ()
  %result = apply %fn<ConformingGenericStruct<Int>, Int>(%1, %0) : $@convention(witness_method: ResilientProtocolWithGeneric) <T where T : ResilientProtocolWithGeneric><U where U : Q> (@in U, @in_guaranteed T) -> ()
  return %result : $()
}