Skip to content

Commit fd38c4d

Browse files
committed
Sema: Pass ExportContext by const reference where possible
1 parent d5ee1da commit fd38c4d

File tree

6 files changed

+40
-37
lines changed

6 files changed

+40
-37
lines changed

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using namespace swift;
2929

3030
bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
3131
const ValueDecl *D,
32-
ExportContext where) {
32+
const ExportContext &where) {
3333
auto fragileKind = where.getFragileFunctionKind();
3434
if (fragileKind.kind == FragileFunctionKind::None)
3535
return false;
@@ -112,7 +112,7 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
112112
bool
113113
TypeChecker::diagnoseDeclRefExportability(SourceLoc loc,
114114
const ValueDecl *D,
115-
ExportContext where) {
115+
const ExportContext &where) {
116116
// Accessors cannot have exportability that's different than the storage,
117117
// so skip them for now.
118118
if (isa<AccessorDecl>(D))
@@ -160,7 +160,7 @@ TypeChecker::diagnoseDeclRefExportability(SourceLoc loc,
160160
bool
161161
TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
162162
const RootProtocolConformance *rootConf,
163-
ExportContext where) {
163+
const ExportContext &where) {
164164
if (!where.mustOnlyReferenceExportedDecls())
165165
return false;
166166

lib/Sema/TypeCheckAccess.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
14481448
/// Local variant to swift::getDisallowedOriginKind for downgrade to warnings.
14491449
DisallowedOriginKind
14501450
swift::getDisallowedOriginKind(const Decl *decl,
1451-
ExportContext where,
1451+
const ExportContext &where,
14521452
DowngradeToWarning &downgradeToWarning) {
14531453
downgradeToWarning = DowngradeToWarning::No;
14541454
ModuleDecl *M = decl->getModuleContext();
@@ -1826,7 +1826,7 @@ static void checkExtensionGenericParamAccess(const ExtensionDecl *ED) {
18261826
}
18271827

18281828
DisallowedOriginKind swift::getDisallowedOriginKind(const Decl *decl,
1829-
ExportContext where) {
1829+
const ExportContext &where) {
18301830
auto downgradeToWarning = DowngradeToWarning::No;
18311831
return getDisallowedOriginKind(decl, where, downgradeToWarning);
18321832
}

lib/Sema/TypeCheckAccess.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ enum class DowngradeToWarning: bool {
5656
/// Returns the kind of origin, implementation-only import or SPI declaration,
5757
/// that restricts exporting \p decl from the given file and context.
5858
DisallowedOriginKind getDisallowedOriginKind(const Decl *decl,
59-
ExportContext where);
59+
const ExportContext &where);
6060

6161
DisallowedOriginKind getDisallowedOriginKind(const Decl *decl,
62-
ExportContext where,
62+
const ExportContext &where,
6363
DowngradeToWarning &downgradeToWarning);
6464

6565
} // end namespace swift

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,8 @@ TypeChecker::overApproximateAvailabilityAtLocation(SourceLoc loc,
926926
}
927927

928928
Optional<UnavailabilityReason>
929-
TypeChecker::checkDeclarationAvailability(const Decl *D, ExportContext where) {
929+
TypeChecker::checkDeclarationAvailability(const Decl *D,
930+
const ExportContext &where) {
930931
auto *referenceDC = where.getDeclContext();
931932
ASTContext &Context = referenceDC->getASTContext();
932933
if (Context.LangOpts.DisableAvailabilityChecking) {
@@ -1668,7 +1669,7 @@ const AvailableAttr *TypeChecker::getDeprecated(const Decl *D) {
16681669
/// Returns true if the reference or any of its parents is an
16691670
/// unconditional unavailable declaration for the same platform.
16701671
static bool isInsideCompatibleUnavailableDeclaration(
1671-
const ValueDecl *D, ExportContext where,
1672+
const ValueDecl *D, const ExportContext &where,
16721673
const AvailableAttr *attr) {
16731674
auto referencedPlatform = where.getUnavailablePlatformKind();
16741675
if (!referencedPlatform)
@@ -2067,7 +2068,7 @@ getAccessorKindAndNameForDiagnostics(const ValueDecl *D) {
20672068
}
20682069

20692070
void TypeChecker::diagnoseIfDeprecated(SourceRange ReferenceRange,
2070-
ExportContext Where,
2071+
const ExportContext &Where,
20712072
const ValueDecl *DeprecatedDecl,
20722073
const ApplyExpr *Call) {
20732074
const AvailableAttr *Attr = TypeChecker::getDeprecated(DeprecatedDecl);
@@ -2201,7 +2202,7 @@ void swift::diagnoseUnavailableOverride(ValueDecl *override,
22012202
/// marked as unavailable, either through "unavailable" or "obsoleted:".
22022203
bool swift::diagnoseExplicitUnavailability(const ValueDecl *D,
22032204
SourceRange R,
2204-
ExportContext Where,
2205+
const ExportContext &Where,
22052206
const ApplyExpr *call,
22062207
DeclAvailabilityFlags Flags) {
22072208
return diagnoseExplicitUnavailability(D, R, Where, Flags,
@@ -2275,7 +2276,7 @@ bool isSubscriptReturningString(const ValueDecl *D, ASTContext &Context) {
22752276
bool swift::diagnoseExplicitUnavailability(
22762277
const ValueDecl *D,
22772278
SourceRange R,
2278-
ExportContext Where,
2279+
const ExportContext &Where,
22792280
DeclAvailabilityFlags Flags,
22802281
llvm::function_ref<void(InFlightDiagnostic &)> attachRenameFixIts) {
22812282
auto *Attr = AvailableAttr::isUnavailable(D);
@@ -2430,10 +2431,10 @@ class ExprAvailabilityWalker : public ASTWalker {
24302431
ASTContext &Context;
24312432
MemberAccessContext AccessContext = MemberAccessContext::Getter;
24322433
SmallVector<const Expr *, 16> ExprStack;
2433-
ExportContext Where;
2434+
const ExportContext &Where;
24342435

24352436
public:
2436-
explicit ExprAvailabilityWalker(ExportContext Where)
2437+
explicit ExprAvailabilityWalker(const ExportContext &Where)
24372438
: Context(Where.getDeclContext()->getASTContext()), Where(Where) {}
24382439

24392440
bool shouldWalkIntoSeparatelyCheckedClosure(ClosureExpr *expr) override {
@@ -2747,7 +2748,7 @@ bool
27472748
swift::diagnoseDeclAvailability(const ValueDecl *D,
27482749
SourceRange R,
27492750
const ApplyExpr *call,
2750-
ExportContext Where,
2751+
const ExportContext &Where,
27512752
DeclAvailabilityFlags Flags) {
27522753
assert(!Where.isImplicit());
27532754

@@ -3025,7 +3026,7 @@ void swift::diagnoseStmtAvailability(const Stmt *S, DeclContext *DC,
30253026
namespace {
30263027

30273028
class TypeReprAvailabilityWalker : public ASTWalker {
3028-
ExportContext where;
3029+
const ExportContext &where;
30293030
DeclAvailabilityFlags flags;
30303031

30313032
bool checkComponentIdentTypeRepr(ComponentIdentTypeRepr *ITR) {
@@ -3053,7 +3054,7 @@ class TypeReprAvailabilityWalker : public ASTWalker {
30533054
public:
30543055
bool foundAnyIssues = false;
30553056

3056-
TypeReprAvailabilityWalker(ExportContext where,
3057+
TypeReprAvailabilityWalker(const ExportContext &where,
30573058
DeclAvailabilityFlags flags)
30583059
: where(where), flags(flags) {}
30593060

@@ -3088,7 +3089,8 @@ class TypeReprAvailabilityWalker : public ASTWalker {
30883089

30893090
}
30903091

3091-
bool swift::diagnoseTypeReprAvailability(const TypeRepr *T, ExportContext where,
3092+
bool swift::diagnoseTypeReprAvailability(const TypeRepr *T,
3093+
const ExportContext &where,
30923094
DeclAvailabilityFlags flags) {
30933095
if (!T)
30943096
return false;
@@ -3101,11 +3103,11 @@ namespace {
31013103

31023104
class ProblematicTypeFinder : public TypeDeclFinder {
31033105
SourceLoc Loc;
3104-
ExportContext Where;
3106+
const ExportContext &Where;
31053107
DeclAvailabilityFlags Flags;
31063108

31073109
public:
3108-
ProblematicTypeFinder(SourceLoc Loc, ExportContext Where,
3110+
ProblematicTypeFinder(SourceLoc Loc, const ExportContext &Where,
31093111
DeclAvailabilityFlags Flags)
31103112
: Loc(Loc), Where(Where), Flags(Flags) {}
31113113

@@ -3179,15 +3181,16 @@ class ProblematicTypeFinder : public TypeDeclFinder {
31793181

31803182
}
31813183

3182-
void swift::diagnoseTypeAvailability(Type T, SourceLoc loc, ExportContext where,
3184+
void swift::diagnoseTypeAvailability(Type T, SourceLoc loc,
3185+
const ExportContext &where,
31833186
DeclAvailabilityFlags flags) {
31843187
if (!T)
31853188
return;
31863189
T.walk(ProblematicTypeFinder(loc, where, flags));
31873190
}
31883191

31893192
void swift::diagnoseTypeAvailability(const TypeRepr *TR, Type T, SourceLoc loc,
3190-
ExportContext where,
3193+
const ExportContext &where,
31913194
DeclAvailabilityFlags flags) {
31923195
if (diagnoseTypeReprAvailability(TR, where, flags))
31933196
return;
@@ -3197,7 +3200,7 @@ void swift::diagnoseTypeAvailability(const TypeRepr *TR, Type T, SourceLoc loc,
31973200
bool
31983201
swift::diagnoseConformanceAvailability(SourceLoc loc,
31993202
ProtocolConformanceRef conformance,
3200-
ExportContext where) {
3203+
const ExportContext &where) {
32013204
if (!conformance.isConcrete())
32023205
return false;
32033206
const ProtocolConformance *concreteConf = conformance.getConcrete();
@@ -3216,7 +3219,7 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
32163219
bool
32173220
swift::diagnoseSubstitutionMapAvailability(SourceLoc loc,
32183221
SubstitutionMap subs,
3219-
ExportContext where) {
3222+
const ExportContext &where) {
32203223
bool hadAnyIssues = false;
32213224
for (ProtocolConformanceRef conformance : subs.getConformances()) {
32223225
if (diagnoseConformanceAvailability(loc, conformance, where))

lib/Sema/TypeCheckAvailability.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,36 +193,36 @@ void diagnoseStmtAvailability(const Stmt *S, DeclContext *DC,
193193

194194
/// Diagnose uses of unavailable declarations in types.
195195
bool diagnoseTypeReprAvailability(const TypeRepr *T,
196-
ExportContext context,
196+
const ExportContext &context,
197197
DeclAvailabilityFlags flags = None);
198198

199199
/// Diagnose uses of unavailable conformances in types.
200200
void diagnoseTypeAvailability(Type T, SourceLoc loc,
201-
ExportContext context,
201+
const ExportContext &context,
202202
DeclAvailabilityFlags flags = None);
203203

204204
/// Checks both a TypeRepr and a Type, but avoids emitting duplicate
205205
/// diagnostics by only checking the Type if the TypeRepr succeeded.
206206
void diagnoseTypeAvailability(const TypeRepr *TR, Type T, SourceLoc loc,
207-
ExportContext context,
207+
const ExportContext &context,
208208
DeclAvailabilityFlags flags = None);
209209

210210
bool
211211
diagnoseConformanceAvailability(SourceLoc loc,
212212
ProtocolConformanceRef conformance,
213-
ExportContext context);
213+
const ExportContext &context);
214214

215215
bool
216216
diagnoseSubstitutionMapAvailability(SourceLoc loc,
217217
SubstitutionMap subs,
218-
ExportContext context);
218+
const ExportContext &context);
219219

220220
/// Diagnose uses of unavailable declarations. Returns true if a diagnostic
221221
/// was emitted.
222222
bool diagnoseDeclAvailability(const ValueDecl *D,
223223
SourceRange R,
224224
const ApplyExpr *call,
225-
ExportContext where,
225+
const ExportContext &where,
226226
DeclAvailabilityFlags flags = None);
227227

228228
void diagnoseUnavailableOverride(ValueDecl *override,
@@ -233,7 +233,7 @@ void diagnoseUnavailableOverride(ValueDecl *override,
233233
/// marked as unavailable, either through "unavailable" or "obsoleted:".
234234
bool diagnoseExplicitUnavailability(const ValueDecl *D,
235235
SourceRange R,
236-
ExportContext Where,
236+
const ExportContext &Where,
237237
const ApplyExpr *call,
238238
DeclAvailabilityFlags Flags = None);
239239

@@ -242,7 +242,7 @@ bool diagnoseExplicitUnavailability(const ValueDecl *D,
242242
bool diagnoseExplicitUnavailability(
243243
const ValueDecl *D,
244244
SourceRange R,
245-
ExportContext Where,
245+
const ExportContext &Where,
246246
DeclAvailabilityFlags Flags,
247247
llvm::function_ref<void(InFlightDiagnostic &)> attachRenameFixIts);
248248

lib/Sema/TypeChecker.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -952,21 +952,21 @@ Expr *buildDefaultInitializer(Type type);
952952
/// \name Resilience diagnostics
953953

954954
bool diagnoseInlinableDeclRefAccess(SourceLoc loc, const ValueDecl *D,
955-
ExportContext where);
955+
const ExportContext &where);
956956

957957
/// Given that a declaration is used from a particular context which
958958
/// exposes it in the interface of the current module, diagnose if it cannot
959959
/// reasonably be shared.
960960
bool diagnoseDeclRefExportability(SourceLoc loc,
961961
const ValueDecl *D,
962-
ExportContext where);
962+
const ExportContext &where);
963963

964964
/// Given that a conformance is used from a particular context which
965965
/// exposes it in the interface of the current module, diagnose if the
966966
/// conformance is SPI or visible via an implementation-only import.
967967
bool diagnoseConformanceExportability(SourceLoc loc,
968968
const RootProtocolConformance *rootConf,
969-
ExportContext where);
969+
const ExportContext &where);
970970

971971
/// \name Availability checking
972972
///
@@ -1010,7 +1010,7 @@ diagnosticIfDeclCannotBePotentiallyUnavailable(const Decl *D);
10101010
/// declaration is unavailable. Returns None is the declaration is
10111011
/// definitely available.
10121012
Optional<UnavailabilityReason>
1013-
checkDeclarationAvailability(const Decl *D, ExportContext where);
1013+
checkDeclarationAvailability(const Decl *D, const ExportContext &where);
10141014

10151015
/// Checks an "ignored" expression to see if it's okay for it to be ignored.
10161016
///
@@ -1045,7 +1045,7 @@ const AvailableAttr *getDeprecated(const Decl *D);
10451045
/// Callers can provide a lambda that adds additional information (such as a
10461046
/// fixit hint) to the deprecation diagnostic, if it is emitted.
10471047
void diagnoseIfDeprecated(SourceRange SourceRange,
1048-
ExportContext Where,
1048+
const ExportContext &Where,
10491049
const ValueDecl *DeprecatedDecl,
10501050
const ApplyExpr *Call);
10511051
/// @}

0 commit comments

Comments
 (0)