File: issue-47644.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 (137 lines) | stat: -rw-r--r-- 8,064 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// RUN: %target-sil-opt %s -sil-combine | %FileCheck %s

// REQUIRES: PTRSIZE=64

// https://github.com/apple/swift/issues/47644

sil_stage canonical

import Builtin
import Swift
import SwiftShims

class UIViewController {
}

class ExternalFramework {
  func objects<T>(_ type: T.Type) -> Results<T> where T : Object
}

class Object {
}

final class Results<T: Object> {
}

public protocol ReadonlyExternalFramework {
  func objects<T>(_ type: T.Type) -> Results<T> where T : Object
}

extension ExternalFramework : ReadonlyExternalFramework {
}

public enum ExternalFrameworkProvider {
  static func readonly() -> ReadonlyExternalFramework
}

public enum ModelDataService {
  public static func getCurrent(from ExternalFramework: ReadonlyExternalFramework) -> Model?
  public static func count(in ExternalFramework: ReadonlyExternalFramework) -> Int
}

var events: [String]

var currentModel: Model { get }

public class Model : Object {
  @_hasStorage var id: Int { get set }
  override init()
  init(value: Any)
  deinit
}

sil @ExternalFrameworkInit : $@convention(method) (@thick ExternalFramework.Type) -> (@owned ExternalFramework, @error Error)

sil @ResultsCountGetter : $@convention(method) <τ_0_0 where τ_0_0 : Object> (@guaranteed Results<τ_0_0>) -> Int

sil @GetRawPointer : $@convention(thin) () -> Builtin.RawPointer

sil @GetOptionalModel : $@convention(method) (@in ReadonlyExternalFramework, @thin ModelDataService.Type) -> @owned Optional<Model>

