@@ -363,11 +363,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
363
363
HasCachedType : 1
364
364
);
365
365
366
- enum { NumFlagBits = 8 };
367
- SWIFT_INLINE_BITFIELD (ParenType, SugarType, NumFlagBits,
368
- // / Whether there is an original type.
369
- Flags : NumFlagBits
370
- );
366
+ SWIFT_INLINE_BITFIELD_EMPTY (ParenType, SugarType);
371
367
372
368
SWIFT_INLINE_BITFIELD_FULL (AnyFunctionType, TypeBase, NumAFTExtInfoBits+1 +1 +1 +16 ,
373
369
// / Extra information which affects how the function is called, like
@@ -429,11 +425,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
429
425
ArgCount : 32
430
426
);
431
427
432
- SWIFT_INLINE_BITFIELD_FULL (TupleType, TypeBase, 1 +32 ,
433
- // / Whether an element of the tuple is inout, __shared or __owned.
434
- // / Values cannot have such tuple types in the language.
435
- HasElementWithOwnership : 1 ,
436
-
428
+ SWIFT_INLINE_BITFIELD_FULL (TupleType, TypeBase, 32 ,
437
429
: NumPadBits,
438
430
439
431
// / The number of elements of the tuple.
@@ -724,8 +716,8 @@ class alignas(1 << TypeAlignInBits) TypeBase
724
716
return getRecursiveProperties ().isLValue ();
725
717
}
726
718
727
- // / Is this a first-class value type, meaning it is not an InOutType or a
728
- // / tuple type containing an InOutType?
719
+ // / Is this a first-class value type, meaning it is not an LValueType or an
720
+ // / InOutType.
729
721
bool isMaterializable ();
730
722
731
723
// / Is this a non-escaping type, that is, a non-escaping function type or a
@@ -1995,11 +1987,6 @@ class TypeAliasType final
1995
1987
}
1996
1988
};
1997
1989
1998
- // TODO: As part of AST modernization, replace with a proper
1999
- // 'ParameterTypeElt' or similar, and have FunctionTypes only have a list
2000
- // of 'ParameterTypeElt's. Then, this information can be removed from
2001
- // TupleTypeElt.
2002
- //
2003
1990
// / Provide parameter type relevant flags, i.e. variadic, autoclosure, and
2004
1991
// / escaping.
2005
1992
class ParameterTypeFlags {
@@ -2123,6 +2110,28 @@ class ParameterTypeFlags {
2123
2110
uint16_t toRaw () const { return value.toRaw (); }
2124
2111
};
2125
2112
2113
+ // / A type that indicates how parameter flags should be handled in an operation
2114
+ // / that requires the conversion into a type that doesn't support them, such as
2115
+ // / tuples.
2116
+ enum class ParameterFlagHandling {
2117
+ // / Ignores any parameter flags that may be present, dropping them from the
2118
+ // / result. This should only be used in specific cases, including e.g:
2119
+ // /
2120
+ // / - The flags have already been handled, and unsuitable flags have been
2121
+ // / rejected or asserted to not be present.
2122
+ // / - The flags aren't relevant for the particular conversion (e.g for type
2123
+ // / printing or compatibility logic).
2124
+ // / - The conversion is only interested in the 'internal argument' of a
2125
+ // / parameter, in which case only the type and label are relevant.
2126
+ // /
2127
+ // / In all other cases, you ought to verify that unsuitable flags are not
2128
+ // / present, or add assertions to that effect.
2129
+ IgnoreNonEmpty,
2130
+
2131
+ // / Asserts that no parameter flags are present.
2132
+ AssertEmpty
2133
+ };
2134
+
2126
2135
class YieldTypeFlags {
2127
2136
enum YieldFlags : uint8_t {
2128
2137
None = 0 ,
@@ -2196,21 +2205,12 @@ class YieldTypeFlags {
2196
2205
2197
2206
// / ParenType - A paren type is a type that's been written in parentheses.
2198
2207
class ParenType : public SugarType {
2199
- friend class ASTContext ;
2200
-
2201
- ParenType (Type UnderlyingType, RecursiveTypeProperties properties,
2202
- ParameterTypeFlags flags);
2208
+ ParenType (Type UnderlyingType, RecursiveTypeProperties properties);
2203
2209
2204
2210
public:
2205
- Type getUnderlyingType () const { return getSinglyDesugaredType (); }
2206
-
2207
- static ParenType *get (const ASTContext &C, Type underlying,
2208
- ParameterTypeFlags flags = {});
2211
+ static ParenType *get (const ASTContext &C, Type underlying);
2209
2212
2210
- // / Get the parameter flags
2211
- ParameterTypeFlags getParameterFlags () const {
2212
- return ParameterTypeFlags::fromRaw (Bits.ParenType .Flags );
2213
- }
2213
+ Type getUnderlyingType () const { return getSinglyDesugaredType (); }
2214
2214
2215
2215
// Implement isa/cast/dyncast/etc.
2216
2216
static bool classof (const TypeBase *T) {
@@ -2226,37 +2226,17 @@ class TupleTypeElt {
2226
2226
// / This is the type of the field.
2227
2227
Type ElementType;
2228
2228
2229
- // / Flags that are specific to and relevant for parameter types
2230
- ParameterTypeFlags Flags;
2231
-
2232
2229
friend class TupleType ;
2233
2230
2234
2231
public:
2235
2232
TupleTypeElt () = default ;
2236
- TupleTypeElt (Type ty, Identifier name = Identifier(),
2237
- ParameterTypeFlags fl = {});
2238
-
2233
+ TupleTypeElt (Type ty, Identifier name = Identifier());
2234
+
2239
2235
bool hasName () const { return !Name.empty (); }
2240
2236
Identifier getName () const { return Name; }
2241
-
2242
- Type getRawType () const { return ElementType; }
2243
- Type getType () const ;
2244
2237
2245
- ParameterTypeFlags getParameterFlags () const { return Flags ; }
2238
+ Type getType () const { return ElementType ; }
2246
2239
2247
- // / Determine whether this field is variadic.
2248
- bool isVararg () const { return Flags.isVariadic (); }
2249
-
2250
- // / Determine whether this field is an autoclosure parameter closure.
2251
- bool isAutoClosure () const { return Flags.isAutoClosure (); }
2252
-
2253
- // / Determine whether this field is marked 'inout'.
2254
- bool isInOut () const { return Flags.isInOut (); }
2255
-
2256
- // / Remove the type of this varargs element designator, without the array
2257
- // / type wrapping it.
2258
- Type getVarargBaseTy () const ;
2259
-
2260
2240
// / Retrieve a copy of this tuple type element with the type replaced.
2261
2241
TupleTypeElt getWithType (Type T) const ;
2262
2242
@@ -2318,11 +2298,6 @@ class TupleType final : public TypeBase, public llvm::FoldingSetNode,
2318
2298
// / getNamedElementId - If this tuple has an element with the specified name,
2319
2299
// / return the element index, otherwise return -1.
2320
2300
int getNamedElementId (Identifier I) const ;
2321
-
2322
- // / Returns true if this tuple has inout, __shared or __owned elements.
2323
- bool hasElementWithOwnership () const {
2324
- return static_cast <bool >(Bits.TupleType .HasElementWithOwnership );
2325
- }
2326
2301
2327
2302
// Implement isa/cast/dyncast/etc.
2328
2303
static bool classof (const TypeBase *T) {
@@ -2337,13 +2312,11 @@ class TupleType final : public TypeBase, public llvm::FoldingSetNode,
2337
2312
2338
2313
private:
2339
2314
TupleType (ArrayRef<TupleTypeElt> elements, const ASTContext *CanCtx,
2340
- RecursiveTypeProperties properties,
2341
- bool hasElementWithOwnership)
2342
- : TypeBase(TypeKind::Tuple, CanCtx, properties) {
2343
- Bits.TupleType .HasElementWithOwnership = hasElementWithOwnership;
2344
- Bits.TupleType .Count = elements.size ();
2345
- std::uninitialized_copy (elements.begin (), elements.end (),
2346
- getTrailingObjects<TupleTypeElt>());
2315
+ RecursiveTypeProperties properties)
2316
+ : TypeBase(TypeKind::Tuple, CanCtx, properties) {
2317
+ Bits.TupleType .Count = elements.size ();
2318
+ std::uninitialized_copy (elements.begin (), elements.end (),
2319
+ getTrailingObjects<TupleTypeElt>());
2347
2320
}
2348
2321
};
2349
2322
BEGIN_CAN_TYPE_WRAPPER (TupleType, Type)
@@ -3127,10 +3100,9 @@ class AnyFunctionType : public TypeBase {
3127
3100
public:
3128
3101
// / Take an array of parameters and turn it into a tuple or paren type.
3129
3102
// /
3130
- // / \param wantParamFlags Whether to preserve the parameter flags from the
3131
- // / given set of parameters.
3103
+ // / \param paramFlagHandling How to handle the parameter flags.
3132
3104
static Type composeTuple (ASTContext &ctx, ArrayRef<Param> params,
3133
- bool wantParamFlags = true );
3105
+ ParameterFlagHandling paramFlagHandling );
3134
3106
3135
3107
// / Given two arrays of parameters determine if they are equal in their
3136
3108
// / canonicalized form. Internal labels and type sugar is *not* taken into
@@ -6533,17 +6505,9 @@ inline bool TypeBase::isTypeSequenceParameter() {
6533
6505
t->castTo <GenericTypeParamType>()->isTypeSequence ();
6534
6506
}
6535
6507
6508
+ // TODO: This will become redundant once InOutType is removed.
6536
6509
inline bool TypeBase::isMaterializable () {
6537
- if (hasLValueType ())
6538
- return false ;
6539
-
6540
- if (is<InOutType>())
6541
- return false ;
6542
-
6543
- if (auto *TTy = getAs<TupleType>())
6544
- return !TTy->hasElementWithOwnership ();
6545
-
6546
- return true ;
6510
+ return !(hasLValueType () || is<InOutType>());
6547
6511
}
6548
6512
6549
6513
inline GenericTypeParamType *TypeBase::getRootGenericParam () {
@@ -6755,26 +6719,12 @@ inline bool CanType::isActuallyCanonicalOrNull() const {
6755
6719
getPointer ()->isCanonical ();
6756
6720
}
6757
6721
6758
- inline Type TupleTypeElt::getVarargBaseTy () const {
6759
- TypeBase *T = getType ().getPointer ();
6760
- if (auto *AT = dyn_cast<VariadicSequenceType>(T))
6761
- return AT->getBaseType ();
6762
- if (auto *BGT = dyn_cast<BoundGenericType>(T)) {
6763
- // It's the stdlib Array<T>.
6764
- return BGT->getGenericArgs ()[0 ];
6765
- }
6766
- assert (T->hasError ());
6767
- return T;
6768
- }
6769
-
6770
6722
inline TupleTypeElt TupleTypeElt::getWithName (Identifier name) const {
6771
- assert (getParameterFlags ().isInOut () == getType ()->is <InOutType>());
6772
- return TupleTypeElt (getRawType (), name, getParameterFlags ());
6723
+ return TupleTypeElt (getType (), name);
6773
6724
}
6774
6725
6775
6726
inline TupleTypeElt TupleTypeElt::getWithType (Type T) const {
6776
- auto flags = getParameterFlags ().withInOut (T->is <InOutType>());
6777
- return TupleTypeElt (T->getInOutObjectType (), getName (), flags);
6727
+ return TupleTypeElt (T, getName ());
6778
6728
}
6779
6729
6780
6730
// / Create one from what's present in the parameter decl and type
0 commit comments