Skip to content

Commit dab78c6

Browse files
committed
[AST] Remove ParameterTypeFlags from ParenType and TupleType
The last clients that relied on stashing parameter type flags on these types are now gone.
1 parent 9973c8f commit dab78c6

24 files changed

+62
-261
lines changed

include/swift/AST/TypeMatcher.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ class TypeMatcher {
125125
const auto &firstElt = firstTuple->getElements()[i];
126126
const auto &secondElt = secondTuple->getElements()[i];
127127

128-
if (firstElt.getName() != secondElt.getName() ||
129-
firstElt.isVararg() != secondElt.isVararg())
128+
if (firstElt.getName() != secondElt.getName()) {
130129
return mismatch(firstTuple.getPointer(), secondTuple,
131130
sugaredFirstType);
131+
}
132132

133133
// Recurse on the tuple elements.
134134
if (!this->visit(firstTuple.getElementType(i), secondElt.getType(),

include/swift/AST/Types.h

Lines changed: 19 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
363363
HasCachedType : 1
364364
);
365365

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);
371367

372368
SWIFT_INLINE_BITFIELD_FULL(AnyFunctionType, TypeBase, NumAFTExtInfoBits+1+1+1+16,
373369
/// Extra information which affects how the function is called, like
@@ -429,11 +425,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
429425
ArgCount : 32
430426
);
431427

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,
437429
: NumPadBits,
438430

439431
/// The number of elements of the tuple.
@@ -724,8 +716,8 @@ class alignas(1 << TypeAlignInBits) TypeBase
724716
return getRecursiveProperties().isLValue();
725717
}
726718

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.
729721
bool isMaterializable();
730722

