@@ -47,23 +47,13 @@ using namespace swift;
47
47
static const Decl *
48
48
concreteSyntaxDeclForAvailableAttribute (const Decl *AbstractSyntaxDecl);
49
49
50
- ExportContext::ExportContext (
51
- DeclContext *DC, AvailabilityRange runningOSVersion,
52
- FragileFunctionKind kind, bool spi, bool exported, bool implicit,
53
- bool deprecated, std::optional<PlatformKind> unavailablePlatformKind)
54
- : DC(DC), RunningOSVersion(runningOSVersion), FragileKind(kind) {
50
+ ExportContext::ExportContext (DeclContext *DC, AvailabilityContext availability,
51
+ FragileFunctionKind kind, bool spi, bool exported,
52
+ bool implicit)
53
+ : DC(DC), Availability(availability), FragileKind(kind) {
55
54
SPI = spi;
56
55
Exported = exported;
57
56
Implicit = implicit;
58
- Deprecated = deprecated;
59
- if (unavailablePlatformKind) {
60
- Unavailable = 1 ;
61
- Platform = unsigned (*unavailablePlatformKind);
62
- } else {
63
- Unavailable = 0 ;
64
- Platform = 0 ;
65
- }
66
-
67
57
Reason = unsigned (ExportabilityReason::General);
68
58
}
69
59
@@ -196,10 +186,8 @@ static void forEachOuterDecl(DeclContext *DC, Fn fn) {
196
186
}
197
187
}
198
188
199
- static void
200
- computeExportContextBits (ASTContext &Ctx, Decl *D, bool *spi, bool *implicit,
201
- bool *deprecated,
202
- std::optional<PlatformKind> *unavailablePlatformKind) {
189
+ static void computeExportContextBits (ASTContext &Ctx, Decl *D, bool *spi,
190
+ bool *implicit) {
203
191
if (D->isSPI () ||
204
192
D->isAvailableAsSPI ())
205
193
*spi = true ;
@@ -211,18 +199,10 @@ computeExportContextBits(ASTContext &Ctx, Decl *D, bool *spi, bool *implicit,
211
199
if (D->isImplicit () && !isDeferBody)
212
200
*implicit = true ;
213
201
214
- if (D->getAttrs ().isDeprecated (Ctx))
215
- *deprecated = true ;
216
-
217
- if (auto *A = D->getAttrs ().getUnavailable (Ctx)) {
218
- *unavailablePlatformKind = A->Platform ;
219
- }
220
-
221
202
if (auto *PBD = dyn_cast<PatternBindingDecl>(D)) {
222
203
for (unsigned i = 0 , e = PBD->getNumPatternEntries (); i < e; ++i) {
223
204
if (auto *VD = PBD->getAnchoringVarDecl (i))
224
- computeExportContextBits (Ctx, VD, spi, implicit, deprecated,
225
- unavailablePlatformKind);
205
+ computeExportContextBits (Ctx, VD, spi, implicit);
226
206
}
227
207
}
228
208
}
@@ -232,56 +212,40 @@ ExportContext ExportContext::forDeclSignature(Decl *D) {
232
212
233
213
auto *DC = D->getInnermostDeclContext ();
234
214
auto fragileKind = DC->getFragileFunctionKind ();
235
- auto runningOSVersion =
215
+ auto availabilityContext =
236
216
(Ctx.LangOpts .DisableAvailabilityChecking
237
- ? AvailabilityRange::alwaysAvailable ()
238
- : TypeChecker::overApproximateAvailabilityAtLocation (D->getLoc (),
239
- DC));
217
+ ? AvailabilityContext::getDefault (Ctx)
218
+ : TypeChecker::availabilityAtLocation (D->getLoc (), DC));
240
219
bool spi = Ctx.LangOpts .LibraryLevel == LibraryLevel::SPI;
241
220
bool implicit = false ;
242
- bool deprecated = false ;
243
- std::optional<PlatformKind> unavailablePlatformKind;
244
- computeExportContextBits (Ctx, D, &spi, &implicit, &deprecated,
245
- &unavailablePlatformKind);
246
- forEachOuterDecl (D->getDeclContext (),
247
- [&](Decl *D) {
248
- computeExportContextBits (Ctx, D,
249
- &spi, &implicit, &deprecated,
250
- &unavailablePlatformKind);
251
- });
221
+ computeExportContextBits (Ctx, D, &spi, &implicit);
222
+ forEachOuterDecl (D->getDeclContext (), [&](Decl *D) {
223
+ computeExportContextBits (Ctx, D, &spi, &implicit);
224
+ });
252
225
253
226
bool exported = ::isExported (D);
254
227
255
- return ExportContext (DC, runningOSVersion, fragileKind,
256
- spi, exported, implicit, deprecated,
257
- unavailablePlatformKind);
228
+ return ExportContext (DC, availabilityContext, fragileKind, spi, exported,
229
+ implicit);
258
230
}
259
231
260
232
ExportContext ExportContext::forFunctionBody (DeclContext *DC, SourceLoc loc) {
261
233
auto &Ctx = DC->getASTContext ();
262
234
263
235
auto fragileKind = DC->getFragileFunctionKind ();
264
- auto runningOSVersion =
236
+ auto availabilityContext =
265
237
(Ctx.LangOpts .DisableAvailabilityChecking
266
- ? AvailabilityRange::alwaysAvailable ()
267
- : TypeChecker::overApproximateAvailabilityAtLocation (loc, DC));
268
-
238
+ ? AvailabilityContext::getDefault (Ctx)
239
+ : TypeChecker::availabilityAtLocation (loc, DC));
269
240
bool spi = Ctx.LangOpts .LibraryLevel == LibraryLevel::SPI;
270
241
bool implicit = false ;
271
- bool deprecated = false ;
272
- std::optional<PlatformKind> unavailablePlatformKind;
273
- forEachOuterDecl (DC,
274
- [&](Decl *D) {
275
- computeExportContextBits (Ctx, D,
276
- &spi, &implicit, &deprecated,
277
- &unavailablePlatformKind);
278
- });
242
+ forEachOuterDecl (
243
+ DC, [&](Decl *D) { computeExportContextBits (Ctx, D, &spi, &implicit); });
279
244
280
245
bool exported = false ;
281
246
282
- return ExportContext (DC, runningOSVersion, fragileKind,
283
- spi, exported, implicit, deprecated,
284
- unavailablePlatformKind);
247
+ return ExportContext (DC, availabilityContext, fragileKind, spi, exported,
248
+ implicit);
285
249
}
286
250
287
251
ExportContext ExportContext::forConformance (DeclContext *DC,
@@ -310,16 +274,11 @@ ExportContext ExportContext::withExported(bool exported) const {
310
274
ExportContext ExportContext::withRefinedAvailability (
311
275
const AvailabilityRange &availability) const {
312
276
auto copy = *this ;
313
- copy.RunningOSVersion .intersectWith (availability);
277
+ copy.Availability .constrainWithPlatformRange (availability,
278
+ DC->getASTContext ());
314
279
return copy;
315
280
}
316
281
317
- std::optional<PlatformKind> ExportContext::getUnavailablePlatformKind () const {
318
- if (Unavailable)
319
- return PlatformKind (Platform);
320
- return std::nullopt;
321
- }
322
-
323
282
bool ExportContext::mustOnlyReferenceExportedDecls () const {
324
283
return Exported || FragileKind.kind != FragileFunctionKind::None;
325
284
}
0 commit comments