Skip to content

Commit c340b65

Browse files
committed
Remove ParenType
1 parent 8c5d7ee commit c340b65

File tree

80 files changed

+1104
-3021
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1104
-3021
lines changed

docs/ABI/Mangling.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,6 @@ productions:
929929
type ::= base-type "XSq" // sugared Optional type
930930
type ::= base-type "XSa" // sugared Array type
931931
type ::= key-type value-type "XSD" // sugared Dictionary type
932-
type ::= base-type "XSp" // sugared Paren type
933932

934933
Generics
935934
~~~~~~~~

include/swift/AST/ASTDemangler.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,6 @@ class ASTBuilder {
229229

230230
Type createDictionaryType(Type key, Type value);
231231

232-
Type createParenType(Type base);
233-
234232
Type createIntegerType(intptr_t value);
235233

236234
Type createNegativeIntegerType(intptr_t value);

include/swift/AST/Decl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8507,6 +8507,8 @@ class EnumElementDecl : public DeclContext, public ValueDecl {
85078507
return hasName() ? getBaseIdentifier().str() : "_";
85088508
}
85098509

8510+
ArrayRef<AnyFunctionType::Param> getAssociatedValueParams() const;
8511+
85108512
Type getArgumentInterfaceType() const;
85118513

85128514
void setParameterList(ParameterList *params);

include/swift/AST/TypeNodes.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ UNCHECKED_TYPE(TypeVariable, Type)
191191
UNCHECKED_TYPE(ErrorUnion, Type)
192192
ALWAYS_CANONICAL_TYPE(Integer, Type)
193193
ABSTRACT_SUGARED_TYPE(Sugar, Type)
194-
SUGARED_TYPE(Paren, SugarType)
195194
SUGARED_TYPE(TypeAlias, SugarType)
196195
ABSTRACT_SUGARED_TYPE(SyntaxSugar, SugarType)
197196
ABSTRACT_SUGARED_TYPE(UnarySyntaxSugar, SyntaxSugarType)
@@ -201,7 +200,7 @@ ABSTRACT_SUGARED_TYPE(Sugar, Type)
201200
TYPE_RANGE(UnarySyntaxSugar, ArraySlice, VariadicSequence)
202201
SUGARED_TYPE(Dictionary, SyntaxSugarType)
203202
TYPE_RANGE(SyntaxSugar, ArraySlice, Dictionary)
204-
TYPE_RANGE(Sugar, Paren, Dictionary)
203+
TYPE_RANGE(Sugar, TypeAlias, Dictionary)
205204
LAST_TYPE(Dictionary) // Sugared types are last to make isa<SugarType>() fast.
206205

207206
#endif

include/swift/AST/TypeTransform.h

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,10 @@ class TypeTransform {
8888

8989
public:
9090
Type doIt(Type t, TypePosition pos) {
91-
if (!isa<ParenType>(t.getPointer())) {
92-
// Transform this type node.
93-
if (std::optional<Type> transformed = asDerived().transform(t.getPointer(), pos))
94-
return *transformed;
95-
96-
// Recur.
97-
}
91+
// Transform this type node.
92+
if (std::optional<Type> transformed =
93+
asDerived().transform(t.getPointer(), pos))
94+
return *transformed;
9895

9996
// Recur into children of this type.
10097
TypeBase *base = t.getPointer();
@@ -488,18 +485,6 @@ case TypeKind::Id:
488485
newUnderlyingTy);
489486
}
490487

491-
case TypeKind::Paren: {
492-
auto paren = cast<ParenType>(base);
493-
Type underlying = doIt(paren->getUnderlyingType(), pos);
494-
if (!underlying)
495-
return Type();
496-
497-
if (underlying.getPointer() == paren->getUnderlyingType().getPointer())
498-
return t;
499-
500-
return ParenType::get(ctx, underlying);
501-
}
502-
503488
case TypeKind::ErrorUnion: {
504489
auto errorUnion = cast<ErrorUnionType>(base);
505490
bool anyChanged = false;

include/swift/AST/Types.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,6 @@ class alignas(1 << TypeAlignInBits) TypeBase
425425
HasCachedType : 1
426426
);
427427

428-
SWIFT_INLINE_BITFIELD_EMPTY(ParenType, SugarType);
429-
430428
SWIFT_INLINE_BITFIELD_FULL(AnyFunctionType, TypeBase, NumAFTExtInfoBits+1+1+1+1+16,
431429
/// Extra information which affects how the function is called, like
432430
/// regparm and the calling convention.
@@ -687,9 +685,6 @@ class alignas(1 << TypeAlignInBits) TypeBase
687685
/// Returns true if this contextual type is (Escapable && !isNoEscape).
688686
bool mayEscape() { return !isNoEscape() && isEscapable(); }
689687

690-
/// Does the type have outer parenthesis?
691-
bool hasParenSugar() const { return getKind() == TypeKind::Paren; }
692-
693688
/// Are values of this type essentially just class references,
694689
/// possibly with some sort of additional information?
695690
///
@@ -1287,9 +1282,6 @@ class alignas(1 << TypeAlignInBits) TypeBase
12871282
/// argument labels removed.
12881283
Type removeArgumentLabels(unsigned numArgumentLabels);
12891284

1290-
/// Retrieve the type without any parentheses around it.
1291-
Type getWithoutParens();
1292-
12931285
/// Replace the base type of the result type of the given function
12941286
/// type with a new result type, as per a DynamicSelf or other
12951287
/// covariant return transformation. The optionality of the
@@ -2477,21 +2469,6 @@ class YieldTypeFlags {
24772469
uint8_t toRaw() const { return value.toRaw(); }
24782470
};
24792471

2480-
/// ParenType - A paren type is a type that's been written in parentheses.
2481-
class ParenType : public SugarType {
2482-
ParenType(Type UnderlyingType, RecursiveTypeProperties properties);
2483-
2484-
public:
2485-
static ParenType *get(const ASTContext &C, Type underlying);
2486-
2487-
Type getUnderlyingType() const { return getSinglyDesugaredType(); }
2488-
2489-
// Implement isa/cast/dyncast/etc.
2490-
static bool classof(const TypeBase *T) {
2491-
return T->getKind() == TypeKind::Paren;
2492-
}
2493-
};
2494-
24952472
/// TupleTypeElt - This represents a single element of a tuple.
24962473
class TupleTypeElt {
24972474
/// An optional name for the field.

include/swift/Demangling/DemangleNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ NODE(AssociatedTypeGenericParamRef)
322322
NODE(SugaredOptional)
323323
NODE(SugaredArray)
324324
NODE(SugaredDictionary)
325-
NODE(SugaredParen)
326325

327326
// Added in Swift 5.1
328327
NODE(AccessorFunctionReference)

include/swift/Demangling/TypeDecoder.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,16 +1467,6 @@ class TypeDecoder {
14671467

14681468
return Builder.createDictionaryType(key.getType(), value.getType());
14691469
}
1470-
case NodeKind::SugaredParen: {
1471-
if (Node->getNumChildren() < 1)
1472-
return MAKE_NODE_TYPE_ERROR0(Node, "no children");
1473-
1474-
auto base = decodeMangledType(Node->getChild(0), depth + 1);
1475-
if (base.isError())
1476-
return base;
1477-
1478-
return Builder.createParenType(base.getType());
1479-
}
14801470
case NodeKind::OpaqueType: {
14811471
if (Node->getNumChildren() < 3)
14821472
return MAKE_NODE_TYPE_ERROR(Node,

include/swift/Sema/CSBindings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct PotentialBinding {
9494
public:
9595
PotentialBinding(Type type, AllowedBindingKind kind, Constraint *source)
9696
: PotentialBinding(
97-
type->getWithoutParens(), kind,
97+
type, kind,
9898
PointerUnion<Constraint *, ConstraintLocator *>(source)) {}
9999

100100
bool isDefaultableBinding() const {

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,9 +1071,6 @@ static StringRef getPrintedName(SDKContext &Ctx, Type Ty,
10711071

10721072
static StringRef getTypeName(SDKContext &Ctx, Type Ty,
10731073
bool IsImplicitlyUnwrappedOptional) {
1074-
if (Ty->getKind() == TypeKind::Paren) {
1075-
return Ctx.buffer("Paren");
1076-
}
10771074
if (Ty->isVoid()) {
10781075
return Ctx.buffer("Void");
10791076
}
@@ -1662,12 +1659,6 @@ SwiftDeclCollector::constructTypeNode(Type T, TypeInitInfo Info) {
16621659

16631660
SDKNode* Root = SDKNodeInitInfo(Ctx, T, Info).createSDKNode(SDKNodeKind::TypeNominal);
16641661

1665-
// Keep paren type as a stand-alone level.
1666-
if (auto *PT = dyn_cast<ParenType>(T.getPointer())) {
1667-
Root->addChild(constructTypeNode(PT->getSinglyDesugaredType()));
1668-
return Root;
1669-
}
1670-
16711662
// Handle the case where Type has sub-types.
16721663
if (auto BGT = T->getAs<BoundGenericType>()) {
16731664
for (auto Arg : BGT->getGenericArgs()) {

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,6 @@ struct ASTContext::Implementation {
537537
llvm::DenseMap<Type, VariadicSequenceType*> VariadicSequenceTypes;
538538
llvm::DenseMap<std::pair<Type, Type>, DictionaryType *> DictionaryTypes;
539539
llvm::DenseMap<Type, OptionalType*> OptionalTypes;
540-
llvm::DenseMap<Type, ParenType*> ParenTypes;
541540
llvm::DenseMap<uintptr_t, ReferenceStorageType*> ReferenceStorageTypes;
542541
llvm::DenseMap<Type, LValueType*> LValueTypes;
543542
llvm::DenseMap<Type, InOutType*> InOutTypes;
@@ -3223,7 +3222,6 @@ size_t ASTContext::Implementation::Arena::getTotalMemory() const {
32233222
llvm::capacity_in_bytes(DictionaryTypes) +
32243223
llvm::capacity_in_bytes(OptionalTypes) +
32253224
llvm::capacity_in_bytes(VariadicSequenceTypes) +
3226-
llvm::capacity_in_bytes(ParenTypes) +
32273225
llvm::capacity_in_bytes(ReferenceStorageTypes) +
32283226
llvm::capacity_in_bytes(LValueTypes) +
32293227
llvm::capacity_in_bytes(InOutTypes) +
@@ -3262,7 +3260,6 @@ void ASTContext::Implementation::Arena::dump(llvm::raw_ostream &os) const {
32623260
SIZE_AND_BYTES(VariadicSequenceTypes);
32633261
SIZE_AND_BYTES(DictionaryTypes);
32643262
SIZE_AND_BYTES(OptionalTypes);
3265-
SIZE_AND_BYTES(ParenTypes);
32663263
SIZE_AND_BYTES(ReferenceStorageTypes);
32673264
SIZE_AND_BYTES(LValueTypes);
32683265
SIZE_AND_BYTES(InOutTypes);
@@ -3579,18 +3576,6 @@ BuiltinVectorType *BuiltinVectorType::get(const ASTContext &context,
35793576
return vecTy;
35803577
}
35813578

3582-
ParenType *ParenType::get(const ASTContext &C, Type underlying) {
3583-
auto properties = underlying->getRecursiveProperties();
3584-
auto arena = getArena(properties);
3585-
ParenType *&Result = C.getImpl().getArena(arena).ParenTypes[underlying];
3586-
if (Result == nullptr) {
3587-
Result = new (C, arena) ParenType(underlying, properties);
3588-
assert((C.hadError() || !underlying->is<InOutType>()) &&
3589-
"Cannot wrap InOutType");
3590-
}
3591-
return Result;
3592-
}
3593-
35943579
CanTupleType TupleType::getEmpty(const ASTContext &C) {
35953580
return cast<TupleType>(CanType(C.TheEmptyTupleType));
35963581
}
@@ -4517,7 +4502,7 @@ Type AnyFunctionType::composeTuple(ASTContext &ctx, ArrayRef<Param> params,
45174502
elements.emplace_back(param.getParameterType(), param.getLabel());
45184503
}
45194504
if (elements.size() == 1 && !elements[0].hasName())
4520-
return ParenType::get(ctx, elements[0].getType());
4505+
return elements[0].getType();
45214506
return TupleType::get(elements, ctx);
45224507
}
45234508

lib/AST/ASTDemangler.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,10 +1035,6 @@ Type ASTBuilder::createDictionaryType(Type key, Type value) {
10351035
return DictionaryType::get(key, value);
10361036
}
10371037

1038-
Type ASTBuilder::createParenType(Type base) {
1039-
return ParenType::get(Ctx, base);
1040-
}
1041-
10421038
Type ASTBuilder::createIntegerType(intptr_t value) {
10431039
return IntegerType::get(std::to_string(value), /*isNegative*/ false, Ctx);
10441040
}

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4120,14 +4120,6 @@ namespace {
41204120
printFoot();
41214121
}
41224122

4123-
void visitParenType(ParenType *T, StringRef label) {
4124-
printCommon("paren_type", label);
4125-
4126-
printRec(T->getUnderlyingType());
4127-
4128-
printFoot();
4129-
}
4130-
41314123
void visitTupleType(TupleType *T, StringRef label) {
41324124
printCommon("tuple_type", label);
41334125

lib/AST/ASTMangler.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,12 +1373,6 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
13731373
return;
13741374
}
13751375

1376-
case TypeKind::Paren:
1377-
assert(DWARFMangling && "sugared types are only legal for the debugger");
1378-
appendType(cast<ParenType>(tybase)->getUnderlyingType(), sig, forDecl);
1379-
appendOperator("XSp");
1380-
return;
1381-
13821376
case TypeKind::ArraySlice:
13831377
assert(DWARFMangling && "sugared types are only legal for the debugger");
13841378
appendType(cast<ArraySliceType>(tybase)->getBaseType(), sig, forDecl);

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6047,12 +6047,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
60476047
}
60486048
}
60496049

6050-
void visitParenType(ParenType *T) {
6051-
Printer << "(";
6052-
visit(T->getUnderlyingType()->getInOutObjectType());
6053-
Printer << ")";
6054-
}
6055-
60566050
void visitPackType(PackType *T) {
60576051
if (Options.PrintExplicitPackTypes || Options.PrintTypesForDebugging)
60586052
Printer << "Pack{";
@@ -6130,7 +6124,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
61306124
Printer << ": ";
61316125
} else if (e == 1 && !EltType->is<PackExpansionType>()) {
61326126
// Unlabeled one-element tuples always print the empty label to
6133-
// distinguish them from the older syntax for ParenType.
6127+
// distinguish them from the older syntax for parens.
61346128
Printer << "_: ";
61356129
}
61366130
visit(EltType);

lib/AST/ASTVerifier.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,16 +2144,6 @@ class Verifier : public ASTWalker {
21442144
verifyCheckedBase(E);
21452145
}
21462146

2147-
void verifyChecked(ParenExpr *E) {
2148-
PrettyStackTraceExpr debugStack(Ctx, "verifying ParenExpr", E);
2149-
auto ty = dyn_cast<ParenType>(E->getType().getPointer());
2150-
if (!ty) {
2151-
Out << "ParenExpr not of ParenType\n";
2152-
abort();
2153-
}
2154-
verifyCheckedBase(E);
2155-
}
2156-
21572147
void verifyChecked(AnyTryExpr *E) {
21582148
PrettyStackTraceExpr debugStack(Ctx, "verifying AnyTryExpr", E);
21592149

lib/AST/ArgumentList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ Expr *ArgumentList::packIntoImplicitTupleOrParen(
239239
if (auto *unary = getUnlabeledUnaryExpr()) {
240240
auto *paren = new (ctx) ParenExpr(getLParenLoc(), unary, getRParenLoc());
241241
if (auto ty = getType(unary))
242-
paren->setType(ParenType::get(ctx, ty));
242+
paren->setType(ty);
243243
paren->setImplicit();
244244
return paren;
245245
}

lib/AST/Decl.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10601,22 +10601,32 @@ SourceRange EnumElementDecl::getSourceRange() const {
1060110601
return {getStartLoc(), getNameLoc()};
1060210602
}
1060310603

10604-
Type EnumElementDecl::getArgumentInterfaceType() const {
10604+
ArrayRef<AnyFunctionType::Param>
10605+
EnumElementDecl::getAssociatedValueParams() const {
1060510606
if (!hasAssociatedValues())
10606-
return nullptr;
10607+
return {};
1060710608

1060810609
auto interfaceType = getInterfaceType();
10609-
if (interfaceType->is<ErrorType>()) {
10610-
return interfaceType;
10611-
}
10610+
if (interfaceType->is<ErrorType>())
10611+
return {};
1061210612

1061310613
auto funcTy = interfaceType->castTo<AnyFunctionType>();
10614-
funcTy = funcTy->getResult()->castTo<FunctionType>();
10614+
return funcTy->getResult()->castTo<FunctionType>()->getParams();
10615+
}
10616+
10617+
Type EnumElementDecl::getArgumentInterfaceType() const {
10618+
if (!hasAssociatedValues())
10619+
return Type();
10620+
10621+
auto interfaceType = getInterfaceType();
10622+
if (interfaceType->is<ErrorType>())
10623+
return interfaceType;
1061510624

1061610625
// The payload type of an enum is an imploded tuple of the internal arguments
1061710626
// of the case constructor. As such, compose a tuple type with the parameter
1061810627
// flags dropped.
10619-
return AnyFunctionType::composeTuple(getASTContext(), funcTy->getParams(),
10628+
return AnyFunctionType::composeTuple(getASTContext(),
10629+
getAssociatedValueParams(),
1062010630
ParameterFlagHandling::IgnoreNonEmpty);
1062110631
}
1062210632

0 commit comments

Comments
 (0)