Skip to content

Commit df7cac3

Browse files
authored
Merge pull request #59141 from hamishknight/wrapping-paper
[AST] Remove ParenType
2 parents d721b6e + 2d7500e commit df7cac3

File tree

69 files changed

+158
-368
lines changed

Some content is hidden

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

69 files changed

+158
-368
lines changed

docs/ABI/Mangling.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,6 @@ productions:
934934
type ::= base-type "XSq" // sugared Optional type
935935
type ::= base-type "XSa" // sugared Array type
936936
type ::= key-type value-type "XSD" // sugared Dictionary type
937-
type ::= base-type "XSp" // sugared Paren type
938937

939938
Generics
940939
~~~~~~~~

include/swift/AST/ASTDemangler.h

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

245245
Type createDictionaryType(Type key, Type value);
246246

247-
Type createParenType(Type base);
248-
249247
Type createIntegerType(intptr_t value);
250248

251249
Type createNegativeIntegerType(intptr_t value);

include/swift/AST/TypeNodes.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ UNCHECKED_TYPE(TypeVariable, Type)
209209
UNCHECKED_TYPE(ErrorUnion, Type)
210210
ALWAYS_CANONICAL_TYPE(Integer, Type)
211211
ABSTRACT_SUGARED_TYPE(Sugar, Type)
212-
SUGARED_TYPE(Paren, SugarType)
213212
SUGARED_TYPE(TypeAlias, SugarType)
214213
ABSTRACT_SUGARED_TYPE(SyntaxSugar, SugarType)
215214
ABSTRACT_SUGARED_TYPE(UnarySyntaxSugar, SyntaxSugarType)
@@ -219,7 +218,7 @@ ABSTRACT_SUGARED_TYPE(Sugar, Type)
219218
TYPE_RANGE(UnarySyntaxSugar, ArraySlice, VariadicSequence)
220219
SUGARED_TYPE(Dictionary, SyntaxSugarType)
221220
TYPE_RANGE(SyntaxSugar, ArraySlice, Dictionary)
222-
TYPE_RANGE(Sugar, Paren, Dictionary)
221+
TYPE_RANGE(Sugar, TypeAlias, Dictionary)
223222
LAST_TYPE(Dictionary) // Sugared types are last to make isa<SugarType>() fast.
224223

225224
#endif

include/swift/AST/TypeTransform.h

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

9595
public:
9696
Type doIt(Type t, TypePosition pos) {
97-
if (!isa<ParenType>(t.getPointer())) {
98-
// Transform this type node.
99-
if (std::optional<Type> transformed = asDerived().transform(t.getPointer(), pos))
100-
return *transformed;
101-
102-
// Recur.
103-
}
97+
// Transform this type node.
98+
if (std::optional<Type> transformed =
99+
asDerived().transform(t.getPointer(), pos))
100+
return *transformed;
104101

105102
// Recur into children of this type.
106103
TypeBase *base = t.getPointer();
@@ -536,18 +533,6 @@ case TypeKind::Id:
536533
newUnderlyingTy);
537534
}
538535

