|
22 | 22 | #include "swift/AST/DiagnosticEngine.h"
|
23 | 23 | #include "swift/AST/GenericSignature.h"
|
24 | 24 | #include "swift/AST/Identifier.h"
|
| 25 | +#include "swift/AST/LifetimeDependence.h" |
25 | 26 | #include "swift/AST/Type.h"
|
26 | 27 | #include "swift/AST/TypeAlignments.h"
|
| 28 | +#include "swift/Basic/Debug.h" |
| 29 | +#include "swift/Basic/InlineBitfield.h" |
| 30 | +#include "swift/Basic/Located.h" |
27 | 31 | #include "llvm/ADT/ArrayRef.h"
|
28 | 32 | #include "llvm/ADT/PointerUnion.h"
|
29 | 33 | #include "llvm/ADT/STLExtras.h"
|
30 |
| -#include "swift/Basic/Debug.h" |
31 |
| -#include "swift/Basic/Located.h" |
32 |
| -#include "swift/Basic/InlineBitfield.h" |
33 | 34 | #include "llvm/Support/ErrorHandling.h"
|
34 | 35 | #include "llvm/Support/TrailingObjects.h"
|
35 | 36 |
|
@@ -109,6 +110,10 @@ class alignas(1 << TypeReprAlignInBits) TypeRepr
|
109 | 110 | NumElements : 32
|
110 | 111 | );
|
111 | 112 |
|
| 113 | + SWIFT_INLINE_BITFIELD_FULL(LifetimeDependentReturnTypeRepr, TypeRepr, 32, |
| 114 | + : NumPadBits, |
| 115 | + NumDependencies : 32 |
| 116 | + ); |
112 | 117 | } Bits;
|
113 | 118 | // clang-format on
|
114 | 119 |
|
@@ -1093,7 +1098,8 @@ class SpecifierTypeRepr : public TypeRepr {
|
1093 | 1098 | return T->getKind() == TypeReprKind::Ownership ||
|
1094 | 1099 | T->getKind() == TypeReprKind::Isolated ||
|
1095 | 1100 | T->getKind() == TypeReprKind::CompileTimeConst ||
|
1096 |
| - T->getKind() == TypeReprKind::ResultDependsOn; |
| 1101 | + T->getKind() == TypeReprKind::ResultDependsOn || |
| 1102 | + T->getKind() == TypeReprKind::LifetimeDependentReturn; |
1097 | 1103 | }
|
1098 | 1104 | static bool classof(const SpecifierTypeRepr *T) { return true; }
|
1099 | 1105 |
|
@@ -1505,6 +1511,50 @@ class SILBoxTypeRepr final : public TypeRepr,
|
1505 | 1511 | friend TypeRepr;
|
1506 | 1512 | };
|
1507 | 1513 |
|
| 1514 | +class LifetimeDependentReturnTypeRepr final |
| 1515 | + : public SpecifierTypeRepr, |
| 1516 | + private llvm::TrailingObjects<LifetimeDependentReturnTypeRepr, |
| 1517 | + LifetimeDependenceSpecifier> { |
| 1518 | + friend TrailingObjects; |
| 1519 | + |
| 1520 | + size_t |
| 1521 | + numTrailingObjects(OverloadToken<LifetimeDependentReturnTypeRepr>) const { |
| 1522 | + return Bits.LifetimeDependentReturnTypeRepr.NumDependencies; |
| 1523 | + } |
| 1524 | + |
| 1525 | +public: |
| 1526 | + LifetimeDependentReturnTypeRepr( |
| 1527 | + TypeRepr *base, ArrayRef<LifetimeDependenceSpecifier> specifiers) |
| 1528 | + : SpecifierTypeRepr(TypeReprKind::LifetimeDependentReturn, base, |
| 1529 | + specifiers.front().getLoc()) { |
| 1530 | + assert(base); |
| 1531 | + Bits.LifetimeDependentReturnTypeRepr.NumDependencies = specifiers.size(); |
| 1532 | + std::uninitialized_copy(specifiers.begin(), specifiers.end(), |
| 1533 | + getTrailingObjects<LifetimeDependenceSpecifier>()); |
| 1534 | + } |
| 1535 | + |
| 1536 | + static LifetimeDependentReturnTypeRepr * |
| 1537 | + create(ASTContext &C, TypeRepr *base, |
| 1538 | + ArrayRef<LifetimeDependenceSpecifier> specifiers); |
| 1539 | + |
| 1540 | + ArrayRef<LifetimeDependenceSpecifier> getLifetimeDependencies() const { |
| 1541 | + return {getTrailingObjects<LifetimeDependenceSpecifier>(), |
| 1542 | + Bits.LifetimeDependentReturnTypeRepr.NumDependencies}; |
| 1543 | + } |
| 1544 | + |
| 1545 | + static bool classof(const TypeRepr *T) { |
| 1546 | + return T->getKind() == TypeReprKind::LifetimeDependentReturn; |
| 1547 | + } |
| 1548 | + static bool classof(const LifetimeDependentReturnTypeRepr *T) { return true; } |
| 1549 | + |
| 1550 | +private: |
| 1551 | + SourceLoc getStartLocImpl() const; |
| 1552 | + SourceLoc getEndLocImpl() const; |
| 1553 | + SourceLoc getLocImpl() const; |
| 1554 | + void printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const; |
| 1555 | + friend class TypeRepr; |
| 1556 | +}; |
| 1557 | + |
1508 | 1558 | inline bool TypeRepr::isSimple() const {
|
1509 | 1559 | // NOTE: Please keep this logic in sync with TypeBase::hasSimpleTypeRepr().
|
1510 | 1560 | switch (getKind()) {
|
@@ -1539,6 +1589,7 @@ inline bool TypeRepr::isSimple() const {
|
1539 | 1589 | case TypeReprKind::Placeholder:
|
1540 | 1590 | case TypeReprKind::CompileTimeConst:
|
1541 | 1591 | case TypeReprKind::ResultDependsOn:
|
| 1592 | + case TypeReprKind::LifetimeDependentReturn: |
1542 | 1593 | return true;
|
1543 | 1594 | }
|
1544 | 1595 | llvm_unreachable("bad TypeRepr kind");
|
|
0 commit comments