@@ -40,6 +40,8 @@ namespace swift {
4040 class TupleTypeRepr ;
4141 class TypeDecl ;
4242
43+ enum class ParamSpecifier : uint8_t ;
44+
4345enum class TypeReprKind : uint8_t {
4446#define TYPEREPR (ID, PARENT ) ID,
4547#define LAST_TYPEREPR (ID ) Last_TypeRepr = ID,
@@ -1062,9 +1064,7 @@ class SpecifierTypeRepr : public TypeRepr {
10621064 SourceLoc getSpecifierLoc () const { return SpecifierLoc; }
10631065
10641066 static bool classof (const TypeRepr *T) {
1065- return T->getKind () == TypeReprKind::InOut ||
1066- T->getKind () == TypeReprKind::Shared ||
1067- T->getKind () == TypeReprKind::Owned ||
1067+ return T->getKind () == TypeReprKind::Ownership ||
10681068 T->getKind () == TypeReprKind::Isolated ||
10691069 T->getKind () == TypeReprKind::CompileTimeConst;
10701070 }
@@ -1077,71 +1077,36 @@ class SpecifierTypeRepr : public TypeRepr {
10771077 friend class TypeRepr ;
10781078};
10791079
1080- // This repr holds types that are associated with some ownership specifier
1081- // like 'inout', '__shared', etc. It's a simple grouping of those specifiers.
1082- class OwnershipTypeRepr : public SpecifierTypeRepr {
1083- public:
1084- OwnershipTypeRepr (TypeReprKind Kind, TypeRepr *Base, SourceLoc OwnershipLoc)
1085- : SpecifierTypeRepr(Kind, Base, OwnershipLoc) {
1086- assert (OwnershipTypeRepr::classof (cast<TypeRepr>(this )));
1087- }
1088-
1089- static bool classof (const TypeRepr *T) {
1090- return T->getKind () == TypeReprKind::InOut ||
1091- T->getKind () == TypeReprKind::Shared ||
1092- T->getKind () == TypeReprKind::Owned;
1093- }
1094- static bool classof (const OwnershipTypeRepr *T) { return true ; }
1095- friend class SpecifierTypeRepr ;
1096- };
1097-
1098- // / An 'inout' type.
1080+ // / A parameter type with an ownership specifier, such as `inout`, `borrowing`,
1081+ // / or `consuming`.
10991082// / \code
11001083// / x : inout Int
1084+ // / y : consuming Int
1085+ // / z : borrowing Int
11011086// / \endcode
1102- class InOutTypeRepr : public OwnershipTypeRepr {
1087+
1088+ class OwnershipTypeRepr : public SpecifierTypeRepr {
1089+ ParamSpecifier Specifier;
11031090public:
1104- InOutTypeRepr (TypeRepr *Base, SourceLoc InOutLoc)
1105- : OwnershipTypeRepr(TypeReprKind::InOut, Base, InOutLoc) {}
1091+ OwnershipTypeRepr (TypeRepr *Base, ParamSpecifier Specifier,
1092+ SourceLoc ModifierLoc)
1093+ : SpecifierTypeRepr(TypeReprKind::Ownership, Base, ModifierLoc),
1094+ Specifier (Specifier) {}
11061095
1107- static bool classof (const TypeRepr *T) {
1108- return T->getKind () == TypeReprKind::InOut;
1109- }
1110- static bool classof (const InOutTypeRepr *T) { return true ; }
1111- };
1096+ ParamSpecifier getSpecifier () const { return Specifier; }
11121097
1113- // / A 'borrowing' parameter type.
1114- // / \code
1115- // / x : borrowing Int
1116- // / \endcode
1117- // / Historically, this attribute was spelled '__shared'.
1118- class SharedTypeRepr : public OwnershipTypeRepr {
1119- public:
1120- SharedTypeRepr (TypeRepr *Base, SourceLoc SharedLoc)
1121- : OwnershipTypeRepr(TypeReprKind::Shared, Base, SharedLoc) {}
1122-
1123- static bool classof (const TypeRepr *T) {
1124- return T->getKind () == TypeReprKind::Shared;
1125- }
1126- static bool classof (const SharedTypeRepr *T) { return true ; }
1127- };
1128-
1129- // / A 'consuming' parameter type.
1130- // / \code
1131- // / x : consuming Int
1132- // / \endcode
1133- // / Historically, this attribute was spelled '__owned'.
1134- class OwnedTypeRepr : public OwnershipTypeRepr {
1135- public:
1136- OwnedTypeRepr (TypeRepr *Base, SourceLoc OwnedLoc)
1137- : OwnershipTypeRepr(TypeReprKind::Owned, Base, OwnedLoc) {}
1098+ // / Return the \c ValueOwnership kind that corresponds to the specifier.
1099+ ValueOwnership getValueOwnership () const ;
1100+
1101+ // / Return the spelling of the ownership specifier as a string.
1102+ StringRef getSpecifierSpelling () const ;
11381103
11391104 static bool classof (const TypeRepr *T) {
1140- return T->getKind () == TypeReprKind::Owned ;
1105+ return T->getKind () == TypeReprKind::Ownership ;
11411106 }
1142- static bool classof (const OwnedTypeRepr *T) { return true ; }
1107+ static bool classof (const OwnershipTypeRepr *T) { return true ; }
11431108};
1144-
1109+
11451110// / An 'isolated' type.
11461111// / \code
11471112// / x : isolated Actor
@@ -1449,7 +1414,7 @@ inline bool TypeRepr::isSimple() const {
14491414 case TypeReprKind::Attributed:
14501415 case TypeReprKind::Error:
14511416 case TypeReprKind::Function:
1452- case TypeReprKind::InOut :
1417+ case TypeReprKind::Ownership :
14531418 case TypeReprKind::Composition:
14541419 case TypeReprKind::OpaqueReturn:
14551420 case TypeReprKind::NamedOpaqueReturn:
@@ -1471,8 +1436,6 @@ inline bool TypeRepr::isSimple() const {
14711436 case TypeReprKind::Fixed:
14721437 case TypeReprKind::Array:
14731438 case TypeReprKind::SILBox:
1474- case TypeReprKind::Shared:
1475- case TypeReprKind::Owned:
14761439 case TypeReprKind::Isolated:
14771440 case TypeReprKind::Placeholder:
14781441 case TypeReprKind::CompileTimeConst:
0 commit comments