16
16
#include " swift/SIL/SILDebugScope.h"
17
17
#include " swift/SIL/SILFunction.h"
18
18
#include " swift/SIL/SILModule.h"
19
+ #include " swift/SIL/SILOpenedArchetypesTracker.h"
19
20
#include " llvm/ADT/PointerUnion.h"
20
21
#include " llvm/ADT/StringExtras.h"
21
22
@@ -40,6 +41,16 @@ class SILBuilder {
40
41
// / recorded in this list.
41
42
SmallVectorImpl<SILInstruction *> *InsertedInstrs = nullptr ;
42
43
44
+ // / An immutable view on the set of available opened archetypes.
45
+ // / It is passed down to SILInstruction constructors and create
46
+ // / methods.
47
+ SILOpenedArchetypesState OpenedArchetypes;
48
+
49
+ // / Maps opened archetypes to their definitions. If provided,
50
+ // / can be used by the builder. It is supposed to be used
51
+ // / only by SILGen or SIL deserializers.
52
+ SILOpenedArchetypesTracker *OpenedArchetypesTracker = nullptr ;
53
+
43
54
public:
44
55
SILBuilder (SILFunction &F) : F(F), BB(0 ) {}
45
56
@@ -75,6 +86,19 @@ class SILBuilder {
75
86
return F.getModule ().getTypeLowering (T);
76
87
}
77
88
89
+ void setOpenedArchetypesTracker (SILOpenedArchetypesTracker *Tracker) {
90
+ this ->OpenedArchetypesTracker = Tracker;
91
+ this ->OpenedArchetypes .setOpenedArchetypesTracker (OpenedArchetypesTracker);
92
+ }
93
+
94
+ SILOpenedArchetypesTracker *getOpenedArchetypesTracker () const {
95
+ return OpenedArchetypesTracker;
96
+ }
97
+
98
+ SILOpenedArchetypesState &getOpenedArchetypes () {
99
+ return OpenedArchetypes;
100
+ }
101
+
78
102
void setCurrentDebugScope (const SILDebugScope *DS) { CurDebugScope = DS; }
79
103
const SILDebugScope *getCurrentDebugScope () const { return CurDebugScope; }
80
104
@@ -261,7 +285,8 @@ class SILBuilder {
261
285
SILType Result, ArrayRef<Substitution> Subs,
262
286
ArrayRef<SILValue> Args, bool isNonThrowing) {
263
287
return insert (ApplyInst::create (getSILDebugLocation (Loc), Fn, SubstFnTy,
264
- Result, Subs, Args, isNonThrowing, F));
288
+ Result, Subs, Args, isNonThrowing, F,
289
+ OpenedArchetypes));
265
290
}
266
291
267
292
ApplyInst *createApply (SILLocation Loc, SILValue Fn, ArrayRef<SILValue> Args,
@@ -278,16 +303,18 @@ class SILBuilder {
278
303
SILBasicBlock *errorBB) {
279
304
return insertTerminator (TryApplyInst::create (getSILDebugLocation (Loc),
280
305
fn, substFnTy, subs, args,
281
- normalBB, errorBB, F));
306
+ normalBB, errorBB, F,
307
+ OpenedArchetypes));
282
308
}
283
309
284
310
PartialApplyInst *createPartialApply (SILLocation Loc, SILValue Fn,
285
311
SILType SubstFnTy,
286
312
ArrayRef<Substitution> Subs,
287
313
ArrayRef<SILValue> Args,
288
314
SILType ClosureTy) {
289
- return insert (PartialApplyInst::create (
290
- getSILDebugLocation (Loc), Fn, SubstFnTy, Subs, Args, ClosureTy, F));
315
+ return insert (PartialApplyInst::create (getSILDebugLocation (Loc), Fn,
316
+ SubstFnTy, Subs, Args, ClosureTy, F,
317
+ OpenedArchetypes));
291
318
}
292
319
293
320
BuiltinInst *createBuiltin (SILLocation Loc, Identifier Name, SILType ResultTy,
@@ -526,8 +553,8 @@ class SILBuilder {
526
553
527
554
UncheckedRefCastInst *createUncheckedRefCast (SILLocation Loc, SILValue Op,
528
555
SILType Ty) {
529
- return insert (new (F. getModule ()) UncheckedRefCastInst (
530
- getSILDebugLocation (Loc), Op, Ty ));
556
+ return insert (UncheckedRefCastInst::create ( getSILDebugLocation (Loc), Op, Ty,
557
+ F, OpenedArchetypes ));
531
558
}
532
559
533
560
UncheckedRefCastAddrInst *
@@ -539,20 +566,20 @@ class SILBuilder {
539
566
540
567
UncheckedAddrCastInst *createUncheckedAddrCast (SILLocation Loc, SILValue Op,
541
568
SILType Ty) {
542
- return insert (new (F. getModule ()) UncheckedAddrCastInst (
543
- getSILDebugLocation (Loc), Op, Ty ));
569
+ return insert (UncheckedAddrCastInst::create ( getSILDebugLocation (Loc), Op,
570
+ Ty, F, OpenedArchetypes ));
544
571
}
545
572
546
573
UncheckedTrivialBitCastInst *
547
574
createUncheckedTrivialBitCast (SILLocation Loc, SILValue Op, SILType Ty) {
548
- return insert (new (F. getModule ()) UncheckedTrivialBitCastInst (
549
- getSILDebugLocation (Loc), Op, Ty));
575
+ return insert (UncheckedTrivialBitCastInst::create (
576
+ getSILDebugLocation (Loc), Op, Ty, F, OpenedArchetypes ));
550
577
}
551
578
552
579
UncheckedBitwiseCastInst *
553
580
createUncheckedBitwiseCast (SILLocation Loc, SILValue Op, SILType Ty) {
554
- return insert (new (F. getModule ()) UncheckedBitwiseCastInst (
555
- getSILDebugLocation (Loc), Op, Ty ));
581
+ return insert (UncheckedBitwiseCastInst::create ( getSILDebugLocation (Loc), Op,
582
+ Ty, F, OpenedArchetypes ));
556
583
}
557
584
558
585
RefToBridgeObjectInst *createRefToBridgeObject (SILLocation Loc, SILValue Ref,
@@ -648,8 +675,8 @@ class SILBuilder {
648
675
649
676
UnconditionalCheckedCastInst *
650
677
createUnconditionalCheckedCast (SILLocation Loc, SILValue op, SILType destTy) {
651
- return insert (new (F. getModule ()) UnconditionalCheckedCastInst (
652
- getSILDebugLocation (Loc), op, destTy));
678
+ return insert (UnconditionalCheckedCastInst::create (
679
+ getSILDebugLocation (Loc), op, destTy, F, OpenedArchetypes ));
653
680
}
654
681
655
682
UnconditionalCheckedCastAddrInst *createUnconditionalCheckedCastAddr (
@@ -896,11 +923,10 @@ class SILBuilder {
896
923
WitnessMethodInst *createWitnessMethod (SILLocation Loc, CanType LookupTy,
897
924
ProtocolConformanceRef Conformance,
898
925
SILDeclRef Member, SILType MethodTy,
899
- SILValue OptionalOpenedExistential,
900
926
bool Volatile = false ) {
901
927
return insert (WitnessMethodInst::create (
902
928
getSILDebugLocation (Loc), LookupTy, Conformance, Member, MethodTy,
903
- &F, OptionalOpenedExistential , Volatile));
929
+ &F, OpenedArchetypes , Volatile));
904
930
}
905
931
906
932
DynamicMethodInst *createDynamicMethod (SILLocation Loc, SILValue Operand,
@@ -912,27 +938,39 @@ class SILBuilder {
912
938
913
939
OpenExistentialAddrInst *
914
940
createOpenExistentialAddr (SILLocation Loc, SILValue Operand, SILType SelfTy) {
915
- return insert (new (F.getModule ()) OpenExistentialAddrInst (
941
+ auto *I = insert (new (F.getModule ()) OpenExistentialAddrInst (
916
942
getSILDebugLocation (Loc), Operand, SelfTy));
943
+ if (OpenedArchetypesTracker)
944
+ OpenedArchetypesTracker->registerOpenedArchetypes (I);
945
+ return I;
917
946
}
918
947
919
948
OpenExistentialMetatypeInst *createOpenExistentialMetatype (SILLocation Loc,
920
949
SILValue operand,
921
950
SILType selfTy) {
922
- return insert (new (F.getModule ()) OpenExistentialMetatypeInst (
951
+ auto *I = insert (new (F.getModule ()) OpenExistentialMetatypeInst (
923
952
getSILDebugLocation (Loc), operand, selfTy));
953
+ if (OpenedArchetypesTracker)
954
+ OpenedArchetypesTracker->registerOpenedArchetypes (I);
955
+ return I;
924
956
}
925
957
926
958
OpenExistentialRefInst *
927
959
createOpenExistentialRef (SILLocation Loc, SILValue Operand, SILType Ty) {
928
- return insert (new (F.getModule ()) OpenExistentialRefInst (
960
+ auto *I = insert (new (F.getModule ()) OpenExistentialRefInst (
929
961
getSILDebugLocation (Loc), Operand, Ty));
962
+ if (OpenedArchetypesTracker)
963
+ OpenedArchetypesTracker->registerOpenedArchetypes (I);
964
+ return I;
930
965
}
931
966
932
967
OpenExistentialBoxInst *
933
968
createOpenExistentialBox (SILLocation Loc, SILValue Operand, SILType Ty) {
934
- return insert (new (F.getModule ()) OpenExistentialBoxInst (
969
+ auto *I = insert (new (F.getModule ()) OpenExistentialBoxInst (
935
970
getSILDebugLocation (Loc), Operand, Ty));
971
+ if (OpenedArchetypesTracker)
972
+ OpenedArchetypesTracker->registerOpenedArchetypes (I);
973
+ return I;
936
974
}
937
975
938
976
InitExistentialAddrInst *
@@ -942,25 +980,25 @@ class SILBuilder {
942
980
ArrayRef<ProtocolConformanceRef> Conformances) {
943
981
return insert (InitExistentialAddrInst::create (
944
982
getSILDebugLocation (Loc), Existential, FormalConcreteType,
945
- LoweredConcreteType, Conformances, &F));
983
+ LoweredConcreteType, Conformances, &F, OpenedArchetypes ));
946
984
}
947
985
948
986
InitExistentialMetatypeInst *
949
987
createInitExistentialMetatype (SILLocation Loc, SILValue metatype,
950
988
SILType existentialType,
951
989
ArrayRef<ProtocolConformanceRef> conformances) {
952
990
return insert (InitExistentialMetatypeInst::create (
953
- getSILDebugLocation (Loc), existentialType, metatype, conformances,
954
- &F ));
991
+ getSILDebugLocation (Loc), existentialType, metatype, conformances, &F,
992
+ OpenedArchetypes ));
955
993
}
956
994
957
995
InitExistentialRefInst *
958
996
createInitExistentialRef (SILLocation Loc, SILType ExistentialType,
959
997
CanType FormalConcreteType, SILValue Concrete,
960
998
ArrayRef<ProtocolConformanceRef> Conformances) {
961
999
return insert (InitExistentialRefInst::create (
962
- getSILDebugLocation (Loc), ExistentialType, FormalConcreteType,
963
- Concrete, Conformances, &F));
1000
+ getSILDebugLocation (Loc), ExistentialType, FormalConcreteType, Concrete,
1001
+ Conformances, &F, OpenedArchetypes ));
964
1002
}
965
1003
966
1004
DeinitExistentialAddrInst *createDeinitExistentialAddr (SILLocation Loc,
@@ -992,8 +1030,8 @@ class SILBuilder {
992
1030
}
993
1031
994
1032
MetatypeInst *createMetatype (SILLocation Loc, SILType Metatype) {
995
- return insert (new (F. getModule ())
996
- MetatypeInst ( getSILDebugLocation (Loc), Metatype ));
1033
+ return insert (MetatypeInst::create ( getSILDebugLocation (Loc), Metatype,
1034
+ &F, OpenedArchetypes ));
997
1035
}
998
1036
999
1037
ObjCMetatypeToObjectInst *
@@ -1306,9 +1344,9 @@ class SILBuilder {
1306
1344
SILValue op, SILType destTy,
1307
1345
SILBasicBlock *successBB,
1308
1346
SILBasicBlock *failureBB) {
1309
- return insertTerminator (new (F. getModule ()) CheckedCastBranchInst (
1310
- getSILDebugLocation (Loc), isExact, op, destTy, successBB,
1311
- failureBB ));
1347
+ return insertTerminator (CheckedCastBranchInst::create (
1348
+ getSILDebugLocation (Loc), isExact, op, destTy, successBB, failureBB, F,
1349
+ OpenedArchetypes ));
1312
1350
}
1313
1351
1314
1352
CheckedCastAddrBranchInst *
0 commit comments