Skip to content

Commit 570ab52

Browse files
committed
Remove ParenType
1 parent c7b6f00 commit 570ab52

File tree

76 files changed

+190
-435
lines changed

Some content is hidden

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

76 files changed

+190
-435
lines changed

docs/ABI/Mangling.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,6 @@ productions:
786786
type ::= base-type "XSq" // sugared Optional type
787787
type ::= base-type "XSa" // sugared Array type
788788
type ::= key-type value-type "XSD" // sugared Dictionary type
789-
type ::= base-type "XSp" // sugared Paren type
790789

791790
Generics
792791
~~~~~~~~

include/swift/AST/ASTDemangler.h

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

178178
Type createDictionaryType(Type key, Type value);
179179

180-
Type createParenType(Type base);
181-
182180
BuiltGenericSignature
183181
createGenericSignature(ArrayRef<BuiltType> params,
184182
ArrayRef<BuiltRequirement> requirements);

include/swift/AST/Decl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7272,7 +7272,9 @@ class EnumElementDecl : public DeclContext, public ValueDecl {
72727272
return hasName() ? getBaseIdentifier().str() : "_";
72737273
}
72747274

7275-
Type getArgumentInterfaceType() const;
7275+
ArrayRef<AnyFunctionType::Param> getAssociatedValueParams() const;
7276+
7277+
Type getAssociatedValueTuple() const;
72767278

72777279
void setParameterList(ParameterList *params);
72787280
ParameterList *getParameterList() const { return Params; }

include/swift/AST/TypeNodes.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ TYPE(Pack, Type)
170170
TYPE(PackExpansion, Type)
171171
UNCHECKED_TYPE(TypeVariable, Type)
172172
ABSTRACT_SUGARED_TYPE(Sugar, Type)
173-
SUGARED_TYPE(Paren, SugarType)
174173
SUGARED_TYPE(TypeAlias, SugarType)
175174
ABSTRACT_SUGARED_TYPE(SyntaxSugar, SugarType)
176175
ABSTRACT_SUGARED_TYPE(UnarySyntaxSugar, SyntaxSugarType)
@@ -180,7 +179,7 @@ ABSTRACT_SUGARED_TYPE(Sugar, Type)
180179
TYPE_RANGE(UnarySyntaxSugar, ArraySlice, VariadicSequence)
181180
SUGARED_TYPE(Dictionary, SyntaxSugarType)
182181
TYPE_RANGE(SyntaxSugar, ArraySlice, Dictionary)
183-
TYPE_RANGE(Sugar, Paren, Dictionary)
182+
TYPE_RANGE(Sugar, TypeAlias, Dictionary)
184183
LAST_TYPE(Dictionary) // Sugared types are last to make isa<SugarType>() fast.
185184

186185
#endif

include/swift/AST/Types.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,6 @@ class alignas(1 << TypeAlignInBits) TypeBase
363363
HasCachedType : 1
364364
);
365365