539-
case TypeKind::Paren: {
540-
auto paren = cast<ParenType>(base);
541-
Type underlying = doIt(paren->getUnderlyingType(), pos);
542-
if (!underlying)
543-
return Type();
544-
545-
if (underlying.getPointer() == paren->getUnderlyingType().getPointer())
546-
return t;
547-
548-
return ParenType::get(ctx, underlying);
549-
}
550-
551536
case TypeKind::ErrorUnion: {
552537
auto errorUnion = cast<ErrorUnionType>(base);
553538
bool anyChanged = false;

include/swift/AST/Types.h

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

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

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

1291-
/// Retrieve the type without any parentheses around it.
1292-
Type getWithoutParens();
1293-
12941286
/// Replace the base type of the result type of the given function
12951287
/// type with a new result type, as per a DynamicSelf or other
12961288
/// covariant return transformation. The optionality of the
@@ -2589,21 +2581,6 @@ class YieldTypeFlags {
25892581
uint8_t toRaw() const { return value.toRaw(); }
25902582
};
25912583

2592-
/// ParenType - A paren type is a type that's been written in parentheses.
2593-
class ParenType : public SugarType {
2594-
ParenType(Type UnderlyingType, RecursiveTypeProperties properties);
2595-
2596-
public:
2597-
static ParenType *get(const ASTContext &C, Type underlying);
2598-
2599-
Type getUnderlyingType() const { return getSinglyDesugaredType(); }
2600-
2601-
// Implement isa/cast/dyncast/etc.
2602-
static bool classof(const TypeBase *T) {
2603-
return T->getKind() == TypeKind::Paren;
2604-
}
2605-
};
2606-
26072584
/// TupleTypeElt - This represents a single element of a tuple.
26082585
class TupleTypeElt {
26092586
/// An optional name for the field.

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ NODE(AssociatedTypeGenericParamRef)
328328
NODE(SugaredOptional)
329329
NODE(SugaredArray)
330330
NODE(SugaredDictionary)
331-
NODE(SugaredParen)
331+
NODE(SugaredParen) // Removed in Swift 6.TBD
332332

333333
// Added in Swift 5.1
334334
NODE(AccessorFunctionReference)

include/swift/Demangling/TypeDecoder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,9 @@ class TypeDecoder {
14791479
if (base.isError())
14801480
return base;
14811481

1482-
return Builder.createParenType(base.getType());
1482+
// ParenType has been removed, return the base type for backwards
1483+
// compatibility.
1484+
return base.getType();
14831485
}
14841486
case NodeKind::OpaqueType: {
14851487
if (Node->getNumChildren() < 3)

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
@@ -542,7 +542,6 @@ struct ASTContext::Implementation {
542542
llvm::DenseMap<Type, VariadicSequenceType*> VariadicSequenceTypes;
543543
llvm::DenseMap<std::pair<Type, Type>, DictionaryType *> DictionaryTypes;
544544
llvm::DenseMap<Type, OptionalType*> OptionalTypes;
545-
llvm::DenseMap<Type, ParenType*> ParenTypes;
546545
llvm::DenseMap<uintptr_t, ReferenceStorageType*> ReferenceStorageTypes;
547546
llvm::DenseMap<Type, LValueType*> LValueTypes;
548547
llvm::DenseMap<Type, InOutType*> InOutTypes;
@@ -3240,7 +3239,6 @@ size_t ASTContext::Implementation::Arena::getTotalMemory() const {
32403239
llvm::capacity_in_bytes(DictionaryTypes) +
32413240
llvm::capacity_in_bytes(OptionalTypes) +
32423241
llvm::capacity_in_bytes(VariadicSequenceTypes) +
3243-
llvm::capacity_in_bytes(ParenTypes) +
32443242
llvm::capacity_in_bytes(ReferenceStorageTypes) +
32453243
llvm::capacity_in_bytes(LValueTypes) +
32463244
llvm::capacity_in_bytes(InOutTypes) +
@@ -3279,7 +3277,6 @@ void ASTContext::Implementation::Arena::dump(llvm::raw_ostream &os) const {
32793277
SIZE_AND_BYTES(VariadicSequenceTypes);
32803278
SIZE_AND_BYTES(DictionaryTypes);
32813279
SIZE_AND_BYTES(OptionalTypes);
3282-
SIZE_AND_BYTES(ParenTypes);
32833280
SIZE_AND_BYTES(ReferenceStorageTypes);
32843281
SIZE_AND_BYTES(LValueTypes);
32853282
SIZE_AND_BYTES(InOutTypes);
@@ -3629,18 +3626,6 @@ BuiltinVectorType *BuiltinVectorType::get(const ASTContext &context,
36293626
return vecTy;
36303627
}
36313628

3632-
ParenType *ParenType::get(const ASTContext &C, Type underlying) {
3633-
auto properties = underlying->getRecursiveProperties();
3634-
auto arena = getArena(properties);
3635-
ParenType *&Result = C.getImpl().getArena(arena).ParenTypes[underlying];
3636-
if (Result == nullptr) {
3637-
Result = new (C, arena) ParenType(underlying, properties);
3638-
assert((C.hadError() || !underlying->is<InOutType>()) &&
3639-
"Cannot wrap InOutType");
3640-
}
3641-
return Result;
3642-
}
3643-
36443629
CanTupleType TupleType::getEmpty(const ASTContext &C) {
36453630
return cast<TupleType>(CanType(C.TheEmptyTupleType));
36463631
}
@@ -4567,7 +4552,7 @@ Type AnyFunctionType::composeTuple(ASTContext &ctx, ArrayRef<Param> params,
45674552
elements.emplace_back(param.getParameterType(), param.getLabel());
45684553
}
45694554
if (elements.size() == 1 && !elements[0].hasName())
4570-
return ParenType::get(ctx, elements[0].getType());
4555+
return elements[0].getType();
45714556
return TupleType::get(elements, ctx);
45724557
}
45734558

lib/AST/ASTDemangler.cpp

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

1056-
Type ASTBuilder::createParenType(Type base) {
1057-
return ParenType::get(Ctx, base);
1058-
}
1059-
10601056
Type ASTBuilder::createIntegerType(intptr_t value) {
10611057
return IntegerType::get(std::to_string(value), /*isNegative*/ false, Ctx);
10621058
}

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4140,14 +4140,6 @@ namespace {
41404140
printFoot();
41414141
}
41424142

4143-
void visitParenType(ParenType *T, StringRef label) {
4144-
printCommon("paren_type", label);
4145-
4146-
printRec(T->getUnderlyingType());
4147-
4148-
printFoot();
4149-
}
4150-
41514143
void visitTupleType(TupleType *T, StringRef label) {
41524144
printCommon("tuple_type", label);
41534145

lib/AST/ASTMangler.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,12 +1396,6 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
13961396
return;
13971397
}
13981398

1399-
case TypeKind::Paren:
1400-
assert(DWARFMangling && "sugared types are only legal for the debugger");
1401-
appendType(cast<ParenType>(tybase)->getUnderlyingType(), sig, forDecl);
1402-
appendOperator("XSp");
1403-
return;
1404-
14051399
case TypeKind::ArraySlice:
14061400
assert(DWARFMangling && "sugared types are only legal for the debugger");
14071401
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
@@ -6102,12 +6102,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
61026102
}
61036103
}
61046104

6105-
void visitParenType(ParenType *T) {
6106-
Printer << "(";
6107-
visit(T->getUnderlyingType()->getInOutObjectType());
6108-
Printer << ")";
6109-
}
6110-
61116105
void visitPackType(PackType *T) {
61126106
if (Options.PrintExplicitPackTypes || Options.PrintTypesForDebugging)
61136107
Printer << "Pack{";
@@ -6185,7 +6179,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
61856179
Printer << ": ";
61866180
} else if (e == 1 && !EltType->is<PackExpansionType>()) {
61876181
// Unlabeled one-element tuples always print the empty label to
6188-
// distinguish them from the older syntax for ParenType.
6182+
// distinguish them from the older syntax for parens.
61896183
Printer << "_: ";
61906184
}
61916185
visit(EltType);

lib/AST/ASTVerifier.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,16 +2135,6 @@ class Verifier : public ASTWalker {
21352135
verifyCheckedBase(E);
21362136
}
21372137

2138-
void verifyChecked(ParenExpr *E) {
2139-
PrettyStackTraceExpr debugStack(Ctx, "verifying ParenExpr", E);
2140-
auto ty = dyn_cast<ParenType>(E->getType().getPointer());
2141-
if (!ty) {
2142-
Out << "ParenExpr not of ParenType\n";
2143-
abort();
2144-
}
2145-
verifyCheckedBase(E);
2146-
}
2147-
21482138
void verifyChecked(AnyTryExpr *E) {
21492139
PrettyStackTraceExpr debugStack(Ctx, "verifying AnyTryExpr", E);
21502140

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
@@ -707,8 +707,8 @@ static bool typeSpellingIsAmbiguous(Type type,
707707
for (auto arg : Args) {
708708
if (arg.getKind() == DiagnosticArgumentKind::Type) {
709709
auto argType = arg.getAsType();
710-
if (argType && argType->getWithoutParens().getPointer() != type.getPointer() &&
711-
argType->getWithoutParens().getString(PO) == type.getString(PO)) {
710+
if (argType && argType.getPointer() != type.getPointer() &&
711+
argType.getString(PO) == type.getString(PO)) {
712712
// Currently, existential types are spelled the same way
713713
// as protocols and compositions. We can remove this once
714714
// existenials are printed with 'any'.
@@ -900,41 +900,20 @@ static void formatDiagnosticArgument(StringRef Modifier,
900900
// Compute the appropriate print options for this argument.
901901
auto printOptions = PrintOptions::forDiagnosticArguments();
902902
if (Arg.getKind() == DiagnosticArgumentKind::Type) {
903-
type = Arg.getAsType()->getWithoutParens();
904-
if (type.isNull()) {
905-
// FIXME: We should never receive a nullptr here, but this is causing
906-
// crashes (rdar://75740683). Remove once ParenType never contains
907-
// nullptr as the underlying type.
908-
Out << "<null>";
909-
break;
910-
}
903+
type = Arg.getAsType();
911904
if (type->getASTContext().TypeCheckerOpts.PrintFullConvention)
912905
printOptions.PrintFunctionRepresentationAttrs =
913906
PrintOptions::FunctionRepresentationMode::Full;
914907
needsQualification = typeSpellingIsAmbiguous(type, Args, printOptions);
915908
} else if (Arg.getKind() == DiagnosticArgumentKind::FullyQualifiedType) {
916-
type = Arg.getAsFullyQualifiedType().getType()->getWithoutParens();
917-
if (type.isNull()) {
918-
// FIXME: We should never receive a nullptr here, but this is causing
919-
// crashes (rdar://75740683). Remove once ParenType never contains
920-
// nullptr as the underlying type.
921-
Out << "<null>";
922-
break;
923-
}
909+
type = Arg.getAsFullyQualifiedType().getType();
924910
if (type->getASTContext().TypeCheckerOpts.PrintFullConvention)
925911
printOptions.PrintFunctionRepresentationAttrs =
926912
PrintOptions::FunctionRepresentationMode::Full;
927913
needsQualification = true;
928914
} else {
929915
assert(Arg.getKind() == DiagnosticArgumentKind::WitnessType);
930-
type = Arg.getAsWitnessType().getType()->getWithoutParens();
931-
if (type.isNull()) {
932-
// FIXME: We should never receive a nullptr here, but this is causing
933-
// crashes (rdar://75740683). Remove once ParenType never contains
934-
// nullptr as the underlying type.
935-
Out << "<null>";
936-
break;
937-
}
916+
type = Arg.getAsWitnessType().getType();
938917
printOptions.PrintGenericRequirements = false;
939918
printOptions.PrintInverseRequirements = false;
940919
needsQualification = typeSpellingIsAmbiguous(type, Args, printOptions);

0 commit comments

Comments
 (0)