Skip to content

Commit d726bd8

Browse files
authored
Merge pull request #13645 from davezarzycki/nfc_hasParenSugar
2 parents 9185ef5 + 6279550 commit d726bd8

File tree

10 files changed

+19
-18
lines changed

10 files changed

+19
-18
lines changed

include/swift/AST/Types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,9 @@ class alignas(1 << TypeAlignInBits) TypeBase {
480480
/// Is this the 'Any' type?
481481
bool isAny();
482482

483+
/// Does the type have outer parenthesis?
484+
bool hasParenSugar() const { return getKind() == TypeKind::Paren; }
485+
483486
/// Are values of this type essentially just class references,
484487
/// possibly with some sort of additional information?
485488
///

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,7 +3581,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
35813581
}
35823582

35833583
bool needsParens =
3584-
!isa<ParenType>(inputType.getPointer()) &&
3584+
!inputType->hasParenSugar() &&
35853585
!inputType->is<TupleType>();
35863586

35873587
if (needsParens)
@@ -3620,7 +3620,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
36203620
Printer << " ";
36213621

36223622
bool needsParens =
3623-
!isa<ParenType>(T->getInput().getPointer()) &&
3623+
!T->getInput()->hasParenSugar() &&
36243624
!T->getInput()->is<TupleType>();
36253625

36263626
if (needsParens)

