@@ -2181,15 +2181,14 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
2181
2181
return getTypeMatchSuccess ();
2182
2182
}
2183
2183
2184
- static bool isStringCompatiblePointerBaseType (TypeChecker &TC,
2185
- DeclContext *DC,
2184
+ static bool isStringCompatiblePointerBaseType (ASTContext &ctx,
2186
2185
Type baseType) {
2187
2186
// Allow strings to be passed to pointer-to-byte or pointer-to-void types.
2188
- if (baseType->isEqual (TC. getInt8Type (DC )))
2187
+ if (baseType->isEqual (TypeChecker:: getInt8Type (ctx )))
2189
2188
return true ;
2190
- if (baseType->isEqual (TC. getUInt8Type (DC )))
2189
+ if (baseType->isEqual (TypeChecker:: getUInt8Type (ctx )))
2191
2190
return true ;
2192
- if (baseType->isEqual (TC. Context .TheEmptyTupleType ))
2191
+ if (baseType->isEqual (ctx .TheEmptyTupleType ))
2193
2192
return true ;
2194
2193
2195
2194
return false ;
@@ -4135,11 +4134,12 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
4135
4134
4136
4135
// The pointer can be converted from a string, if the element
4137
4136
// type is compatible.
4138
- if (type1->isEqual (TC.getStringType (DC))) {
4137
+ auto &ctx = getASTContext ();
4138
+ if (type1->isEqual (TypeChecker::getStringType (ctx))) {
4139
4139
auto baseTy = getFixedTypeRecursive (pointeeTy, false );
4140
4140
4141
4141
if (baseTy->isTypeVariableOrMember () ||
4142
- isStringCompatiblePointerBaseType (TC, DC , baseTy))
4142
+ isStringCompatiblePointerBaseType (ctx , baseTy))
4143
4143
conversionsOrFixes.push_back (
4144
4144
ConversionRestrictionKind::StringToPointer);
4145
4145
}
@@ -4462,7 +4462,7 @@ ConstraintSystem::simplifyConstructionConstraint(
4462
4462
// The constructor will have function type T -> T2, for a fresh type
4463
4463
// variable T. T2 is the result type provided via the construction
4464
4464
// constraint itself.
4465
- addValueMemberConstraint (MetatypeType::get (valueType, TC. Context ),
4465
+ addValueMemberConstraint (MetatypeType::get (valueType, getASTContext () ),
4466
4466
DeclBaseName::createConstructor (),
4467
4467
memberType,
4468
4468
useDC, functionRefKind,
@@ -5160,6 +5160,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
5160
5160
5161
5161
// If the base type is a tuple type, look for the named or indexed member
5162
5162
// of the tuple.
5163
+ auto &ctx = getASTContext ();
5163
5164
if (auto baseTuple = baseObjTy->getAs <TupleType>()) {
5164
5165
// Tuples don't have compound-name members.
5165
5166
if (!memberName.isSimpleName () || memberName.isSpecial ())
@@ -5198,7 +5199,8 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
5198
5199
// anything else, because the cost of the general search is so
5199
5200
// high.
5200
5201
if (auto info = getArgumentInfo (memberLocator)) {
5201
- memberName = DeclName (TC.Context , memberName.getBaseName (), info->Labels );
5202
+ memberName = DeclName (ctx, memberName.getBaseName (),
5203
+ info->Labels );
5202
5204
}
5203
5205
}
5204
5206
@@ -5232,8 +5234,8 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
5232
5234
// If the instance type is String bridged to NSString, compute
5233
5235
// the type we'll look in for bridging.
5234
5236
Type bridgedType;
5235
- if (baseObjTy->getAnyNominal () == TC. Context .getStringDecl ()) {
5236
- if (Type classType = TC. Context .getBridgedToObjC (DC, instanceTy)) {
5237
+ if (baseObjTy->getAnyNominal () == ctx .getStringDecl ()) {
5238
+ if (Type classType = ctx .getBridgedToObjC (DC, instanceTy)) {
5237
5239
bridgedType = classType;
5238
5240
}
5239
5241
}
@@ -5500,7 +5502,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
5500
5502
if (!(info && info->Labels .size () == 1 &&
5501
5503
info->Labels [0 ] == getASTContext ().Id_dynamicMember )) {
5502
5504
return OverloadChoice::getDynamicMemberLookup (
5503
- baseTy, subscript, TC. Context .getIdentifier (" subscript" ),
5505
+ baseTy, subscript, ctx .getIdentifier (" subscript" ),
5504
5506
/* isKeyPathBased=*/ true );
5505
5507
}
5506
5508
}
@@ -5518,11 +5520,11 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
5518
5520
// Backward compatibility hack. In Swift 4, `init` and init were
5519
5521
// the same name, so you could write "foo.init" to look up a
5520
5522
// method or property named `init`.
5521
- if (!TC. Context .isSwiftVersionAtLeast (5 ) &&
5523
+ if (!ctx .isSwiftVersionAtLeast (5 ) &&
5522
5524
memberName.getBaseName () == DeclBaseName::createConstructor () &&
5523
5525
!isImplicitInit) {
5524
5526
auto &compatLookup = lookupMember (instanceTy,
5525
- TC. Context .getIdentifier (" init" ));
5527
+ ctx .getIdentifier (" init" ));
5526
5528
for (auto result : compatLookup)
5527
5529
addChoice (getOverloadChoice (result.getValueDecl (),
5528
5530
/* isBridged=*/ false ,
@@ -6392,12 +6394,13 @@ ConstraintSystem::simplifyBridgingConstraint(Type type1,
6392
6394
}
6393
6395
6394
6396
// Explicit bridging from a value type to an Objective-C class type.
6397
+ auto &ctx = getASTContext ();
6395
6398
if (unwrappedFromType->isPotentiallyBridgedValueType () &&
6396
6399
(unwrappedToType->isBridgeableObjectType () ||
6397
6400
(unwrappedToType->isExistentialType () &&
6398
6401
!unwrappedToType->isAny ()))) {
6399
6402
countOptionalInjections ();
6400
- if (Type classType = TC. Context .getBridgedToObjC (DC, unwrappedFromType)) {
6403
+ if (Type classType = ctx .getBridgedToObjC (DC, unwrappedFromType)) {
6401
6404
return matchTypes (classType, unwrappedToType, ConstraintKind::Conversion,
6402
6405
subflags, locator);
6403
6406
}
@@ -6409,26 +6412,26 @@ ConstraintSystem::simplifyBridgingConstraint(Type type1,
6409
6412
if (unwrappedFromType->mayHaveSuperclass () &&
6410
6413
unwrappedToType->isPotentiallyBridgedValueType ()) {
6411
6414
Type bridgedValueType;
6412
- if (auto objcClass = TC. Context .getBridgedToObjC (DC, unwrappedToType,
6413
- &bridgedValueType)) {
6415
+ if (auto objcClass = ctx .getBridgedToObjC (DC, unwrappedToType,
6416
+ &bridgedValueType)) {
6414
6417
// Bridging NSNumber to NSValue is one-way, since there are multiple Swift
6415
6418
// value types that bridge to those object types. It requires a checked
6416
6419
// cast to get back.
6417
- if (TC. Context .isObjCClassWithMultipleSwiftBridgedTypes (objcClass))
6420
+ if (ctx .isObjCClassWithMultipleSwiftBridgedTypes (objcClass))
6418
6421
return SolutionKind::Error;
6419
6422
6420
6423
// If the bridged value type is generic, the generic arguments
6421
6424
// must either match or be bridged.
6422
6425
// FIXME: This should be an associated type of the protocol.
6423
6426
auto &ctx = getASTContext ();
6424
6427
if (auto fromBGT = unwrappedToType->getAs <BoundGenericType>()) {
6425
- if (fromBGT->getDecl () == TC. Context .getArrayDecl ()) {
6428
+ if (fromBGT->getDecl () == ctx .getArrayDecl ()) {
6426
6429
// [AnyObject]
6427
6430
addConstraint (ConstraintKind::Bind, fromBGT->getGenericArgs ()[0 ],
6428
- TC. Context .getAnyObjectType (),
6431
+ ctx .getAnyObjectType (),
6429
6432
getConstraintLocator (locator.withPathElement (
6430
6433
LocatorPathElt::GenericArgument (0 ))));
6431
- } else if (fromBGT->getDecl () == TC. Context .getDictionaryDecl ()) {
6434
+ } else if (fromBGT->getDecl () == ctx .getDictionaryDecl ()) {
6432
6435
// [NSObject : AnyObject]
6433
6436
auto nsObjectType = ctx.getNSObjectType ();
6434
6437
if (!nsObjectType) {
@@ -6443,11 +6446,11 @@ ConstraintSystem::simplifyBridgingConstraint(Type type1,
6443
6446
LocatorPathElt::GenericArgument (0 ))));
6444
6447
6445
6448
addConstraint (ConstraintKind::Bind, fromBGT->getGenericArgs ()[1 ],
6446
- TC. Context .getAnyObjectType (),
6449
+ ctx .getAnyObjectType (),
6447
6450
getConstraintLocator (
6448
6451
locator.withPathElement (
6449
6452
LocatorPathElt::GenericArgument (1 ))));
6450
- } else if (fromBGT->getDecl () == TC. Context .getSetDecl ()) {
6453
+ } else if (fromBGT->getDecl () == ctx .getSetDecl ()) {
6451
6454
auto nsObjectType = ctx.getNSObjectType ();
6452
6455
if (!nsObjectType) {
6453
6456
// Not a bridging case. Should we detect this earlier?
@@ -6580,7 +6583,7 @@ ConstraintSystem::simplifyOpenedExistentialOfConstraint(
6580
6583
assert (instanceTy->isExistentialType ());
6581
6584
Type openedTy = OpenedArchetypeType::get (instanceTy);
6582
6585
if (isMetatype)
6583
- openedTy = MetatypeType::get (openedTy, TC. Context );
6586
+ openedTy = MetatypeType::get (openedTy, getASTContext () );
6584
6587
return matchTypes (type1, openedTy, ConstraintKind::Bind, subflags, locator);
6585
6588
}
6586
6589
if (!type2->isTypeVariableOrMember ())
@@ -7880,15 +7883,18 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
7880
7883
if (flags.contains (TMF_GenerateConstraints)) {
7881
7884
increaseScore (ScoreKind::SK_ValueToPointerConversion);
7882
7885
7886
+ auto &ctx = getASTContext ();
7883
7887
auto int8Con = Constraint::create (*this , ConstraintKind::Bind,
7884
- baseType2, TC.getInt8Type (DC),
7885
- getConstraintLocator (locator));
7888
+ baseType2,
7889
+ TypeChecker::getInt8Type (ctx),
7890
+ getConstraintLocator (locator));
7886
7891
auto uint8Con = Constraint::create (*this , ConstraintKind::Bind,
7887
- baseType2, TC.getUInt8Type (DC),
7888
- getConstraintLocator (locator));
7892
+ baseType2,
7893
+ TypeChecker::getUInt8Type (ctx),
7894
+ getConstraintLocator (locator));
7889
7895
auto voidCon = Constraint::create (*this , ConstraintKind::Bind,
7890
- baseType2, TC. Context .TheEmptyTupleType ,
7891
- getConstraintLocator (locator));
7896
+ baseType2, ctx .TheEmptyTupleType ,
7897
+ getConstraintLocator (locator));
7892
7898
7893
7899
Constraint *disjunctionChoices[] = {int8Con, uint8Con, voidCon};
7894
7900
addDisjunctionConstraint (disjunctionChoices, locator);
@@ -7898,7 +7904,7 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
7898
7904
return SolutionKind::Unsolved;
7899
7905
}
7900
7906
7901
- if (!isStringCompatiblePointerBaseType (TC, DC , baseType2)) {
7907
+ if (!isStringCompatiblePointerBaseType (getASTContext () , baseType2)) {
7902
7908
return SolutionKind::Error;
7903
7909
}
7904
7910
@@ -8007,7 +8013,7 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
8007
8013
}
8008
8014
8009
8015
auto hashableProtocol =
8010
- TC. Context .getProtocol (KnownProtocolKind::Hashable);
8016
+ getASTContext () .getProtocol (KnownProtocolKind::Hashable);
8011
8017
if (!hashableProtocol)
8012
8018
return SolutionKind::Error;
8013
8019
0 commit comments