Skip to content

Commit a5b8c64

Browse files
authored
Merge pull request #27964 from CodaFi/is-this-a-dynamic-language
[NFC] Squash Out Some More TypeChecker Dependencies
2 parents 5c2185f + abc6db1 commit a5b8c64

33 files changed

+635
-636
lines changed

lib/Sema/CSApply.cpp

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static bool buildObjCKeyPathString(KeyPathExpr *E,
272272
static Expr *buildDynamicMemberLookupIndexExpr(StringRef name, SourceLoc loc,
273273
DeclContext *dc,
274274
ConstraintSystem &cs) {
275-
auto &ctx = cs.TC.Context;
275+
auto &ctx = cs.getASTContext();
276276

277277
auto *stringDecl = ctx.getStringDecl();
278278
auto stringType = stringDecl->getDeclaredType();
@@ -1837,12 +1837,12 @@ namespace {
18371837
return expr;
18381838

18391839
auto &tc = cs.getTypeChecker();
1840-
ProtocolDecl *protocol
1841-
= tc.getProtocol(expr->getLoc(),
1842-
KnownProtocolKind::ExpressibleByIntegerLiteral);
1843-
ProtocolDecl *builtinProtocol
1844-
= tc.getProtocol(expr->getLoc(),
1845-
KnownProtocolKind::ExpressibleByBuiltinIntegerLiteral);
1840+
ProtocolDecl *protocol = TypeChecker::getProtocol(
1841+
cs.getASTContext(), expr->getLoc(),
1842+
KnownProtocolKind::ExpressibleByIntegerLiteral);
1843+
ProtocolDecl *builtinProtocol = TypeChecker::getProtocol(
1844+
cs.getASTContext(), expr->getLoc(),
1845+
KnownProtocolKind::ExpressibleByBuiltinIntegerLiteral);
18461846

18471847
// For type-sugar reasons, prefer the spelling of the default literal
18481848
// type.
@@ -1851,9 +1851,9 @@ namespace {
18511851
if (defaultType->isEqual(type))
18521852
type = defaultType;
18531853
}
1854-
if (auto floatProtocol
1855-
= tc.getProtocol(expr->getLoc(),
1856-
KnownProtocolKind::ExpressibleByFloatLiteral)) {
1854+
if (auto floatProtocol = TypeChecker::getProtocol(
1855+
cs.getASTContext(), expr->getLoc(),
1856+
KnownProtocolKind::ExpressibleByFloatLiteral)) {
18571857
if (auto defaultFloatType = tc.getDefaultType(floatProtocol, dc)) {
18581858
if (defaultFloatType->isEqual(type))
18591859
type = defaultFloatType;
@@ -1888,8 +1888,9 @@ namespace {
18881888
}
18891889

18901890
auto &tc = cs.getTypeChecker();
1891-
auto *protocol = tc.getProtocol(expr->getLoc(),
1892-
KnownProtocolKind::ExpressibleByNilLiteral);
1891+
auto *protocol =
1892+
TypeChecker::getProtocol(cs.getASTContext(), expr->getLoc(),
1893+
KnownProtocolKind::ExpressibleByNilLiteral);
18931894

18941895
// For type-sugar reasons, prefer the spelling of the default literal
18951896
// type.
@@ -1920,12 +1921,12 @@ namespace {
19201921
return expr;
19211922

19221923
auto &tc = cs.getTypeChecker();
1923-
ProtocolDecl *protocol
1924-
= tc.getProtocol(expr->getLoc(),
1925-
KnownProtocolKind::ExpressibleByFloatLiteral);
1926-
ProtocolDecl *builtinProtocol
1927-
= tc.getProtocol(expr->getLoc(),
1928-
KnownProtocolKind::ExpressibleByBuiltinFloatLiteral);
1924+
ProtocolDecl *protocol = TypeChecker::getProtocol(
1925+
cs.getASTContext(), expr->getLoc(),
1926+
KnownProtocolKind::ExpressibleByFloatLiteral);
1927+
ProtocolDecl *builtinProtocol = TypeChecker::getProtocol(
1928+
cs.getASTContext(), expr->getLoc(),
1929+
KnownProtocolKind::ExpressibleByBuiltinFloatLiteral);
19291930

19301931
// For type-sugar reasons, prefer the spelling of the default literal
19311932
// type.
@@ -1964,12 +1965,12 @@ namespace {
19641965
return expr;
19651966

19661967
auto &tc = cs.getTypeChecker();
1967-
ProtocolDecl *protocol
1968-
= tc.getProtocol(expr->getLoc(),
1969-
KnownProtocolKind::ExpressibleByBooleanLiteral);
1970-
ProtocolDecl *builtinProtocol
1971-
= tc.getProtocol(expr->getLoc(),
1972-
KnownProtocolKind::ExpressibleByBuiltinBooleanLiteral);
1968+
ProtocolDecl *protocol = TypeChecker::getProtocol(
1969+
cs.getASTContext(), expr->getLoc(),
1970+
KnownProtocolKind::ExpressibleByBooleanLiteral);
1971+
ProtocolDecl *builtinProtocol = TypeChecker::getProtocol(
1972+
cs.getASTContext(), expr->getLoc(),
1973+
KnownProtocolKind::ExpressibleByBuiltinBooleanLiteral);
19731974
if (!protocol || !builtinProtocol)
19741975
return nullptr;
19751976

@@ -2001,24 +2002,25 @@ namespace {
20012002

20022003
bool isStringLiteral = true;
20032004
bool isGraphemeClusterLiteral = false;
2004-
ProtocolDecl *protocol = tc.getProtocol(
2005-
expr->getLoc(), KnownProtocolKind::ExpressibleByStringLiteral);
2005+
ProtocolDecl *protocol = TypeChecker::getProtocol(
2006+
cs.getASTContext(), expr->getLoc(),
2007+
KnownProtocolKind::ExpressibleByStringLiteral);
20062008

20072009
if (!TypeChecker::conformsToProtocol(
20082010
type, protocol, cs.DC, ConformanceCheckFlags::InExpression)) {
20092011
// If the type does not conform to ExpressibleByStringLiteral, it should
20102012
// be ExpressibleByExtendedGraphemeClusterLiteral.
2011-
protocol = tc.getProtocol(
2012-
expr->getLoc(),
2013+
protocol = TypeChecker::getProtocol(
2014+
cs.getASTContext(), expr->getLoc(),
20132015
KnownProtocolKind::ExpressibleByExtendedGraphemeClusterLiteral);
20142016
isStringLiteral = false;
20152017
isGraphemeClusterLiteral = true;
20162018
}
20172019
if (!TypeChecker::conformsToProtocol(
20182020
type, protocol, cs.DC, ConformanceCheckFlags::InExpression)) {
20192021
// ... or it should be ExpressibleByUnicodeScalarLiteral.
2020-
protocol = tc.getProtocol(
2021-
expr->getLoc(),
2022+
protocol = TypeChecker::getProtocol(
2023+
cs.getASTContext(), expr->getLoc(),
20222024
KnownProtocolKind::ExpressibleByUnicodeScalarLiteral);
20232025
isStringLiteral = false;
20242026
isGraphemeClusterLiteral = false;
@@ -2044,8 +2046,8 @@ namespace {
20442046
literalFuncName = DeclName(tc.Context, DeclBaseName::createConstructor(),
20452047
{ tc.Context.Id_stringLiteral });
20462048

2047-
builtinProtocol = tc.getProtocol(
2048-
expr->getLoc(),
2049+
builtinProtocol = TypeChecker::getProtocol(
2050+
cs.getASTContext(), expr->getLoc(),
20492051
KnownProtocolKind::ExpressibleByBuiltinStringLiteral);
20502052
builtinLiteralFuncName
20512053
= DeclName(tc.Context, DeclBaseName::createConstructor(),
@@ -2070,9 +2072,10 @@ namespace {
20702072
tc.Context.getIdentifier("utf8CodeUnitCount"),
20712073
tc.Context.getIdentifier("isASCII") });
20722074

2073-
builtinProtocol = tc.getProtocol(
2074-
expr->getLoc(),
2075-
KnownProtocolKind::ExpressibleByBuiltinExtendedGraphemeClusterLiteral);
2075+
builtinProtocol = TypeChecker::getProtocol(
2076+
cs.getASTContext(), expr->getLoc(),
2077+
KnownProtocolKind::
2078+
ExpressibleByBuiltinExtendedGraphemeClusterLiteral);
20762079
brokenProtocolDiag =
20772080
diag::extended_grapheme_cluster_literal_broken_proto;
20782081
brokenBuiltinProtocolDiag =
@@ -2088,8 +2091,8 @@ namespace {
20882091
= DeclName(tc.Context, DeclBaseName::createConstructor(),
20892092
{tc.Context.Id_builtinUnicodeScalarLiteral});
20902093

2091-
builtinProtocol = tc.getProtocol(
2092-
expr->getLoc(),
2094+
builtinProtocol = TypeChecker::getProtocol(
2095+
cs.getASTContext(), expr->getLoc(),
20932096
KnownProtocolKind::ExpressibleByBuiltinUnicodeScalarLiteral);
20942097

20952098
brokenProtocolDiag = diag::unicode_scalar_literal_broken_proto;
@@ -2125,10 +2128,10 @@ namespace {
21252128
auto loc = expr->getStartLoc();
21262129

21272130
auto fetchProtocolInitWitness =
2128-
[&](KnownProtocolKind protocolKind, Type type,
2129-
ArrayRef<Identifier> argLabels) -> ConcreteDeclRef {
2130-
2131-
auto proto = tc.getProtocol(loc, protocolKind);
2131+
[&](KnownProtocolKind protocolKind, Type type,
2132+
ArrayRef<Identifier> argLabels) -> ConcreteDeclRef {
2133+
auto proto =
2134+
TypeChecker::getProtocol(cs.getASTContext(), loc, protocolKind);
21322135
assert(proto && "Missing string interpolation protocol?");
21332136

21342137
auto conformance =
@@ -2145,9 +2148,9 @@ namespace {
21452148
return witness;
21462149
};
21472150

2148-
auto *interpolationProto =
2149-
tc.getProtocol(expr->getLoc(),
2150-
KnownProtocolKind::ExpressibleByStringInterpolation);
2151+
auto *interpolationProto = TypeChecker::getProtocol(
2152+
cs.getASTContext(), expr->getLoc(),
2153+
KnownProtocolKind::ExpressibleByStringInterpolation);
21512154
auto associatedTypeDecl = interpolationProto->getAssociatedType(
21522155
tc.Context.Id_StringInterpolation);
21532156
if (associatedTypeDecl == nullptr) {
@@ -2235,7 +2238,7 @@ namespace {
22352238
}
22362239

22372240
// Find the appropriate object literal protocol.
2238-
auto proto = tc.getLiteralProtocol(expr);
2241+
auto proto = TypeChecker::getLiteralProtocol(cs.getASTContext(), expr);
22392242
assert(proto && "Missing object literal protocol?");
22402243
auto conformance =
22412244
TypeChecker::conformsToProtocol(conformingType, proto, cs.DC,
@@ -2494,10 +2497,9 @@ namespace {
24942497
auto baseTyNominalDecl = baseTyUnwrapped
24952498
->getNominalOrBoundGenericNominal();
24962499
auto &tc = cs.getTypeChecker();
2497-
auto results = tc.lookupMember(baseTyNominalDecl->getModuleContext(),
2498-
baseTyUnwrapped,
2499-
memberName,
2500-
defaultMemberLookupOptions);
2500+
auto results = TypeChecker::lookupMember(
2501+
baseTyNominalDecl->getModuleContext(), baseTyUnwrapped,
2502+
memberName, defaultMemberLookupOptions);
25012503

25022504
// Filter out any functions, instance members, enum cases with
25032505
// associated values or variables whose type does not match the
@@ -2892,9 +2894,9 @@ namespace {
28922894
Type arrayTy = cs.getType(expr);
28932895
auto &tc = cs.getTypeChecker();
28942896

2895-
ProtocolDecl *arrayProto
2896-
= tc.getProtocol(expr->getLoc(),
2897-
KnownProtocolKind::ExpressibleByArrayLiteral);
2897+
ProtocolDecl *arrayProto = TypeChecker::getProtocol(
2898+
cs.getASTContext(), expr->getLoc(),
2899+
KnownProtocolKind::ExpressibleByArrayLiteral);
28982900
assert(arrayProto && "type-checked array literal w/o protocol?!");
28992901

29002902
auto conformance =
@@ -2938,9 +2940,9 @@ namespace {
29382940
Type dictionaryTy = cs.getType(expr);
29392941

29402942
auto &tc = cs.getTypeChecker();
2941-
ProtocolDecl *dictionaryProto
2942-
= tc.getProtocol(expr->getLoc(),
2943-
KnownProtocolKind::ExpressibleByDictionaryLiteral);
2943+
ProtocolDecl *dictionaryProto = TypeChecker::getProtocol(
2944+
cs.getASTContext(), expr->getLoc(),
2945+
KnownProtocolKind::ExpressibleByDictionaryLiteral);
29442946

29452947
auto conformance =
29462948
TypeChecker::conformsToProtocol(dictionaryTy, dictionaryProto, cs.DC,
@@ -4585,7 +4587,7 @@ namespace {
45854587
auto dc = subscript->getInnermostDeclContext();
45864588

45874589
auto indexType = AnyFunctionType::composeInput(
4588-
cs.TC.Context,
4590+
cs.getASTContext(),
45894591
subscript->getInterfaceType()->castTo<AnyFunctionType>()->getParams(),
45904592
/*canonicalVararg=*/false);
45914593

@@ -6773,8 +6775,8 @@ ExprRewriter::finishApplyDynamicCallable(ApplyExpr *apply,
67736775
auto dictLitProto =
67746776
ctx.getProtocol(KnownProtocolKind::ExpressibleByDictionaryLiteral);
67756777
auto conformance =
6776-
cs.TC.conformsToProtocol(argumentType, dictLitProto, cs.DC,
6777-
ConformanceCheckFlags::InExpression);
6778+
TypeChecker::conformsToProtocol(argumentType, dictLitProto, cs.DC,
6779+
ConformanceCheckFlags::InExpression);
67786780
auto keyType = conformance.getTypeWitnessByName(argumentType, ctx.Id_Key);
67796781
auto valueType =
67806782
conformance.getTypeWitnessByName(argumentType, ctx.Id_Value);
@@ -6827,7 +6829,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, ConcreteDeclRef callee,
68276829
= [&](ApplyExpr *apply,
68286830
ConcreteDeclRef declRef,
68296831
Type openedType) -> Expr* {
6830-
switch (cs.TC.getDeclTypeCheckingSemantics(declRef.getDecl())) {
6832+
switch (TypeChecker::getDeclTypeCheckingSemantics(declRef.getDecl())) {
68316833
case DeclTypeCheckingSemantics::TypeOf: {
68326834
// Resolve into a DynamicTypeExpr.
68336835
auto arg = apply->getArg();

lib/Sema/CSBindings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ ConstraintSystem::determineBestBindings() {
8585
}
8686
}
8787

88-
if (TC.getLangOpts().DebugConstraintSolver) {
88+
if (getASTContext().LangOpts.DebugConstraintSolver) {
8989
auto &log = getASTContext().TypeCheckerDebug->getStream();
9090
bindings.dump(typeVar, log, solverState->depth * 2);
9191
}

lib/Sema/CSDiag.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,9 @@ bool FailureDiagnosis::diagnoseGeneralConversionFailure(Constraint *constraint){
811811
// tries to add a specific diagnosis/fixit to explicitly invoke 'boolValue'.
812812
if (toType->isBool() &&
813813
fromType->mayHaveMembers()) {
814-
auto LookupResult = CS.TC.lookupMember(
815-
CS.DC, fromType, DeclName(CS.TC.Context.getIdentifier("boolValue")));
814+
auto LookupResult = TypeChecker::lookupMember(
815+
CS.DC, fromType,
816+
DeclName(CS.getASTContext().getIdentifier("boolValue")));
816817
if (!LookupResult.empty()) {
817818
if (isa<VarDecl>(LookupResult.begin()->getValueDecl())) {
818819
if (anchor->canAppendPostfixExpression())
@@ -1740,7 +1741,8 @@ static void emitFixItForExplicitlyQualifiedReference(
17401741

17411742
void ConstraintSystem::diagnoseDeprecatedConditionalConformanceOuterAccess(
17421743
UnresolvedDotExpr *UDE, ValueDecl *choice) {
1743-
auto result = TC.lookupUnqualified(DC, UDE->getName(), UDE->getLoc());
1744+
auto result =
1745+
TypeChecker::lookupUnqualified(DC, UDE->getName(), UDE->getLoc());
17441746
assert(result && "names can't just disappear");
17451747
// These should all come from the same place.
17461748
auto exampleInner = result.front();
@@ -1939,7 +1941,8 @@ bool FailureDiagnosis::diagnoseImplicitSelfErrors(
19391941
// For each of the parent contexts, let's try to find any candidates
19401942
// which have the same name and the same number of arguments as callee.
19411943
while (context->getParent()) {
1942-
auto result = TC.lookupUnqualified(context, UDE->getName(), UDE->getLoc());
1944+
auto result =
1945+
TypeChecker::lookupUnqualified(context, UDE->getName(), UDE->getLoc());
19431946
context = context->getParent();
19441947

19451948
if (!result || result.empty())
@@ -3662,7 +3665,8 @@ bool FailureDiagnosis::visitArrayExpr(ArrayExpr *E) {
36623665

36633666
// Validate that the contextual type conforms to ExpressibleByArrayLiteral and
36643667
// figure out what the contextual element type is in place.
3665-
auto ALC = CS.TC.getProtocol(E->getLoc(),
3668+
auto ALC =
3669+
TypeChecker::getProtocol(CS.getASTContext(), E->getLoc(),
36663670
KnownProtocolKind::ExpressibleByArrayLiteral);
36673671
if (!ALC)
36683672
return visitExpr(E);
@@ -3712,8 +3716,9 @@ bool FailureDiagnosis::visitDictionaryExpr(DictionaryExpr *E) {
37123716
// surely initializing whatever is inside.
37133717
contextualType = contextualType->lookThroughAllOptionalTypes();
37143718

3715-
auto DLC = CS.TC.getProtocol(
3716-
E->getLoc(), KnownProtocolKind::ExpressibleByDictionaryLiteral);
3719+
auto DLC = TypeChecker::getProtocol(
3720+
CS.getASTContext(), E->getLoc(),
3721+
KnownProtocolKind::ExpressibleByDictionaryLiteral);
37173722
if (!DLC) return visitExpr(E);
37183723

37193724
// Validate the contextual type conforms to ExpressibleByDictionaryLiteral
@@ -3773,7 +3778,7 @@ bool FailureDiagnosis::visitObjectLiteralExpr(ObjectLiteralExpr *E) {
37733778
auto &TC = CS.getTypeChecker();
37743779

37753780
// Type check the argument first.
3776-
auto protocol = TC.getLiteralProtocol(E);
3781+
auto protocol = TypeChecker::getLiteralProtocol(CS.getASTContext(), E);
37773782
if (!protocol)
37783783
return false;
37793784
DeclName constrName = TC.getObjectLiteralConstructorName(E);
@@ -4151,7 +4156,8 @@ bool FailureDiagnosis::diagnoseMemberFailures(
41514156

41524157
// Since the lookup was allowing inaccessible members, let's check
41534158
// if it found anything of that sort, which is easy to diagnose.
4154-
bool allUnavailable = !CS.TC.getLangOpts().DisableAvailabilityChecking;
4159+
bool allUnavailable =
4160+
!CS.getASTContext().LangOpts.DisableAvailabilityChecking;
41554161
bool allInaccessible = true;
41564162
for (auto &member : viableCandidatesToReport) {
41574163
if (!member.isDecl()) {

lib/Sema/CSDiagnostics.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,10 +2613,8 @@ bool ContextualFailure::tryProtocolConformanceFixIt(
26132613
// Let's build a list of protocols that the context does not conform to.
26142614
SmallVector<std::string, 8> missingProtoTypeStrings;
26152615
for (auto protocol : layout.getProtocols()) {
2616-
if (getTypeChecker()
2617-
.conformsToProtocol(FromType, protocol->getDecl(), getDC(),
2618-
ConformanceCheckFlags::InExpression)
2619-
.isInvalid()) {
2616+
if (!TypeChecker::conformsToProtocol(FromType, protocol->getDecl(), getDC(),
2617+
ConformanceCheckFlags::InExpression)) {
26202618
missingProtoTypeStrings.push_back(protocol->getString());
26212619
}
26222620
}

0 commit comments

Comments
 (0)