Skip to content

Commit be8defb

Browse files
committed
Rename lookThroughAllAnyOptionalTypes to lookThroughAllOptionalTypes.
1 parent fdd86fe commit be8defb

16 files changed

+43
-43
lines changed

include/swift/AST/Types.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -1002,13 +1002,13 @@ class alignas(1 << TypeAlignInBits) TypeBase {
10021002
// otherwise, return the null type.
10031003
Type getSwiftNewtypeUnderlyingType();
10041004

1005-
/// Return the type T after looking through all of the optional or
1006-
/// implicitly-unwrapped optional types.
1007-
Type lookThroughAllAnyOptionalTypes();
1005+
/// Return the type T after looking through all of the optional
1006+
/// types.
1007+
Type lookThroughAllOptionalTypes();
10081008

1009-
/// Return the type T after looking through all of the optional or
1010-
/// implicitly-unwrapped optional types.
1011-
Type lookThroughAllAnyOptionalTypes(SmallVectorImpl<Type> &optionals);
1009+
/// Return the type T after looking through all of the optional
1010+
/// types.
1011+
Type lookThroughAllOptionalTypes(SmallVectorImpl<Type> &optionals);
10121012

10131013
/// Whether this is the AnyObject type.
10141014
bool isAnyObject();

lib/AST/Type.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -554,15 +554,15 @@ Type TypeBase::getAnyPointerElementType(PointerTypeKind &PTK) {
554554
return Type();
555555
}
556556

557-
Type TypeBase::lookThroughAllAnyOptionalTypes() {
557+
Type TypeBase::lookThroughAllOptionalTypes() {
558558
Type type(this);
559559
while (auto objType = type->getOptionalObjectType())
560560
type = objType;
561561

562562
return type;
563563
}
564564

565-
Type TypeBase::lookThroughAllAnyOptionalTypes(SmallVectorImpl<Type> &optionals){
565+
Type TypeBase::lookThroughAllOptionalTypes(SmallVectorImpl<Type> &optionals){
566566
Type type(this);
567567
while (auto objType = type->getOptionalObjectType()) {
568568
optionals.push_back(type);

lib/IDE/CodeCompletion.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
16701670
bool isImplicitlyCurriedIM = isImplicitlyCurriedInstanceMethod(D);
16711671
for (auto expectedType : ExpectedTypes) {
16721672
if (expectedType &&
1673-
expectedType->lookThroughAllAnyOptionalTypes()
1673+
expectedType->lookThroughAllOptionalTypes()
16741674
->is<AnyFunctionType>() &&
16751675
calculateTypeRelationForDecl(D, expectedType, isImplicitlyCurriedIM,
16761676
/*UseFuncResultType=*/false) >=
@@ -3746,7 +3746,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
37463746
bool addedSelector = false;
37473747
bool addedKeyPath = false;
37483748
for (auto T : ExpectedTypes) {
3749-
T = T->lookThroughAllAnyOptionalTypes();
3749+
T = T->lookThroughAllOptionalTypes();
37503750
if (auto structDecl = T->getStructOrBoundGenericStruct()) {
37513751
if (!addedSelector &&
37523752
structDecl->getName() == Ctx.Id_Selector &&

lib/IDE/CodeCompletionResultBuilder.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ class CodeCompletionResultBuilder {
384384

385385
// Look through optional types and type aliases to find out if we have
386386
// function/closure parameter type that is not an autoclosure.
387-
Ty = Ty->lookThroughAllAnyOptionalTypes();
387+
Ty = Ty->lookThroughAllOptionalTypes();
388388
if (auto AFT = Ty->getAs<AnyFunctionType>()) {
389389
if (!AFT->isAutoClosure()) {
390390
// If this is a closure type, add ChunkKind::CallParameterClosureType.

lib/PrintAsObjC/PrintAsObjC.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
19111911
PrettyStackTraceType trace(M.getASTContext(), "printing", ty);
19121912

19131913
if (isFuncParam)
1914-
if (auto fnTy = ty->lookThroughAllAnyOptionalTypes()
1914+
if (auto fnTy = ty->lookThroughAllOptionalTypes()
19151915
->getAs<AnyFunctionType>())
19161916
if (fnTy->isNoEscape())
19171917
os << "SWIFT_NOESCAPE ";

lib/SILGen/SILGenConvert.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ static bool isMatchedAnyToAnyObjectConversion(CanType from, CanType to) {
12801280
}
12811281

12821282
if (from->isAny()) {
1283-
assert(to->lookThroughAllAnyOptionalTypes()->isAnyObject());
1283+
assert(to->lookThroughAllOptionalTypes()->isAnyObject());
12841284
return true;
12851285
}
12861286
return false;

lib/Sema/CSApply.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -3176,9 +3176,9 @@ namespace {
31763176

31773177
// Dig through the optionals in the from/to types.
31783178
SmallVector<Type, 2> fromOptionals;
3179-
fromType->lookThroughAllAnyOptionalTypes(fromOptionals);
3179+
fromType->lookThroughAllOptionalTypes(fromOptionals);
31803180
SmallVector<Type, 2> toOptionals;
3181-
toType->lookThroughAllAnyOptionalTypes(toOptionals);
3181+
toType->lookThroughAllOptionalTypes(toOptionals);
31823182

31833183
// If we have an imbalance of optionals or a collection
31843184
// downcast, handle this as a checked cast followed by a
@@ -3293,11 +3293,11 @@ namespace {
32933293
Type srcType = cs.getType(subExpr);
32943294

32953295
SmallVector<Type, 4> srcOptionals;
3296-
srcType = srcType->lookThroughAllAnyOptionalTypes(srcOptionals);
3296+
srcType = srcType->lookThroughAllOptionalTypes(srcOptionals);
32973297

32983298
SmallVector<Type, 4> destOptionals;
32993299
auto destValueType
3300-
= finalResultType->lookThroughAllAnyOptionalTypes(destOptionals);
3300+
= finalResultType->lookThroughAllOptionalTypes(destOptionals);
33013301

33023302
// When performing a bridging operation, if the destination value type
33033303
// is 'AnyObject', leave any extra optionals on the source in place.
@@ -5359,10 +5359,10 @@ Expr *ExprRewriter::coerceOptionalToOptional(Expr *expr, Type toType,
53595359
tc.requireOptionalIntrinsics(expr->getLoc());
53605360

53615361
SmallVector<Type, 4> fromOptionals;
5362-
(void)fromType->lookThroughAllAnyOptionalTypes(fromOptionals);
5362+
(void)fromType->lookThroughAllOptionalTypes(fromOptionals);
53635363

53645364
SmallVector<Type, 4> toOptionals;
5365-
(void)toType->lookThroughAllAnyOptionalTypes(toOptionals);
5365+
(void)toType->lookThroughAllOptionalTypes(toOptionals);
53665366

53675367
assert(!toOptionals.empty());
53685368
assert(!fromOptionals.empty());

lib/Sema/CSDiag.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -2496,7 +2496,7 @@ static bool tryRawRepresentableFixIts(InFlightDiagnostic &diag,
24962496
const Expr *expr) {
24972497
// The following fixes apply for optional destination types as well.
24982498
bool toTypeIsOptional = !toType->getOptionalObjectType().isNull();
2499-
toType = toType->lookThroughAllAnyOptionalTypes();
2499+
toType = toType->lookThroughAllOptionalTypes();
25002500

25012501
Type fromTypeUnwrapped = fromType->getOptionalObjectType();
25022502
bool fromTypeIsOptional = !fromTypeUnwrapped.isNull();
@@ -2697,7 +2697,7 @@ static bool addTypeCoerceFixit(InFlightDiagnostic &diag, ConstraintSystem &CS,
26972697
Type fromType, Type toType, Expr *expr) {
26982698
// Look through optional types; casts can add them, but can't remove extra
26992699
// ones.
2700-
toType = toType->lookThroughAllAnyOptionalTypes();
2700+
toType = toType->lookThroughAllOptionalTypes();
27012701

27022702
CheckedCastKind Kind = CS.getTypeChecker().typeCheckCheckedCast(
27032703
fromType, toType, CheckedCastContextKind::None, CS.DC, SourceLoc(),
@@ -2736,7 +2736,7 @@ static bool tryDiagnoseNonEscapingParameterToEscaping(
27362736
// the event of an implicit promotion.
27372737
auto srcFT = srcType->getAs<AnyFunctionType>();
27382738
auto dstFT =
2739-
dstType->lookThroughAllAnyOptionalTypes()->getAs<AnyFunctionType>();
2739+
dstType->lookThroughAllOptionalTypes()->getAs<AnyFunctionType>();
27402740

27412741
if (!srcFT || !dstFT || !srcFT->isNoEscape() || dstFT->isNoEscape())
27422742
return false;
@@ -4294,7 +4294,7 @@ diagnoseSingleCandidateFailures(CalleeCandidateInfo &CCI, Expr *fnExpr,
42944294
isa<ConstructorDecl>(candidate.getDecl()) && candidate.level == 1) {
42954295
AnyFunctionType::Param &arg = args[0];
42964296
auto resTy =
4297-
candidate.getResultType()->lookThroughAllAnyOptionalTypes();
4297+
candidate.getResultType()->lookThroughAllOptionalTypes();
42984298
auto rawTy = isRawRepresentable(resTy, CCI.CS);
42994299
if (rawTy && arg.getType() && resTy->isEqual(arg.getType())) {
43004300
auto getInnerExpr = [](Expr *E) -> Expr * {
@@ -4338,8 +4338,8 @@ diagnoseSingleCandidateFailures(CalleeCandidateInfo &CCI, Expr *fnExpr,
43384338
static bool isRawRepresentableMismatch(Type fromType, Type toType,
43394339
KnownProtocolKind kind,
43404340
const ConstraintSystem &CS) {
4341-
toType = toType->lookThroughAllAnyOptionalTypes();
4342-
fromType = fromType->lookThroughAllAnyOptionalTypes();
4341+
toType = toType->lookThroughAllOptionalTypes();
4342+
fromType = fromType->lookThroughAllOptionalTypes();
43434343

43444344
// First check if this is an attempt to convert from something to
43454345
// raw representable.
@@ -6636,7 +6636,7 @@ static bool diagnoseKeyPathComponents(ConstraintSystem &CS, KeyPathExpr *KPE,
66366636
Type currentType = rootType;
66376637
auto updateState = [&](bool isProperty, Type newType) {
66386638
// Strip off optionals.
6639-
newType = newType->lookThroughAllAnyOptionalTypes();
6639+
newType = newType->lookThroughAllOptionalTypes();
66406640

66416641
// If updating to a type, just set the new type; there's nothing
66426642
// more to do.
@@ -7027,7 +7027,7 @@ bool FailureDiagnosis::visitArrayExpr(ArrayExpr *E) {
70277027

70287028
// If our contextual type is an optional, look through them, because we're
70297029
// surely initializing whatever is inside.
7030-
contextualType = contextualType->lookThroughAllAnyOptionalTypes();
7030+
contextualType = contextualType->lookThroughAllOptionalTypes();
70317031

70327032
// Validate that the contextual type conforms to ExpressibleByArrayLiteral and
70337033
// figure out what the contextual element type is in place.
@@ -7115,7 +7115,7 @@ bool FailureDiagnosis::visitDictionaryExpr(DictionaryExpr *E) {
71157115
if (auto contextualType = CS.getContextualType()) {
71167116
// If our contextual type is an optional, look through them, because we're
71177117
// surely initializing whatever is inside.
7118-
contextualType = contextualType->lookThroughAllAnyOptionalTypes();
7118+
contextualType = contextualType->lookThroughAllOptionalTypes();
71197119

71207120
auto DLC = CS.TC.getProtocol(
71217121
E->getLoc(), KnownProtocolKind::ExpressibleByDictionaryLiteral);

lib/Sema/CSSimplify.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1370,10 +1370,10 @@ static void enumerateOptionalConversionRestrictions(
13701370
ConstraintKind kind, ConstraintLocatorBuilder locator,
13711371
llvm::function_ref<void(ConversionRestrictionKind)> fn) {
13721372
SmallVector<Type, 2> optionals1;
1373-
Type objType1 = type1->lookThroughAllAnyOptionalTypes(optionals1);
1373+
Type objType1 = type1->lookThroughAllOptionalTypes(optionals1);
13741374

13751375
SmallVector<Type, 2> optionals2;
1376-
Type objType2 = type2->lookThroughAllAnyOptionalTypes(optionals2);
1376+
Type objType2 = type2->lookThroughAllOptionalTypes(optionals2);
13771377

13781378
if (optionals1.empty() && optionals2.empty())
13791379
return;
@@ -2653,8 +2653,8 @@ ConstraintSystem::simplifyCheckedCastConstraint(
26532653

26542654
// Peel off optionals metatypes from the types, because we might cast through
26552655
// them.
2656-
toType = toType->lookThroughAllAnyOptionalTypes();
2657-
fromType = fromType->lookThroughAllAnyOptionalTypes();
2656+
toType = toType->lookThroughAllOptionalTypes();
2657+
fromType = fromType->lookThroughAllOptionalTypes();
26582658

26592659
// Peel off metatypes, since if we can cast two types, we can cast their
26602660
// metatypes.
@@ -4511,7 +4511,7 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
45114511
case ConversionRestrictionKind::HashableToAnyHashable: {
45124512
// We never want to do this if the LHS is already AnyHashable.
45134513
if (isAnyHashableType(
4514-
type1->getRValueType()->lookThroughAllAnyOptionalTypes())) {
4514+
type1->getRValueType()->lookThroughAllOptionalTypes())) {
45154515
return SolutionKind::Error;
45164516
}
45174517

lib/Sema/ConstraintSystem.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void ConstraintSystem::setMustBeMaterializableRecursive(Type type)
199199
"argument to setMustBeMaterializableRecursive may not be inherently "
200200
"non-materializable");
201201
type = getFixedTypeRecursive(type, /*wantRValue=*/false);
202-
type = type->lookThroughAllAnyOptionalTypes();
202+
type = type->lookThroughAllOptionalTypes();
203203

204204
if (auto typeVar = type->getAs<TypeVariableType>()) {
205205
typeVar->getImpl().setMustBeMaterializable(getSavedBindings());

lib/Sema/MiscDiagnostics.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3477,13 +3477,13 @@ static void diagnoseUnintendedOptionalBehavior(TypeChecker &TC, const Expr *E,
34773477
size_t &difference) {
34783478
SmallVector<Type, 4> destOptionals;
34793479
auto destValueType =
3480-
destType->lookThroughAllAnyOptionalTypes(destOptionals);
3480+
destType->lookThroughAllOptionalTypes(destOptionals);
34813481

34823482
if (!destValueType->isAny())
34833483
return false;
34843484

34853485
SmallVector<Type, 4> srcOptionals;
3486-
srcType->lookThroughAllAnyOptionalTypes(srcOptionals);
3486+
srcType->lookThroughAllOptionalTypes(srcOptionals);
34873487

34883488
if (srcOptionals.size() > destOptionals.size()) {
34893489
difference = srcOptionals.size() - destOptionals.size();

lib/Sema/TypeCheckAttr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ void AttributeChecker::visitRethrowsAttr(RethrowsAttr *attr) {
13971397
for (auto paramList : fn->getParameterLists()) {
13981398
for (auto param : *paramList)
13991399
if (hasThrowingFunctionParameter(param->getType()
1400-
->lookThroughAllAnyOptionalTypes()
1400+
->lookThroughAllOptionalTypes()
14011401
->getCanonicalType()))
14021402
return;
14031403
}

lib/Sema/TypeCheckError.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ class ApplyClassifier {
520520

521521
Classification classifyThrowingParameterBody(ParamDecl *param,
522522
PotentialReason reason) {
523-
assert(param->getType()->lookThroughAllAnyOptionalTypes()->castTo<AnyFunctionType>()->throws());
523+
assert(param->getType()->lookThroughAllOptionalTypes()->castTo<AnyFunctionType>()->throws());
524524

525525
// If we're currently doing rethrows-checking on the body of the
526526
// function which declares the parameter, it's rethrowing-only.
@@ -706,7 +706,7 @@ class ApplyClassifier {
706706

707707
// Otherwise, if the original parameter type was not a throwing
708708
// function type, it does not contribute to 'rethrows'.
709-
auto paramFnType = paramType->lookThroughAllAnyOptionalTypes()->getAs<AnyFunctionType>();
709+
auto paramFnType = paramType->lookThroughAllOptionalTypes()->getAs<AnyFunctionType>();
710710
if (!paramFnType || !paramFnType->throws())
711711
return Classification();
712712

lib/Sema/TypeCheckExprObjC.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
7878
Type currentType;
7979
auto updateState = [&](bool isProperty, Type newType) {
8080
// Strip off optionals.
81-
newType = newType->lookThroughAllAnyOptionalTypes();
81+
newType = newType->lookThroughAllOptionalTypes();
8282

8383
// If updating to a type, just set the new type; there's nothing
8484
// more to do.

lib/Sema/TypeCheckPattern.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1221,9 +1221,9 @@ bool TypeChecker::coercePatternToType(Pattern *&P, DeclContext *dc, Type type,
12211221

12221222
// Determine whether we have an imbalance in the number of optionals.
12231223
SmallVector<Type, 2> inputTypeOptionals;
1224-
type->lookThroughAllAnyOptionalTypes(inputTypeOptionals);
1224+
type->lookThroughAllOptionalTypes(inputTypeOptionals);
12251225
SmallVector<Type, 2> castTypeOptionals;
1226-
castType->lookThroughAllAnyOptionalTypes(castTypeOptionals);
1226+
castType->lookThroughAllOptionalTypes(castTypeOptionals);
12271227

12281228
// If we have extra optionals on the input type. Create ".Some" patterns
12291229
// wrapping the isa pattern to balance out the optionals.

lib/Sema/TypeCheckStmt.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ bool TypeChecker::typeCheckCatchPattern(CatchStmt *S, DeclContext *DC) {
10301030
static bool isDiscardableType(Type type) {
10311031
return (type->hasError() ||
10321032
type->isUninhabited() ||
1033-
type->lookThroughAllAnyOptionalTypes()->isVoid());
1033+
type->lookThroughAllOptionalTypes()->isVoid());
10341034
}
10351035

10361036
static void diagnoseIgnoredLiteral(TypeChecker &TC, LiteralExpr *LE) {

0 commit comments

Comments
 (0)