Skip to content

Commit 90b1cf1

Browse files
committed
xxx
1 parent ef02b47 commit 90b1cf1

22 files changed

+49
-227
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: 14 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
345345
HasCachedType : 1
346346
);
347347

348-
enum { NumFlagBits = 8 };
349-
SWIFT_INLINE_BITFIELD(ParenType, SugarType, NumFlagBits,
350-
/// Whether there is an original type.
351-
Flags : NumFlagBits
352-
);
348+
SWIFT_INLINE_BITFIELD_EMPTY(ParenType, SugarType);
353349

354350
SWIFT_INLINE_BITFIELD_FULL(AnyFunctionType, TypeBase, NumAFTExtInfoBits+1+1+1+16,
355351
/// Extra information which affects how the function is called, like
@@ -407,11 +403,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
407403
Count : 32
408404
);
409405

410-
SWIFT_INLINE_BITFIELD_FULL(TupleType, TypeBase, 1+32,
411-
/// Whether an element of the tuple is inout, __shared or __owned.
412-
/// Values cannot have such tuple types in the language.
413-
HasElementWithOwnership : 1,
414-
406+
SWIFT_INLINE_BITFIELD_FULL(TupleType, TypeBase, 32,
415407
: NumPadBits,
416408

417409
/// The number of elements of the tuple.
@@ -2104,20 +2096,13 @@ class YieldTypeFlags {
21042096
/// ParenType - A paren type is a type that's been written in parentheses.
21052097
class ParenType : public SugarType {
21062098
friend class ASTContext;
2107-
2108-
ParenType(Type UnderlyingType, RecursiveTypeProperties properties,
2109-
ParameterTypeFlags flags);
2099+
2100+
ParenType(Type UnderlyingType, RecursiveTypeProperties properties);
21102101

21112102
public:
21122103
Type getUnderlyingType() const { return getSinglyDesugaredType(); }
21132104

2114-
static ParenType *get(const ASTContext &C, Type underlying,
2115-
ParameterTypeFlags flags = {});
2116-
2117-
/// Get the parameter flags
2118-
ParameterTypeFlags getParameterFlags() const {
2119-
return ParameterTypeFlags::fromRaw(Bits.ParenType.Flags);
2120-
}
2105+
static ParenType *get(const ASTContext &C, Type underlying);
21212106

21222107
// Implement isa/cast/dyncast/etc.
21232108
static bool classof(const TypeBase *T) {
@@ -2133,37 +2118,18 @@ class TupleTypeElt {
21332118
/// This is the type of the field.
21342119
Type ElementType;
21352120

2136-
/// Flags that are specific to and relevant for parameter types
2137-
ParameterTypeFlags Flags;
2138-
21392121
friend class TupleType;
21402122

21412123
public:
21422124
TupleTypeElt() = default;
2143-
TupleTypeElt(Type ty, Identifier name = Identifier(),
2144-
ParameterTypeFlags fl = {});
2145-
2125+
TupleTypeElt(Type ty, Identifier name = Identifier());
2126+
21462127
bool hasName() const { return !Name.empty(); }
21472128
Identifier getName() const { return Name; }
21482129

21492130
Type getRawType() const { return ElementType; }
21502131
Type getType() const;
21512132

2152-
ParameterTypeFlags getParameterFlags() const { return Flags; }
2153-
2154-
/// Determine whether this field is variadic.
2155-
bool isVararg() const { return Flags.isVariadic(); }
2156-
2157-
/// Determine whether this field is an autoclosure parameter closure.
2158-
bool isAutoClosure() const { return Flags.isAutoClosure(); }
2159-
2160-
/// Determine whether this field is marked 'inout'.
2161-
bool isInOut() const { return Flags.isInOut(); }
2162-
2163-
/// Remove the type of this varargs element designator, without the array
2164-
/// type wrapping it.
2165-
Type getVarargBaseTy() const;
2166-
21672133
/// Retrieve a copy of this tuple type element with the type replaced.
21682134
TupleTypeElt getWithType(Type T) const;
21692135

@@ -2225,11 +2191,6 @@ class TupleType final : public TypeBase, public llvm::FoldingSetNode,
22252191
/// getNamedElementId - If this tuple has an element with the specified name,
22262192
/// return the element index, otherwise return -1.
22272193
int getNamedElementId(Identifier I) const;
2228-
2229-
/// Returns true if this tuple has inout, __shared or __owned elements.
2230-
bool hasElementWithOwnership() const {
2231-
return static_cast<bool>(Bits.TupleType.HasElementWithOwnership);
2232-
}
22332194

22342195
// Implement isa/cast/dyncast/etc.
22352196
static bool classof(const TypeBase *T) {
@@ -2244,13 +2205,11 @@ class TupleType final : public TypeBase, public llvm::FoldingSetNode,
22442205

22452206
private:
22462207
TupleType(ArrayRef<TupleTypeElt> elements, const ASTContext *CanCtx,
2247-
RecursiveTypeProperties properties,
2248-
bool hasElementWithOwnership)
2249-
: TypeBase(TypeKind::Tuple, CanCtx, properties) {
2250-
Bits.TupleType.HasElementWithOwnership = hasElementWithOwnership;
2251-
Bits.TupleType.Count = elements.size();
2252-
std::uninitialized_copy(elements.begin(), elements.end(),
2253-
getTrailingObjects<TupleTypeElt>());
2208+
RecursiveTypeProperties properties)
2209+
: TypeBase(TypeKind::Tuple, CanCtx, properties) {
2210+
Bits.TupleType.Count = elements.size();
2211+
std::uninitialized_copy(elements.begin(), elements.end(),
2212+
getTrailingObjects<TupleTypeElt>());
22542213
}
22552214
};
22562215
BEGIN_CAN_TYPE_WRAPPER(TupleType, Type)
@@ -6061,9 +6020,6 @@ inline bool TypeBase::isMaterializable() {
60616020
if (is<InOutType>())
60626021
return false;
60636022

6064-
if (auto *TTy = getAs<TupleType>())
6065-
return !TTy->hasElementWithOwnership();
6066-
60676023
return true;
60686024
}
60696025

@@ -6254,26 +6210,12 @@ inline bool CanType::isActuallyCanonicalOrNull() const {
62546210
getPointer()->isCanonical();
62556211
}
62566212

6257-
inline Type TupleTypeElt::getVarargBaseTy() const {
6258-
TypeBase *T = getType().getPointer();
6259-
if (auto *AT = dyn_cast<VariadicSequenceType>(T))
6260-
return AT->getBaseType();
6261-
if (auto *BGT = dyn_cast<BoundGenericType>(T)) {
6262-
// It's the stdlib Array<T>.
6263-
return BGT->getGenericArgs()[0];
6264-
}
6265-
assert(T->hasError());
6266-
return T;
6267-
}
6268-
62696213
inline TupleTypeElt TupleTypeElt::getWithName(Identifier name) const {
6270-
assert(getParameterFlags().isInOut() == getType()->is<InOutType>());
6271-
return TupleTypeElt(getRawType(), name, getParameterFlags());
6214+
return TupleTypeElt(getRawType(), name);
62726215
}
62736216

62746217
inline TupleTypeElt TupleTypeElt::getWithType(Type T) const {
6275-
auto flags = getParameterFlags().withInOut(T->is<InOutType>());
6276-
return TupleTypeElt(T->getInOutObjectType(), getName(), flags);
6218+
return TupleTypeElt(T, getName());
62776219
}
62786220

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

lib/AST/ASTContext.cpp

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ struct ASTContext::Implementation {
396396
llvm::DenseMap<Type, VariadicSequenceType*> VariadicSequenceTypes;
397397
llvm::DenseMap<std::pair<Type, Type>, DictionaryType *> DictionaryTypes;
398398
llvm::DenseMap<Type, OptionalType*> OptionalTypes;
399-
llvm::DenseMap<Type, ParenType*> SimpleParenTypes; // Most are simple
400-
llvm::DenseMap<std::pair<Type, unsigned>, ParenType*> ParenTypes;
399+
llvm::DenseMap<Type, ParenType*> ParenTypes;
401400
llvm::DenseMap<uintptr_t, ReferenceStorageType*> ReferenceStorageTypes;
402401
llvm::DenseMap<Type, LValueType*> LValueTypes;
403402
llvm::DenseMap<Type, InOutType*> InOutTypes;
@@ -2577,7 +2576,6 @@ size_t ASTContext::Implementation::Arena::getTotalMemory() const {
25772576
llvm::capacity_in_bytes(DictionaryTypes) +
25782577
llvm::capacity_in_bytes(OptionalTypes) +
25792578
llvm::capacity_in_bytes(VariadicSequenceTypes) +
2580-
llvm::capacity_in_bytes(SimpleParenTypes) +
25812579
llvm::capacity_in_bytes(ParenTypes) +
25822580
llvm::capacity_in_bytes(ReferenceStorageTypes) +
25832581
llvm::capacity_in_bytes(LValueTypes) +
@@ -2787,22 +2785,14 @@ BuiltinVectorType *BuiltinVectorType::get(const ASTContext &context,
27872785
return vecTy;
27882786
}
27892787

2790-
ParenType *ParenType::get(const ASTContext &C, Type underlying,
2791-
ParameterTypeFlags fl) {
2792-
if (fl.isInOut())
2793-
assert(!underlying->is<InOutType>() && "caller did not pass a base type");
2794-
if (underlying->is<InOutType>())
2795-
assert(fl.isInOut() && "caller did not set flags correctly");
2796-
2788+
ParenType *ParenType::get(const ASTContext &C, Type underlying) {
27972789
auto properties = underlying->getRecursiveProperties();
27982790
auto arena = getArena(properties);
2799-
auto flags = fl.toRaw();
2800-
ParenType *&Result = flags == 0
2801-
? C.getImpl().getArena(arena).SimpleParenTypes[underlying]
2802-
: C.getImpl().getArena(arena).ParenTypes[{underlying, flags}];
2791+
ParenType *&Result = C.getImpl().getArena(arena).ParenTypes[underlying];
28032792
if (Result == nullptr) {
2804-
Result = new (C, arena) ParenType(underlying,
2805-
properties, fl);
2793+
Result = new (C, arena) ParenType(underlying, properties);
2794+
assert((C.hadError() || !underlying->is<InOutType>()) &&
2795+
"Cannot wrap InOutType");
28062796
}
28072797
return Result;
28082798
}
@@ -2817,35 +2807,19 @@ void TupleType::Profile(llvm::FoldingSetNodeID &ID,
28172807
for (const TupleTypeElt &Elt : Fields) {
28182808
ID.AddPointer(Elt.Name.get());
28192809
ID.AddPointer(Elt.getType().getPointer());
2820-
ID.AddInteger(Elt.Flags.toRaw());
28212810
}
28222811
}
28232812

28242813
/// getTupleType - Return the uniqued tuple type with the specified elements.
28252814
Type TupleType::get(ArrayRef<TupleTypeElt> Fields, const ASTContext &C) {
2826-
if (Fields.size() == 1 && !Fields[0].isVararg() && !Fields[0].hasName())
2827-
return ParenType::get(C, Fields[0].getRawType(),
2828-
Fields[0].getParameterFlags());
2815+
if (Fields.size() == 1 && !Fields[0].hasName())
2816+
return ParenType::get(C, Fields[0].getRawType());
28292817

28302818
RecursiveTypeProperties properties;
2831-
bool hasElementWithOwnership = false;
28322819
for (const TupleTypeElt &Elt : Fields) {
28332820
auto eltTy = Elt.getType();
28342821
if (!eltTy) continue;
2835-
28362822
properties |= eltTy->getRecursiveProperties();
2837-
// Recur into paren types and canonicalized paren types. 'inout' in nested
2838-
// non-paren tuples are malformed and will be diagnosed later.
2839-
if (auto *TTy = Elt.getType()->getAs<TupleType>()) {
2840-
if (TTy->getNumElements() == 1)
2841-
hasElementWithOwnership |= TTy->hasElementWithOwnership();
2842-
} else if (auto *Pty = dyn_cast<ParenType>(Elt.getType().getPointer())) {
2843-
hasElementWithOwnership |= (Pty->getParameterFlags().getValueOwnership() !=
2844-
ValueOwnership::Default);
2845-
} else {
2846-
hasElementWithOwnership |= (Elt.getParameterFlags().getValueOwnership() !=
2847-
ValueOwnership::Default);
2848-
}
28492823
}
28502824

28512825
auto arena = getArena(properties);
@@ -2870,23 +2844,18 @@ Type TupleType::get(ArrayRef<TupleTypeElt> Fields, const ASTContext &C) {
28702844
size_t bytes = totalSizeToAlloc<TupleTypeElt>(Fields.size());
28712845
// TupleType will copy the fields list into ASTContext owned memory.
28722846
void *mem = C.Allocate(bytes, alignof(TupleType), arena);
2873-
auto New = new (mem) TupleType(Fields, IsCanonical ? &C : nullptr, properties,
2874-
hasElementWithOwnership);
2847+
auto New = new (mem) TupleType(Fields, IsCanonical ? &C : nullptr,
2848+
properties);
28752849
C.getImpl().getArena(arena).TupleTypes.InsertNode(New, InsertPos);
28762850
return New;
28772851
}
28782852

2879-
TupleTypeElt::TupleTypeElt(Type ty, Identifier name,
2880-
ParameterTypeFlags fl)
2881-
: Name(name), ElementType(ty), Flags(fl) {
2882-
if (fl.isInOut())
2883-
assert(!ty->is<InOutType>() && "caller did not pass a base type");
2884-
if (ty->is<InOutType>())
2885-
assert(fl.isInOut() && "caller did not set flags correctly");
2853+
TupleTypeElt::TupleTypeElt(Type ty, Identifier name)
2854+
: Name(name), ElementType(ty) {
2855+
assert(!ty->is<InOutType>() && "Cannot have InOutType in a tuple");
28862856
}
28872857

28882858
Type TupleTypeElt::getType() const {
2889-
if (Flags.isInOut()) return InOutType::get(ElementType);
28902859
return ElementType;
28912860
}
28922861

lib/AST/ASTDumper.cpp

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

35713571
void visitParenType(ParenType *T, StringRef label) {
35723572
printCommon(label, "paren_type");
3573-
dumpParameterFlags(T->getParameterFlags());
35743573
printRec(T->getUnderlyingType());
35753574
PrintWithColorRAII(OS, ParenthesisColor) << ')';
35763575
}
@@ -3585,7 +3584,6 @@ namespace {
35853584
PrintWithColorRAII(OS, TypeFieldColor) << "tuple_type_elt";
35863585
if (elt.hasName())
35873586
printField("name", elt.getName().str());
3588-
dumpParameterFlags(elt.getParameterFlags());
35893587
printRec(elt.getType());
35903588
OS << ")";
35913589
}

lib/AST/ASTMangler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2576,7 +2576,6 @@ void ASTMangler::appendTypeList(Type listTy, GenericSignature sig,
25762576
return appendOperator("y");
25772577
bool firstField = true;
25782578
for (auto &field : tuple->getElements()) {
2579-
assert(field.getParameterFlags().isNone());
25802579
appendTypeListElement(field.getName(), field.getRawType(),
25812580
ParameterTypeFlags(),
25822581
sig, forDecl);

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4504,8 +4504,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
45044504

45054505
void visitParenType(ParenType *T) {
45064506
Printer << "(";
4507-
printParameterFlags(Printer, Options, T->getParameterFlags(),
4508-
/*escaping*/ false);
45094507
visit(T->getUnderlyingType()->getInOutObjectType());
45104508
Printer << ")";
45114509
}
@@ -4532,14 +4530,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
45324530
Printer.printName(TD.getName(), PrintNameContext::TupleElement);
45334531
Printer << ": ";
45344532
}
4535-
if (TD.isVararg()) {
4536-
visit(TD.getVarargBaseTy());
4537-
Printer << "...";
4538-
} else {
4539-
printParameterFlags(Printer, Options, TD.getParameterFlags(),
4540-
/*escaping*/ false);
4541-
visit(EltType);
4542-
}
4533+
visit(EltType);
45434534
}
45444535
Printer << ")";
45454536
}

lib/AST/ASTVerifier.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,13 +1149,6 @@ class Verifier : public ASTWalker {
11491149
Out << elt->getType() << "\n";
11501150
abort();
11511151
}
1152-
if (!field.getParameterFlags().isNone()) {
1153-
Out << "TupleExpr has non-empty parameter flags?\n";
1154-
Out << "sub expr: \n";
1155-
elt->dump(Out);
1156-
Out << "\n";
1157-
abort();
1158-
}
11591152
});
11601153
verifyCheckedBase(E);
11611154
}
@@ -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)