// CHECK-LABEL: sil hidden @BuggyFunction : $@convention(thin) () -> @owned Model {
// CHECK: [[ALLOC:%.*]] = alloc_stack $any ReadonlyExternalFramework, let, name "ExternalFramework"
// CHECK-NEXT: [[INITE:%.*]] = init_existential_addr [[ALLOC]] : $*any ReadonlyExternalFramework, $ExternalFramework
// CHECK: [[TALLOC1:%.*]] = alloc_stack $any ReadonlyExternalFramework
// CHECK-NEXT: copy_addr [[ALLOC]] to [init] [[TALLOC1]] : $*any ReadonlyExternalFramework
// CHECK-NEXT: apply {{%.*}}([[TALLOC1]], {{%.*}}) : $@convention(method) (@in any ReadonlyExternalFramework, @thin ModelDataService.Type) -> @owned Optional<Model>
// CHECK: [[TALLOC2:%.*]] = alloc_stack $any ReadonlyExternalFramework
// CHECK-NEXT: copy_addr [[ALLOC]] to [init] [[TALLOC2]] : $*any ReadonlyExternalFramework
// CHECK-NEXT: destroy_addr [[ALLOC]]
// CHECK: [[OEADDR:%.*]] = open_existential_addr immutable_access [[TALLOC2]] : $*any ReadonlyExternalFramework
sil hidden @BuggyFunction : $@convention(thin) () -> @owned Model {
bb0:
  %0 = alloc_stack $ReadonlyExternalFramework, let, name "ExternalFramework" // users: %1, %166, %72, %163, %71, %168, %10
  %1 = init_existential_addr %0 : $*ReadonlyExternalFramework, $ExternalFramework // user: %6
  // function_ref ExternalFramework.__allocating_init()
  %2 = function_ref @ExternalFrameworkInit : $@convention(method) (@thick ExternalFramework.Type) -> (@owned ExternalFramework, @error Error) // user: %4
  %3 = metatype $@thick ExternalFramework.Type                // user: %4
  try_apply %2(%3) : $@convention(method) (@thick ExternalFramework.Type) -> (@owned ExternalFramework, @error Error), normal bb1, error bb2 // id: %4

// %5                                             // user: %6
bb1(%5 : $ExternalFramework):                                 // Preds: bb0
  store %5 to %1 : $*ExternalFramework                        // id: %6
  // function_ref static ModelDataService.getCurrent(from:)
  %7 = function_ref @GetOptionalModel : $@convention(method) (@in ReadonlyExternalFramework, @thin ModelDataService.Type) -> @owned Optional<Model> // user: %11
  %8 = metatype $@thin ModelDataService.Type      // user: %11
  %9 = alloc_stack $ReadonlyExternalFramework                 // users: %12, %11, %10
  copy_addr %0 to [init] %9 : $*ReadonlyExternalFramework // id: %10
  %11 = apply %7(%9, %8) : $@convention(method) (@in ReadonlyExternalFramework, @thin ModelDataService.Type) -> @owned Optional<Model> // user: %13
  dealloc_stack %9 : $*ReadonlyExternalFramework              // id: %12
  switch_enum %11 : $Optional<Model>, case #Optional.some!enumelt: bb4, case #Optional.none!enumelt: bb3 // id: %13

// %14                                            // user: %15
bb2(%14 : $Error):                                // Preds: bb0
  %15 = builtin "unexpectedError"(%14 : $Error) : $()
  unreachable                                     // id: %16

bb3:                                              // Preds: bb1
  // function_ref events.unsafeMutableAddressor
  %17 = function_ref @GetRawPointer : $@convention(thin) () -> Builtin.RawPointer // user: %18
  %18 = apply %17() : $@convention(thin) () -> Builtin.RawPointer // user: %19
  %19 = pointer_to_address %18 : $Builtin.RawPointer to [strict] $*Array<String> // users: %158, %156, %152, %151
  %70 = alloc_stack $ReadonlyExternalFramework                // users: %106, %99, %73, %107, %71
  copy_addr %0 to [init] %70 : $*ReadonlyExternalFramework // id: %71
  destroy_addr %0 : $*ReadonlyExternalFramework               // id: %72
  debug_value %70 : $*ReadonlyExternalFramework, let, name "ExternalFramework", argno 1, expr op_deref // id: %73
  %75 = integer_literal $Builtin.Word, 1          // user: %78
  %76 = integer_literal $Builtin.Int64, 1         // user: %77
  %77 = struct $Int (%76 : $Builtin.Int64)        // user: %81
  %78 = alloc_ref [tail_elems $Any * %75 : $Builtin.Word] $_ContiguousArrayStorage<Any> // user: %81
  %79 = metatype $@thin Array<Any>.Type           // user: %81
  %99 = open_existential_addr immutable_access %70 : $*ReadonlyExternalFramework to $*@opened("ED59E038-AA25-11E7-9DEA-685B3593C496", ReadonlyExternalFramework) Self // users: %102, %102, %100
  %100 = witness_method $@opened("ED59E038-AA25-11E7-9DEA-685B3593C496", ReadonlyExternalFramework) Self, #ReadonlyExternalFramework.objects : <Self where Self : ReadonlyExternalFramework><T where T : Object> (Self) -> (T.Type) -> Results<T>, %99 : $*@opened("ED59E038-AA25-11E7-9DEA-685B3593C496", ReadonlyExternalFramework) Self : $@convention(witness_method: ReadonlyExternalFramework) <τ_0_0 where τ_0_0 : ReadonlyExternalFramework><τ_1_0 where τ_1_0 : Object> (@thick τ_1_0.Type, @in_guaranteed τ_0_0) -> @owned Results<τ_1_0> // type-defs: %99; user: %102
  %101 = metatype $@thick Model.Type              // user: %102
  %102 = apply %100<@opened("ED59E038-AA25-11E7-9DEA-685B3593C496", ReadonlyExternalFramework) Self, Model>(%101, %99) : $@convention(witness_method: ReadonlyExternalFramework) <τ_0_0 where τ_0_0 : ReadonlyExternalFramework><τ_1_0 where τ_1_0 : Object> (@thick τ_1_0.Type, @in_guaranteed τ_0_0) -> @owned Results<τ_1_0> // type-defs: %99; users: %105, %104
  // function_ref Results.count.getter
  %103 = function_ref @ResultsCountGetter : $@convention(method) <τ_0_0 where τ_0_0 : Object> (@guaranteed Results<τ_0_0>) -> Int // user: %104
  %104 = apply %103<Model>(%102) : $@convention(method) <τ_0_0 where τ_0_0 : Object> (@guaranteed Results<τ_0_0>) -> Int // user: %108
  strong_release %102 : $Results<Model>           // id: %105
  destroy_addr %70 : $*ReadonlyExternalFramework              // id: %106
  dealloc_stack %70 : $*ReadonlyExternalFramework             // id: %107
  %159 = tuple ()
  %160 = alloc_ref [objc] $Model                  // users: %162, %161
  dealloc_stack %0 : $*ReadonlyExternalFramework              // id: %163
  br bb5(%160 : $Model)                           // id: %164

// %165                                           // users: %169, %167
bb4(%165 : $Model):                               // Preds: bb1
  destroy_addr %0 : $*ReadonlyExternalFramework               // id: %166
  debug_value %165 : $Model, let, name "user"     // id: %167
  dealloc_stack %0 : $*ReadonlyExternalFramework              // id: %168
  br bb5(%165 : $Model)                           // id: %169

// %170                                           // user: %171
bb5(%170 : $Model):                               // Preds: bb3 bb4
  return %170 : $Model                            // id: %171
} // end sil function 'BuggyFunction'