Skip to content

Commit 2822baf

Browse files
committed
Sema: Pull diagnoseDeclAvailability() out of AvailabilityWalker
1 parent a072655 commit 2822baf

File tree

4 files changed

+31
-39
lines changed

4 files changed

+31
-39
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1990,7 +1990,8 @@ SynthesizeMainFunctionRequest::evaluate(Evaluator &evaluator,
19901990
}
19911991

19921992
auto where = ExportContext::forDeclSignature(D);
1993-
diagnoseDeclAvailability(mainFunction, attr->getRange(), where, None);
1993+
diagnoseDeclAvailability(mainFunction, attr->getRange(), nullptr,
1994+
where, None);
19941995

19951996
auto *const func = FuncDecl::createImplicit(
19961997
context, StaticSpellingKind::KeywordStatic,

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,10 +2514,6 @@ class AvailabilityWalker : public ASTWalker {
25142514
const ApplyExpr *call = nullptr,
25152515
DeclAvailabilityFlags flags = None) const;
25162516

2517-
bool diagnoseDeclAvailability(const ValueDecl *D, SourceRange R,
2518-
const ApplyExpr *call = nullptr,
2519-
DeclAvailabilityFlags flags = None) const;
2520-
25212517
private:
25222518
bool diagnoseIncDecRemoval(const ValueDecl *D, SourceRange R,
25232519
const AvailableAttr *Attr) const;
@@ -2581,7 +2577,8 @@ class AvailabilityWalker : public ASTWalker {
25812577

25822578
ValueDecl *D = E->getMember().getDecl();
25832579
// Diagnose for the member declaration itself.
2584-
if (diagnoseDeclAvailability(D, E->getNameLoc().getSourceRange()))
2580+
if (diagnoseDeclAvailability(D, E->getNameLoc().getSourceRange(),
2581+
nullptr, Where))
25852582
return;
25862583

25872584
// Diagnose for appropriate accessors, given the access context.
@@ -2682,9 +2679,13 @@ class AvailabilityWalker : public ASTWalker {
26822679
void diagAccessorAvailability(AccessorDecl *D, SourceRange ReferenceRange,
26832680
const DeclContext *ReferenceDC,
26842681
DeclAvailabilityFlags Flags) const {
2682+
if (!D)
2683+
return;
2684+
26852685
Flags &= DeclAvailabilityFlag::ForInout;
26862686
Flags |= DeclAvailabilityFlag::ContinueOnPotentialUnavailability;
2687-
if (diagnoseDeclAvailability(D, ReferenceRange, /*call*/nullptr, Flags))
2687+
if (diagnoseDeclAvailability(D, ReferenceRange, /*call*/nullptr,
2688+
Where, Flags))
26882689
return;
26892690
}
26902691
};
@@ -2700,7 +2701,14 @@ AvailabilityWalker::diagnoseDeclRefAvailability(
27002701
return false;
27012702
const ValueDecl *D = declRef.getDecl();
27022703

2703-
diagnoseDeclAvailability(D, R, call, Flags);
2704+
if (auto *attr = AvailableAttr::isUnavailable(D)) {
2705+
if (diagnoseIncDecRemoval(D, R, attr))
2706+
return true;
2707+
if (call && diagnoseMemoryLayoutMigration(D, R, attr, call))
2708+
return true;
2709+
}
2710+
2711+
diagnoseDeclAvailability(D, R, call, Where, Flags);
27042712

27052713
if (R.isValid()) {
27062714
if (diagnoseSubstitutionMapAvailability(R.Start, declRef.getSubstitutions(),
@@ -2715,20 +2723,17 @@ AvailabilityWalker::diagnoseDeclRefAvailability(
27152723
/// Diagnose uses of unavailable declarations. Returns true if a diagnostic
27162724
/// was emitted.
27172725
bool
2718-
AvailabilityWalker::diagnoseDeclAvailability(
2719-
const ValueDecl *D, SourceRange R, const ApplyExpr *call,
2720-
DeclAvailabilityFlags Flags) const {
2726+
swift::diagnoseDeclAvailability(const ValueDecl *D,
2727+
SourceRange R,
2728+
const ApplyExpr *call,
2729+
ExportContext Where,
2730+
DeclAvailabilityFlags Flags) {
2731+
assert(!Where.isImplicit());
2732+
27212733
// Generic parameters are always available.
27222734
if (isa<GenericTypeParamDecl>(D))
27232735
return false;
27242736

2725-
if (auto *attr = AvailableAttr::isUnavailable(D)) {
2726-
if (diagnoseIncDecRemoval(D, R, attr))
2727-
return true;
2728-
if (call && diagnoseMemoryLayoutMigration(D, R, attr, call))
2729-
return true;
2730-
}
2731-
27322737
// Keep track if this is an accessor.
27332738
auto accessor = dyn_cast<AccessorDecl>(D);
27342739

@@ -2996,7 +3001,7 @@ class TypeReprAvailabilityWalker : public ASTWalker {
29963001
bool checkComponentIdentTypeRepr(ComponentIdentTypeRepr *ITR) {
29973002
if (auto *typeDecl = ITR->getBoundDecl()) {
29983003
auto range = ITR->getNameLoc().getSourceRange();
2999-
if (diagnoseDeclAvailability(typeDecl, range, where, flags))
3004+
if (diagnoseDeclAvailability(typeDecl, range, nullptr, where, flags))
30003005
return true;
30013006
}
30023007

@@ -3190,20 +3195,6 @@ swift::diagnoseSubstitutionMapAvailability(SourceLoc loc,
31903195
return hadAnyIssues;
31913196
}
31923197

3193-
/// Run the Availability-diagnostics algorithm otherwise used in an expr
3194-
/// context, but for non-expr contexts such as TypeDecls referenced from
3195-
/// TypeReprs.
3196-
bool swift::diagnoseDeclAvailability(const ValueDecl *Decl,
3197-
SourceRange R,
3198-
ExportContext Where,
3199-
DeclAvailabilityFlags Flags)
3200-
{
3201-
assert(!Where.isImplicit());
3202-
AvailabilityWalker AW(Where);
3203-
return AW.diagnoseDeclAvailability(const_cast<ValueDecl *>(Decl), R,
3204-
nullptr, Flags);
3205-
}
3206-
32073198
/// Should we warn that \p decl needs an explicit availability annotation
32083199
/// in -require-explicit-availability mode?
32093200
static bool declNeedsExplicitAvailability(const Decl *decl) {

lib/Sema/TypeCheckAvailability.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ diagnoseSubstitutionMapAvailability(SourceLoc loc,
205205
SubstitutionMap subs,
206206
ExportContext context);
207207

208-
/// Run the Availability-diagnostics algorithm otherwise used in an expr
209-
/// context, but for non-expr contexts such as TypeDecls referenced from
210-
/// TypeReprs.
211-
bool diagnoseDeclAvailability(const ValueDecl *Decl,
208+
/// Diagnose uses of unavailable declarations. Returns true if a diagnostic
209+
/// was emitted.
210+
bool diagnoseDeclAvailability(const ValueDecl *D,
212211
SourceRange R,
213-
ExportContext context,
212+
const ApplyExpr *call,
213+
ExportContext where,
214214
DeclAvailabilityFlags flags = None);
215215

216216
void diagnoseUnavailableOverride(ValueDecl *override,

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ static bool checkSuperInit(ConstructorDecl *fromCtor,
16971697

16981698
// Make sure we can reference the designated initializer correctly.
16991699
diagnoseDeclAvailability(
1700-
ctor, fromCtor->getLoc(),
1700+
ctor, fromCtor->getLoc(), nullptr,
17011701
ExportContext::forFunctionBody(fromCtor));
17021702
}
17031703

0 commit comments

Comments
 (0)