Skip to content

Commit 5905517

Browse files
committed
Pass a ConcreteDeclRef through for availability checking where present
This will be used in the next commit for checking conformance use in inlinable function bodies, but for now it's No Functionality Change.
1 parent 5c27568 commit 5905517

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ enum class DowngradeToWarning: bool {
9999
};
100100

101101
bool TypeChecker::diagnoseInlinableDeclRef(SourceLoc loc,
102-
const ValueDecl *D,
102+
ConcreteDeclRef declRef,
103103
const DeclContext *DC,
104104
FragileFunctionKind Kind,
105105
bool TreatUsableFromInlineAsPublic) {
106+
const ValueDecl *D = declRef.getDecl();
106107
// Do some important fast-path checks that apply to all cases.
107108

108109
// Local declarations are OK.

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,7 @@ class AvailabilityWalker : public ASTWalker {
22932293
// DerivedConformanceRawRepresentable will do the right thing.
22942294
flags |= DeclAvailabilityFlag::AllowPotentiallyUnavailable;
22952295

2296-
diagAvailability(DR->getDecl(), DR->getSourceRange(),
2296+
diagAvailability(DR->getDeclRef(), DR->getSourceRange(),
22972297
getEnclosingApplyExpr(), flags);
22982298
maybeDiagStorageAccess(DR->getDecl(), DR->getSourceRange(), DC);
22992299
}
@@ -2302,18 +2302,18 @@ class AvailabilityWalker : public ASTWalker {
23022302
return skipChildren();
23032303
}
23042304
if (auto OCDR = dyn_cast<OtherConstructorDeclRefExpr>(E))
2305-
diagAvailability(OCDR->getDecl(),
2305+
diagAvailability(OCDR->getDeclRef(),
23062306
OCDR->getConstructorLoc().getSourceRange(),
23072307
getEnclosingApplyExpr());
23082308
if (auto DMR = dyn_cast<DynamicMemberRefExpr>(E))
2309-
diagAvailability(DMR->getMember().getDecl(),
2309+
diagAvailability(DMR->getMember(),
23102310
DMR->getNameLoc().getSourceRange(),
23112311
getEnclosingApplyExpr());
23122312
if (auto DS = dyn_cast<DynamicSubscriptExpr>(E))
2313-
diagAvailability(DS->getMember().getDecl(), DS->getSourceRange());
2313+
diagAvailability(DS->getMember(), DS->getSourceRange());
23142314
if (auto S = dyn_cast<SubscriptExpr>(E)) {
23152315
if (S->hasDecl()) {
2316-
diagAvailability(S->getDecl().getDecl(), S->getSourceRange());
2316+
diagAvailability(S->getDecl(), S->getSourceRange());
23172317
maybeDiagStorageAccess(S->getDecl().getDecl(), S->getSourceRange(), DC);
23182318
}
23192319
}
@@ -2328,7 +2328,7 @@ class AvailabilityWalker : public ASTWalker {
23282328
walkInOutExpr(IO);
23292329
return skipChildren();
23302330
}
2331-
2331+
23322332
return visitChildren();
23332333
}
23342334

@@ -2339,16 +2339,16 @@ class AvailabilityWalker : public ASTWalker {
23392339
return E;
23402340
}
23412341

2342-
bool diagAvailability(const ValueDecl *D, SourceRange R,
2342+
bool diagAvailability(ConcreteDeclRef declRef, SourceRange R,
23432343
const ApplyExpr *call = nullptr,
2344-
DeclAvailabilityFlags flags = None);
2344+
DeclAvailabilityFlags flags = None) const;
23452345

23462346
private:
23472347
bool diagnoseIncDecRemoval(const ValueDecl *D, SourceRange R,
2348-
const AvailableAttr *Attr);
2348+
const AvailableAttr *Attr) const;
23492349
bool diagnoseMemoryLayoutMigration(const ValueDecl *D, SourceRange R,
23502350
const AvailableAttr *Attr,
2351-
const ApplyExpr *call);
2351+
const ApplyExpr *call) const;
23522352

23532353
/// Walks up from a potential callee to the enclosing ApplyExpr.
23542354
const ApplyExpr *getEnclosingApplyExpr() const {
@@ -2502,10 +2502,7 @@ class AvailabilityWalker : public ASTWalker {
25022502
DeclAvailabilityFlags Flags) const {
25032503
Flags &= DeclAvailabilityFlag::ForInout;
25042504
Flags |= DeclAvailabilityFlag::ContinueOnPotentialUnavailability;
2505-
if (diagnoseDeclAvailability(D, TC,
2506-
const_cast<DeclContext*>(ReferenceDC),
2507-
ReferenceRange,
2508-
Flags))
2505+
if (diagAvailability(D, ReferenceRange, /*call*/nullptr, Flags))
25092506
return;
25102507
}
25112508
};
@@ -2514,11 +2511,12 @@ class AvailabilityWalker : public ASTWalker {
25142511
/// Diagnose uses of unavailable declarations. Returns true if a diagnostic
25152512
/// was emitted.
25162513
bool
2517-
AvailabilityWalker::diagAvailability(const ValueDecl *D, SourceRange R,
2514+
AvailabilityWalker::diagAvailability(ConcreteDeclRef declRef, SourceRange R,
25182515
const ApplyExpr *call,
2519-
DeclAvailabilityFlags Flags) {
2520-
if (!D)
2516+
DeclAvailabilityFlags Flags) const {
2517+
if (!declRef)
25212518
return false;
2519+
const ValueDecl *D = declRef.getDecl();
25222520

25232521
if (auto *attr = AvailableAttr::isUnavailable(D)) {
25242522
if (diagnoseIncDecRemoval(D, R, attr))
@@ -2539,7 +2537,7 @@ AvailabilityWalker::diagAvailability(const ValueDecl *D, SourceRange R,
25392537

25402538
if (FragileKind)
25412539
if (R.isValid())
2542-
if (TC.diagnoseInlinableDeclRef(R.Start, D, DC, *FragileKind,
2540+
if (TC.diagnoseInlinableDeclRef(R.Start, declRef, DC, *FragileKind,
25432541
TreatUsableFromInlineAsPublic))
25442542
return true;
25452543

@@ -2602,9 +2600,9 @@ static bool isIntegerOrFloatingPointType(Type ty, DeclContext *DC,
26022600

26032601
/// If this is a call to an unavailable ++ / -- operator, try to diagnose it
26042602
/// with a fixit hint and return true. If not, or if we fail, return false.
2605-
bool AvailabilityWalker::diagnoseIncDecRemoval(const ValueDecl *D,
2606-
SourceRange R,
2607-
const AvailableAttr *Attr) {
2603+
bool
2604+
AvailabilityWalker::diagnoseIncDecRemoval(const ValueDecl *D, SourceRange R,
2605+
const AvailableAttr *Attr) const {
26082606
// We can only produce a fixit if we're talking about ++ or --.
26092607
bool isInc = D->getBaseName() == "++";
26102608
if (!isInc && D->getBaseName() != "--")
@@ -2664,10 +2662,11 @@ bool AvailabilityWalker::diagnoseIncDecRemoval(const ValueDecl *D,
26642662

26652663
/// If this is a call to an unavailable sizeof family function, diagnose it
26662664
/// with a fixit hint and return true. If not, or if we fail, return false.
2667-
bool AvailabilityWalker::diagnoseMemoryLayoutMigration(const ValueDecl *D,
2668-
SourceRange R,
2669-
const AvailableAttr *Attr,
2670-
const ApplyExpr *call) {
2665+
bool
2666+
AvailabilityWalker::diagnoseMemoryLayoutMigration(const ValueDecl *D,
2667+
SourceRange R,
2668+
const AvailableAttr *Attr,
2669+
const ApplyExpr *call) const {
26712670

26722671
if (!D->getModuleContext()->isStdlibModule())
26732672
return false;
@@ -2750,5 +2749,5 @@ bool swift::diagnoseDeclAvailability(const ValueDecl *Decl,
27502749
DeclAvailabilityFlags Flags)
27512750
{
27522751
AvailabilityWalker AW(TC, DC);
2753-
return AW.diagAvailability(Decl, R, nullptr, Flags);
2752+
return AW.diagAvailability(const_cast<ValueDecl *>(Decl), R, nullptr, Flags);
27542753
}

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,7 @@ class TypeChecker final : public LazyResolver {
18761876
PropertyInitializer
18771877
};
18781878

1879-
bool diagnoseInlinableDeclRef(SourceLoc loc, const ValueDecl *D,
1879+
bool diagnoseInlinableDeclRef(SourceLoc loc, ConcreteDeclRef declRef,
18801880
const DeclContext *DC,
18811881
FragileFunctionKind Kind,
18821882
bool TreatUsableFromInlineAsPublic);

0 commit comments

Comments
 (0)