Skip to content

Commit b280f61

Browse files
committed
Sema: Resilience diagnostics pre-compute a few things
1 parent 05ea885 commit b280f61

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,8 @@ void TypeChecker::diagnoseInlinableLocalType(const NominalTypeDecl *NTD) {
7272

7373
bool TypeChecker::diagnoseInlinableDeclRef(SourceLoc loc,
7474
const ValueDecl *D,
75-
const DeclContext *DC) {
76-
auto expansion = DC->getResilienceExpansion();
77-
78-
// Internal declarations referenced from non-inlinable contexts are OK.
79-
if (expansion == ResilienceExpansion::Maximal)
80-
return false;
81-
75+
const DeclContext *DC,
76+
FragileFunctionKind Kind) {
8277
// Local declarations are OK.
8378
if (D->getDeclContext()->isLocalContext())
8479
return false;
@@ -89,7 +84,7 @@ bool TypeChecker::diagnoseInlinableDeclRef(SourceLoc loc,
8984

9085
// Public declarations are OK.
9186
if (D->getFormalAccessScope(/*useDC=*/nullptr,
92-
/*respectVersionedAttr=*/true).isPublic())
87+
/*treatUsableFromInlineAsPublic*/true).isPublic())
9388
return false;
9489

9590
// Enum cases are handled as part of their containing enum.
@@ -114,7 +109,7 @@ bool TypeChecker::diagnoseInlinableDeclRef(SourceLoc loc,
114109
diagnose(loc, diag::resilience_decl_unavailable,
115110
D->getDescriptiveKind(), D->getFullName(),
116111
D->getFormalAccessScope().accessLevelForDiagnostics(),
117-
static_cast<unsigned>(getFragileFunctionKind(DC)));
112+
static_cast<unsigned>(Kind));
118113

119114
bool isDefaultArgument = false;
120115
while (DC->isLocalContext()) {

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,10 +2233,16 @@ class AvailabilityWalker : public ASTWalker {
22332233
DeclContext *DC;
22342234
MemberAccessContext AccessContext = MemberAccessContext::Getter;
22352235
SmallVector<const Expr *, 16> ExprStack;
2236+
ResilienceExpansion Expansion;
2237+
Optional<TypeChecker::FragileFunctionKind> FragileKind;
22362238

22372239
public:
22382240
AvailabilityWalker(
2239-
TypeChecker &TC, DeclContext *DC) : TC(TC), DC(DC) {}
2241+
TypeChecker &TC, DeclContext *DC) : TC(TC), DC(DC) {
2242+
Expansion = DC->getResilienceExpansion();
2243+
if (Expansion == ResilienceExpansion::Minimal)
2244+
FragileKind = TC.getFragileFunctionKind(DC);
2245+
}
22402246

22412247
std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
22422248
ExprStack.push_back(E);
@@ -2457,9 +2463,10 @@ bool AvailabilityWalker::diagAvailability(const ValueDecl *D, SourceRange R,
24572463
return true;
24582464
}
24592465

2460-
if (R.isValid())
2461-
if (TC.diagnoseInlinableDeclRef(R.Start, D, DC))
2462-
return true;
2466+
if (FragileKind)
2467+
if (R.isValid())
2468+
if (TC.diagnoseInlinableDeclRef(R.Start, D, DC, *FragileKind))
2469+
return true;
24632470

24642471
if (TC.diagnoseExplicitUnavailability(D, R, DC, call))
24652472
return true;

lib/Sema/TypeChecker.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2298,9 +2298,6 @@ class TypeChecker final : public LazyResolver {
22982298

22992299
void diagnoseInlinableLocalType(const NominalTypeDecl *NTD);
23002300

2301-
bool diagnoseInlinableDeclRef(SourceLoc loc, const ValueDecl *D,
2302-
const DeclContext *DC);
2303-
23042301
/// Used in diagnostic %selects.
23052302
enum class FragileFunctionKind : unsigned {
23062303
Transparent,
@@ -2310,6 +2307,10 @@ class TypeChecker final : public LazyResolver {
23102307
PropertyInitializer
23112308
};
23122309

2310+
bool diagnoseInlinableDeclRef(SourceLoc loc, const ValueDecl *D,
2311+
const DeclContext *DC,
2312+
FragileFunctionKind Kind);
2313+
23132314
/// Given that \p DC is within a fragile context for some reason, describe
23142315
/// why.
23152316
///

0 commit comments

Comments
 (0)