|
11 | 11 | //===----------------------------------------------------------------------===// |
12 | 12 |
|
13 | 13 | #include "swift/Basic/BridgingUtils.h" |
| 14 | +#include "swift/AST/Attr.h" |
| 15 | +#include "swift/AST/SemanticAttrs.h" |
14 | 16 | #include "swift/SIL/SILNode.h" |
15 | 17 | #include "swift/SIL/ApplySite.h" |
16 | 18 | #include "swift/SIL/SILBridgingUtils.h" |
@@ -587,6 +589,48 @@ bool SILType_isCalleeConsumedFunction(BridgedType type) { |
587 | 589 | return funcTy->isCalleeConsumed() && !funcTy->isNoEscape(); |
588 | 590 | } |
589 | 591 |
|
| 592 | +static bool hasImmortalAttr(NominalTypeDecl *nominal) { |
| 593 | + if (auto *semAttr = nominal->getAttrs().getAttribute<SemanticsAttr>()) { |
| 594 | + if (semAttr->Value == semantics::ARC_IMMORTAL) { |
| 595 | + return true; |
| 596 | + } |
| 597 | + } |
| 598 | + return false; |
| 599 | +} |
| 600 | + |
| 601 | +static bool isMarkedAsImmortal(NominalTypeDecl *nominal) { |
| 602 | + if (hasImmortalAttr(nominal)) |
| 603 | + return true; |
| 604 | + |
| 605 | + if (!isa<ProtocolDecl>(nominal)) { |
| 606 | + for (ProtocolDecl *p : nominal->getAllProtocols()) { |
| 607 | + if (hasImmortalAttr(p)) |
| 608 | + return true; |
| 609 | + } |
| 610 | + } |
| 611 | + return false; |
| 612 | +} |
| 613 | + |
| 614 | +bool SILType_isMarkedAsImmortal(BridgedType type) { |
| 615 | + SILType ty = castToSILType(type); |
| 616 | + NominalTypeDecl *nominal = ty.getNominalOrBoundGenericNominal(); |
| 617 | + if (!nominal) |
| 618 | + return false; |
| 619 | + |
| 620 | + if (isMarkedAsImmortal(nominal)) |
| 621 | + return true; |
| 622 | + |
| 623 | + if (ClassDecl *cl = dyn_cast<ClassDecl>(nominal)) { |
| 624 | + cl = cl->getSuperclassDecl(); |
| 625 | + while (cl) { |
| 626 | + if (isMarkedAsImmortal(cl)) |
| 627 | + return true; |
| 628 | + cl = cl->getSuperclassDecl(); |
| 629 | + } |
| 630 | + } |
| 631 | + return false; |
| 632 | +} |
| 633 | + |
590 | 634 | SwiftInt SILType_getNumTupleElements(BridgedType type) { |
591 | 635 | TupleType *tupleTy = castToSILType(type).castTo<TupleType>(); |
592 | 636 | return tupleTy->getNumElements(); |
|
0 commit comments