@@ -86,6 +86,8 @@ enum class SILValueCategory : uint8_t {
86
86
Address,
87
87
};
88
88
89
+ class SILPrinter ;
90
+
89
91
// / SILType - A Swift type that has been lowered to a SIL representation type.
90
92
// / In addition to the Swift type system, SIL adds "address" types that can
91
93
// / reference any Swift type (but cannot take the address of an address). *T
@@ -113,6 +115,8 @@ class SILType {
113
115
114
116
friend class Lowering ::TypeConverter;
115
117
friend struct llvm ::DenseMapInfo<SILType>;
118
+ friend class SILPrinter ;
119
+
116
120
public:
117
121
SILType () = default ;
118
122
@@ -184,8 +188,11 @@ class SILType {
184
188
// / type. This is done under the assumption that in all cases where we are
185
189
// / performing these AST queries on SILType, we are not interested in the
186
190
// / move only-ness of the value (which we can query separately anyways).
187
- CanType getASTType () const { return withoutMoveOnly ().getRawASTType (); }
191
+ CanType getASTType () const {
192
+ return removingMoveOnlyWrapper ().getRawASTType ();
193
+ }
188
194
195
+ private:
189
196
// / Returns the canonical AST type references by this SIL type without looking
190
197
// / through move only. Should only be used by internal utilities of SILType.
191
198
CanType getRawASTType () const { return CanType (value.getPointer ()); }
@@ -597,33 +604,34 @@ class SILType {
597
604
// /
598
605
// / Canonical way to check if a SILType is move only. Using is/getAs/castTo
599
606
// / will look through moveonly-ness.
600
- bool isMoveOnly () const { return getRawASTType ()->is <SILMoveOnlyType>(); }
607
+ bool isMoveOnlyWrapped () const {
608
+ return getRawASTType ()->is <SILMoveOnlyType>();
609
+ }
601
610
602
- // / Return * this if already move only... otherwise, wrap the current type
603
- // / within a move only type wrapper and return that. Idempotent!
604
- SILType asMoveOnly () const {
605
- if (isMoveOnly ())
611
+ // / If this is already a move only wrapped type, return *this. Otherwise, wrap
612
+ // / the copyable type in the mov eonly wrapper.
613
+ SILType addingMoveOnlyWrapper () const {
614
+ if (isMoveOnlyWrapped ())
606
615
return *this ;
607
616
auto newType = SILMoveOnlyType::get (getRawASTType ());
608
617
return SILType::getPrimitiveType (newType, getCategory ());
609
618
}
610
619
611
- // / Return this SILType, removing moveonly-ness.
612
- // /
613
- // / Is idempotent.
614
- SILType withoutMoveOnly () const {
615
- if (!isMoveOnly ())
620
+ // / If this is already a copyable type, just return *this. Otherwise, if this
621
+ // / is a move only wrapped copyable type, return the inner type.
622
+ SILType removingMoveOnlyWrapper () const {
623
+ if (!isMoveOnlyWrapped ())
616
624
return *this ;
617
625
auto moveOnly = getRawASTType ()->castTo <SILMoveOnlyType>();
618
626
return SILType::getPrimitiveType (moveOnly->getInnerType (), getCategory ());
619
627
}
620
628
621
- // / If \p otherType is move only, return this type that is move only as
622
- // / well. Otherwise, returns self. Useful for propagating "move only"-ness
629
+ // / If \p otherType is move only wrapped , return this type that is move only
630
+ // / as well. Otherwise, returns self. Useful for propagating "move only"-ness
623
631
// / from a parent type to a subtype.
624
- SILType copyMoveOnly (SILType otherType) const {
625
- if (otherType.isMoveOnly ()) {
626
- return asMoveOnly ();
632
+ SILType copyingMoveOnlyWrapper (SILType otherType) const {
633
+ if (otherType.isMoveOnlyWrapped ()) {
634
+ return addingMoveOnlyWrapper ();
627
635
}
628
636
return *this ;
629
637
}
0 commit comments