731723
/// Is this a non-escaping type, that is, a non-escaping function type or a
@@ -2201,21 +2193,12 @@ class YieldTypeFlags {
22012193

22022194
/// ParenType - A paren type is a type that's been written in parentheses.
22032195
class ParenType : public SugarType {
2204-
friend class ASTContext;
2205-
2206-
ParenType(Type UnderlyingType, RecursiveTypeProperties properties,
2207-
ParameterTypeFlags flags);
2196+
ParenType(Type UnderlyingType, RecursiveTypeProperties properties);
22082197

22092198
public:
2210-
Type getUnderlyingType() const { return getSinglyDesugaredType(); }
2199+
static ParenType *get(const ASTContext &C, Type underlying);
22112200

2212-
static ParenType *get(const ASTContext &C, Type underlying,
2213-
ParameterTypeFlags flags = {});
2214-
2215-
/// Get the parameter flags
2216-
ParameterTypeFlags getParameterFlags() const {
2217-
return ParameterTypeFlags::fromRaw(Bits.ParenType.Flags);
2218-
}
2201+
Type getUnderlyingType() const { return getSinglyDesugaredType(); }
22192202

22202203
// Implement isa/cast/dyncast/etc.
22212204
static bool classof(const TypeBase *T) {
@@ -2231,37 +2214,17 @@ class TupleTypeElt {
22312214
/// This is the type of the field.
22322215
Type ElementType;
22332216

2234-
/// Flags that are specific to and relevant for parameter types
2235-
ParameterTypeFlags Flags;
2236-
22372217
friend class TupleType;
22382218

22392219
public:
22402220
TupleTypeElt() = default;
2241-
TupleTypeElt(Type ty, Identifier name = Identifier(),
2242-
ParameterTypeFlags fl = {});
2243-
2221+
TupleTypeElt(Type ty, Identifier name = Identifier());
2222+
22442223
bool hasName() const { return !Name.empty(); }
22452224
Identifier getName() const { return Name; }
2246-
2247-
Type getRawType() const { return ElementType; }
2248-
Type getType() const;
2249-
2250-
ParameterTypeFlags getParameterFlags() const { return Flags; }
2251-
2252-
/// Determine whether this field is variadic.
2253-
bool isVararg() const { return Flags.isVariadic(); }
22542225

2255-
/// Determine whether this field is an autoclosure parameter closure.
2256-
bool isAutoClosure() const { return Flags.isAutoClosure(); }
2226+
Type getType() const { return ElementType; }
22572227

2258-
/// Determine whether this field is marked 'inout'.
2259-
bool isInOut() const { return Flags.isInOut(); }
2260-
2261-
/// Remove the type of this varargs element designator, without the array
2262-
/// type wrapping it.
2263-
Type getVarargBaseTy() const;
2264-
22652228
/// Retrieve a copy of this tuple type element with the type replaced.
22662229
TupleTypeElt getWithType(Type T) const;
22672230

@@ -2323,11 +2286,6 @@ class TupleType final : public TypeBase, public llvm::FoldingSetNode,
23232286
/// getNamedElementId - If this tuple has an element with the specified name,
23242287
/// return the element index, otherwise return -1.
23252288
int getNamedElementId(Identifier I) const;
2326-
2327-
/// Returns true if this tuple has inout, __shared or __owned elements.
2328-
bool hasElementWithOwnership() const {
2329-
return static_cast<bool>(Bits.TupleType.HasElementWithOwnership);
2330-
}
23312289

23322290
// Implement isa/cast/dyncast/etc.
23332291
static bool classof(const TypeBase *T) {
@@ -2342,13 +2300,11 @@ class TupleType final : public TypeBase, public llvm::FoldingSetNode,
23422300

23432301
private:
23442302
TupleType(ArrayRef<TupleTypeElt> elements, const ASTContext *CanCtx,
2345-
RecursiveTypeProperties properties,
2346-
bool hasElementWithOwnership)
2347-
: TypeBase(TypeKind::Tuple, CanCtx, properties) {
2348-
Bits.TupleType.HasElementWithOwnership = hasElementWithOwnership;
2349-
Bits.TupleType.Count = elements.size();
2350-
std::uninitialized_copy(elements.begin(), elements.end(),
2351-
getTrailingObjects<TupleTypeElt>());
2303+
RecursiveTypeProperties properties)
2304+
: TypeBase(TypeKind::Tuple, CanCtx, properties) {
2305+
Bits.TupleType.Count = elements.size();
2306+
std::uninitialized_copy(elements.begin(), elements.end(),
2307+
getTrailingObjects<TupleTypeElt>());
23522308
}
23532309
};
23542310
BEGIN_CAN_TYPE_WRAPPER(TupleType, Type)
@@ -6537,17 +6493,9 @@ inline bool TypeBase::isTypeSequenceParameter() {
65376493
t->castTo<GenericTypeParamType>()->isTypeSequence();
65386494
}
65396495

6496+
// TODO: This will become redundant once InOutType is removed.
65406497
inline bool TypeBase::isMaterializable() {
6541-
if (hasLValueType())
6542-
return false;
6543-
6544-
if (is<InOutType>())
6545-
return false;
6546-
6547-
if (auto *TTy = getAs<TupleType>())
6548-
return !TTy->hasElementWithOwnership();
6549-
6550-
return true;
6498+
return !(hasLValueType() || is<InOutType>());
65516499
}
65526500

65536501
inline GenericTypeParamType *TypeBase::getRootGenericParam() {
@@ -6759,26 +6707,12 @@ inline bool CanType::isActuallyCanonicalOrNull() const {
67596707
getPointer()->isCanonical();
67606708
}
67616709

6762-
inline Type TupleTypeElt::getVarargBaseTy() const {
6763-
TypeBase *T = getType().getPointer();
6764-
if (auto *AT = dyn_cast<VariadicSequenceType>(T))
6765-
return AT->getBaseType();
6766-
if (auto *BGT = dyn_cast<BoundGenericType>(T)) {
6767-
// It's the stdlib Array<T>.
6768-
return BGT->getGenericArgs()[0];
6769-
}
6770-
assert(T->hasError());
6771-
return T;
6772-
}
6773-
67746710
inline TupleTypeElt TupleTypeElt::getWithName(Identifier name) const {
6775-
assert(getParameterFlags().isInOut() == getType()->is<InOutType>());
6776-
return TupleTypeElt(getRawType(), name, getParameterFlags());
6711+
return TupleTypeElt(getType(), name);
67776712
}
67786713

67796714
inline TupleTypeElt TupleTypeElt::getWithType(Type T) const {
6780-
auto flags = getParameterFlags().withInOut(T->is<InOutType>());
6781-
return TupleTypeElt(T->getInOutObjectType(), getName(), flags);
6715+
return TupleTypeElt(T, getName());
67826716
}
67836717

67846718
/// Create one from what's present in the parameter decl and type

lib/AST/ASTContext.cpp

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,7 @@ struct ASTContext::Implementation {
397397
llvm::DenseMap<Type, VariadicSequenceType*> VariadicSequenceTypes;
398398
llvm::DenseMap<std::pair<Type, Type>, DictionaryType *> DictionaryTypes;
399399
llvm::DenseMap<Type, OptionalType*> OptionalTypes;
400-
llvm::DenseMap<Type, ParenType*> SimpleParenTypes; // Most are simple
401-
llvm::DenseMap<std::pair<Type, unsigned>, ParenType*> ParenTypes;
400+
llvm::DenseMap<Type, ParenType*> ParenTypes;
402401
llvm::DenseMap<uintptr_t, ReferenceStorageType*> ReferenceStorageTypes;
403402
llvm::DenseMap<Type, LValueType*> LValueTypes;
404403
llvm::DenseMap<Type, InOutType*> InOutTypes;
@@ -2626,7 +2625,6 @@ size_t ASTContext::Implementation::Arena::getTotalMemory() const {
26262625
llvm::capacity_in_bytes(DictionaryTypes) +
26272626
llvm::capacity_in_bytes(OptionalTypes) +
26282627
llvm::capacity_in_bytes(VariadicSequenceTypes) +
2629-
llvm::capacity_in_bytes(SimpleParenTypes) +
26302628
llvm::capacity_in_bytes(ParenTypes) +
26312629
llvm::capacity_in_bytes(ReferenceStorageTypes) +
26322630
llvm::capacity_in_bytes(LValueTypes) +
@@ -2836,22 +2834,14 @@ BuiltinVectorType *BuiltinVectorType::get(const ASTContext &context,
28362834
return vecTy;
28372835
}
28382836

2839-
ParenType *ParenType::get(const ASTContext &C, Type underlying,
2840-
ParameterTypeFlags fl) {
2841-
if (fl.isInOut())
2842-
assert(!underlying->is<InOutType>() && "caller did not pass a base type");
2843-
if (underlying->is<InOutType>())
2844-
assert(fl.isInOut() && "caller did not set flags correctly");
2845-
2837+
ParenType *ParenType::get(const ASTContext &C, Type underlying) {
28462838
auto properties = underlying->getRecursiveProperties();
28472839
auto arena = getArena(properties);
2848-
auto flags = fl.toRaw();
2849-
ParenType *&Result = flags == 0
2850-
? C.getImpl().getArena(arena).SimpleParenTypes[underlying]
2851-
: C.getImpl().getArena(arena).ParenTypes[{underlying, flags}];
2840+
ParenType *&Result = C.getImpl().getArena(arena).ParenTypes[underlying];
28522841
if (Result == nullptr) {
2853-
Result = new (C, arena) ParenType(underlying,
2854-
properties, fl);
2842+
Result = new (C, arena) ParenType(underlying, properties);
2843+
assert((C.hadError() || !underlying->is<InOutType>()) &&
2844+
"Cannot wrap InOutType");
28552845
}
28562846
return Result;
28572847
}
@@ -2866,35 +2856,19 @@ void TupleType::Profile(llvm::FoldingSetNodeID &ID,
28662856
for (const TupleTypeElt &Elt : Fields) {
28672857
ID.AddPointer(Elt.Name.get());
28682858
ID.AddPointer(Elt.getType().getPointer());
2869-
ID.AddInteger(Elt.Flags.toRaw());
28702859
}
28712860
}
28722861

28732862
/// getTupleType - Return the uniqued tuple type with the specified elements.
28742863
Type TupleType::get(ArrayRef<TupleTypeElt> Fields, const ASTContext &C) {
2875-
if (Fields.size() == 1 && !Fields[0].isVararg() && !Fields[0].hasName())
2876-
return ParenType::get(C, Fields[0].getRawType(),
2877-
Fields[0].getParameterFlags());
2864+
if (Fields.size() == 1 && !Fields[0].hasName())
2865+
return ParenType::get(C, Fields[0].getType());
28782866

28792867
RecursiveTypeProperties properties;
2880-
bool hasElementWithOwnership = false;
28812868
for (const TupleTypeElt &Elt : Fields) {
28822869
auto eltTy = Elt.getType();
28832870
if (!eltTy) continue;
2884-
28852871
properties |= eltTy->getRecursiveProperties();
2886-
// Recur into paren types and canonicalized paren types. 'inout' in nested
2887-
// non-paren tuples are malformed and will be diagnosed later.
2888-
if (auto *TTy = Elt.getType()->getAs<TupleType>()) {
2889-
if (TTy->getNumElements() == 1)
2890-
hasElementWithOwnership |= TTy->hasElementWithOwnership();
2891-
} else if (auto *Pty = dyn_cast<ParenType>(Elt.getType().getPointer())) {
2892-
hasElementWithOwnership |= (Pty->getParameterFlags().getValueOwnership() !=
2893-
ValueOwnership::Default);
2894-
} else {
2895-
hasElementWithOwnership |= (Elt.getParameterFlags().getValueOwnership() !=
2896-
ValueOwnership::Default);
2897-
}
28982872
}
28992873

29002874
auto arena = getArena(properties);
@@ -2919,24 +2893,15 @@ Type TupleType::get(ArrayRef<TupleTypeElt> Fields, const ASTContext &C) {
29192893
size_t bytes = totalSizeToAlloc<TupleTypeElt>(Fields.size());
29202894
// TupleType will copy the fields list into ASTContext owned memory.
29212895
void *mem = C.Allocate(bytes, alignof(TupleType), arena);
2922-
auto New = new (mem) TupleType(Fields, IsCanonical ? &C : nullptr, properties,
2923-
hasElementWithOwnership);
2896+
auto New = new (mem) TupleType(Fields, IsCanonical ? &C : nullptr,
2897+
properties);
29242898
C.getImpl().getArena(arena).TupleTypes.InsertNode(New, InsertPos);
29252899
return New;
29262900
}
29272901

2928-
TupleTypeElt::TupleTypeElt(Type ty, Identifier name,
2929-
ParameterTypeFlags fl)
2930-
: Name(name), ElementType(ty), Flags(fl) {
2931-
if (fl.isInOut())
2932-
assert(!ty->is<InOutType>() && "caller did not pass a base type");
2933-
if (ty->is<InOutType>())
2934-
assert(fl.isInOut() && "caller did not set flags correctly");
2935-
}
2936-
2937-
Type TupleTypeElt::getType() const {
2938-
if (Flags.isInOut()) return InOutType::get(ElementType);
2939-
return ElementType;
2902+
TupleTypeElt::TupleTypeElt(Type ty, Identifier name)
2903+
: Name(name), ElementType(ty) {
2904+
assert(!ty->is<InOutType>() && "Cannot have InOutType in a tuple");
29402905
}
29412906

29422907
PackExpansionType *PackExpansionType::get(Type patternTy) {

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3649,7 +3649,6 @@ namespace {
36493649

36503650
void visitParenType(ParenType *T, StringRef label) {
36513651
printCommon(label, "paren_type");
3652-
dumpParameterFlags(T->getParameterFlags());
36533652
printRec(T->getUnderlyingType());
36543653
PrintWithColorRAII(OS, ParenthesisColor) << ')';
36553654
}
@@ -3664,7 +3663,6 @@ namespace {
36643663
PrintWithColorRAII(OS, TypeFieldColor) << "tuple_type_elt";
36653664
if (elt.hasName())
36663665
printField("name", elt.getName().str());
3667-
dumpParameterFlags(elt.getParameterFlags());
36683666
printRec(elt.getType());
36693667
OS << ")";
36703668
}

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,8 +2749,7 @@ void ASTMangler::appendTypeList(Type listTy, GenericSignature sig,
27492749
return appendOperator("y");
27502750
bool firstField = true;
27512751
for (auto &field : tuple->getElements()) {
2752-
assert(field.getParameterFlags().isNone());
2753-
appendTypeListElement(field.getName(), field.getRawType(),
2752+
appendTypeListElement(field.getName(), field.getType(),
27542753
ParameterTypeFlags(),
27552754
sig, forDecl);
27562755
appendListSeparator(firstField);

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5498,8 +5498,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
54985498

54995499
void visitParenType(ParenType *T) {
55005500
Printer << "(";
5501-
printParameterFlags(Printer, Options, T->getParameterFlags(),
5502-
/*escaping*/ false);
55035501
visit(T->getUnderlyingType()->getInOutObjectType());
55045502
Printer << ")";
55055503
}
@@ -5534,7 +5532,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
55345532
if (i)
55355533
Printer << ", ";
55365534
const TupleTypeElt &TD = Fields[i];
5537-
Type EltType = TD.getRawType();
5535+
Type EltType = TD.getType();
55385536

55395537
Printer.callPrintStructurePre(PrintStructureKind::TupleElement);
55405538
SWIFT_DEFER {
@@ -5545,14 +5543,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
55455543
Printer.printName(TD.getName(), PrintNameContext::TupleElement);
55465544
Printer << ": ";
55475545
}
5548-
if (TD.isVararg()) {
5549-
visit(TD.getVarargBaseTy());
5550-
Printer << "...";
5551-
} else {
5552-
printParameterFlags(Printer, Options, TD.getParameterFlags(),
5553-
/*escaping*/ false);
5554-
visit(EltType);
5555-
}
5546+
visit(EltType);
55565547
}
55575548
Printer << ")";
55585549
}

lib/AST/ASTVerifier.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,13 +1130,6 @@ class Verifier : public ASTWalker {
11301130
Out << elt->getType() << "\n";
11311131
abort();
11321132
}
1133-
if (!field.getParameterFlags().isNone()) {
1134-
Out << "TupleExpr has non-empty parameter flags?\n";
1135-
Out << "sub expr: \n";
1136-
elt->dump(Out);
1137-
Out << "\n";
1138-
abort();
1139-
}
11401133
});
11411134
verifyCheckedBase(E);
11421135
}
@@ -1982,10 +1975,6 @@ class Verifier : public ASTWalker {
19821975
Out << "ParenExpr not of ParenType\n";
19831976
abort();
19841977
}
1985-
if (!ty->getParameterFlags().isNone()) {
1986-
Out << "ParenExpr has non-empty parameter flags?\n";
1987-
abort();
1988-
}
19891978
verifyCheckedBase(E);
19901979
}
19911980

0 commit comments

Comments
 (0)