366-
SWIFT_INLINE_BITFIELD_EMPTY(ParenType, SugarType);
367-
368366
SWIFT_INLINE_BITFIELD_FULL(AnyFunctionType, TypeBase, NumAFTExtInfoBits+1+1+1+16,
369367
/// Extra information which affects how the function is called, like
370368
/// regparm and the calling convention.
@@ -576,9 +574,6 @@ class alignas(1 << TypeAlignInBits) TypeBase
576574

577575
bool isPlaceholder();
578576

579-
/// Does the type have outer parenthesis?
580-
bool hasParenSugar() const { return getKind() == TypeKind::Paren; }
581-
582577
/// Are values of this type essentially just class references,
583578
/// possibly with some sort of additional information?
584579
///
@@ -1101,9 +1096,6 @@ class alignas(1 << TypeAlignInBits) TypeBase
11011096
/// argument labels removed.
11021097
Type removeArgumentLabels(unsigned numArgumentLabels);
11031098

1104-
/// Retrieve the type without any parentheses around it.
1105-
Type getWithoutParens();
1106-
11071099
/// Replace the base type of the result type of the given function
11081100
/// type with a new result type, as per a DynamicSelf or other
11091101
/// covariant return transformation. The optionality of the
@@ -2191,21 +2183,6 @@ class YieldTypeFlags {
21912183
uint8_t toRaw() const { return value.toRaw(); }
21922184
};
21932185

2194-
/// ParenType - A paren type is a type that's been written in parentheses.
2195-
class ParenType : public SugarType {
2196-
ParenType(Type UnderlyingType, RecursiveTypeProperties properties);
2197-
2198-
public:
2199-
static ParenType *get(const ASTContext &C, Type underlying);
2200-
2201-
Type getUnderlyingType() const { return getSinglyDesugaredType(); }
2202-
2203-
// Implement isa/cast/dyncast/etc.
2204-
static bool classof(const TypeBase *T) {
2205-
return T->getKind() == TypeKind::Paren;
2206-
}
2207-
};
2208-
22092186
/// TupleTypeElt - This represents a single element of a tuple.
22102187
class TupleTypeElt {
22112188
/// 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
@@ -291,7 +291,6 @@ NODE(AssociatedTypeGenericParamRef)
291291
NODE(SugaredOptional)
292292
NODE(SugaredArray)
293293
NODE(SugaredDictionary)
294-
NODE(SugaredParen)
295294

296295
// Added in Swift 5.1
297296
NODE(AccessorFunctionReference)

include/swift/Demangling/TypeDecoder.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,16 +1256,6 @@ return {}; // Not Implemented!
12561256

12571257
return Builder.createDictionaryType(key.getType(), value.getType());
12581258
}
1259-
case NodeKind::SugaredParen: {
1260-
if (Node->getNumChildren() < 1)
1261-
return MAKE_NODE_TYPE_ERROR0(Node, "no children");
1262-
1263-
auto base = decodeMangledType(Node->getChild(0), depth + 1);
1264-
if (base.isError())
1265-
return base;
1266-
1267-
return Builder.createParenType(base.getType());
1268-
}
12691259
case NodeKind::OpaqueType: {
12701260
if (Node->getNumChildren() < 3)
12711261
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
@@ -90,7 +90,7 @@ struct PotentialBinding {
9090
public:
9191
PotentialBinding(Type type, AllowedBindingKind kind, Constraint *source)
9292
: PotentialBinding(
93-
type->getWithoutParens(), kind,
93+
type, kind,
9494
PointerUnion<Constraint *, ConstraintLocator *>(source)) {}
9595

9696
bool isDefaultableBinding() const {

lib/APIDigester/ModuleAnalyzerNodes.cpp

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

10521052
static StringRef getTypeName(SDKContext &Ctx, Type Ty,
10531053
bool IsImplicitlyUnwrappedOptional) {
1054-
if (Ty->getKind() == TypeKind::Paren) {
1055-
return Ctx.buffer("Paren");
1056-
}
10571054
if (Ty->isVoid()) {
10581055
return Ctx.buffer("Void");
10591056
}
@@ -1609,12 +1606,6 @@ SwiftDeclCollector::constructTypeNode(Type T, TypeInitInfo Info) {
16091606

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

1612-
// Keep paren type as a stand-alone level.
1613-
if (auto *PT = dyn_cast<ParenType>(T.getPointer())) {
1614-
Root->addChild(constructTypeNode(PT->getSinglyDesugaredType()));
1615-
return Root;
1616-
}
1617-
16181609
// Handle the case where Type has sub-types.
16191610
if (auto BGT = T->getAs<BoundGenericType>()) {
16201611
for (auto Arg : BGT->getGenericArgs()) {

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ struct ASTContext::Implementation {
390390
llvm::DenseMap<Type, VariadicSequenceType*> VariadicSequenceTypes;
391391
llvm::DenseMap<std::pair<Type, Type>, DictionaryType *> DictionaryTypes;
392392
llvm::DenseMap<Type, OptionalType*> OptionalTypes;
393-
llvm::DenseMap<Type, ParenType*> ParenTypes;
394393
llvm::DenseMap<uintptr_t, ReferenceStorageType*> ReferenceStorageTypes;
395394
llvm::DenseMap<Type, LValueType*> LValueTypes;
396395
llvm::DenseMap<Type, InOutType*> InOutTypes;
@@ -2618,7 +2617,6 @@ size_t ASTContext::Implementation::Arena::getTotalMemory() const {
26182617
llvm::capacity_in_bytes(DictionaryTypes) +
26192618
llvm::capacity_in_bytes(OptionalTypes) +
26202619
llvm::capacity_in_bytes(VariadicSequenceTypes) +
2621-
llvm::capacity_in_bytes(ParenTypes) +
26222620
llvm::capacity_in_bytes(ReferenceStorageTypes) +
26232621
llvm::capacity_in_bytes(LValueTypes) +
26242622
llvm::capacity_in_bytes(InOutTypes) +
@@ -2827,18 +2825,6 @@ BuiltinVectorType *BuiltinVectorType::get(const ASTContext &context,
28272825
return vecTy;
28282826
}
28292827

2830-
ParenType *ParenType::get(const ASTContext &C, Type underlying) {
2831-
auto properties = underlying->getRecursiveProperties();
2832-
auto arena = getArena(properties);
2833-
ParenType *&Result = C.getImpl().getArena(arena).ParenTypes[underlying];
2834-
if (Result == nullptr) {
2835-
Result = new (C, arena) ParenType(underlying, properties);
2836-
assert((C.hadError() || !underlying->is<InOutType>()) &&
2837-
"Cannot wrap InOutType");
2838-
}
2839-
return Result;
2840-
}
2841-
28422828
CanTupleType TupleType::getEmpty(const ASTContext &C) {
28432829
return cast<TupleType>(CanType(C.TheEmptyTupleType));
28442830
}
@@ -2855,7 +2841,7 @@ void TupleType::Profile(llvm::FoldingSetNodeID &ID,
28552841
/// getTupleType - Return the uniqued tuple type with the specified elements.
28562842
Type TupleType::get(ArrayRef<TupleTypeElt> Fields, const ASTContext &C) {
28572843
if (Fields.size() == 1 && !Fields[0].hasName())
2858-
return ParenType::get(C, Fields[0].getType());
2844+
return Fields[0].getType();
28592845

28602846
RecursiveTypeProperties properties;
28612847
for (const TupleTypeElt &Elt : Fields) {

lib/AST/ASTDemangler.cpp

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

829-
Type ASTBuilder::createParenType(Type base) {
830-
return ParenType::get(Ctx, base);
831-
}
832-
833829
GenericSignature
834830
ASTBuilder::createGenericSignature(ArrayRef<BuiltType> builtParams,
835831
ArrayRef<BuiltRequirement> requirements) {

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3647,12 +3647,6 @@ namespace {
36473647
PrintWithColorRAII(OS, ParenthesisColor) << ')';
36483648
}
36493649

3650-
void visitParenType(ParenType *T, StringRef label) {
3651-
printCommon(label, "paren_type");
3652-
printRec(T->getUnderlyingType());
3653-
PrintWithColorRAII(OS, ParenthesisColor) << ')';
3654-
}
3655-
36563650
void visitTupleType(TupleType *T, StringRef label) {
36573651
printCommon(label, "tuple_type");
36583652
printField("num_elements", T->getNumElements());

lib/AST/ASTMangler.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,12 +1206,6 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
12061206
llvm_unreachable("Unimplemented");
12071207
return;
12081208

1209-
case TypeKind::Paren:
1210-
assert(DWARFMangling && "sugared types are only legal for the debugger");
1211-
appendType(cast<ParenType>(tybase)->getUnderlyingType(), sig, forDecl);
1212-
appendOperator("XSp");
1213-
return;
1214-
12151209
case TypeKind::ArraySlice:
12161210
assert(DWARFMangling && "sugared types are only legal for the debugger");
12171211
appendType(cast<ArraySliceType>(tybase)->getBaseType(), sig, forDecl);

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5496,12 +5496,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
54965496
printGenericArgs(T->getDirectGenericArgs());
54975497
}
54985498

5499-
void visitParenType(ParenType *T) {
5500-
Printer << "(";
5501-
visit(T->getUnderlyingType()->getInOutObjectType());
5502-
Printer << ")";
5503-
}
5504-
55055499
void visitPackType(PackType *T) {
55065500
Printer << "(";
55075501

lib/AST/ASTVerifier.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,16 +1968,6 @@ class Verifier : public ASTWalker {
19681968
verifyCheckedBase(E);
19691969
}
19701970

1971-
void verifyChecked(ParenExpr *E) {
1972-
PrettyStackTraceExpr debugStack(Ctx, "verifying ParenExpr", E);
1973-
auto ty = dyn_cast<ParenType>(E->getType().getPointer());
1974-
if (!ty) {
1975-
Out << "ParenExpr not of ParenType\n";
1976-
abort();
1977-
}
1978-
verifyCheckedBase(E);
1979-
}
1980-
19811971
void verifyChecked(AnyTryExpr *E) {
19821972
PrettyStackTraceExpr debugStack(Ctx, "verifying AnyTryExpr", E);
19831973

lib/AST/ArgumentList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ Expr *ArgumentList::packIntoImplicitTupleOrParen(
233233
if (auto *unary = getUnlabeledUnaryExpr()) {
234234
auto *paren = new (ctx) ParenExpr(getLParenLoc(), unary, getRParenLoc());
235235
if (auto ty = getType(unary))
236-
paren->setType(ParenType::get(ctx, ty));
236+
paren->setType(ty);
237237
paren->setImplicit();
238238
return paren;
239239
}

lib/AST/Decl.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8801,20 +8801,29 @@ SourceRange EnumElementDecl::getSourceRange() const {
88018801
return {getStartLoc(), getNameLoc()};
88028802
}
88038803

8804-
Type EnumElementDecl::getArgumentInterfaceType() const {
8804+
ArrayRef<AnyFunctionType::Param>
8805+
EnumElementDecl::getAssociatedValueParams() const {
88058806
if (!hasAssociatedValues())
8806-
return nullptr;
8807+
return {};
88078808

88088809
auto interfaceType = getInterfaceType();
8809-
if (interfaceType->is<ErrorType>()) {
8810-
return interfaceType;
8811-
}
8810+
if (interfaceType->is<ErrorType>())
8811+
return {};
88128812

88138813
auto funcTy = interfaceType->castTo<AnyFunctionType>();
8814-
funcTy = funcTy->getResult()->castTo<FunctionType>();
8814+
return funcTy->getResult()->castTo<FunctionType>()->getParams();
8815+
}
8816+
8817+
Type EnumElementDecl::getAssociatedValueTuple() const {
8818+
if (!hasAssociatedValues())
8819+
return Type();
8820+
8821+
auto interfaceType = getInterfaceType();
8822+
if (interfaceType->is<ErrorType>())
8823+
return interfaceType;
88158824

8816-
return AnyFunctionType::composeTuple(getASTContext(), funcTy->getParams(),
8817-
ParameterFlagHandling::Drop);
8825+
return AnyFunctionType::composeTuple(
8826+
getASTContext(), getAssociatedValueParams(), ParameterFlagHandling::Drop);
88188827
}
88198828

88208829
void EnumElementDecl::setParameterList(ParameterList *params) {

lib/AST/DiagnosticEngine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,8 @@ static bool typeSpellingIsAmbiguous(Type type,
547547
for (auto arg : Args) {
548548
if (arg.getKind() == DiagnosticArgumentKind::Type) {
549549
auto argType = arg.getAsType();
550-
if (argType && argType->getWithoutParens().getPointer() != type.getPointer() &&
551-
argType->getWithoutParens().getString(PO) == type.getString(PO)) {
550+
if (argType && argType.getPointer() != type.getPointer() &&
551+
argType.getString(PO) == type.getString(PO)) {
552552
// Currently, existential types are spelled the same way
553553
// as protocols and compositions. We can remove this once
554554
// existenials are printed with 'any'.
@@ -673,7 +673,7 @@ static void formatDiagnosticArgument(StringRef Modifier,
673673
// Compute the appropriate print options for this argument.
674674
auto printOptions = PrintOptions::forDiagnosticArguments();
675675
if (Arg.getKind() == DiagnosticArgumentKind::Type) {
676-
type = Arg.getAsType()->getWithoutParens();
676+
type = Arg.getAsType();
677677
if (type.isNull()) {
678678
// FIXME: We should never receive a nullptr here, but this is causing
679679
// crashes (rdar://75740683). Remove once ParenType never contains
@@ -687,7 +687,7 @@ static void formatDiagnosticArgument(StringRef Modifier,
687687
needsQualification = typeSpellingIsAmbiguous(type, Args, printOptions);
688688
} else {
689689
assert(Arg.getKind() == DiagnosticArgumentKind::FullyQualifiedType);
690-
type = Arg.getAsFullyQualifiedType().getType()->getWithoutParens();
690+
type = Arg.getAsFullyQualifiedType().getType();
691691
if (type.isNull()) {
692692
// FIXME: We should never receive a nullptr here, but this is causing
693693
// crashes (rdar://75740683). Remove once ParenType never contains

0 commit comments

Comments
 (0)