Skip to content

[NFC] Squash Out Some More TypeChecker Dependencies #27964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 61 additions & 59 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ static bool buildObjCKeyPathString(KeyPathExpr *E,
static Expr *buildDynamicMemberLookupIndexExpr(StringRef name, SourceLoc loc,
DeclContext *dc,
ConstraintSystem &cs) {
auto &ctx = cs.TC.Context;
auto &ctx = cs.getASTContext();

auto *stringDecl = ctx.getStringDecl();
auto stringType = stringDecl->getDeclaredType();
Expand Down Expand Up @@ -1837,12 +1837,12 @@ namespace {
return expr;

auto &tc = cs.getTypeChecker();
ProtocolDecl *protocol
= tc.getProtocol(expr->getLoc(),
KnownProtocolKind::ExpressibleByIntegerLiteral);
ProtocolDecl *builtinProtocol
= tc.getProtocol(expr->getLoc(),
KnownProtocolKind::ExpressibleByBuiltinIntegerLiteral);
ProtocolDecl *protocol = TypeChecker::getProtocol(
cs.getASTContext(), expr->getLoc(),
KnownProtocolKind::ExpressibleByIntegerLiteral);
ProtocolDecl *builtinProtocol = TypeChecker::getProtocol(
cs.getASTContext(), expr->getLoc(),
KnownProtocolKind::ExpressibleByBuiltinIntegerLiteral);

// For type-sugar reasons, prefer the spelling of the default literal
// type.
Expand All @@ -1851,9 +1851,9 @@ namespace {
if (defaultType->isEqual(type))
type = defaultType;
}
if (auto floatProtocol
= tc.getProtocol(expr->getLoc(),
KnownProtocolKind::ExpressibleByFloatLiteral)) {
if (auto floatProtocol = TypeChecker::getProtocol(
cs.getASTContext(), expr->getLoc(),
KnownProtocolKind::ExpressibleByFloatLiteral)) {
if (auto defaultFloatType = tc.getDefaultType(floatProtocol, dc)) {
if (defaultFloatType->isEqual(type))
type = defaultFloatType;
Expand Down Expand Up @@ -1888,8 +1888,9 @@ namespace {
}

auto &tc = cs.getTypeChecker();
auto *protocol = tc.getProtocol(expr->getLoc(),
KnownProtocolKind::ExpressibleByNilLiteral);
auto *protocol =
TypeChecker::getProtocol(cs.getASTContext(), expr->getLoc(),
KnownProtocolKind::ExpressibleByNilLiteral);

// For type-sugar reasons, prefer the spelling of the default literal
// type.
Expand Down Expand Up @@ -1920,12 +1921,12 @@ namespace {
return expr;

auto &tc = cs.getTypeChecker();
ProtocolDecl *protocol
= tc.getProtocol(expr->getLoc(),
KnownProtocolKind::ExpressibleByFloatLiteral);
ProtocolDecl *builtinProtocol
= tc.getProtocol(expr->getLoc(),
KnownProtocolKind::ExpressibleByBuiltinFloatLiteral);
ProtocolDecl *protocol = TypeChecker::getProtocol(
cs.getASTContext(), expr->getLoc(),
KnownProtocolKind::ExpressibleByFloatLiteral);
ProtocolDecl *builtinProtocol = TypeChecker::getProtocol(
cs.getASTContext(), expr->getLoc(),
KnownProtocolKind::ExpressibleByBuiltinFloatLiteral);

// For type-sugar reasons, prefer the spelling of the default literal
// type.
Expand Down Expand Up @@ -1964,12 +1965,12 @@ namespace {
return expr;

auto &tc = cs.getTypeChecker();
ProtocolDecl *protocol
= tc.getProtocol(expr->getLoc(),
KnownProtocolKind::ExpressibleByBooleanLiteral);
ProtocolDecl *builtinProtocol
= tc.getProtocol(expr->getLoc(),
KnownProtocolKind::ExpressibleByBuiltinBooleanLiteral);
ProtocolDecl *protocol = TypeChecker::getProtocol(
cs.getASTContext(), expr->getLoc(),
KnownProtocolKind::ExpressibleByBooleanLiteral);
ProtocolDecl *builtinProtocol = TypeChecker::getProtocol(
cs.getASTContext(), expr->getLoc(),
KnownProtocolKind::ExpressibleByBuiltinBooleanLiteral);
if (!protocol || !builtinProtocol)
return nullptr;

Expand Down Expand Up @@ -2001,24 +2002,25 @@ namespace {

bool isStringLiteral = true;
bool isGraphemeClusterLiteral = false;
ProtocolDecl *protocol = tc.getProtocol(
expr->getLoc(), KnownProtocolKind::ExpressibleByStringLiteral);
ProtocolDecl *protocol = TypeChecker::getProtocol(
cs.getASTContext(), expr->getLoc(),
KnownProtocolKind::ExpressibleByStringLiteral);

if (!TypeChecker::conformsToProtocol(
type, protocol, cs.DC, ConformanceCheckFlags::InExpression)) {
// If the type does not conform to ExpressibleByStringLiteral, it should
// be ExpressibleByExtendedGraphemeClusterLiteral.
protocol = tc.getProtocol(
expr->getLoc(),
protocol = TypeChecker::getProtocol(
cs.getASTContext(), expr->getLoc(),
KnownProtocolKind::ExpressibleByExtendedGraphemeClusterLiteral);
isStringLiteral = false;
isGraphemeClusterLiteral = true;
}
if (!TypeChecker::conformsToProtocol(
type, protocol, cs.DC, ConformanceCheckFlags::InExpression)) {
// ... or it should be ExpressibleByUnicodeScalarLiteral.
protocol = tc.getProtocol(
expr->getLoc(),
protocol = TypeChecker::getProtocol(
cs.getASTContext(), expr->getLoc(),
KnownProtocolKind::ExpressibleByUnicodeScalarLiteral);
isStringLiteral = false;
isGraphemeClusterLiteral = false;
Expand All @@ -2044,8 +2046,8 @@ namespace {
literalFuncName = DeclName(tc.Context, DeclBaseName::createConstructor(),
{ tc.Context.Id_stringLiteral });

builtinProtocol = tc.getProtocol(
expr->getLoc(),
builtinProtocol = TypeChecker::getProtocol(
cs.getASTContext(), expr->getLoc(),
KnownProtocolKind::ExpressibleByBuiltinStringLiteral);
builtinLiteralFuncName
= DeclName(tc.Context, DeclBaseName::createConstructor(),
Expand All @@ -2070,9 +2072,10 @@ namespace {
tc.Context.getIdentifier("utf8CodeUnitCount"),
tc.Context.getIdentifier("isASCII") });

builtinProtocol = tc.getProtocol(
expr->getLoc(),
KnownProtocolKind::ExpressibleByBuiltinExtendedGraphemeClusterLiteral);
builtinProtocol = TypeChecker::getProtocol(
cs.getASTContext(), expr->getLoc(),
KnownProtocolKind::
ExpressibleByBuiltinExtendedGraphemeClusterLiteral);
brokenProtocolDiag =
diag::extended_grapheme_cluster_literal_broken_proto;
brokenBuiltinProtocolDiag =
Expand All @@ -2088,8 +2091,8 @@ namespace {
= DeclName(tc.Context, DeclBaseName::createConstructor(),
{tc.Context.Id_builtinUnicodeScalarLiteral});

builtinProtocol = tc.getProtocol(
expr->getLoc(),
builtinProtocol = TypeChecker::getProtocol(
cs.getASTContext(), expr->getLoc(),
KnownProtocolKind::ExpressibleByBuiltinUnicodeScalarLiteral);

brokenProtocolDiag = diag::unicode_scalar_literal_broken_proto;
Expand Down Expand Up @@ -2125,10 +2128,10 @@ namespace {
auto loc = expr->getStartLoc();

auto fetchProtocolInitWitness =
[&](KnownProtocolKind protocolKind, Type type,
ArrayRef<Identifier> argLabels) -> ConcreteDeclRef {

auto proto = tc.getProtocol(loc, protocolKind);
[&](KnownProtocolKind protocolKind, Type type,
ArrayRef<Identifier> argLabels) -> ConcreteDeclRef {
auto proto =
TypeChecker::getProtocol(cs.getASTContext(), loc, protocolKind);
assert(proto && "Missing string interpolation protocol?");

auto conformance =
Expand All @@ -2145,9 +2148,9 @@ namespace {
return witness;
};

auto *interpolationProto =
tc.getProtocol(expr->getLoc(),
KnownProtocolKind::ExpressibleByStringInterpolation);
auto *interpolationProto = TypeChecker::getProtocol(
cs.getASTContext(), expr->getLoc(),
KnownProtocolKind::ExpressibleByStringInterpolation);
auto associatedTypeDecl = interpolationProto->getAssociatedType(
tc.Context.Id_StringInterpolation);
if (associatedTypeDecl == nullptr) {
Expand Down Expand Up @@ -2235,7 +2238,7 @@ namespace {
}

// Find the appropriate object literal protocol.
auto proto = tc.getLiteralProtocol(expr);
auto proto = TypeChecker::getLiteralProtocol(cs.getASTContext(), expr);
assert(proto && "Missing object literal protocol?");
auto conformance =
TypeChecker::conformsToProtocol(conformingType, proto, cs.DC,
Expand Down Expand Up @@ -2494,10 +2497,9 @@ namespace {
auto baseTyNominalDecl = baseTyUnwrapped
->getNominalOrBoundGenericNominal();
auto &tc = cs.getTypeChecker();
auto results = tc.lookupMember(baseTyNominalDecl->getModuleContext(),
baseTyUnwrapped,
memberName,
defaultMemberLookupOptions);
auto results = TypeChecker::lookupMember(
baseTyNominalDecl->getModuleContext(), baseTyUnwrapped,
memberName, defaultMemberLookupOptions);

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

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

auto conformance =
Expand Down Expand Up @@ -2938,9 +2940,9 @@ namespace {
Type dictionaryTy = cs.getType(expr);

auto &tc = cs.getTypeChecker();
ProtocolDecl *dictionaryProto
= tc.getProtocol(expr->getLoc(),
KnownProtocolKind::ExpressibleByDictionaryLiteral);
ProtocolDecl *dictionaryProto = TypeChecker::getProtocol(
cs.getASTContext(), expr->getLoc(),
KnownProtocolKind::ExpressibleByDictionaryLiteral);

auto conformance =
TypeChecker::conformsToProtocol(dictionaryTy, dictionaryProto, cs.DC,
Expand Down Expand Up @@ -4585,7 +4587,7 @@ namespace {
auto dc = subscript->getInnermostDeclContext();

auto indexType = AnyFunctionType::composeInput(
cs.TC.Context,
cs.getASTContext(),
subscript->getInterfaceType()->castTo<AnyFunctionType>()->getParams(),
/*canonicalVararg=*/false);

Expand Down Expand Up @@ -6773,8 +6775,8 @@ ExprRewriter::finishApplyDynamicCallable(ApplyExpr *apply,
auto dictLitProto =
ctx.getProtocol(KnownProtocolKind::ExpressibleByDictionaryLiteral);
auto conformance =
cs.TC.conformsToProtocol(argumentType, dictLitProto, cs.DC,
ConformanceCheckFlags::InExpression);
TypeChecker::conformsToProtocol(argumentType, dictLitProto, cs.DC,
ConformanceCheckFlags::InExpression);
auto keyType = conformance.getTypeWitnessByName(argumentType, ctx.Id_Key);
auto valueType =
conformance.getTypeWitnessByName(argumentType, ctx.Id_Value);
Expand Down Expand Up @@ -6827,7 +6829,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, ConcreteDeclRef callee,
= [&](ApplyExpr *apply,
ConcreteDeclRef declRef,
Type openedType) -> Expr* {
switch (cs.TC.getDeclTypeCheckingSemantics(declRef.getDecl())) {
switch (TypeChecker::getDeclTypeCheckingSemantics(declRef.getDecl())) {
case DeclTypeCheckingSemantics::TypeOf: {
// Resolve into a DynamicTypeExpr.
auto arg = apply->getArg();
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/CSBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ ConstraintSystem::determineBestBindings() {
}
}

if (TC.getLangOpts().DebugConstraintSolver) {
if (getASTContext().LangOpts.DebugConstraintSolver) {
auto &log = getASTContext().TypeCheckerDebug->getStream();
bindings.dump(typeVar, log, solverState->depth * 2);
}
Expand Down
24 changes: 15 additions & 9 deletions lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,9 @@ bool FailureDiagnosis::diagnoseGeneralConversionFailure(Constraint *constraint){
// tries to add a specific diagnosis/fixit to explicitly invoke 'boolValue'.
if (toType->isBool() &&
fromType->mayHaveMembers()) {
auto LookupResult = CS.TC.lookupMember(
CS.DC, fromType, DeclName(CS.TC.Context.getIdentifier("boolValue")));
auto LookupResult = TypeChecker::lookupMember(
CS.DC, fromType,
DeclName(CS.getASTContext().getIdentifier("boolValue")));
if (!LookupResult.empty()) {
if (isa<VarDecl>(LookupResult.begin()->getValueDecl())) {
if (anchor->canAppendPostfixExpression())
Expand Down Expand Up @@ -1740,7 +1741,8 @@ static void emitFixItForExplicitlyQualifiedReference(

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

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

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

auto DLC = CS.TC.getProtocol(
E->getLoc(), KnownProtocolKind::ExpressibleByDictionaryLiteral);
auto DLC = TypeChecker::getProtocol(
CS.getASTContext(), E->getLoc(),
KnownProtocolKind::ExpressibleByDictionaryLiteral);
if (!DLC) return visitExpr(E);

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

// Type check the argument first.
auto protocol = TC.getLiteralProtocol(E);
auto protocol = TypeChecker::getLiteralProtocol(CS.getASTContext(), E);
if (!protocol)
return false;
DeclName constrName = TC.getObjectLiteralConstructorName(E);
Expand Down Expand Up @@ -4151,7 +4156,8 @@ bool FailureDiagnosis::diagnoseMemberFailures(

// Since the lookup was allowing inaccessible members, let's check
// if it found anything of that sort, which is easy to diagnose.
bool allUnavailable = !CS.TC.getLangOpts().DisableAvailabilityChecking;
bool allUnavailable =
!CS.getASTContext().LangOpts.DisableAvailabilityChecking;
bool allInaccessible = true;
for (auto &member : viableCandidatesToReport) {
if (!member.isDecl()) {
Expand Down
6 changes: 2 additions & 4 deletions lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2613,10 +2613,8 @@ bool ContextualFailure::tryProtocolConformanceFixIt(
// Let's build a list of protocols that the context does not conform to.
SmallVector<std::string, 8> missingProtoTypeStrings;
for (auto protocol : layout.getProtocols()) {
if (getTypeChecker()
.conformsToProtocol(FromType, protocol->getDecl(), getDC(),
ConformanceCheckFlags::InExpression)
.isInvalid()) {
if (!TypeChecker::conformsToProtocol(FromType, protocol->getDecl(), getDC(),
ConformanceCheckFlags::InExpression)) {
missingProtoTypeStrings.push_back(protocol->getString());
}
}
Expand Down
Loading