@@ -237,38 +237,35 @@ struct RuntimeVersionCheck {
237
237
// / information about the runtime check needed to ensure it is available to
238
238
// / \c versionCheck and returns true.
239
239
static bool
240
- checkAvailability (const EnumElementDecl *elt, ASTContext &C,
240
+ checkAvailability (const EnumElementDecl *elt, DeclContext *dc,
241
+ AvailabilityContext availabilityContext,
241
242
std::optional<RuntimeVersionCheck> &versionCheck) {
242
- auto *attr = elt->getAttrs ().getPotentiallyUnavailable (C);
243
+ auto &C = dc->getASTContext ();
244
+ auto constraint =
245
+ getUnsatisfiedAvailabilityConstraint (elt, dc, availabilityContext);
243
246
244
247
// Is it always available?
245
- if (!attr )
248
+ if (!constraint )
246
249
return true ;
247
250
248
- // For type-checking purposes, iOS availability is inherited for visionOS
249
- // targets. However, it is not inherited for the sake of code-generation
250
- // of runtime availability queries, and is assumed to be available.
251
- if ((attr->Platform == PlatformKind::iOS ||
252
- attr->Platform == PlatformKind::iOSApplicationExtension) &&
253
- C.LangOpts .Target .isXROS ())
251
+ // Some constraints are active for type checking but can't translate to
252
+ // runtime restrictions.
253
+ if (!constraint->isActiveForRuntimeQueries (C))
254
254
return true ;
255
255
256
- AvailableVersionComparison availability = attr->getVersionAvailability (C);
257
-
258
- assert (availability != AvailableVersionComparison::Available &&
259
- " DeclAttributes::getPotentiallyUnavailable() shouldn't "
260
- " return an available attribute" );
261
-
262
256
// Is it never available?
263
- if (availability != AvailableVersionComparison::PotentiallyUnavailable )
257
+ if (!constraint-> isConditionallySatisfiable () )
264
258
return false ;
265
259
266
260
// It's conditionally available; create a version constraint and return true.
267
- assert (attr->getPlatformAgnosticAvailability () ==
268
- PlatformAgnosticAvailabilityKind::None &&
269
- " can only express #available(somePlatform version) checks" );
270
- versionCheck.emplace (attr->Platform , *attr->Introduced );
261
+ auto platform = constraint->getPlatform ();
262
+ auto range = constraint->getRequiredNewerAvailabilityRange (C);
263
+
264
+ // Only platform version constraints are supported currently.
265
+ ASSERT (platform != PlatformKind::none);
266
+ ASSERT (range);
271
267
268
+ versionCheck.emplace (platform, range->getRawMinimumVersion ());
272
269
return true ;
273
270
}
274
271
@@ -295,6 +292,7 @@ deriveBodyRawRepresentable_init(AbstractFunctionDecl *initDecl, void *) {
295
292
296
293
auto parentDC = initDecl->getDeclContext ();
297
294
ASTContext &C = parentDC->getASTContext ();
295
+ auto availabilityContext = AvailabilityContext::forDeploymentTarget (C);
298
296
299
297
auto nominalTypeDecl = parentDC->getSelfNominalTypeDecl ();
300
298
auto enumDecl = cast<EnumDecl>(nominalTypeDecl);
@@ -318,7 +316,7 @@ deriveBodyRawRepresentable_init(AbstractFunctionDecl *initDecl, void *) {
318
316
// information about that check in versionCheck and keep processing this
319
317
// element.
320
318
std::optional<RuntimeVersionCheck> versionCheck (std::nullopt );
321
- if (!checkAvailability (elt, C , versionCheck))
319
+ if (!checkAvailability (elt, parentDC, availabilityContext , versionCheck))
322
320
continue ;
323
321
324
322
// litPat = elt.rawValueExpr as a pattern
0 commit comments