|
19 | 19 | #include "swift/AST/ASTMangler.h"
|
20 | 20 | #include "swift/AST/ASTVisitor.h"
|
21 | 21 | #include "swift/AST/Attr.h"
|
| 22 | +#include "swift/AST/Builtins.h" |
22 | 23 | #include "swift/AST/ClangModuleLoader.h"
|
23 | 24 | #include "swift/AST/Comment.h"
|
24 | 25 | #include "swift/AST/Decl.h"
|
@@ -2511,6 +2512,100 @@ static bool usesFeatureConcurrentFunctions(Decl *decl) {
|
2511 | 2512 | return false;
|
2512 | 2513 | }
|
2513 | 2514 |
|
| 2515 | +static bool usesFeatureRethrowsProtocol( |
| 2516 | + Decl *decl, SmallPtrSet<Decl *, 16> &checked) { |
| 2517 | + // Make sure we don't recurse. |
| 2518 | + if (!checked.insert(decl).second) |
| 2519 | + return false; |
| 2520 | + |
| 2521 | + if (auto proto = dyn_cast<ProtocolDecl>(decl)) { |
| 2522 | + if (proto->getAttrs().hasAttribute<AtRethrowsAttr>()) |
| 2523 | + return true; |
| 2524 | + } |
| 2525 | + |
| 2526 | + if (auto ext = dyn_cast<ExtensionDecl>(decl)) { |
| 2527 | + if (auto proto = ext->getSelfProtocolDecl()) |
| 2528 | + if (usesFeatureRethrowsProtocol(proto, checked)) |
| 2529 | + return true; |
| 2530 | + } |
| 2531 | + |
| 2532 | + if (auto genericSig = decl->getInnermostDeclContext() |
| 2533 | + ->getGenericSignatureOfContext()) { |
| 2534 | + for (const auto &req : genericSig->getRequirements()) { |
| 2535 | + if (req.getKind() == RequirementKind::Conformance && |
| 2536 | + usesFeatureRethrowsProtocol( |
| 2537 | + req.getSecondType()->getAs<ProtocolType>()->getDecl(), checked)) |
| 2538 | + return true; |
| 2539 | + } |
| 2540 | + } |
| 2541 | + |
| 2542 | + if (auto value = dyn_cast<ValueDecl>(decl)) { |
| 2543 | + if (Type type = value->getInterfaceType()) { |
| 2544 | + bool hasRethrowsProtocol = type.findIf([&](Type type) { |
| 2545 | + if (auto nominal = type->getAnyNominal()) { |
| 2546 | + if (usesFeatureRethrowsProtocol(nominal, checked)) |
| 2547 | + return true; |
| 2548 | + } |
| 2549 | + |
| 2550 | + return false; |
| 2551 | + }); |
| 2552 | + |
| 2553 | + if (hasRethrowsProtocol) |
| 2554 | + return true; |
| 2555 | + } |
| 2556 | + } |
| 2557 | + |
| 2558 | + return false; |
| 2559 | +} |
| 2560 | + |
| 2561 | +static bool usesFeatureRethrowsProtocol(Decl *decl) { |
| 2562 | + SmallPtrSet<Decl *, 16> checked; |
| 2563 | + return usesFeatureRethrowsProtocol(decl, checked); |
| 2564 | +} |
| 2565 | + |
| 2566 | +static bool usesFeatureGlobalActors(Decl *decl) { |
| 2567 | + if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) { |
| 2568 | + if (nominal->getAttrs().hasAttribute<GlobalActorAttr>()) |
| 2569 | + return true; |
| 2570 | + } |
| 2571 | + |
| 2572 | + if (auto ext = dyn_cast<ExtensionDecl>(decl)) { |
| 2573 | + if (auto nominal = ext->getExtendedNominal()) |
| 2574 | + if (usesFeatureGlobalActors(nominal)) |
| 2575 | + return true; |
| 2576 | + } |
| 2577 | + |
| 2578 | + return false; |
| 2579 | +} |
| 2580 | + |
| 2581 | +static bool usesFeatureBuiltinJob(Decl *decl) { |
| 2582 | + auto typeHasBuiltinJob = [](Type type) { |
| 2583 | + return type.findIf([&](Type type) { |
| 2584 | + if (auto builtinTy = type->getAs<BuiltinType>()) |
| 2585 | + return builtinTy->getBuiltinTypeKind() == BuiltinTypeKind::BuiltinJob; |
| 2586 | + |
| 2587 | + return false; |
| 2588 | + }); |
| 2589 | + }; |
| 2590 | + |
| 2591 | + if (auto value = dyn_cast<ValueDecl>(decl)) { |
| 2592 | + if (Type type = value->getInterfaceType()) { |
| 2593 | + if (typeHasBuiltinJob(type)) |
| 2594 | + return true; |
| 2595 | + } |
| 2596 | + } |
| 2597 | + |
| 2598 | + if (auto patternBinding = dyn_cast<PatternBindingDecl>(decl)) { |
| 2599 | + for (unsigned idx : range(patternBinding->getNumPatternEntries())) { |
| 2600 | + if (Type type = patternBinding->getPattern(idx)->getType()) |
| 2601 | + if (typeHasBuiltinJob(type)) |
| 2602 | + return true; |
| 2603 | + } |
| 2604 | + } |
| 2605 | + |
| 2606 | + return false; |
| 2607 | +} |
| 2608 | + |
2514 | 2609 | /// Determine the set of "new" features used on a given declaration.
|
2515 | 2610 | ///
|
2516 | 2611 | /// Note: right now, all features we check for are "new". At some point, we'll
|
|
0 commit comments