@@ -323,9 +323,18 @@ static bool usesFeatureAllowUnsafeAttribute(Decl *decl) {
323323 return decl->getAttrs ().hasAttribute <UnsafeAttr>();
324324}
325325
326+ static ABIAttr *getABIAttr (Decl *decl) {
327+ if (auto pbd = dyn_cast<PatternBindingDecl>(decl))
328+ for (auto i : range (pbd->getNumPatternEntries ()))
329+ if (auto anchorVar = pbd->getAnchoringVarDecl (i))
330+ return getABIAttr (anchorVar);
331+ // FIXME: EnumCaseDecl/EnumElementDecl
332+
333+ return decl->getAttrs ().getAttribute <ABIAttr>();
334+ }
335+
326336static bool usesFeatureABIAttribute (Decl *decl) {
327- auto abiAttr = decl->getAttrs ().getAttribute <ABIAttr>();
328- return abiAttr && !abiAttr->isInverse ();
337+ return getABIAttr (decl) != nullptr ;
329338}
330339
331340UNINTERESTING_FEATURE (WarnUnsafe)
@@ -430,26 +439,38 @@ static bool allowFeatureSuppression(StringRef featureName, Decl *decl) {
430439// / Go through all the features used by the given declaration and
431440// / either add or remove them to this set.
432441void FeatureSet::collectFeaturesUsed (Decl *decl, InsertOrRemove operation) {
442+ // Count feature usage in an ABI decl as feature usage by the API, not itself,
443+ // since we can't use `#if` inside an @abi attribute.
444+ Decl *abiDecl = nullptr ;
445+ if (auto abiAttr = getABIAttr (decl)) {
446+ abiDecl = abiAttr->abiDecl ;
447+ }
448+
449+ #define CHECK (Function ) (Function(decl) || (abiDecl && Function(abiDecl)))
450+ #define CHECK_ARG (Function, Arg ) (Function(Arg, decl) || (abiDecl && Function(Arg, abiDecl)))
451+
433452 // Go through each of the features, checking whether the
434453 // declaration uses that feature.
435454#define LANGUAGE_FEATURE (FeatureName, SENumber, Description ) \
436- if (usesFeature##FeatureName (decl)) \
455+ if (CHECK ( usesFeature##FeatureName)) \
437456 collectRequiredFeature (Feature::FeatureName, operation);
438457#define SUPPRESSIBLE_LANGUAGE_FEATURE (FeatureName, SENumber, Description ) \
439- if (usesFeature##FeatureName (decl )) { \
440- if (disallowFeatureSuppression (#FeatureName, decl)) \
458+ if (CHECK ( usesFeature##FeatureName)) { \
459+ if (CHECK_ARG (disallowFeatureSuppression, #FeatureName)) \
441460 collectRequiredFeature (Feature::FeatureName, operation); \
442461 else \
443462 collectSuppressibleFeature (Feature::FeatureName, operation); \
444463 }
445464#define CONDITIONALLY_SUPPRESSIBLE_LANGUAGE_FEATURE (FeatureName, SENumber, Description ) \
446- if (usesFeature##FeatureName (decl )) { \
447- if (allowFeatureSuppression (#FeatureName, decl)) \
465+ if (CHECK ( usesFeature##FeatureName)) { \
466+ if (CHECK_ARG (allowFeatureSuppression, #FeatureName)) \
448467 collectSuppressibleFeature (Feature::FeatureName, operation); \
449468 else \
450469 collectRequiredFeature (Feature::FeatureName, operation); \
451470 }
452471#include " swift/Basic/Features.def"
472+ #undef CHECK
473+ #undef CHECK_ARG
453474}
454475
455476FeatureSet swift::getUniqueFeaturesUsed (Decl *decl) {
0 commit comments