Skip to content

Commit 2ca6d57

Browse files
committed
Remove ParenType
1 parent e3fc308 commit 2ca6d57

File tree

72 files changed

+135
-383
lines changed

Some content is hidden

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

72 files changed

+135
-383
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/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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,13 +1065,12 @@ static StringRef getPrintedName(SDKContext &Ctx, Type Ty,
10651065
if (IsImplicitlyUnwrappedOptional)
10661066
PO.PrintOptionalAsImplicitlyUnwrapped = true;
10671067

1068-
Ty->getWithoutParens().print(OS, PO);
1068+
Ty.print(OS, PO);
10691069
return Ctx.buffer(OS.str());
10701070
}
10711071

10721072
static StringRef getTypeName(SDKContext &Ctx, Type Ty,
10731073
bool IsImplicitlyUnwrappedOptional) {
1074-
Ty = Ty->getWithoutParens();
10751074
if (Ty->isVoid()) {
10761075
return Ctx.buffer("Void");
10771076
}

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ struct ASTContext::Implementation {
538538
llvm::DenseMap<Type, VariadicSequenceType*> VariadicSequenceTypes;
539539
llvm::DenseMap<std::pair<Type, Type>, DictionaryType *> DictionaryTypes;
540540
llvm::DenseMap<Type, OptionalType*> OptionalTypes;
541-
llvm::DenseMap<Type, ParenType*> ParenTypes;
542541
llvm::DenseMap<uintptr_t, ReferenceStorageType*> ReferenceStorageTypes;
543542
llvm::DenseMap<Type, LValueType*> LValueTypes;
544543
llvm::DenseMap<Type, InOutType*> InOutTypes;
@@ -3225,7 +3224,6 @@ size_t ASTContext::Implementation::Arena::getTotalMemory() const {
32253224
llvm::capacity_in_bytes(DictionaryTypes) +
32263225
llvm::capacity_in_bytes(OptionalTypes) +
32273226
llvm::capacity_in_bytes(VariadicSequenceTypes) +
3228-
llvm::capacity_in_bytes(ParenTypes) +
32293227
llvm::capacity_in_bytes(ReferenceStorageTypes) +
32303228
llvm::capacity_in_bytes(LValueTypes) +
32313229
llvm::capacity_in_bytes(InOutTypes) +
@@ -3264,7 +3262,6 @@ void ASTContext::Implementation::Arena::dump(llvm::raw_ostream &os) const {
32643262
SIZE_AND_BYTES(VariadicSequenceTypes);
32653263
SIZE_AND_BYTES(DictionaryTypes);
32663264
SIZE_AND_BYTES(OptionalTypes);
3267-
SIZE_AND_BYTES(ParenTypes);
32683265
SIZE_AND_BYTES(ReferenceStorageTypes);
32693266
SIZE_AND_BYTES(LValueTypes);
32703267
SIZE_AND_BYTES(InOutTypes);
@@ -3581,18 +3578,6 @@ BuiltinVectorType *BuiltinVectorType::get(const ASTContext &context,
35813578
return vecTy;
35823579
}
35833580

3584-
ParenType *ParenType::get(const ASTContext &C, Type underlying) {
3585-
auto properties = underlying->getRecursiveProperties();
3586-
auto arena = getArena(properties);
3587-
ParenType *&Result = C.getImpl().getArena(arena).ParenTypes[underlying];
3588-
if (Result == nullptr) {
3589-
Result = new (C, arena) ParenType(underlying, properties);
3590-
assert((C.hadError() || !underlying->is<InOutType>()) &&
3591-
"Cannot wrap InOutType");
3592-
}
3593-
return Result;
3594-
}
3595-
35963581
CanTupleType TupleType::getEmpty(const ASTContext &C) {
35973582
return cast<TupleType>(CanType(C.TheEmptyTupleType));
35983583
}
@@ -4519,7 +4504,7 @@ Type AnyFunctionType::composeTuple(ASTContext &ctx, ArrayRef<Param> params,
45194504
elements.emplace_back(param.getParameterType(), param.getLabel());
45204505
}
45214506
if (elements.size() == 1 && !elements[0].hasName())
4522-
return ParenType::get(ctx, elements[0].getType());
4507+
return elements[0].getType();
45234508
return TupleType::get(elements, ctx);
45244509
}
45254510

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/DiagnosticEngine.cpp

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,8 @@ static bool typeSpellingIsAmbiguous(Type type,
699699
for (auto arg : Args) {
700700
if (arg.getKind() == DiagnosticArgumentKind::Type) {
701701
auto argType = arg.getAsType();
702-
if (argType && argType->getWithoutParens().getPointer() != type.getPointer() &&
703-
argType->getWithoutParens().getString(PO) == type.getString(PO)) {
702+
if (argType && argType.getPointer() != type.getPointer() &&
703+
argType.getString(PO) == type.getString(PO)) {
704704
// Currently, existential types are spelled the same way
705705
// as protocols and compositions. We can remove this once
706706
// existenials are printed with 'any'.
@@ -892,41 +892,20 @@ static void formatDiagnosticArgument(StringRef Modifier,
892892
// Compute the appropriate print options for this argument.
893893
auto printOptions = PrintOptions::forDiagnosticArguments();
894894
if (Arg.getKind() == DiagnosticArgumentKind::Type) {
895-
type = Arg.getAsType()->getWithoutParens();
896-
if (type.isNull()) {
897-
// FIXME: We should never receive a nullptr here, but this is causing
898-
// crashes (rdar://75740683). Remove once ParenType never contains
899-
// nullptr as the underlying type.
900-
Out << "<null>";
901-
break;
902-
}
895+
type = Arg.getAsType();
903896
if (type->getASTContext().TypeCheckerOpts.PrintFullConvention)
904897
printOptions.PrintFunctionRepresentationAttrs =
905898
PrintOptions::FunctionRepresentationMode::Full;
906899
needsQualification = typeSpellingIsAmbiguous(type, Args, printOptions);
907900
} else if (Arg.getKind() == DiagnosticArgumentKind::FullyQualifiedType) {
908-
type = Arg.getAsFullyQualifiedType().getType()->getWithoutParens();
909-
if (type.isNull()) {
910-
// FIXME: We should never receive a nullptr here, but this is causing
911-
// crashes (rdar://75740683). Remove once ParenType never contains
912-
// nullptr as the underlying type.
913-
Out << "<null>";
914-
break;
915-
}
901+
type = Arg.getAsFullyQualifiedType().getType();
916902
if (type->getASTContext().TypeCheckerOpts.PrintFullConvention)
917903
printOptions.PrintFunctionRepresentationAttrs =
918904
PrintOptions::FunctionRepresentationMode::Full;
919905
needsQualification = true;
920906
} else {
921907
assert(Arg.getKind() == DiagnosticArgumentKind::WitnessType);
922-
type = Arg.getAsWitnessType().getType()->getWithoutParens();
923-
if (type.isNull()) {
924-
// FIXME: We should never receive a nullptr here, but this is causing
925-
// crashes (rdar://75740683). Remove once ParenType never contains
926-
// nullptr as the underlying type.
927-
Out << "<null>";
928-
break;
929-
}
908+
type = Arg.getAsWitnessType().getType();
930909
printOptions.PrintGenericRequirements = false;
931910
printOptions.PrintInverseRequirements = false;
932911
needsQualification = typeSpellingIsAmbiguous(type, Args, printOptions);

0 commit comments

Comments
 (0)