lib/AST/Expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ static ArrayRef<Identifier> getArgumentLabelsFromArgument(
10971097

10981098
// Otherwise, use the type information.
10991099
auto type = getType(arg);
1100-
if (isa<ParenType>(type.getPointer())) {
1100+
if (type->hasParenSugar()) {
11011101
scratch.clear();
11021102
scratch.push_back(Identifier());
11031103
return scratch;

lib/AST/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ static Type
10281028
getCanonicalInputType(AnyFunctionType *funcType,
10291029
llvm::function_ref<CanType(Type)> getCanonicalType) {
10301030
auto origInputType = funcType->getInput();
1031-
bool isParen = isa<ParenType>(origInputType.getPointer());
1031+
bool isParen = origInputType->hasParenSugar();
10321032
Type inputType = getCanonicalType(origInputType);
10331033

10341034
if (!isParen && AnyFunctionType::isCanonicalFunctionInputType(inputType))

lib/IDE/CodeCompletion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
16331633
Type In = AFT->getInput();
16341634
if (!In)
16351635
return;
1636-
if (isa<ParenType>(In.getPointer())) {
1636+
if (In->hasParenSugar()) {
16371637
FoundFunctionsWithoutFirstKeyword = true;
16381638
return;
16391639
}
@@ -3696,7 +3696,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
36963696
}
36973697

36983698
void unboxType(Type T) {
3699-
if (isa<ParenType>(T.getPointer())) {
3699+
if (T->hasParenSugar()) {
37003700
unboxType(T->getDesugaredType());
37013701
} else if (T->is<TupleType>()) {
37023702
for (auto Ele : T->getAs<TupleType>()->getElements()) {

lib/SILGen/SILGenExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,7 +2677,7 @@ RValue RValueEmitter::visitTupleShuffleExpr(TupleShuffleExpr *E,
26772677
//
26782678
// FIXME: Remove this eventually.
26792679
if (I->canSplitIntoTupleElements() &&
2680-
!(isa<ParenType>(E->getType().getPointer()) &&
2680+
!(E->getType()->hasParenSugar() &&
26812681
SGF.getASTContext().isSwiftVersion3())) {
26822682
emitTupleShuffleExprInto(*this, E, I);
26832683
return RValue::forInContext();
@@ -2700,7 +2700,7 @@ RValue RValueEmitter::visitTupleShuffleExpr(TupleShuffleExpr *E,
27002700
// that case.
27012701
//
27022702
// FIXME: Remove this eventually.
2703-
if (isa<ParenType>(E->getType().getPointer()) &&
2703+
if (E->getType()->hasParenSugar() &&
27042704
SGF.getASTContext().isSwiftVersion3()) {
27052705
assert(E->getElementMapping().size() == 1);
27062706
auto shuffleIndex = E->getElementMapping()[0];

lib/Sema/CSDiag.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace swift {
4040

4141
// Always make sure to have at least one set of parens
4242
bool forceParens =
43-
!type->is<TupleType>() && !isa<ParenType>(type.getPointer());
43+
!type->is<TupleType>() && !type->hasParenSugar();
4444
if (forceParens)
4545
result.push_back('(');
4646

@@ -4110,7 +4110,7 @@ class ArgumentMatcher : public MatchCallArgumentListener {
41104110
// FIXME: Due to a quirk of CSApply, we can end up without a
41114111
// ParenExpr if the argument has an '@lvalue TupleType'.
41124112
assert((isa<TupleType>(CS.getType(ArgExpr).getPointer()) ||
4113-
isa<ParenType>(CS.getType(ArgExpr).getPointer())) &&
4113+
CS.getType(ArgExpr)->hasParenSugar()) &&
41144114
"unexpected argument expression type");
41154115
insertLoc = ArgExpr->getLoc();
41164116

lib/Sema/CSSimplify.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
11711171
if (last != path.rend()) {
11721172
if (last->getKind() == ConstraintLocator::ApplyArgToParam) {
11731173
if (auto *paren2 = dyn_cast<ParenType>(func2Input.getPointer())) {
1174-
if (!isa<ParenType>(func1Input.getPointer()))
1174+
if (!func1Input->hasParenSugar())
11751175
func2Input = paren2->getUnderlyingType();
11761176
}
11771177
}
@@ -1562,8 +1562,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
15621562
typeVar2 = dyn_cast<TypeVariableType>(type2.getPointer());
15631563

15641564
// If the types are obviously equivalent, we're done.
1565-
if (isa<ParenType>(type1.getPointer()) ==
1566-
isa<ParenType>(type2.getPointer()) &&
1565+
if (type1->hasParenSugar() == type2->hasParenSugar() &&
15671566
type1->isEqual(type2))
15681567
return SolutionKind::Solved;
15691568
} else {
@@ -1747,8 +1746,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
17471746
if (isArgumentTupleMatch &&
17481747
!isSwiftVersion3) {
17491748
if (!typeVar1 && !typeVar2) {
1750-
if (isa<ParenType>(type1.getPointer()) !=
1751-
isa<ParenType>(type2.getPointer())) {
1749+
if (type1->hasParenSugar() != type2->hasParenSugar()) {
17521750
return SolutionKind::Error;
17531751
}
17541752
}

lib/Sema/TypeCheckDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5616,7 +5616,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
56165616
return;
56175617

56185618
// Allow silencing this warning using parens.
5619-
if (isa<ParenType>(TL.getType().getPointer()))
5619+
if (TL.getType()->hasParenSugar())
56205620
return;
56215621

56225622
TC.diagnose(decl->getStartLoc(), diag::override_unnecessary_IUO,
@@ -5685,7 +5685,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
56855685
return;
56865686

56875687
// Allow silencing this warning using parens.
5688-
if (isa<ParenType>(resultTy.getPointer()))
5688+
if (resultTy->hasParenSugar())
56895689
return;
56905690

56915691
TC.diagnose(resultTL.getSourceRange().Start,

lib/Sema/TypeCheckPattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,7 @@ bool TypeChecker::coerceParameterListToType(ParameterList *P, ClosureExpr *CE,
15991599
// with a single underlying TupleType. In that case, check if
16001600
// the closure argument is also one to avoid the tuple splat
16011601
// from happening.
1602-
if (!hadError && isa<ParenType>(paramListType.getPointer())) {
1602+
if (!hadError && paramListType->hasParenSugar()) {
16031603
auto underlyingTy = cast<ParenType>(paramListType.getPointer())
16041604
->getUnderlyingType();
16051605

0 commit comments

Comments
 (0)