Skip to content

Commit df7cac3

Browse files
authored
Merge pull request swiftlang#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

0 commit comments

Comments
 (0)