@@ -2198,15 +2198,14 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
2198
2198
return getTypeMatchSuccess ();
2199
2199
}
2200
2200
2201
- static bool isStringCompatiblePointerBaseType (TypeChecker &TC,
2202
- DeclContext *DC,
2201
+ static bool isStringCompatiblePointerBaseType (ASTContext &ctx,
2203
2202
Type baseType) {
2204
2203
// Allow strings to be passed to pointer-to-byte or pointer-to-void types.
2205
- if (baseType->isEqual (TC. getInt8Type (DC )))
2204
+ if (baseType->isEqual (TypeChecker:: getInt8Type (ctx )))
2206
2205
return true ;
2207
- if (baseType->isEqual (TC. getUInt8Type (DC )))
2206
+ if (baseType->isEqual (TypeChecker:: getUInt8Type (ctx )))
2208
2207
return true ;
2209
- if (baseType->isEqual (TC. Context .TheEmptyTupleType ))
2208
+ if (baseType->isEqual (ctx .TheEmptyTupleType ))
2210
2209
return true ;
2211
2210
2212
2211
return false ;
@@ -4152,11 +4151,12 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
4152
4151
4153
4152
// The pointer can be converted from a string, if the element
4154
4153
// type is compatible.
4155
- if (type1->isEqual (TC.getStringType (DC))) {
4154
+ auto &ctx = getASTContext ();
4155
+ if (type1->isEqual (TypeChecker::getStringType (ctx))) {
4156
4156
auto baseTy = getFixedTypeRecursive (pointeeTy, false );
4157
4157
4158
4158
if (baseTy->isTypeVariableOrMember () ||
4159
- isStringCompatiblePointerBaseType (TC, DC , baseTy))
4159
+ isStringCompatiblePointerBaseType (ctx , baseTy))
4160
4160
conversionsOrFixes.push_back (
4161
4161
ConversionRestrictionKind::StringToPointer);
4162
4162
}
@@ -4479,7 +4479,7 @@ ConstraintSystem::simplifyConstructionConstraint(
4479
4479
// The constructor will have function type T -> T2, for a fresh type
4480
4480
// variable T. T2 is the result type provided via the construction
4481
4481
// constraint itself.
4482
- addValueMemberConstraint (MetatypeType::get (valueType, TC. Context ),
4482
+ addValueMemberConstraint (MetatypeType::get (valueType, getASTContext () ),
4483
4483
DeclBaseName::createConstructor (),
4484
4484
memberType,
4485
4485
useDC, functionRefKind,
@@ -5177,6 +5177,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
5177
5177
5178
5178
// If the base type is a tuple type, look for the named or indexed member
5179
5179
// of the tuple.
5180
+ auto &ctx = getASTContext ();
5180
5181
if (auto baseTuple = baseObjTy->getAs <TupleType>()) {
5181
5182
// Tuples don't have compound-name members.
5182
5183
if (!memberName.isSimpleName () || memberName.isSpecial ())
@@ -5215,7 +5216,8 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
5215
5216
// anything else, because the cost of the general search is so
5216
5217
// high.
5217
5218
if (auto info = getArgumentInfo (memberLocator)) {
5218
- memberName = DeclName (TC.Context , memberName.getBaseName (), info->Labels );
5219
+ memberName = DeclName (ctx, memberName.getBaseName (),
5220
+ info->Labels );
5219
5221
}
5220
5222
}
5221
5223
@@ -5249,8 +5251,8 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
5249
5251
// If the instance type is String bridged to NSString, compute
5250
5252
// the type we'll look in for bridging.
5251
5253
Type bridgedType;
5252
- if (baseObjTy->getAnyNominal () == TC. Context .getStringDecl ()) {
5253
- if (Type classType = TC. Context .getBridgedToObjC (DC, instanceTy)) {
5254
+ if (baseObjTy->getAnyNominal () == ctx .getStringDecl ()) {
5255
+ if (Type classType = ctx .getBridgedToObjC (DC, instanceTy)) {
5254
5256
bridgedType = classType;
5255
5257
}
5256
5258
}
@@ -5517,7 +5519,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
5517
5519
if (!(info && info->Labels .size () == 1 &&
5518
5520
info->Labels [0 ] == getASTContext ().Id_dynamicMember )) {
5519
5521
return OverloadChoice::getDynamicMemberLookup (
5520
- baseTy, subscript, TC. Context .getIdentifier (" subscript" ),
5522
+ baseTy, subscript, ctx .getIdentifier (" subscript" ),
5521
5523
/* isKeyPathBased=*/ true );
5522
5524
}
5523
5525
}
@@ -5535,11 +5537,11 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
5535
5537
// Backward compatibility hack. In Swift 4, `init` and init were
5536
5538
// the same name, so you could write "foo.init" to look up a
5537
5539
// method or property named `init`.
5538
- if (!TC. Context .isSwiftVersionAtLeast (5 ) &&
5540
+ if (!ctx .isSwiftVersionAtLeast (5 ) &&
5539
5541
memberName.getBaseName () == DeclBaseName::createConstructor () &&
5540
5542
!isImplicitInit) {
5541
5543
auto &compatLookup = lookupMember (instanceTy,
5542
- TC. Context .getIdentifier (" init" ));
5544
+ ctx .getIdentifier (" init" ));
5543
5545
for (auto result : compatLookup)
5544
5546
addChoice (getOverloadChoice (result.getValueDecl (),
5545
5547
/* isBridged=*/ false ,
@@ -6409,12 +6411,13 @@ ConstraintSystem::simplifyBridgingConstraint(Type type1,
6409
6411
}
6410
6412
6411
6413
// Explicit bridging from a value type to an Objective-C class type.
6414
+ auto &ctx = getASTContext ();
6412
6415
if (unwrappedFromType->isPotentiallyBridgedValueType () &&
6413
6416
(unwrappedToType->isBridgeableObjectType () ||
6414
6417
(unwrappedToType->isExistentialType () &&
6415
6418
!unwrappedToType->isAny ()))) {
6416
6419
countOptionalInjections ();
6417
- if (Type classType = TC. Context .getBridgedToObjC (DC, unwrappedFromType)) {
6420
+ if (Type classType = ctx .getBridgedToObjC (DC, unwrappedFromType)) {
6418
6421
return matchTypes (classType, unwrappedToType, ConstraintKind::Conversion,
6419
6422
subflags, locator);
6420
6423
}
@@ -6426,26 +6429,26 @@ ConstraintSystem::simplifyBridgingConstraint(Type type1,
6426
6429
if (unwrappedFromType->mayHaveSuperclass () &&
6427
6430
unwrappedToType->isPotentiallyBridgedValueType ()) {
6428
6431
Type bridgedValueType;
6429
- if (auto objcClass = TC. Context .getBridgedToObjC (DC, unwrappedToType,
6430
- &bridgedValueType)) {
6432
+ if (auto objcClass = ctx .getBridgedToObjC (DC, unwrappedToType,
6433
+ &bridgedValueType)) {
6431
6434
// Bridging NSNumber to NSValue is one-way, since there are multiple Swift
6432
6435
// value types that bridge to those object types. It requires a checked
6433
6436
// cast to get back.
6434
- if (TC. Context .isObjCClassWithMultipleSwiftBridgedTypes (objcClass))
6437
+ if (ctx .isObjCClassWithMultipleSwiftBridgedTypes (objcClass))
6435
6438
return SolutionKind::Error;
6436
6439
6437
6440
// If the bridged value type is generic, the generic arguments
6438
6441
// must either match or be bridged.
6439
6442
// FIXME: This should be an associated type of the protocol.
6440
6443
auto &ctx = getASTContext ();
6441
6444
if (auto fromBGT = unwrappedToType->getAs <BoundGenericType>()) {
6442
- if (fromBGT->getDecl () == TC. Context .getArrayDecl ()) {
6445
+ if (fromBGT->getDecl () == ctx .getArrayDecl ()) {
6443
6446
// [AnyObject]
6444
6447
addConstraint (ConstraintKind::Bind, fromBGT->getGenericArgs ()[0 ],
6445
- TC. Context .getAnyObjectType (),
6448
+ ctx .getAnyObjectType (),
6446
6449
getConstraintLocator (locator.withPathElement (
6447
6450
LocatorPathElt::GenericArgument (0 ))));
6448
- } else if (fromBGT->getDecl () == TC. Context .getDictionaryDecl ()) {
6451
+ } else if (fromBGT->getDecl () == ctx .getDictionaryDecl ()) {
6449
6452
// [NSObject : AnyObject]
6450
6453
auto nsObjectType = ctx.getNSObjectType ();
6451
6454
if (!nsObjectType) {
@@ -6460,11 +6463,11 @@ ConstraintSystem::simplifyBridgingConstraint(Type type1,
6460
6463
LocatorPathElt::GenericArgument (0 ))));
6461
6464
6462
6465
addConstraint (ConstraintKind::Bind, fromBGT->getGenericArgs ()[1 ],
6463
- TC. Context .getAnyObjectType (),
6466
+ ctx .getAnyObjectType (),
6464
6467
getConstraintLocator (
6465
6468
locator.withPathElement (
6466
6469
LocatorPathElt::GenericArgument (1 ))));
6467
- } else if (fromBGT->getDecl () == TC. Context .getSetDecl ()) {
6470
+ } else if (fromBGT->getDecl () == ctx .getSetDecl ()) {
6468
6471
auto nsObjectType = ctx.getNSObjectType ();
6469
6472
if (!nsObjectType) {
6470
6473
// Not a bridging case. Should we detect this earlier?
@@ -6597,7 +6600,7 @@ ConstraintSystem::simplifyOpenedExistentialOfConstraint(
6597
6600
assert (instanceTy->isExistentialType ());
6598
6601
Type openedTy = OpenedArchetypeType::get (instanceTy);
6599
6602
if (isMetatype)
6600
- openedTy = MetatypeType::get (openedTy, TC. Context );
6603
+ openedTy = MetatypeType::get (openedTy, getASTContext () );
6601
6604
return matchTypes (type1, openedTy, ConstraintKind::Bind, subflags, locator);
6602
6605
}
6603
6606
if (!type2->isTypeVariableOrMember ())
@@ -7897,15 +7900,18 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
7897
7900
if (flags.contains (TMF_GenerateConstraints)) {
7898
7901
increaseScore (ScoreKind::SK_ValueToPointerConversion);
7899
7902
7903
+ auto &ctx = getASTContext ();
7900
7904
auto int8Con = Constraint::create (*this , ConstraintKind::Bind,
7901
- baseType2, TC.getInt8Type (DC),
7902
- getConstraintLocator (locator));
7905
+ baseType2,
7906
+ TypeChecker::getInt8Type (ctx),
7907
+ getConstraintLocator (locator));
7903
7908
auto uint8Con = Constraint::create (*this , ConstraintKind::Bind,
7904
- baseType2, TC.getUInt8Type (DC),
7905
- getConstraintLocator (locator));
7909
+ baseType2,
7910
+ TypeChecker::getUInt8Type (ctx),
7911
+ getConstraintLocator (locator));
7906
7912
auto voidCon = Constraint::create (*this , ConstraintKind::Bind,
7907
- baseType2, TC. Context .TheEmptyTupleType ,
7908
- getConstraintLocator (locator));
7913
+ baseType2, ctx .TheEmptyTupleType ,
7914
+ getConstraintLocator (locator));
7909
7915
7910
7916
Constraint *disjunctionChoices[] = {int8Con, uint8Con, voidCon};
7911
7917
addDisjunctionConstraint (disjunctionChoices, locator);
@@ -7915,7 +7921,7 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
7915
7921
return SolutionKind::Unsolved;
7916
7922
}
7917
7923
7918
- if (!isStringCompatiblePointerBaseType (TC, DC , baseType2)) {
7924
+ if (!isStringCompatiblePointerBaseType (getASTContext () , baseType2)) {
7919
7925
return SolutionKind::Error;
7920
7926
}
7921
7927
@@ -8024,7 +8030,7 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
8024
8030
}
8025
8031
8026
8032
auto hashableProtocol =
8027
- TC. Context .getProtocol (KnownProtocolKind::Hashable);
8033
+ getASTContext () .getProtocol (KnownProtocolKind::Hashable);
8028
8034
if (!hashableProtocol)
8029
8035
return SolutionKind::Error;
8030
8036
0 commit comments