Skip to content

Commit a73c1f4

Browse files
authored
Merge pull request #28030 from CodaFi/unit-normals
[NFC] Plot The Demise of LazyResolver
2 parents e45574e + a29bfb4 commit a73c1f4

File tree

8 files changed

+45
-56
lines changed

8 files changed

+45
-56
lines changed

include/swift/AST/LazyResolver.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ class LazyResolver {
5353
virtual void resolveWitness(const NormalProtocolConformance *conformance,
5454
ValueDecl *requirement) = 0;
5555

56-
/// Resolve any implicitly-declared constructors within the given nominal.
57-
virtual void resolveImplicitConstructors(NominalTypeDecl *nominal) = 0;
58-
5956
/// Resolve an implicitly-generated member with the given name.
6057
virtual void resolveImplicitMember(NominalTypeDecl *nominal, DeclName member) = 0;
6158
};

lib/AST/NameLookup.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,9 +1572,6 @@ bool DeclContext::lookupQualified(ArrayRef<NominalTypeDecl *> typeDecls,
15721572

15731573
// Make sure we've resolved implicit members, if we need them.
15741574
if (typeResolver) {
1575-
if (member.getBaseName() == DeclBaseName::createConstructor())
1576-
typeResolver->resolveImplicitConstructors(current);
1577-
15781575
typeResolver->resolveImplicitMember(current, member);
15791576
}
15801577

lib/Sema/CodeSynthesis.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,9 @@ void TypeChecker::synthesizeMemberForLookup(NominalTypeDecl *target,
10771077
DeclName member) {
10781078
auto baseName = member.getBaseName();
10791079

1080+
if (baseName == DeclBaseName::createConstructor())
1081+
addImplicitConstructors(target);
1082+
10801083
// Checks whether the target conforms to the given protocol. If the
10811084
// conformance is incomplete, force the conformance.
10821085
//
@@ -1097,7 +1100,7 @@ void TypeChecker::synthesizeMemberForLookup(NominalTypeDecl *target,
10971100
if (auto *conformance = dyn_cast<NormalProtocolConformance>(
10981101
ref.getConcrete()->getRootConformance())) {
10991102
if (conformance->getState() == ProtocolConformanceState::Incomplete) {
1100-
checkConformance(conformance);
1103+
TypeChecker::checkConformance(conformance);
11011104
}
11021105
}
11031106

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,7 @@ static EnumDecl *synthesizeCodingKeysEnum(DerivedConformance &derived) {
370370
return nullptr;
371371

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

378375
// Add to the type.
379376
target->addMember(enumDecl);

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4450,9 +4450,6 @@ EmittedMembersRequest::evaluate(Evaluator &evaluator,
44504450

44514451
auto &Context = CD->getASTContext();
44524452

4453-
// FIXME: Remove TypeChecker dependencies below
4454-
auto &TC = *(TypeChecker *) Context.getLazyResolver();
4455-
44564453
// We need to add implicit initializers because they
44574454
// affect vtable layout.
44584455
TypeChecker::addImplicitConstructors(CD);
@@ -4469,7 +4466,7 @@ EmittedMembersRequest::evaluate(Evaluator &evaluator,
44694466
auto conformance = ref.getConcrete();
44704467
if (conformance->getDeclContext() == CD &&
44714468
conformance->getState() == ProtocolConformanceState::Incomplete) {
4472-
TC.checkConformance(conformance->getRootNormalConformance());
4469+
TypeChecker::checkConformance(conformance->getRootNormalConformance());
44734470
}
44744471
};
44754472

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -981,8 +981,9 @@ bool WitnessChecker::findBestWitness(
981981
bool anyFromUnconstrainedExtension;
982982
numViable = 0;
983983

984-
// FIXME: Remove dependnecy on the lazy resolver.
985-
auto *TC = static_cast<TypeChecker *>(getASTContext().getLazyResolver());
984+
// FIXME: Remove dependency on the lazy resolver.
985+
auto *TC = static_cast<TypeChecker *>(
986+
requirement->getASTContext().getLazyResolver());
986987
for (Attempt attempt = Regular; numViable == 0 && attempt != Done;
987988
attempt = static_cast<Attempt>(attempt + 1)) {
988989
SmallVector<ValueDecl *, 4> witnesses;
@@ -1265,7 +1266,7 @@ RequirementCheck WitnessChecker::checkWitness(ValueDecl *requirement,
12651266
/// having this wrapper can help issue a fixit that inserts protocol stubs from
12661267
/// multiple protocols under checking.
12671268
class swift::MultiConformanceChecker {
1268-
TypeChecker &TC;
1269+
ASTContext &Context;
12691270
llvm::SmallVector<ValueDecl*, 16> UnsatisfiedReqs;
12701271
llvm::SmallVector<ConformanceChecker, 4> AllUsedCheckers;
12711272
llvm::SmallVector<NormalProtocolConformance*, 4> AllConformances;
@@ -1279,9 +1280,9 @@ class swift::MultiConformanceChecker {
12791280
/// Determine whether the given requirement was left unsatisfied.
12801281
bool isUnsatisfiedReq(NormalProtocolConformance *conformance, ValueDecl *req);
12811282
public:
1282-
MultiConformanceChecker(TypeChecker &TC): TC(TC){}
1283+
MultiConformanceChecker(ASTContext &ctx) : Context(ctx) {}
12831284

1284-
ASTContext &getASTContext() const { return TC.Context; }
1285+
ASTContext &getASTContext() const { return Context; }
12851286

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

42234224
void TypeChecker::checkConformance(NormalProtocolConformance *conformance) {
4224-
MultiConformanceChecker checker(*this);
4225+
MultiConformanceChecker checker(conformance->getProtocol()->getASTContext());
42254226
checker.addConformance(conformance);
42264227
checker.checkAllConformances();
42274228
}
@@ -4522,10 +4523,8 @@ static bool shouldWarnAboutPotentialWitness(
45224523
}
45234524

45244525
/// Diagnose a potential witness.
4525-
static void diagnosePotentialWitness(TypeChecker &tc,
4526-
NormalProtocolConformance *conformance,
4527-
ValueDecl *req,
4528-
ValueDecl *witness,
4526+
static void diagnosePotentialWitness(NormalProtocolConformance *conformance,
4527+
ValueDecl *req, ValueDecl *witness,
45294528
AccessLevel access) {
45304529
auto proto = cast<ProtocolDecl>(req->getDeclContext());
45314530

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

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

48244826
bool anyInvalid = false;
48254827
for (auto conformance : conformances) {
@@ -4899,11 +4901,11 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
48994901
auto diagID = differentlyConditional
49004902
? diag::redundant_conformance_adhoc_conditional
49014903
: diag::redundant_conformance_adhoc;
4902-
diagnose(diag.Loc, diagID, dc->getDeclaredInterfaceType(),
4903-
diag.Protocol->getName(),
4904-
existingModule->getName() ==
4905-
extendedNominal->getParentModule()->getName(),
4906-
existingModule->getName());
4904+
Context.Diags.diagnose(diag.Loc, diagID, dc->getDeclaredInterfaceType(),
4905+
diag.Protocol->getName(),
4906+
existingModule->getName() ==
4907+
extendedNominal->getParentModule()->getName(),
4908+
existingModule->getName());
49074909

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

4931-
diagnose(value, diag::redundant_conformance_witness_ignored,
4932-
value->getDescriptiveKind(), value->getFullName(),
4933-
diag.Protocol->getFullName());
4933+
value->diagnose(diag::redundant_conformance_witness_ignored,
4934+
value->getDescriptiveKind(), value->getFullName(),
4935+
diag.Protocol->getFullName());
49344936
break;
49354937
}
49364938
}
49374939
} else {
49384940
auto diagID = differentlyConditional
49394941
? diag::redundant_conformance_conditional
49404942
: diag::redundant_conformance;
4941-
diagnose(diag.Loc, diagID, dc->getDeclaredInterfaceType(),
4942-
diag.Protocol->getName());
4943+
Context.Diags.diagnose(diag.Loc, diagID, dc->getDeclaredInterfaceType(),
4944+
diag.Protocol->getName());
49434945
}
49444946

49454947
// Special case: explain that 'RawRepresentable' conformance
@@ -4951,18 +4953,19 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
49514953
diag.Protocol) &&
49524954
enumDecl->hasRawType() &&
49534955
enumDecl->getInherited()[0].getSourceRange().isValid()) {
4954-
diagnose(enumDecl->getInherited()[0].getSourceRange().Start,
4955-
diag::enum_declares_rawrep_with_raw_type,
4956-
dc->getDeclaredInterfaceType(), enumDecl->getRawType());
4956+
auto inheritedLoc = enumDecl->getInherited()[0].getSourceRange().Start;
4957+
Context.Diags.diagnose(
4958+
inheritedLoc, diag::enum_declares_rawrep_with_raw_type,
4959+
dc->getDeclaredInterfaceType(), enumDecl->getRawType());
49574960
continue;
49584961
}
49594962
}
49604963

4961-
diagnose(existingDecl, diag::declared_protocol_conformance_here,
4962-
dc->getDeclaredInterfaceType(),
4963-
static_cast<unsigned>(diag.ExistingKind),
4964-
diag.Protocol->getName(),
4965-
diag.ExistingExplicitProtocol->getName());
4964+
existingDecl->diagnose(diag::declared_protocol_conformance_here,
4965+
dc->getDeclaredInterfaceType(),
4966+
static_cast<unsigned>(diag.ExistingKind),
4967+
diag.Protocol->getName(),
4968+
diag.ExistingExplicitProtocol->getName());
49664969
}
49674970

49684971
// If there were any unsatisfied requirements, check whether there
@@ -5034,8 +5037,7 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
50345037
bool diagnosed = false;
50355038
for (auto conformance : conformances) {
50365039
if (conformance->getProtocol() == req->getDeclContext()) {
5037-
diagnosePotentialWitness(*this,
5038-
conformance->getRootNormalConformance(),
5040+
diagnosePotentialWitness(conformance->getRootNormalConformance(),
50395041
req, value, defaultAccess);
50405042
diagnosed = true;
50415043
break;

lib/Sema/TypeChecker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@ static void typeCheckFunctionsAndExternalDecls(SourceFile &SF, TypeChecker &TC)
293293
for (unsigned i = 0; i != TC.ConformanceContexts.size(); ++i) {
294294
auto decl = TC.ConformanceContexts[i];
295295
if (auto *ext = dyn_cast<ExtensionDecl>(decl))
296-
TC.checkConformancesInContext(ext, ext);
296+
TypeChecker::checkConformancesInContext(ext, ext);
297297
else {
298298
auto *ntd = cast<NominalTypeDecl>(decl);
299-
TC.checkConformancesInContext(ntd, ntd);
299+
TypeChecker::checkConformancesInContext(ntd, ntd);
300300

301301
// Finally, we can check classes for missing initializers.
302302
if (auto *classDecl = dyn_cast<ClassDecl>(ntd))

lib/Sema/TypeChecker.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,10 +1015,6 @@ class TypeChecker final : public LazyResolver {
10151015
static Type checkReferenceOwnershipAttr(VarDecl *D, Type interfaceType,
10161016
ReferenceOwnershipAttr *attr);
10171017

1018-
virtual void resolveImplicitConstructors(NominalTypeDecl *nominal) override {
1019-
addImplicitConstructors(nominal);
1020-
}
1021-
10221018
virtual void resolveImplicitMember(NominalTypeDecl *nominal, DeclName member) override {
10231019
synthesizeMemberForLookup(nominal, member);
10241020
}
@@ -1524,11 +1520,11 @@ class TypeChecker final : public LazyResolver {
15241520
};
15251521

15261522
/// Completely check the given conformance.
1527-
void checkConformance(NormalProtocolConformance *conformance);
1523+
static void checkConformance(NormalProtocolConformance *conformance);
15281524

15291525
/// Check all of the conformances in the given context.
1530-
void checkConformancesInContext(DeclContext *dc,
1531-
IterableDeclContext *idc);
1526+
static void checkConformancesInContext(DeclContext *dc,
1527+
IterableDeclContext *idc);
15321528

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

0 commit comments

Comments
 (0)