Skip to content

[NFC] Plot The Demise of LazyResolver #28030

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 2 commits into from
Nov 2, 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
3 changes: 0 additions & 3 deletions include/swift/AST/LazyResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ class LazyResolver {
virtual void resolveWitness(const NormalProtocolConformance *conformance,
ValueDecl *requirement) = 0;

/// Resolve any implicitly-declared constructors within the given nominal.
virtual void resolveImplicitConstructors(NominalTypeDecl *nominal) = 0;

/// Resolve an implicitly-generated member with the given name.
virtual void resolveImplicitMember(NominalTypeDecl *nominal, DeclName member) = 0;
};
Expand Down
3 changes: 0 additions & 3 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1572,9 +1572,6 @@ bool DeclContext::lookupQualified(ArrayRef<NominalTypeDecl *> typeDecls,

// Make sure we've resolved implicit members, if we need them.
if (typeResolver) {
if (member.getBaseName() == DeclBaseName::createConstructor())
typeResolver->resolveImplicitConstructors(current);

typeResolver->resolveImplicitMember(current, member);
}

Expand Down
5 changes: 4 additions & 1 deletion lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,9 @@ void TypeChecker::synthesizeMemberForLookup(NominalTypeDecl *target,
DeclName member) {
auto baseName = member.getBaseName();

if (baseName == DeclBaseName::createConstructor())
addImplicitConstructors(target);

// Checks whether the target conforms to the given protocol. If the
// conformance is incomplete, force the conformance.
//
Expand All @@ -1097,7 +1100,7 @@ void TypeChecker::synthesizeMemberForLookup(NominalTypeDecl *target,
if (auto *conformance = dyn_cast<NormalProtocolConformance>(
ref.getConcrete()->getRootConformance())) {
if (conformance->getState() == ProtocolConformanceState::Incomplete) {
checkConformance(conformance);
TypeChecker::checkConformance(conformance);
}
}

Expand Down
5 changes: 1 addition & 4 deletions lib/Sema/DerivedConformanceCodable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,7 @@ static EnumDecl *synthesizeCodingKeysEnum(DerivedConformance &derived) {
return nullptr;

// Forcibly derive conformance to CodingKey.
//
// FIXME: Drop the dependency on the type checker.
auto *tc = static_cast<TypeChecker *>(C.getLazyResolver());
tc->checkConformancesInContext(enumDecl, enumDecl);
TypeChecker::checkConformancesInContext(enumDecl, enumDecl);

// Add to the type.
target->addMember(enumDecl);
Expand Down
5 changes: 1 addition & 4 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4450,9 +4450,6 @@ EmittedMembersRequest::evaluate(Evaluator &evaluator,

auto &Context = CD->getASTContext();

// FIXME: Remove TypeChecker dependencies below
auto &TC = *(TypeChecker *) Context.getLazyResolver();

// We need to add implicit initializers because they
// affect vtable layout.
TypeChecker::addImplicitConstructors(CD);
Expand All @@ -4469,7 +4466,7 @@ EmittedMembersRequest::evaluate(Evaluator &evaluator,
auto conformance = ref.getConcrete();
if (conformance->getDeclContext() == CD &&
conformance->getState() == ProtocolConformanceState::Incomplete) {
TC.checkConformance(conformance->getRootNormalConformance());
TypeChecker::checkConformance(conformance->getRootNormalConformance());
}
};

Expand Down
66 changes: 34 additions & 32 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,8 +981,9 @@ bool WitnessChecker::findBestWitness(
bool anyFromUnconstrainedExtension;
numViable = 0;

// FIXME: Remove dependnecy on the lazy resolver.
auto *TC = static_cast<TypeChecker *>(getASTContext().getLazyResolver());
// FIXME: Remove dependency on the lazy resolver.
auto *TC = static_cast<TypeChecker *>(
requirement->getASTContext().getLazyResolver());
for (Attempt attempt = Regular; numViable == 0 && attempt != Done;
attempt = static_cast<Attempt>(attempt + 1)) {
SmallVector<ValueDecl *, 4> witnesses;
Expand Down Expand Up @@ -1265,7 +1266,7 @@ RequirementCheck WitnessChecker::checkWitness(ValueDecl *requirement,
/// having this wrapper can help issue a fixit that inserts protocol stubs from
/// multiple protocols under checking.
class swift::MultiConformanceChecker {
TypeChecker &TC;
ASTContext &Context;
llvm::SmallVector<ValueDecl*, 16> UnsatisfiedReqs;
llvm::SmallVector<ConformanceChecker, 4> AllUsedCheckers;
llvm::SmallVector<NormalProtocolConformance*, 4> AllConformances;
Expand All @@ -1279,9 +1280,9 @@ class swift::MultiConformanceChecker {
/// Determine whether the given requirement was left unsatisfied.
bool isUnsatisfiedReq(NormalProtocolConformance *conformance, ValueDecl *req);
public:
MultiConformanceChecker(TypeChecker &TC): TC(TC){}
MultiConformanceChecker(ASTContext &ctx) : Context(ctx) {}

ASTContext &getASTContext() const { return TC.Context; }
ASTContext &getASTContext() const { return Context; }

/// Add a conformance into the batched checker.
void addConformance(NormalProtocolConformance *conformance) {
Expand Down Expand Up @@ -4221,7 +4222,7 @@ operator()(CanType dependentType, Type conformingReplacementType,
}

void TypeChecker::checkConformance(NormalProtocolConformance *conformance) {
MultiConformanceChecker checker(*this);
MultiConformanceChecker checker(conformance->getProtocol()->getASTContext());
checker.addConformance(conformance);
checker.checkAllConformances();
}
Expand Down Expand Up @@ -4522,10 +4523,8 @@ static bool shouldWarnAboutPotentialWitness(
}

/// Diagnose a potential witness.
static void diagnosePotentialWitness(TypeChecker &tc,
NormalProtocolConformance *conformance,
ValueDecl *req,
ValueDecl *witness,
static void diagnosePotentialWitness(NormalProtocolConformance *conformance,
ValueDecl *req, ValueDecl *witness,
AccessLevel access) {
auto proto = cast<ProtocolDecl>(req->getDeclContext());

Expand All @@ -4538,7 +4537,9 @@ static void diagnosePotentialWitness(TypeChecker &tc,
// Describe why the witness didn't satisfy the requirement.
WitnessChecker::RequirementEnvironmentCache oneUseCache;
auto dc = conformance->getDeclContext();
auto match = matchWitness(tc, oneUseCache, conformance->getProtocol(),
// FIXME: Remove dependency on the lazy resolver.
auto *TC = static_cast<TypeChecker *>(req->getASTContext().getLazyResolver());
auto match = matchWitness(*TC, oneUseCache, conformance->getProtocol(),
conformance, dc, req, witness);
if (match.Kind == MatchKind::ExactMatch &&
req->isObjC() && !witness->isObjC()) {
Expand Down Expand Up @@ -4819,7 +4820,8 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
&diagnostics);

// The conformance checker bundle that checks all conformances in the context.
MultiConformanceChecker groupChecker(*this);
auto &Context = dc->getASTContext();
MultiConformanceChecker groupChecker(Context);

bool anyInvalid = false;
for (auto conformance : conformances) {
Expand Down Expand Up @@ -4899,11 +4901,11 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
auto diagID = differentlyConditional
? diag::redundant_conformance_adhoc_conditional
: diag::redundant_conformance_adhoc;
diagnose(diag.Loc, diagID, dc->getDeclaredInterfaceType(),
diag.Protocol->getName(),
existingModule->getName() ==
extendedNominal->getParentModule()->getName(),
existingModule->getName());
Context.Diags.diagnose(diag.Loc, diagID, dc->getDeclaredInterfaceType(),
diag.Protocol->getName(),
existingModule->getName() ==
extendedNominal->getParentModule()->getName(),
existingModule->getName());

// Complain about any declarations in this extension whose names match
// a requirement in that protocol.
Expand All @@ -4928,18 +4930,18 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
if (valueIsType != requirementIsType)
continue;

diagnose(value, diag::redundant_conformance_witness_ignored,
value->getDescriptiveKind(), value->getFullName(),
diag.Protocol->getFullName());
value->diagnose(diag::redundant_conformance_witness_ignored,
value->getDescriptiveKind(), value->getFullName(),
diag.Protocol->getFullName());
break;
}
}
} else {
auto diagID = differentlyConditional
? diag::redundant_conformance_conditional
: diag::redundant_conformance;
diagnose(diag.Loc, diagID, dc->getDeclaredInterfaceType(),
diag.Protocol->getName());
Context.Diags.diagnose(diag.Loc, diagID, dc->getDeclaredInterfaceType(),
diag.Protocol->getName());
}

// Special case: explain that 'RawRepresentable' conformance
Expand All @@ -4951,18 +4953,19 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
diag.Protocol) &&
enumDecl->hasRawType() &&
enumDecl->getInherited()[0].getSourceRange().isValid()) {
diagnose(enumDecl->getInherited()[0].getSourceRange().Start,
diag::enum_declares_rawrep_with_raw_type,
dc->getDeclaredInterfaceType(), enumDecl->getRawType());
auto inheritedLoc = enumDecl->getInherited()[0].getSourceRange().Start;
Context.Diags.diagnose(
inheritedLoc, diag::enum_declares_rawrep_with_raw_type,
dc->getDeclaredInterfaceType(), enumDecl->getRawType());
continue;
}
}

diagnose(existingDecl, diag::declared_protocol_conformance_here,
dc->getDeclaredInterfaceType(),
static_cast<unsigned>(diag.ExistingKind),
diag.Protocol->getName(),
diag.ExistingExplicitProtocol->getName());
existingDecl->diagnose(diag::declared_protocol_conformance_here,
dc->getDeclaredInterfaceType(),
static_cast<unsigned>(diag.ExistingKind),
diag.Protocol->getName(),
diag.ExistingExplicitProtocol->getName());
}

// If there were any unsatisfied requirements, check whether there
Expand Down Expand Up @@ -5034,8 +5037,7 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
bool diagnosed = false;
for (auto conformance : conformances) {
if (conformance->getProtocol() == req->getDeclContext()) {
diagnosePotentialWitness(*this,
conformance->getRootNormalConformance(),
diagnosePotentialWitness(conformance->getRootNormalConformance(),
req, value, defaultAccess);
diagnosed = true;
break;
Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@ static void typeCheckFunctionsAndExternalDecls(SourceFile &SF, TypeChecker &TC)
for (unsigned i = 0; i != TC.ConformanceContexts.size(); ++i) {
auto decl = TC.ConformanceContexts[i];
if (auto *ext = dyn_cast<ExtensionDecl>(decl))
TC.checkConformancesInContext(ext, ext);
TypeChecker::checkConformancesInContext(ext, ext);
else {
auto *ntd = cast<NominalTypeDecl>(decl);
TC.checkConformancesInContext(ntd, ntd);
TypeChecker::checkConformancesInContext(ntd, ntd);

// Finally, we can check classes for missing initializers.
if (auto *classDecl = dyn_cast<ClassDecl>(ntd))
Expand Down
10 changes: 3 additions & 7 deletions lib/Sema/TypeChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -1015,10 +1015,6 @@ class TypeChecker final : public LazyResolver {
static Type checkReferenceOwnershipAttr(VarDecl *D, Type interfaceType,
ReferenceOwnershipAttr *attr);

virtual void resolveImplicitConstructors(NominalTypeDecl *nominal) override {
addImplicitConstructors(nominal);
}

virtual void resolveImplicitMember(NominalTypeDecl *nominal, DeclName member) override {
synthesizeMemberForLookup(nominal, member);
}
Expand Down Expand Up @@ -1524,11 +1520,11 @@ class TypeChecker final : public LazyResolver {
};

/// Completely check the given conformance.
void checkConformance(NormalProtocolConformance *conformance);
static void checkConformance(NormalProtocolConformance *conformance);

/// Check all of the conformances in the given context.
void checkConformancesInContext(DeclContext *dc,
IterableDeclContext *idc);
static void checkConformancesInContext(DeclContext *dc,
IterableDeclContext *idc);

/// Check that the type of the given property conforms to NSCopying.
static ProtocolConformanceRef checkConformanceToNSCopying(VarDecl *var);
Expand Down