forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevirt_try_apply.sil
908 lines (701 loc) · 31.7 KB
/
devirt_try_apply.sil
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
// RUN: %target-sil-opt -enable-sil-verify-all %s -sil-combine -devirtualizer -redundant-load-elim -inline | FileCheck %s --check-prefix=CHECK-DEVIRT
// RUN: %target-sil-opt -enable-sil-verify-all %s -early-inline | FileCheck %s --check-prefix=CHECK-EARLY-INLINE
// RUN: %target-sil-opt -enable-sil-verify-all %s -specdevirt | FileCheck %s --check-prefix=CHECK-SPECDEVIRT
// RUN: %target-sil-opt -enable-sil-verify-all %s -mandatory-inlining | FileCheck %s --check-prefix=CHECK-MANDATORY-INLINING
sil_stage canonical
import Builtin
import Swift
import SwiftShims
public class Base {
@inline(never) func foo() throws -> Int32?
@inline(never) func boo1() throws -> Base
@inline(never) func boo2() throws -> Base?
deinit
init()
}
public class Derived1 : Base {
@inline(never) override func foo() throws -> Int32?
@inline(never) override func boo1() throws -> Derived1
@inline(never) override func boo2() throws -> Derived1?
deinit
override init()
}
public class Derived2 : Base {
@inline(never) override func foo() throws -> Int32
@inline(never) override func boo1() throws -> Derived2
@inline(never) override func boo2() throws -> Derived2
deinit
override init()
}
public protocol P {
func foo() throws -> Int32
}
public class CP1 : P {
public func foo() throws -> Int32
deinit
init()
}
public class CP2 : CP1 {
override public func foo() throws -> Int32
deinit
override init()
}
@inline(never) public func testTryApplyDevirt1(b: Base) -> Int32?
@inline(never) public func testTryApplyDevirt2(b: Base) -> Base?
@inline(never) public func testTryApplyDevirt3(b: Base) -> Base?
public func test1()
public func test2()
public func test3()
public func test4() -> Int32
public func test5() -> Int32
public func test6() -> Int32?
sil_global [fragile] @_TZvOs7Process5_argcVs5Int32 : $Int32
sil_global private_external [fragile] @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token5 : $Builtin.Word
sil_global [fragile] @_TZvOs7Process11_unsafeArgvGVs20UnsafeMutablePointerGS0_Vs4Int8__ : $UnsafeMutablePointer<UnsafeMutablePointer<Int8>>
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<UnsafeMutablePointer<Int8>>) -> Int32 {
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<UnsafeMutablePointer<Int8>>):
%2 = global_addr @_TZvOs7Process5_argcVs5Int32 : $*Int32
store %0 to %2 : $*Int32
%4 = global_addr @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token5 : $*Builtin.Word
%5 = address_to_pointer %4 : $*Builtin.Word to $Builtin.RawPointer
%6 = function_ref @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func5 : $@convention(thin) () -> ()
%7 = builtin "once"(%5 : $Builtin.RawPointer, %6 : $@convention(thin) () -> ()) : $()
%8 = global_addr @_TZvOs7Process11_unsafeArgvGVs20UnsafeMutablePointerGS0_Vs4Int8__ : $*UnsafeMutablePointer<UnsafeMutablePointer<Int8>>
store %1 to %8 : $*UnsafeMutablePointer<UnsafeMutablePointer<Int8>>
%10 = tuple ()
%11 = integer_literal $Builtin.Int32, 0
%12 = struct $Int32 (%11 : $Builtin.Int32)
return %12 : $Int32
}
sil [transparent] [fragile] @_TFs13_didEnterMainFTVs5Int324argvGVs20UnsafeMutablePointerGS0_Vs4Int8___T_ : $@convention(thin) (Int32, UnsafeMutablePointer<UnsafeMutablePointer<Int8>>) -> ()
sil hidden [noinline] @_TFC16devirt_try_apply4Base3foofS0_FzT_GSqVs5Int32_ : $@convention(method) (@guaranteed Base) -> (Optional<Int32>, @error ErrorType) {
bb0(%0 : $Base):
debug_value %0 : $Base
%2 = integer_literal $Builtin.Int32, 0
%3 = struct $Int32 (%2 : $Builtin.Int32)
%4 = enum $Optional<Int32>, #Optional.Some!enumelt.1, %3 : $Int32
return %4 : $Optional<Int32>
}
sil [transparent] [fragile] @_TFVs5Int32CfMS_FT22_builtinIntegerLiteralBi2048__S_ : $@convention(thin) (Builtin.Int2048, @thin Int32.Type) -> Int32
sil hidden [noinline] @_TFC16devirt_try_apply4Base4boo1fS0_FzT_S0_ : $@convention(method) (@guaranteed Base) -> (@owned Base, @error ErrorType) {
bb0(%0 : $Base):
debug_value %0 : $Base
strong_retain %0 : $Base
return %0 : $Base
}
sil hidden [noinline] @_TFC16devirt_try_apply4Base4boo2fS0_FzT_GSqS0__ : $@convention(method) (@guaranteed Base) -> (@owned Optional<Base>, @error ErrorType) {
bb0(%0 : $Base):
debug_value %0 : $Base
strong_retain %0 : $Base
%3 = enum $Optional<Base>, #Optional.Some!enumelt.1, %0 : $Base
return %3 : $Optional<Base>
}
sil @_TFC16devirt_try_apply4BaseD : $@convention(method) (@owned Base) -> () {
bb0(%0 : $Base):
debug_value %0 : $Base
%2 = function_ref @_TFC16devirt_try_apply4Based : $@convention(method) (@guaranteed Base) -> @owned Builtin.NativeObject
%3 = apply %2(%0) : $@convention(method) (@guaranteed Base) -> @owned Builtin.NativeObject
%4 = unchecked_ref_cast %3 : $Builtin.NativeObject to $Base
dealloc_ref %4 : $Base
%6 = tuple ()
return %6 : $()
}
sil @_TFC16devirt_try_apply4Based : $@convention(method) (@guaranteed Base) -> @owned Builtin.NativeObject {
bb0(%0 : $Base):
debug_value %0 : $Base
%2 = unchecked_ref_cast %0 : $Base to $Builtin.NativeObject
return %2 : $Builtin.NativeObject
}
sil hidden @_TFC16devirt_try_apply4BasecfMS0_FT_S0_ : $@convention(method) (@owned Base) -> @owned Base {
bb0(%0 : $Base):
debug_value %0 : $Base
return %0 : $Base
}
sil hidden @_TFC16devirt_try_apply4BaseCfMS0_FT_S0_ : $@convention(thin) (@thick Base.Type) -> @owned Base {
bb0(%0 : $@thick Base.Type):
%1 = alloc_ref $Base
%2 = function_ref @_TFC16devirt_try_apply4BasecfMS0_FT_S0_ : $@convention(method) (@owned Base) -> @owned Base
%3 = apply %2(%1) : $@convention(method) (@owned Base) -> @owned Base
return %3 : $Base
}
sil hidden [noinline] @_TFC16devirt_try_apply8Derived13foofS0_FzT_GSqVs5Int32_ : $@convention(method) (@guaranteed Derived1) -> (Optional<Int32>, @error ErrorType) {
bb0(%0 : $Derived1):
debug_value %0 : $Derived1
%2 = integer_literal $Builtin.Int32, 1
%3 = struct $Int32 (%2 : $Builtin.Int32)
%4 = enum $Optional<Int32>, #Optional.Some!enumelt.1, %3 : $Int32
return %4 : $Optional<Int32>
}
sil hidden [noinline] @_TFC16devirt_try_apply8Derived14boo1fS0_FzT_S0_ : $@convention(method) (@guaranteed Derived1) -> (@owned Derived1, @error ErrorType) {
bb0(%0 : $Derived1):
debug_value %0 : $Derived1
strong_retain %0 : $Derived1
return %0 : $Derived1
}
sil hidden [noinline] @_TFC16devirt_try_apply8Derived14boo2fS0_FzT_GSqS0__ : $@convention(method) (@guaranteed Derived1) -> (@owned Optional<Derived1>, @error ErrorType) {
bb0(%0 : $Derived1):
debug_value %0 : $Derived1
strong_retain %0 : $Derived1
%3 = enum $Optional<Derived1>, #Optional.Some!enumelt.1, %0 : $Derived1
return %3 : $Optional<Derived1>
}
sil @_TFC16devirt_try_apply8Derived1D : $@convention(method) (@owned Derived1) -> () {
bb0(%0 : $Derived1):
debug_value %0 : $Derived1
%2 = function_ref @_TFC16devirt_try_apply8Derived1d : $@convention(method) (@guaranteed Derived1) -> @owned Builtin.NativeObject
%3 = apply %2(%0) : $@convention(method) (@guaranteed Derived1) -> @owned Builtin.NativeObject
%4 = unchecked_ref_cast %3 : $Builtin.NativeObject to $Derived1
dealloc_ref %4 : $Derived1
%6 = tuple ()
return %6 : $()
}
sil @_TFC16devirt_try_apply8Derived1d : $@convention(method) (@guaranteed Derived1) -> @owned Builtin.NativeObject {
bb0(%0 : $Derived1):
debug_value %0 : $Derived1
%2 = upcast %0 : $Derived1 to $Base
%3 = function_ref @_TFC16devirt_try_apply4Based : $@convention(method) (@guaranteed Base) -> @owned Builtin.NativeObject
%4 = apply %3(%2) : $@convention(method) (@guaranteed Base) -> @owned Builtin.NativeObject
return %4 : $Builtin.NativeObject
}
sil hidden @_TFC16devirt_try_apply8Derived1cfMS0_FT_S0_ : $@convention(method) (@owned Derived1) -> @owned Derived1 {
bb0(%0 : $Derived1):
%1 = alloc_stack $Derived1
store %0 to %1#1 : $*Derived1
%3 = upcast %0 : $Derived1 to $Base
%4 = function_ref @_TFC16devirt_try_apply4BasecfMS0_FT_S0_ : $@convention(method) (@owned Base) -> @owned Base
%7 = apply %4(%3) : $@convention(method) (@owned Base) -> @owned Base
%8 = unchecked_ref_cast %7 : $Base to $Derived1
store %8 to %1#1 : $*Derived1
dealloc_stack %1#0 : $*@local_storage Derived1
return %8 : $Derived1
}
sil hidden @_TFC16devirt_try_apply8Derived1CfMS0_FT_S0_ : $@convention(thin) (@thick Derived1.Type) -> @owned Derived1 {
bb0(%0 : $@thick Derived1.Type):
%1 = alloc_ref $Derived1
%2 = function_ref @_TFC16devirt_try_apply8Derived1cfMS0_FT_S0_ : $@convention(method) (@owned Derived1) -> @owned Derived1
%3 = apply %2(%1) : $@convention(method) (@owned Derived1) -> @owned Derived1
return %3 : $Derived1
}
sil private @_TTVFC16devirt_try_apply8Derived23foofS0_FzT_Vs5Int32 : $@convention(method) (@guaranteed Derived2) -> (Optional<Int32>, @error ErrorType) {
bb0(%0 : $Derived2):
%1 = function_ref @_TFC16devirt_try_apply8Derived23foofS0_FzT_Vs5Int32 : $@convention(method) (@guaranteed Derived2) -> (Int32, @error ErrorType)
try_apply %1(%0) : $@convention(method) (@guaranteed Derived2) -> (Int32, @error ErrorType), normal bb1, error bb2
bb1(%3 : $Int32):
%4 = enum $Optional<Int32>, #Optional.Some!enumelt.1, %3 : $Int32
return %4 : $Optional<Int32>
bb2(%6 : $ErrorType):
%7 = builtin "willThrow"(%6 : $ErrorType) : $()
throw %6 : $ErrorType
}
sil hidden [noinline] @_TFC16devirt_try_apply8Derived23foofS0_FzT_Vs5Int32 : $@convention(method) (@guaranteed Derived2) -> (Int32, @error ErrorType) {
bb0(%0 : $Derived2):
debug_value %0 : $Derived2
%2 = integer_literal $Builtin.Int32, 2
%3 = struct $Int32 (%2 : $Builtin.Int32)
return %3 : $Int32
}
sil hidden [noinline] @_TFC16devirt_try_apply8Derived24boo1fS0_FzT_S0_ : $@convention(method) (@guaranteed Derived2) -> (@owned Derived2, @error ErrorType) {
bb0(%0 : $Derived2):
debug_value %0 : $Derived2
strong_retain %0 : $Derived2
return %0 : $Derived2
}
sil hidden [noinline] @_TFC16devirt_try_apply8Derived24boo2fS0_FzT_S0_ : $@convention(method) (@guaranteed Derived2) -> (@owned Derived2, @error ErrorType) {
bb0(%0 : $Derived2):
debug_value %0 : $Derived2
strong_retain %0 : $Derived2
return %0 : $Derived2
}
sil @_TFC16devirt_try_apply8Derived2D : $@convention(method) (@owned Derived2) -> () {
bb0(%0 : $Derived2):
debug_value %0 : $Derived2
%2 = function_ref @_TFC16devirt_try_apply8Derived2d : $@convention(method) (@guaranteed Derived2) -> @owned Builtin.NativeObject
%3 = apply %2(%0) : $@convention(method) (@guaranteed Derived2) -> @owned Builtin.NativeObject
%4 = unchecked_ref_cast %3 : $Builtin.NativeObject to $Derived2
dealloc_ref %4 : $Derived2
%6 = tuple ()
return %6 : $()
}
sil @_TFC16devirt_try_apply8Derived2d : $@convention(method) (@guaranteed Derived2) -> @owned Builtin.NativeObject {
bb0(%0 : $Derived2):
debug_value %0 : $Derived2
%2 = upcast %0 : $Derived2 to $Base
%3 = function_ref @_TFC16devirt_try_apply4Based : $@convention(method) (@guaranteed Base) -> @owned Builtin.NativeObject
%4 = apply %3(%2) : $@convention(method) (@guaranteed Base) -> @owned Builtin.NativeObject
return %4 : $Builtin.NativeObject
}
sil hidden @_TFC16devirt_try_apply8Derived2cfMS0_FT_S0_ : $@convention(method) (@owned Derived2) -> @owned Derived2 {
bb0(%0 : $Derived2):
%1 = alloc_stack $Derived2
store %0 to %1#1 : $*Derived2
%3 = upcast %0 : $Derived2 to $Base
%4 = function_ref @_TFC16devirt_try_apply4BasecfMS0_FT_S0_ : $@convention(method) (@owned Base) -> @owned Base
%7 = apply %4(%3) : $@convention(method) (@owned Base) -> @owned Base
%8 = unchecked_ref_cast %7 : $Base to $Derived2
store %8 to %1#1 : $*Derived2
dealloc_stack %1#0 : $*@local_storage Derived2
return %8 : $Derived2
}
sil @_TFC16devirt_try_apply3CP13foofS0_FzT_Vs5Int32 : $@convention(method) (@guaranteed CP1) -> (Int32, @error ErrorType) {
bb0(%0 : $CP1):
debug_value %0 : $CP1
%2 = integer_literal $Builtin.Int32, 1
%3 = struct $Int32 (%2 : $Builtin.Int32)
return %3 : $Int32
}
sil @_TFC16devirt_try_apply3CP1D : $@convention(method) (@owned CP1) -> () {
bb0(%0 : $CP1):
debug_value %0 : $CP1
%2 = function_ref @_TFC16devirt_try_apply3CP1d : $@convention(method) (@guaranteed CP1) -> @owned Builtin.NativeObject
%3 = apply %2(%0) : $@convention(method) (@guaranteed CP1) -> @owned Builtin.NativeObject
%4 = unchecked_ref_cast %3 : $Builtin.NativeObject to $CP1
dealloc_ref %4 : $CP1
%6 = tuple ()
return %6 : $()
}
sil @_TFC16devirt_try_apply3CP1d : $@convention(method) (@guaranteed CP1) -> @owned Builtin.NativeObject {
bb0(%0 : $CP1):
debug_value %0 : $CP1
%2 = unchecked_ref_cast %0 : $CP1 to $Builtin.NativeObject
return %2 : $Builtin.NativeObject
}
sil hidden @_TFC16devirt_try_apply3CP1cfMS0_FT_S0_ : $@convention(method) (@owned CP1) -> @owned CP1 {
bb0(%0 : $CP1):
debug_value %0 : $CP1
return %0 : $CP1
}
sil hidden @_TFC16devirt_try_apply3CP1CfMS0_FT_S0_ : $@convention(thin) (@thick CP1.Type) -> @owned CP1 {
bb0(%0 : $@thick CP1.Type):
%1 = alloc_ref $CP1
%2 = function_ref @_TFC16devirt_try_apply3CP1cfMS0_FT_S0_ : $@convention(method) (@owned CP1) -> @owned CP1
%3 = apply %2(%1) : $@convention(method) (@owned CP1) -> @owned CP1
return %3 : $CP1
}
sil [transparent] [thunk] @_TTWC16devirt_try_apply3CP1S_1PS_FS1_3foouRq_S1__fq_FzT_Vs5Int32 : $@convention(witness_method) (@in_guaranteed CP1) -> (Int32, @error ErrorType) {
bb0(%0 : $*CP1):
%1 = load %0 : $*CP1
strong_retain %1 : $CP1
%3 = class_method %1 : $CP1, #CP1.foo!1 : CP1 -> () throws -> Int32 , $@convention(method) (@guaranteed CP1) -> (Int32, @error ErrorType)
try_apply %3(%1) : $@convention(method) (@guaranteed CP1) -> (Int32, @error ErrorType), normal bb1, error bb2
bb1(%5 : $Int32):
strong_release %1 : $CP1
return %5 : $Int32
bb2(%8 : $ErrorType):
%9 = builtin "willThrow"(%8 : $ErrorType) : $()
strong_release %1 : $CP1
throw %8 : $ErrorType
}
sil @_TFC16devirt_try_apply3CP23foofS0_FzT_Vs5Int32 : $@convention(method) (@guaranteed CP2) -> (Int32, @error ErrorType) {
bb0(%0 : $CP2):
debug_value %0 : $CP2
%2 = integer_literal $Builtin.Int32, 2
%3 = struct $Int32 (%2 : $Builtin.Int32)
return %3 : $Int32
}
sil @_TFC16devirt_try_apply3CP2D : $@convention(method) (@owned CP2) -> () {
bb0(%0 : $CP2):
debug_value %0 : $CP2
%2 = function_ref @_TFC16devirt_try_apply3CP2d : $@convention(method) (@guaranteed CP2) -> @owned Builtin.NativeObject
%3 = apply %2(%0) : $@convention(method) (@guaranteed CP2) -> @owned Builtin.NativeObject
%4 = unchecked_ref_cast %3 : $Builtin.NativeObject to $CP2
dealloc_ref %4 : $CP2
%6 = tuple ()
return %6 : $()
}
sil @_TFC16devirt_try_apply3CP2d : $@convention(method) (@guaranteed CP2) -> @owned Builtin.NativeObject {
bb0(%0 : $CP2):
debug_value %0 : $CP2
%2 = upcast %0 : $CP2 to $CP1
%3 = function_ref @_TFC16devirt_try_apply3CP1d : $@convention(method) (@guaranteed CP1) -> @owned Builtin.NativeObject
%4 = apply %3(%2) : $@convention(method) (@guaranteed CP1) -> @owned Builtin.NativeObject
return %4 : $Builtin.NativeObject
}
sil hidden @_TFC16devirt_try_apply3CP2cfMS0_FT_S0_ : $@convention(method) (@owned CP2) -> @owned CP2 {
bb0(%0 : $CP2):
%1 = alloc_stack $CP2
store %0 to %1#1 : $*CP2
%3 = upcast %0 : $CP2 to $CP1
%4 = function_ref @_TFC16devirt_try_apply3CP1cfMS0_FT_S0_ : $@convention(method) (@owned CP1) -> @owned CP1
%7 = apply %4(%3) : $@convention(method) (@owned CP1) -> @owned CP1
%8 = unchecked_ref_cast %7 : $CP1 to $CP2
store %8 to %1#1 : $*CP2
dealloc_stack %1#0 : $*@local_storage CP2
return %8 : $CP2
}
sil hidden @_TFC16devirt_try_apply3CP2CfMS0_FT_S0_ : $@convention(thin) (@thick CP2.Type) -> @owned CP2 {
bb0(%0 : $@thick CP2.Type):
%1 = alloc_ref $CP2
%2 = function_ref @_TFC16devirt_try_apply3CP2cfMS0_FT_S0_ : $@convention(method) (@owned CP2) -> @owned CP2
%3 = apply %2(%1) : $@convention(method) (@owned CP2) -> @owned CP2
return %3 : $CP2
}
// Check that -specdevirt can devirtualize it
// CHECK-SPECDEVIRT-LABEL: sil [noinline] @_TF16devirt_try_apply19testTryApplyDevirt1FCS_4BaseGSqVs5Int32_
// CHECK-SPECDEVIRT: checked_cast_br [exact]
// CHECK-SPECDEVIRT: }
sil [noinline] @_TF16devirt_try_apply19testTryApplyDevirt1FCS_4BaseGSqVs5Int32_ : $@convention(thin) (@owned Base) -> Optional<Int32> {
bb0(%0 : $Base):
%1 = alloc_stack $Optional<Int32>
debug_value %0 : $Base
%3 = alloc_stack $Optional<Int32>
inject_enum_addr %3#1 : $*Optional<Int32>, #Optional.None!enumelt
%5 = tuple ()
%6 = load %3#1 : $*Optional<Int32>
store %6 to %1#1 : $*Optional<Int32>
dealloc_stack %3#0 : $*@local_storage Optional<Int32>
%9 = class_method %0 : $Base, #Base.foo!1 : Base -> () throws -> Int32? , $@convention(method) (@guaranteed Base) -> (Optional<Int32>, @error ErrorType)
try_apply %9(%0) : $@convention(method) (@guaranteed Base) -> (Optional<Int32>, @error ErrorType), normal bb1, error bb4
bb1(%11 : $Optional<Int32>):
store %11 to %1#1 : $*Optional<Int32>
br bb2
bb2:
%14 = load %1#1 : $*Optional<Int32>
strong_release %0 : $Base
dealloc_stack %1#0 : $*@local_storage Optional<Int32>
return %14 : $Optional<Int32>
bb3:
strong_release %20 : $ErrorType
br bb2
bb4(%20 : $ErrorType):
br bb3
}
sil [transparent] [fragile] @_TFSqCurfMGSqq__FT10nilLiteralT__GSqq__ : $@convention(thin) <T> (@out Optional<T>, @thin Optional<T>.Type) -> ()
// Check that -specdevirt can devirtualize it
// CHECK-SPECDEVIRT-LABEL: sil [noinline] @_TF16devirt_try_apply19testTryApplyDevirt2FCS_4BaseGSqS0__
// CHECK-SPECDEVIRT: checked_cast_br [exact]
// CHECK-SPECDEVIRT: }
sil [noinline] @_TF16devirt_try_apply19testTryApplyDevirt2FCS_4BaseGSqS0__ : $@convention(thin) (@owned Base) -> @owned Optional<Base> {
bb0(%0 : $Base):
%1 = alloc_stack $Optional<Base>
debug_value %0 : $Base
%3 = alloc_stack $Optional<Base>
inject_enum_addr %3#1 : $*Optional<Base>, #Optional.None!enumelt
%5 = tuple ()
%6 = load %3#1 : $*Optional<Base>
store %6 to %1#1 : $*Optional<Base>
dealloc_stack %3#0 : $*@local_storage Optional<Base>
%9 = class_method %0 : $Base, #Base.boo1!1 : Base -> () throws -> Base , $@convention(method) (@guaranteed Base) -> (@owned Base, @error ErrorType)
try_apply %9(%0) : $@convention(method) (@guaranteed Base) -> (@owned Base, @error ErrorType), normal bb1, error bb4
bb1(%11 : $Base):
%12 = enum $Optional<Base>, #Optional.Some!enumelt.1, %11 : $Base
store %12 to %1#1 : $*Optional<Base>
release_value %6 : $Optional<Base>
br bb2
bb2:
%16 = load %1#1 : $*Optional<Base>
retain_value %16 : $Optional<Base>
destroy_addr %1#1 : $*Optional<Base>
strong_release %0 : $Base
dealloc_stack %1#0 : $*@local_storage Optional<Base>
return %16 : $Optional<Base>
bb3:
strong_release %24 : $ErrorType
br bb2
bb4(%24 : $ErrorType):
br bb3
}
// Check that -specdevirt can devirtualize it
// CHECK-SPECDEVIRT-LABEL: sil [noinline] @_TF16devirt_try_apply19testTryApplyDevirt3FCS_4BaseGSqS0__
// CHECK-SPECDEVIRT: checked_cast_br [exact]
// CHECK-SPECDEVIRT: }
sil [noinline] @_TF16devirt_try_apply19testTryApplyDevirt3FCS_4BaseGSqS0__ : $@convention(thin) (@owned Base) -> @owned Optional<Base> {
bb0(%0 : $Base):
%1 = alloc_stack $Optional<Base>
debug_value %0 : $Base
%3 = alloc_stack $Optional<Base>
inject_enum_addr %3#1 : $*Optional<Base>, #Optional.None!enumelt
%5 = tuple ()
%6 = load %3#1 : $*Optional<Base>
store %6 to %1#1 : $*Optional<Base>
dealloc_stack %3#0 : $*@local_storage Optional<Base>
%9 = class_method %0 : $Base, #Base.boo2!1 : Base -> () throws -> Base? , $@convention(method) (@guaranteed Base) -> (@owned Optional<Base>, @error ErrorType)
try_apply %9(%0) : $@convention(method) (@guaranteed Base) -> (@owned Optional<Base>, @error ErrorType), normal bb1, error bb4
bb1(%11 : $Optional<Base>):
store %11 to %1#1 : $*Optional<Base>
release_value %6 : $Optional<Base>
br bb2
bb2:
%15 = load %1#1 : $*Optional<Base>
retain_value %15 : $Optional<Base>
destroy_addr %1#1 : $*Optional<Base>
strong_release %0 : $Base
dealloc_stack %1#0 : $*@local_storage Optional<Base>
return %15 : $Optional<Base>
bb3:
strong_release %23 : $ErrorType
br bb2
bb4(%23 : $ErrorType):
br bb3
}
sil @_TF16devirt_try_apply5test1FT_T_ : $@convention(thin) () -> () {
bb0:
%0 = function_ref @_TF16devirt_try_apply19testTryApplyDevirt1FCS_4BaseGSqVs5Int32_ : $@convention(thin) (@owned Base) -> Optional<Int32>
%1 = function_ref @_TFC16devirt_try_apply4BaseCfMS0_FT_S0_ : $@convention(thin) (@thick Base.Type) -> @owned Base
%2 = metatype $@thick Base.Type
%3 = apply %1(%2) : $@convention(thin) (@thick Base.Type) -> @owned Base
%4 = apply %0(%3) : $@convention(thin) (@owned Base) -> Optional<Int32>
%5 = tuple ()
return %5 : $()
}
sil @_TF16devirt_try_apply5test2FT_T_ : $@convention(thin) () -> () {
bb0:
%0 = function_ref @_TF16devirt_try_apply19testTryApplyDevirt2FCS_4BaseGSqS0__ : $@convention(thin) (@owned Base) -> @owned Optional<Base>
%1 = function_ref @_TFC16devirt_try_apply4BaseCfMS0_FT_S0_ : $@convention(thin) (@thick Base.Type) -> @owned Base
%2 = metatype $@thick Base.Type
%3 = apply %1(%2) : $@convention(thin) (@thick Base.Type) -> @owned Base
%4 = apply %0(%3) : $@convention(thin) (@owned Base) -> @owned Optional<Base>
release_value %4 : $Optional<Base>
%6 = tuple ()
return %6 : $()
}
sil @_TF16devirt_try_apply5test3FT_T_ : $@convention(thin) () -> () {
bb0:
%0 = function_ref @_TF16devirt_try_apply19testTryApplyDevirt3FCS_4BaseGSqS0__ : $@convention(thin) (@owned Base) -> @owned Optional<Base>
%1 = function_ref @_TFC16devirt_try_apply4BaseCfMS0_FT_S0_ : $@convention(thin) (@thick Base.Type) -> @owned Base
%2 = metatype $@thick Base.Type
%3 = apply %1(%2) : $@convention(thin) (@thick Base.Type) -> @owned Base
%4 = apply %0(%3) : $@convention(thin) (@owned Base) -> @owned Optional<Base>
release_value %4 : $Optional<Base>
%6 = tuple ()
return %6 : $()
}
// Check that -specdevirt can devirtualize it
// CHECK-SPECDEVIRT-LABEL: sil @_TF16devirt_try_apply5test4FT_Vs5Int32
// CHECK-SPECDEVIRT: checked_cast_br [exact]
// CHECK-SPECDEVIRT: }
// CHECK-DEVIRT-LABEL: sil @_TF16devirt_try_apply5test4FT_Vs5Int32
// CHECK-DEVIRT-NOT: checked_cast_br [exact]
// CHECK-DEVIRT-NOT: class_method
// CHECK-DEVIRT: }
// CHECK-EARLY-INLINE-LABEL: sil @_TF16devirt_try_apply5test4FT_Vs5Int32
// CHECK-EARLY-INLINE-NOT: checked_cast_br [exact]
// CHECK-EARLY-INLINE-NOT: class_method
// CHECK-EARLY-INLINE: }
sil @_TF16devirt_try_apply5test4FT_Vs5Int32 : $@convention(thin) () -> Int32 {
bb0:
%0 = alloc_stack $Int32
%1 = function_ref @_TFC16devirt_try_apply3CP2CfMS0_FT_S0_ : $@convention(thin) (@thick CP2.Type) -> @owned CP2
%2 = metatype $@thick CP2.Type
%3 = apply %1(%2) : $@convention(thin) (@thick CP2.Type) -> @owned CP2
debug_value %3 : $CP2
%5 = integer_literal $Builtin.Int32, 0
%6 = struct $Int32 (%5 : $Builtin.Int32)
store %6 to %0#1 : $*Int32
%8 = class_method %3 : $CP2, #CP2.foo!1 : CP2 -> () throws -> Int32 , $@convention(method) (@guaranteed CP2) -> (Int32, @error ErrorType)
try_apply %8(%3) : $@convention(method) (@guaranteed CP2) -> (Int32, @error ErrorType), normal bb1, error bb4
bb1(%10 : $Int32):
store %10 to %0#1 : $*Int32
br bb2
bb2:
%13 = load %0#1 : $*Int32
strong_release %3 : $CP2
dealloc_stack %0#0 : $*@local_storage Int32
return %13 : $Int32
bb3:
strong_release %19 : $ErrorType
br bb2
bb4(%19 : $ErrorType):
br bb3
}
// DISABLE THIS TEST CASE FOR NOW. AS RLE GETS BETTER. WILL RE-ENABLE.
//
// DISABLECHECK-DEVIRT-LABEL: sil @_TF16devirt_try_apply5test5FT_Vs5Int32
// DISABLECHECK-DEVIRT-NOT: = witness_method
// DISABLECHECK-DEVIRT-NOT: = class_method
// DISABLECHECK-DEVIRT: }
sil @_TF16devirt_try_apply5test5FT_Vs5Int32 : $@convention(thin) () -> Int32 {
bb0:
%0 = alloc_stack $Int32
%1 = alloc_stack $P
%2 = init_existential_addr %1#1 : $*P, $CP1
%3 = function_ref @_TFC16devirt_try_apply3CP1CfMS0_FT_S0_ : $@convention(thin) (@thick CP1.Type) -> @owned CP1
%4 = metatype $@thick CP1.Type
%5 = apply %3(%4) : $@convention(thin) (@thick CP1.Type) -> @owned CP1
store %5 to %2 : $*CP1
%7 = integer_literal $Builtin.Int32, 0
%8 = struct $Int32 (%7 : $Builtin.Int32)
store %8 to %0#1 : $*Int32
%10 = open_existential_addr %1#1 : $*P to $*@opened("3F4928FC-364E-11E5-9488-B8E856428C60") P
%11 = witness_method $@opened("3F4928FC-364E-11E5-9488-B8E856428C60") P, #P.foo!1, %10 : $*@opened("3F4928FC-364E-11E5-9488-B8E856428C60") P : $@convention(witness_method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> (Int32, @error ErrorType)
try_apply %11<@opened("3F4928FC-364E-11E5-9488-B8E856428C60") P>(%10) : $@convention(witness_method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> (Int32, @error ErrorType), normal bb1, error bb4
bb1(%13 : $Int32):
store %13 to %0#1 : $*Int32
br bb2
bb2:
%16 = load %0#1 : $*Int32
destroy_addr %1#1 : $*P
dealloc_stack %1#0 : $*@local_storage P
dealloc_stack %0#0 : $*@local_storage Int32
return %16 : $Int32
bb3:
strong_release %23 : $ErrorType
br bb2
bb4(%23 : $ErrorType):
br bb3
}
// Check that devirtualization happens even at -inline, without an explicit invocation of the -devirtualize.
// CHECK-SPECDEVIRT-LABEL: sil @_TF16devirt_try_apply5test6FT_GSqVs5Int32_
// CHECK-SPECDEVIRT: checked_cast_br [exact]
// CHECK-SPECDEVIRT: }
// CHECK-DEVIRT-LABEL: sil @_TF16devirt_try_apply5test6FT_GSqVs5Int32_
// CHECK-DEVIRT-NOT: class_method
// CHECK-DEVIRT: }
// CHECK-EARLY-INLINE-LABEL: sil @_TF16devirt_try_apply5test6FT_GSqVs5Int32_
// CHECK-EARLY-INLINE-NOT: class_method
// CHECK-EARLY-INLINE: }
sil @_TF16devirt_try_apply5test6FT_GSqVs5Int32_ : $@convention(thin) () -> Optional<Int32> {
bb0:
%0 = alloc_stack $Optional<Int32>
%1 = function_ref @_TFC16devirt_try_apply8Derived1CfMS0_FT_S0_ : $@convention(thin) (@thick Derived1.Type) -> @owned Derived1
%2 = metatype $@thick Derived1.Type
%3 = apply %1(%2) : $@convention(thin) (@thick Derived1.Type) -> @owned Derived1
debug_value %3 : $Derived1
%5 = integer_literal $Builtin.Int32, 0
%6 = struct $Int32 (%5 : $Builtin.Int32)
%7 = enum $Optional<Int32>, #Optional.Some!enumelt.1, %6 : $Int32
store %7 to %0#1 : $*Optional<Int32>
%9 = class_method %3 : $Derived1, #Derived1.foo!1 : Derived1 -> () throws -> Int32? , $@convention(method) (@guaranteed Derived1) -> (Optional<Int32>, @error ErrorType)
try_apply %9(%3) : $@convention(method) (@guaranteed Derived1) -> (Optional<Int32>, @error ErrorType), normal bb1, error bb4
bb1(%11 : $Optional<Int32>):
store %11 to %0#1 : $*Optional<Int32>
br bb2
bb2:
%14 = load %0#1 : $*Optional<Int32>
strong_release %3 : $Derived1
dealloc_stack %0#0 : $*@local_storage Optional<Int32>
return %14 : $Optional<Int32>
bb3:
strong_release %20 : $ErrorType
br bb2
bb4(%20 : $ErrorType):
br bb3
}
// Check that -specdevirt can devirtualize it
// CHECK-SPECDEVIRT-LABEL: sil @_TF16devirt_try_apply5test7FT_Vs5Int32
// CHECK-SPECDEVIRT: checked_cast_br [exact]
// CHECK-SPECDEVIRT: }
// CHECK-DEVIRT-LABEL: sil @_TF16devirt_try_apply5test7FT_Vs5Int32
// CHECK-DEVIRT-NOT: checked_cast_br [exact]
// CHECK-DEVIRT-NOT: class_method
// CHECK-DEVIRT: }
// CHECK-EARLY-INLINE-LABEL: sil @_TF16devirt_try_apply5test7FT_Vs5Int32
// CHECK-EARLY-INLINE-NOT: checked_cast_br [exact]
// CHECK-EARLY-INLINE-NOT: class_method
// CHECK-EARLY-INLINE: }
// CHECK-MANDATORY-INLINING-LABEL: sil @_TF16devirt_try_apply5test7FT_Vs5Int32
// CHECK-MANDATORY-INLINING-NOT: checked_cast_br [exact]
// CHECK-MANDATORY-INLINING-NOT: class_method
// CHECK-MANDATORY-INLINING: }
sil @_TF16devirt_try_apply5test7FT_Vs5Int32 : $@convention(thin) () -> Int32 {
bb0:
%0 = alloc_stack $Int32
%1 = alloc_ref $CP2
%5 = integer_literal $Builtin.Int32, 0
%6 = struct $Int32 (%5 : $Builtin.Int32)
store %6 to %0#1 : $*Int32
%8 = class_method %1 : $CP2, #CP2.foo!1 : CP2 -> () throws -> Int32 , $@convention(method) (@guaranteed CP2) -> (Int32, @error ErrorType)
try_apply %8(%1) : $@convention(method) (@guaranteed CP2) -> (Int32, @error ErrorType), normal bb1, error bb4
bb1(%10 : $Int32):
store %10 to %0#1 : $*Int32
br bb2
bb2:
%13 = load %0#1 : $*Int32
strong_release %1 : $CP2
dealloc_stack %0#0 : $*@local_storage Int32
return %13 : $Int32
bb3:
strong_release %19 : $ErrorType
br bb2
bb4(%19 : $ErrorType):
br bb3
}
sil private_external [fragile] @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func5 : $@convention(thin) () -> ()
public class A {
deinit
init()
}
class D1 {
func f1() throws -> A?
deinit
init()
}
class D3 : D1 {
override func f1() throws -> A
deinit
override init()
}
// devirt_try_apply.D1.f1 () throws -> Swift.Optional<devirt_try_apply.A>
sil @_TFC16devirt_try_apply2D12f1fzT_GSqCS_1A_ : $@convention(method) (@guaranteed D1) -> (@owned Optional<A>, @error ErrorType)
// devirt_try_apply.D3.f1 () throws -> devirt_try_apply.A
sil @_TFC16devirt_try_apply2D32f1fzT_CS_1A : $@convention(method) (@guaranteed D3) -> (@owned A, @error ErrorType)
sil @compute_something : $@convention(thin) () -> (@owned Optional<A>, @error ErrorType)
// CHECK-MANDATORY-INLINING-LABEL: sil @test_devirt_try_apply_at_Onone
// CHECK-MANDATORY-INLINING: bb0:
// CHECK-MANDATORY-INLINING-NOT: bb1:
// CHECK-MANDATORY-INLINING: try_apply {{.*}}, normal [[NORMAL:bb[0-9]+]], error [[ERROR:bb[0-9]+]]
// Check that normal BB was reused and its argument was adjusted accordingly, i.e. its type is changed from Optional<A> to A
// CHECK-MANDATORY-INLINING: [[NORMAL]]({{%[0-9]+}} : $A):
// CHECK-MANDATORY-INLINING: strong_release
// CHECK-MANDATORY-INLINING: return
// Check that error BB was reused, because it only had a single predecessor and thus
// no critical edge would be created by this reuse.
// CHECK-MANDATORY-INLINING: [[ERROR]]({{%[0-9]+}} : $ErrorType):
// CHECK-MANDATORY-INLINING: strong_release
// CHECK-MANDATORY-INLINING: throw
// CHECK-MANDATORY-INLINING-NOT: bb3
// CHECK-MANDATORY-INLINING: }
sil @test_devirt_try_apply_at_Onone : $@convention(thin) () -> (@owned Optional<A>, @error ErrorType) {
bb0:
%2 = alloc_ref $D3
%3 = upcast %2 : $D3 to $D1
%4 = class_method %3 : $D1, #D1.f1!1 : D1 -> () throws -> Optional<A> , $@convention(method) (@guaranteed D1) -> (@owned Optional<A>, @error ErrorType)
try_apply %4(%3) : $@convention(method) (@guaranteed D1) -> (@owned Optional<A>, @error ErrorType), normal bb1, error bb2
bb1(%6 : $Optional<A>):
strong_release %2 : $D3
return %6 : $Optional<A>
bb2(%10 : $ErrorType):
strong_release %2 : $D3
throw %10 : $ErrorType
}
sil_vtable A {
}
sil_vtable D1 {
#D1.f1!1: _TFC16devirt_try_apply2D12f1fzT_GSqCS_1A_// devirt_try_apply.D1.f1 () throws -> Swift.Optional<devirt_try_apply.A>
}
sil_vtable D3 {
#D1.f1!1: _TFC16devirt_try_apply2D32f1fzT_CS_1A// devirt_try_apply.D3.f1 () throws -> devirt_try_apply.A
}
sil_vtable Base {
#Base.foo!1: _TFC16devirt_try_apply4Base3foofS0_FzT_GSqVs5Int32_
#Base.boo1!1: _TFC16devirt_try_apply4Base4boo1fS0_FzT_S0_
#Base.boo2!1: _TFC16devirt_try_apply4Base4boo2fS0_FzT_GSqS0__
#Base.deinit!deallocator: _TFC16devirt_try_apply4BaseD
#Base.init!initializer.1: _TFC16devirt_try_apply4BasecfMS0_FT_S0_
}
sil_vtable Derived1 {
#Base.foo!1: _TFC16devirt_try_apply8Derived13foofS0_FzT_GSqVs5Int32_
#Base.boo1!1: _TFC16devirt_try_apply8Derived14boo1fS0_FzT_S0_
#Base.boo2!1: _TFC16devirt_try_apply8Derived14boo2fS0_FzT_GSqS0__
#Base.init!initializer.1: _TFC16devirt_try_apply8Derived1cfMS0_FT_S0_
#Derived1.deinit!deallocator: _TFC16devirt_try_apply8Derived1D
}
sil_vtable Derived2 {
#Base.foo!1: _TTVFC16devirt_try_apply8Derived23foofS0_FzT_Vs5Int32
#Base.boo1!1: _TFC16devirt_try_apply8Derived24boo1fS0_FzT_S0_
#Base.boo2!1: _TFC16devirt_try_apply8Derived24boo2fS0_FzT_S0_
#Base.init!initializer.1: _TFC16devirt_try_apply8Derived2cfMS0_FT_S0_
#Derived2.deinit!deallocator: _TFC16devirt_try_apply8Derived2D
}
sil_vtable CP1 {
#CP1.foo!1: _TFC16devirt_try_apply3CP13foofS0_FzT_Vs5Int32
#CP1.deinit!deallocator: _TFC16devirt_try_apply3CP1D
#CP1.init!initializer.1: _TFC16devirt_try_apply3CP1cfMS0_FT_S0_
}
sil_vtable CP2 {
#CP1.foo!1: _TFC16devirt_try_apply3CP23foofS0_FzT_Vs5Int32
#CP1.init!initializer.1: _TFC16devirt_try_apply3CP2cfMS0_FT_S0_
#CP2.deinit!deallocator: _TFC16devirt_try_apply3CP2D
}
sil_witness_table CP1: P module devirt_try_apply {
method #P.foo!1: @_TTWC16devirt_try_apply3CP1S_1PS_FS1_3foouRq_S1__fq_FzT_Vs5Int32
}