Skip to content

Commit e786544

Browse files
committed
typecheck
1 parent 2086eb3 commit e786544

File tree

1 file changed

+24
-33
lines changed

1 file changed

+24
-33
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
21162116
}, /*visitFreestandingExpanded=*/false);
21172117
}
21182118

2119-
if (auto *Stats = getASTContext().Stats)
2119+
if (auto *Stats = Ctx.Stats)
21202120
++Stats->getFrontendCounters().NumDeclsTypechecked;
21212121

21222122
FrontendStatsTracer StatsTracer(getASTContext().Stats,
@@ -2131,8 +2131,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
21312131
TypeChecker::checkExistentialTypes(decl);
21322132

21332133
if (auto VD = dyn_cast<ValueDecl>(decl)) {
2134-
auto &Context = getASTContext();
2135-
TypeChecker::checkForForbiddenPrefix(Context, VD->getBaseName());
2134+
TypeChecker::checkForForbiddenPrefix(Ctx, VD->getBaseName());
21362135

21372136
// Force some requests, which can produce diagnostics.
21382137

@@ -2205,15 +2204,15 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
22052204

22062205
auto target = ID->getModule();
22072206
if (target && // module would be nil if loading fails
2208-
!getASTContext().LangOpts.PackageName.empty() &&
2209-
getASTContext().LangOpts.PackageName == target->getPackageName().str() &&
2207+
!Ctx.LangOpts.PackageName.empty() &&
2208+
Ctx.LangOpts.PackageName == target->getPackageName().str() &&
22102209
!target->isNonSwiftModule() && // target is a Swift module
22112210
target->isNonUserModule()) { // target module is in distributed SDK
22122211
// If reached here, a binary module (.swiftmodule) instead of interface of the
22132212
// target was loaded for the main module, where both belong to the same package;
22142213
// this is an expected behavior, but it should have been loaded from the local
22152214
// build directory, not from distributed SDK. In such case, we show a warning.
2216-
auto &diags = ID->getASTContext().Diags;
2215+
auto &diags = ID->Ctx.Diags;
22172216
diags.diagnose(ID,
22182217
diag::in_package_module_not_compiled_locally,
22192218
target->getBaseIdentifier(),
@@ -2222,15 +2221,15 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
22222221
}
22232222

22242223
// Report the public import of a private module.
2225-
if (ID->getASTContext().LangOpts.LibraryLevel == LibraryLevel::API) {
2224+
if (ID->Ctx.LangOpts.LibraryLevel == LibraryLevel::API) {
22262225
auto importer = ID->getModuleContext();
22272226
if (target &&
22282227
!ID->getAttrs().hasAttribute<ImplementationOnlyAttr>() &&
22292228
!ID->getAttrs().hasAttribute<SPIOnlyAttr>() &&
22302229
ID->getAccessLevel() == AccessLevel::Public &&
22312230
target->getLibraryLevel() == LibraryLevel::SPI) {
22322231

2233-
auto &diags = ID->getASTContext().Diags;
2232+
auto &diags = ID->Ctx.Diags;
22342233
InFlightDiagnostic inFlight =
22352234
diags.diagnose(ID, diag::error_public_import_of_private_module,
22362235
target->getName(), importer->getName());
@@ -2485,7 +2484,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
24852484
//
24862485
// NOTE: We do this here instead of TypeCheckAttr since types are not
24872486
// completely type checked at that point.
2488-
auto &DE = getASTContext().Diags;
2487+
auto &DE = Ctx.Diags;
24892488
if (auto attr = VD->getAttrs().getAttribute<NoImplicitCopyAttr>()) {
24902489
if (auto *nom = VD->getInterfaceType()->getNominalOrBoundGenericNominal()) {
24912490
if (!nom->canBeCopyable()) {
@@ -2498,10 +2497,10 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
24982497

24992498
// @_staticExclusiveOnly types cannot be put into 'var's, only 'let'.
25002499
if (auto SD = VD->getInterfaceType()->getStructOrBoundGenericStruct()) {
2501-
if (getASTContext().LangOpts.hasFeature(Feature::StaticExclusiveOnly) &&
2500+
if (Ctx.LangOpts.hasFeature(Feature::StaticExclusiveOnly) &&
25022501
SD->getAttrs().hasAttribute<StaticExclusiveOnlyAttr>() &&
25032502
!VD->isLet()) {
2504-
SD->getASTContext().Diags.diagnoseWithNotes(
2503+
SD->Ctx.Diags.diagnoseWithNotes(
25052504
VD->diagnose(diag::attr_static_exclusive_only_let_only,
25062505
VD->getInterfaceType()),
25072506
[&]() {
@@ -2538,7 +2537,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
25382537
isInSILMode = sourceFile->Kind == SourceFileKind::SIL;
25392538
bool isTypeContext = DC->isTypeContext();
25402539

2541-
auto &Ctx = getASTContext();
25422540
for (auto i : range(PBD->getNumPatternEntries())) {
25432541
const auto *entry = PBD->isFullyValidated(i)
25442542
? &PBD->getPatternList()[i]
@@ -2881,7 +2879,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
28812879
});
28822880

28832881
if (mentionsItself) {
2884-
auto &DE = getASTContext().Diags;
2882+
auto &DE = Ctx.Diags;
28852883
DE.diagnose(AT->getDefaultDefinitionTypeRepr()->getLoc(),
28862884
diag::recursive_decl_reference, AT);
28872885
AT->diagnose(diag::kind_declared_here, DescriptiveDeclKind::Type);
@@ -2993,7 +2991,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
29932991

29942992
TypeChecker::checkPatternBindingCaptures(ED);
29952993

2996-
auto &DE = getASTContext().Diags;
2994+
auto &DE = Ctx.Diags;
29972995
if (auto rawTy = ED->getRawType()) {
29982996
// The raw type must be one of the blessed literal convertible types.
29992997
if (!computeAutomaticEnumValueKind(ED)) {
@@ -3376,7 +3374,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
33763374
}
33773375
}
33783376

3379-
if (!getASTContext().isAccessControlDisabled()) {
3377+
if (!Ctx.isAccessControlDisabled()) {
33803378
// Require the superclass to be open if this is outside its
33813379
// defining module. But don't emit another diagnostic if we
33823380
// already complained about the class being inherently
@@ -3451,7 +3449,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
34513449
if (!SF || SF->Kind != SourceFileKind::Interface)
34523450
TypeChecker::inferDefaultWitnesses(PD);
34533451

3454-
if (PD->getASTContext().TypeCheckerOpts.DebugGenericSignatures) {
3452+
if (Ctx.TypeCheckerOpts.DebugGenericSignatures) {
34553453
auto sig = PD->getRequirementSignatureAsGenericSignature();
34563454
llvm::errs() << "\n";
34573455
llvm::errs() << "Protocol requirement signature:\n";
@@ -3613,13 +3611,12 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
36133611
if (isRepresentableInObjC(FD, reason, asyncConvention, errorConvention)) {
36143612
if (FD->hasAsync()) {
36153613
FD->setForeignAsyncConvention(*asyncConvention);
3616-
getASTContext().Diags.diagnose(
3614+
Ctx.Diags.diagnose(
36173615
CDeclAttr->getLocation(), diag::attr_decl_async,
36183616
CDeclAttr->getAttrName(), FD->getDescriptiveKind());
36193617
} else if (FD->hasThrows()) {
36203618
FD->setForeignErrorConvention(*errorConvention);
3621-
getASTContext().Diags.diagnose(CDeclAttr->getLocation(),
3622-
diag::cdecl_throws);
3619+
Ctx.Diags.diagnose(CDeclAttr->getLocation(), diag::cdecl_throws);
36233620
}
36243621
} else {
36253622
reason.setAttrInvalid();
@@ -3648,7 +3645,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
36483645
checkVariadicParameters(PL, EED);
36493646
}
36503647

3651-
auto &DE = getASTContext().Diags;
3648+
auto &DE = Ctx.Diags;
36523649
// We don't yet support raw values on payload cases.
36533650
if (EED->hasAssociatedValues()) {
36543651
if (auto rawTy = ED->getRawType()) {
@@ -3843,10 +3840,11 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
38433840

38443841
// Produce any diagnostics for the generic signature.
38453842
(void) ED->getGenericSignature();
3843+
dumpGenericSignature(Ctx, ED);
38463844

38473845
checkInheritanceClause(ED);
38483846

3849-
diagnoseRetroactiveConformances(ED, getASTContext().Diags);
3847+
diagnoseRetroactiveConformances(ED, Ctx.Diags);
38503848

38513849
// Only generic and protocol types are permitted to have
38523850
// trailing where clauses.
@@ -3909,8 +3907,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
39093907
void visitPoundDiagnosticDecl(PoundDiagnosticDecl *PDD) {
39103908
if (PDD->hasBeenEmitted()) { return; }
39113909
PDD->markEmitted();
3912-
getASTContext()
3913-
.Diags
3910+
Ctx.Diags
39143911
.diagnose(PDD->getMessage()->getStartLoc(),
39153912
PDD->isError() ? diag::pound_error : diag::pound_warning,
39163913
PDD->getMessage()->getValue())
@@ -3973,8 +3970,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
39733970
} else {
39743971
CD->diagnose(diag::required_initializer_override_wrong_keyword)
39753972
.fixItReplace(attr->getLocation(), "required");
3976-
CD->getAttrs().add(new (getASTContext())
3977-
RequiredAttr(/*IsImplicit=*/true));
3973+
CD->getAttrs().add(new (Ctx) RequiredAttr(/*IsImplicit=*/true));
39783974
}
39793975

39803976
auto *reqInit =
@@ -4016,8 +4012,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
40164012
auto *reqInit = findNonImplicitRequiredInit(CD->getOverriddenDecl());
40174013
reqInit->diagnose(diag::overridden_required_initializer_here);
40184014

4019-
CD->getAttrs().add(new (getASTContext())
4020-
RequiredAttr(/*IsImplicit=*/true));
4015+
CD->getAttrs().add(new (Ctx) RequiredAttr(/*IsImplicit=*/true));
40214016
}
40224017
}
40234018

@@ -4074,10 +4069,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
40744069
}
40754070

40764071
void visitDestructorDecl(DestructorDecl *DD) {
4077-
auto haveFeature = [=](Feature f) -> bool {
4078-
return DD->getASTContext().LangOpts.hasFeature(f);
4079-
};
4080-
40814072
// Only check again for destructor decl outside of a class if our destructor
40824073
// is not marked as invalid.
40834074
if (!DD->isInvalid()) {
@@ -4086,7 +4077,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
40864077
if (!nom || isa<ProtocolDecl>(nom)) {
40874078
DD->diagnose(diag::destructor_decl_outside_class_or_noncopyable);
40884079

4089-
} else if (!haveFeature(Feature::NoncopyableGenerics)
4080+
} else if (!Ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)
40904081
&& !isa<ClassDecl>(nom)
40914082
&& nom->canBeCopyable()) {
40924083
// When we have NoncopyableGenerics, deinits get validated as part of
@@ -4096,7 +4087,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
40964087

40974088
// Temporarily ban deinit on noncopyable enums, unless the experimental
40984089
// feature flag is set.
4099-
if (!haveFeature(Feature::MoveOnlyEnumDeinits)
4090+
if (!Ctx.LangOpts.hasFeature(Feature::MoveOnlyEnumDeinits)
41004091
&& isa<EnumDecl>(nom)
41014092
&& !nom->canBeCopyable()) {
41024093
DD->diagnose(diag::destructor_decl_on_noncopyable_enum);

0 commit comments

Comments
 (0)