Skip to content

Commit c2ed347

Browse files
committed
Sema: Pass ValueDecl instead of ConcreteDeclRef in a few places in availability checking
The substitution map is checked elsewhere.
1 parent e10df96 commit c2ed347

File tree

3 files changed

+16
-30
lines changed

3 files changed

+16
-30
lines changed

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@
2828
using namespace swift;
2929

3030
bool TypeChecker::diagnoseInlinableDeclRef(SourceLoc loc,
31-
ConcreteDeclRef declRef,
31+
const ValueDecl *D,
3232
const DeclContext *DC,
3333
FragileFunctionKind Kind) {
3434
assert(Kind.kind != FragileFunctionKind::None);
3535

36-
const ValueDecl *D = declRef.getDecl();
3736
// Do some important fast-path checks that apply to all cases.
3837

3938
// Type parameters are OK.
@@ -48,7 +47,7 @@ bool TypeChecker::diagnoseInlinableDeclRef(SourceLoc loc,
4847
// Skip this check for accessors because the associated property or subscript
4948
// will also be checked, and will provide a better error message.
5049
if (!isa<AccessorDecl>(D))
51-
if (diagnoseDeclRefExportability(loc, declRef, DC,
50+
if (diagnoseDeclRefExportability(loc, D, DC,
5251
None, Kind))
5352
return true;
5453

@@ -141,19 +140,22 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
141140
return (downgradeToWarning == DowngradeToWarning::No);
142141
}
143142

144-
static bool diagnoseDeclExportability(SourceLoc loc, const ValueDecl *D,
145-
const SourceFile &userSF,
146-
const DeclContext *userDC,
147-
Optional<ExportabilityReason> reason,
148-
FragileFunctionKind fragileKind) {
143+
bool
144+
TypeChecker::diagnoseDeclRefExportability(SourceLoc loc,
145+
const ValueDecl *D,
146+
const DeclContext *DC,
147+
Optional<ExportabilityReason> reason,
148+
FragileFunctionKind fragileKind) {
149149
if (fragileKind.kind == FragileFunctionKind::None && !reason.hasValue())
150150
return false;
151151

152152
auto definingModule = D->getModuleContext();
153153

154154
auto downgradeToWarning = DowngradeToWarning::No;
155155
auto originKind = getDisallowedOriginKind(
156-
D, userSF, userDC->getInnermostDeclarationDeclContext(),
156+
D,
157+
*DC->getParentSourceFile(),
158+
DC->getInnermostDeclarationDeclContext(),
157159
downgradeToWarning);
158160
if (originKind == DisallowedOriginKind::None)
159161
return false;
@@ -211,20 +213,3 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
211213
static_cast<unsigned>(originKind));
212214
return true;
213215
}
214-
215-
bool
216-
TypeChecker::diagnoseDeclRefExportability(SourceLoc loc,
217-
ConcreteDeclRef declRef,
218-
const DeclContext *DC,
219-
Optional<ExportabilityReason> reason,
220-
FragileFunctionKind fragileKind) {
221-
// We're only interested in diagnosing uses from source files.
222-
auto userSF = DC->getParentSourceFile();
223-
if (!userSF)
224-
return false;
225-
226-
const ValueDecl *D = declRef.getDecl();
227-
if (diagnoseDeclExportability(loc, D, *userSF, DC, reason, fragileKind))
228-
return true;
229-
return false;
230-
}

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2653,11 +2653,11 @@ AvailabilityWalker::diagAvailability(ConcreteDeclRef declRef, SourceRange R,
26532653

26542654
if (FragileKind.kind != FragileFunctionKind::None) {
26552655
if (R.isValid())
2656-
if (TypeChecker::diagnoseInlinableDeclRef(R.Start, declRef, DC, FragileKind))
2656+
if (TypeChecker::diagnoseInlinableDeclRef(R.Start, D, DC, FragileKind))
26572657
return true;
26582658
} else if (ExportReason.hasValue()) {
26592659
if (R.isValid())
2660-
if (TypeChecker::diagnoseDeclRefExportability(R.Start, declRef, DC,
2660+
if (TypeChecker::diagnoseDeclRefExportability(R.Start, D, DC,
26612661
ExportReason, FragileKind))
26622662
return true;
26632663
}

lib/Sema/TypeChecker.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ DeclName getObjectLiteralConstructorName(ASTContext &ctx,
947947
ModuleDecl *getStdlibModule(const DeclContext *dc);
948948

949949
/// \name Resilience diagnostics
950-
bool diagnoseInlinableDeclRef(SourceLoc loc, ConcreteDeclRef declRef,
950+
bool diagnoseInlinableDeclRef(SourceLoc loc, const ValueDecl *D,
951951
const DeclContext *DC, FragileFunctionKind Kind);
952952

953953
Expr *buildDefaultInitializer(Type type);
@@ -959,7 +959,8 @@ bool diagnoseInlinableDeclRefAccess(SourceLoc loc, const ValueDecl *D,
959959
/// Given that a declaration is used from a particular context which
960960
/// exposes it in the interface of the current module, diagnose if it cannot
961961
/// reasonably be shared.
962-
bool diagnoseDeclRefExportability(SourceLoc loc, ConcreteDeclRef declRef,
962+
bool diagnoseDeclRefExportability(SourceLoc loc,
963+
const ValueDecl *D,
963964
const DeclContext *DC,
964965
Optional<ExportabilityReason> exportability,
965966
FragileFunctionKind fragileKind);

0 commit comments

Comments
 (0)