Skip to content

Commit 392071e

Browse files
committed
Sema: Peel off more code from the TypeChecker instance
1 parent ad230a0 commit 392071e

File tree

6 files changed

+33
-38
lines changed

6 files changed

+33
-38
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4090,7 +4090,7 @@ namespace {
40904090
method = func;
40914091
} else if (auto var = dyn_cast<VarDecl>(foundDecl)) {
40924092
// Properties.
4093-
maybeAddAccessorsToStorage(tc, var);
4093+
maybeAddAccessorsToStorage(var);
40944094

40954095
// If this isn't a property on a type, complain.
40964096
if (!var->getDeclContext()->isTypeContext()) {

lib/Sema/CodeSynthesis.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,8 @@ static bool checkConformanceToNSCopying(ASTContext &ctx, VarDecl *var,
620620
auto dc = var->getDeclContext();
621621
auto proto = getNSCopyingProtocol(ctx, dc);
622622

623-
// FIXME: Remove this usage of TypeChecker
624-
auto &TC = *(TypeChecker *) ctx.getLazyResolver();
625-
if (!proto || !TC.conformsToProtocol(type, proto, dc, None)) {
626-
TC.diagnose(var->getLoc(), diag::nscopying_doesnt_conform);
623+
if (!proto || !TypeChecker::conformsToProtocol(type, proto, dc, None)) {
624+
ctx.Diags.diagnose(var->getLoc(), diag::nscopying_doesnt_conform);
627625
return true;
628626
}
629627
return false;
@@ -1337,7 +1335,9 @@ static void synthesizeLazySetterBody(AbstractFunctionDecl *fn, void *context) {
13371335
underlyingStorage, ctx);
13381336
}
13391337

1340-
void TypeChecker::completeLazyVarImplementation(VarDecl *VD) {
1338+
void swift::completeLazyVarImplementation(VarDecl *VD) {
1339+
auto &Context = VD->getASTContext();
1340+
13411341
assert(VD->getAttrs().hasAttribute<LazyAttr>());
13421342
assert(VD->getReadImpl() == ReadImplKind::Get);
13431343
assert(VD->getWriteImpl() == WriteImplKind::Set);
@@ -1406,13 +1406,13 @@ static bool wouldBeCircularSynthesis(AbstractStorageDecl *storage,
14061406
void swift::triggerAccessorSynthesis(TypeChecker &TC,
14071407
AbstractStorageDecl *storage) {
14081408
auto VD = dyn_cast<VarDecl>(storage);
1409-
maybeAddAccessorsToStorage(TC, storage);
1409+
maybeAddAccessorsToStorage(storage);
14101410

14111411
// Synthesize accessors for lazy, all checking already been performed.
14121412
bool lazy = false;
14131413
if (VD && VD->getAttrs().hasAttribute<LazyAttr>() && !VD->isStatic() &&
14141414
!VD->getGetter()->hasBody()) {
1415-
TC.completeLazyVarImplementation(VD);
1415+
completeLazyVarImplementation(VD);
14161416
lazy = true;
14171417
}
14181418

@@ -1466,11 +1466,12 @@ static void maybeAddAccessorsToLazyVariable(VarDecl *var, ASTContext &ctx) {
14661466
/// Note that the parser synthesizes accessors in some cases:
14671467
/// - it synthesizes a getter and setter for an observing property
14681468
/// - it synthesizes a setter for get+mutableAddress
1469-
void swift::maybeAddAccessorsToStorage(TypeChecker &TC,
1470-
AbstractStorageDecl *storage) {
1469+
void swift::maybeAddAccessorsToStorage(AbstractStorageDecl *storage) {
1470+
auto &ctx = storage->getASTContext();
1471+
14711472
// Lazy properties require special handling.
14721473
if (storage->getAttrs().hasAttribute<LazyAttr>()) {
1473-
maybeAddAccessorsToLazyVariable(cast<VarDecl>(storage), TC.Context);
1474+
maybeAddAccessorsToLazyVariable(cast<VarDecl>(storage), ctx);
14741475
return;
14751476
}
14761477

@@ -1487,7 +1488,7 @@ void swift::maybeAddAccessorsToStorage(TypeChecker &TC,
14871488
if (!dc->isTypeContext()) {
14881489
// dynamic globals need accessors.
14891490
if (dc->isModuleScopeContext() && storage->isNativeDynamic()) {
1490-
addTrivialAccessorsToStorage(storage, TC.Context);
1491+
addTrivialAccessorsToStorage(storage, ctx);
14911492
return;
14921493
}
14931494
// Fixed-layout global variables don't get accessors.
@@ -1502,12 +1503,13 @@ void swift::maybeAddAccessorsToStorage(TypeChecker &TC,
15021503
auto var = cast<VarDecl>(storage);
15031504

15041505
if (var->isLet()) {
1505-
TC.diagnose(var->getLoc(),
1506-
diag::protocol_property_must_be_computed_var)
1506+
ctx.Diags.diagnose(var->getLoc(),
1507+
diag::protocol_property_must_be_computed_var)
15071508
.fixItReplace(var->getParentPatternBinding()->getLoc(), "var")
15081509
.fixItInsertAfter(var->getTypeLoc().getLoc(), " { get }");
15091510
} else {
1510-
auto diag = TC.diagnose(var->getLoc(), diag::protocol_property_must_be_computed);
1511+
auto diag = ctx.Diags.diagnose(var->getLoc(),
1512+
diag::protocol_property_must_be_computed);
15111513
auto braces = var->getBracesRange();
15121514

15131515
if (braces.isValid())
@@ -1517,14 +1519,14 @@ void swift::maybeAddAccessorsToStorage(TypeChecker &TC,
15171519
}
15181520
}
15191521

1520-
setProtocolStorageImpl(storage, TC.Context);
1522+
setProtocolStorageImpl(storage, ctx);
15211523
return;
15221524

15231525
// NSManaged properties on classes require special handling.
15241526
} else if (dc->getSelfClassDecl()) {
15251527
auto var = dyn_cast<VarDecl>(storage);
15261528
if (var && var->getAttrs().hasAttribute<NSManagedAttr>()) {
1527-
convertNSManagedStoredVarToComputed(var, TC.Context);
1529+
convertNSManagedStoredVarToComputed(var, ctx);
15281530
return;
15291531
}
15301532

@@ -1539,13 +1541,13 @@ void swift::maybeAddAccessorsToStorage(TypeChecker &TC,
15391541
if (auto sourceFile = dc->getParentSourceFile())
15401542
if (sourceFile->Kind == SourceFileKind::SIL) {
15411543
if (storage->getGetter()) {
1542-
addExpectedOpaqueAccessorsToStorage(storage, TC.Context);
1544+
addExpectedOpaqueAccessorsToStorage(storage, ctx);
15431545
}
15441546
return;
15451547
}
15461548

15471549
// Everything else gets mandatory accessors.
1548-
addTrivialAccessorsToStorage(storage, TC.Context);
1550+
addTrivialAccessorsToStorage(storage, ctx);
15491551
}
15501552

15511553
static void synthesizeGetterBody(AccessorDecl *getter,

lib/Sema/CodeSynthesis.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ void makeFinal(ASTContext &ctx, ValueDecl *D);
4949
bool checkOverrides(ValueDecl *decl);
5050

5151
// These are implemented in CodeSynthesis.cpp.
52-
void maybeAddAccessorsToStorage(TypeChecker &TC, AbstractStorageDecl *storage);
52+
void maybeAddAccessorsToStorage(AbstractStorageDecl *storage);
5353

5454
void triggerAccessorSynthesis(TypeChecker &TC, AbstractStorageDecl *storage);
5555

56+
/// Provide storage and accessor implementations for the given property,
57+
/// which must be lazy.
58+
void completeLazyVarImplementation(VarDecl *lazyVar);
59+
5660
/// Describes the kind of implicit constructor that will be
5761
/// generated.
5862
enum class ImplicitConstructorKind {

lib/Sema/TypeCheckDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,7 @@ static void finalizeAbstractStorageDecl(TypeChecker &TC,
20182018
TC.validateDecl(storage);
20192019

20202020
// Add any mandatory accessors now.
2021-
maybeAddAccessorsToStorage(TC, storage);
2021+
maybeAddAccessorsToStorage(storage);
20222022

20232023
for (auto accessor : storage->getAllAccessors()) {
20242024
// Are there accessors we can safely ignore here, like maybe observers?
@@ -2124,7 +2124,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
21242124
TC.validateDecl(VD);
21252125

21262126
// Set up accessors.
2127-
maybeAddAccessorsToStorage(TC, VD);
2127+
maybeAddAccessorsToStorage(VD);
21282128

21292129
// WARNING: Anything you put in this function will only be run when the
21302130
// VarDecl is fully type-checked within its own file. It will NOT be run
@@ -4292,7 +4292,7 @@ void TypeChecker::requestMemberLayout(ValueDecl *member) {
42924292
// because if they never get validated at all then conformance checkers
42934293
// will complain about selector mismatches.
42944294
if (storage->isObjC()) {
4295-
maybeAddAccessorsToStorage(*this, storage);
4295+
maybeAddAccessorsToStorage(storage);
42964296
for (auto accessor : storage->getAllAccessors()) {
42974297
requestMemberLayout(accessor);
42984298
}
@@ -4345,7 +4345,7 @@ static void finalizeType(TypeChecker &TC, NominalTypeDecl *nominal) {
43454345
if (prop->getAttrs().hasAttribute<LazyAttr>() && !prop->isStatic() &&
43464346
(!prop->getGetter() || !prop->getGetter()->hasBody())) {
43474347
finalizeAbstractStorageDecl(TC, prop);
4348-
TC.completeLazyVarImplementation(prop);
4348+
completeLazyVarImplementation(prop);
43494349
}
43504350
}
43514351

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -859,11 +859,8 @@ bool OverrideMatcher::checkOverride(ValueDecl *baseDecl,
859859
auto matchASD = cast<AbstractStorageDecl>(baseDecl);
860860
if (matchASD->isSetterAccessibleFrom(dc)) {
861861
// Match sure we've created the setter.
862-
if (!matchASD->getSetter()) {
863-
maybeAddAccessorsToStorage(
864-
*static_cast<TypeChecker *>(ctx.getLazyResolver()),
865-
matchASD);
866-
}
862+
if (!matchASD->getSetter())
863+
maybeAddAccessorsToStorage(matchASD);
867864

868865
auto matchSetterAccessScope = matchASD->getSetter()
869866
->getFormalAccessScope(dc);
@@ -1759,13 +1756,9 @@ OverriddenDeclsRequest::evaluate(Evaluator &evaluator, ValueDecl *decl) const {
17591756

17601757
// Check the various overridden storage declarations.
17611758
SmallVector<OverrideMatch, 2> matches;
1762-
ASTContext &ctx = decl->getASTContext();
17631759
for (auto overridden : overridingASD->getOverriddenDecls()) {
17641760
auto baseASD = cast<AbstractStorageDecl>(overridden);
1765-
if (auto lazyResolver = ctx.getLazyResolver()) {
1766-
maybeAddAccessorsToStorage(*static_cast<TypeChecker *>(lazyResolver),
1767-
baseASD);
1768-
}
1761+
maybeAddAccessorsToStorage(baseASD);
17691762

17701763
auto kind = accessor->getAccessorKind();
17711764

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,10 +1266,6 @@ class TypeChecker final : public LazyResolver {
12661266
void synthesizeWitnessAccessorsForStorage(AbstractStorageDecl *requirement,
12671267
AbstractStorageDecl *storage);
12681268

1269-
/// Provide storage and accessor implementations for the given property,
1270-
/// which must be lazy.
1271-
void completeLazyVarImplementation(VarDecl *lazyVar);
1272-
12731269
/// Pre-check the expression, validating any types that occur in the
12741270
/// expression and folding sequence expressions.
12751271
bool preCheckExpression(Expr *&expr, DeclContext *dc);

0 commit comments

Comments
 (0)