@@ -72,6 +72,7 @@ class InOutType;
7272class OpaqueTypeDecl ;
7373class OpenedArchetypeType ;
7474class PackType ;
75+ enum class ParamSpecifier : uint8_t ;
7576class PlaceholderTypeRepr ;
7677enum class ReferenceCounting : uint8_t ;
7778enum class ResilienceExpansion : unsigned ;
@@ -2069,6 +2070,29 @@ class TypeAliasType final
20692070 }
20702071};
20712072
2073+ // / The various spellings of ownership modifier that can be used in source.
2074+ enum class ParamSpecifier : uint8_t {
2075+ // / No explicit ownership specifier was provided. The parameter will use the
2076+ // / default ownership convention for the declaration.
2077+ Default = 0 ,
2078+
2079+ // / `inout`, indicating exclusive mutable access to the argument for the
2080+ // / duration of a call.
2081+ InOut = 1 ,
2082+
2083+ // / `borrowing`, indicating nonexclusive access to the argument for the
2084+ // / duration of a call.
2085+ Borrowing = 2 ,
2086+ // / `consuming`, indicating ownership transfer of the argument from caller
2087+ // / to callee.
2088+ Consuming = 3 ,
2089+
2090+ // / `__shared`, a legacy spelling of `borrowing`.
2091+ LegacyShared = 4 ,
2092+ // / `__owned`, a legacy spelling of `consuming`.
2093+ LegacyOwned = 5 ,
2094+ };
2095+
20722096// / Provide parameter type relevant flags, i.e. variadic, autoclosure, and
20732097// / escaping.
20742098class ParameterTypeFlags {
@@ -2077,8 +2101,8 @@ class ParameterTypeFlags {
20772101 Variadic = 1 << 0 ,
20782102 AutoClosure = 1 << 1 ,
20792103 NonEphemeral = 1 << 2 ,
2080- OwnershipShift = 3 ,
2081- Ownership = 7 << OwnershipShift ,
2104+ SpecifierShift = 3 ,
2105+ Specifier = 7 << SpecifierShift ,
20822106 NoDerivative = 1 << 6 ,
20832107 Isolated = 1 << 7 ,
20842108 CompileTimeConst = 1 << 8 ,
@@ -2096,19 +2120,19 @@ class ParameterTypeFlags {
20962120 }
20972121
20982122 ParameterTypeFlags (bool variadic, bool autoclosure, bool nonEphemeral,
2099- ValueOwnership ownership , bool isolated, bool noDerivative,
2123+ ParamSpecifier specifier , bool isolated, bool noDerivative,
21002124 bool compileTimeConst)
21012125 : value((variadic ? Variadic : 0 ) | (autoclosure ? AutoClosure : 0 ) |
21022126 (nonEphemeral ? NonEphemeral : 0 ) |
2103- uint8_t (ownership ) << OwnershipShift |
2127+ uint8_t (specifier ) << SpecifierShift |
21042128 (isolated ? Isolated : 0 ) |
21052129 (noDerivative ? NoDerivative : 0 ) |
21062130 (compileTimeConst ? CompileTimeConst : 0 )){}
21072131
21082132 // / Create one from what's present in the parameter type
21092133 inline static ParameterTypeFlags
21102134 fromParameterType (Type paramTy, bool isVariadic, bool isAutoClosure,
2111- bool isNonEphemeral, ValueOwnership ownership,
2135+ bool isNonEphemeral, ParamSpecifier ownership,
21122136 bool isolated, bool isNoDerivative,
21132137 bool compileTimeConst);
21142138
@@ -2123,18 +2147,21 @@ class ParameterTypeFlags {
21232147 bool isCompileTimeConst () const { return value.contains (CompileTimeConst); }
21242148 bool isNoDerivative () const { return value.contains (NoDerivative); }
21252149
2126- ValueOwnership getValueOwnership () const {
2127- return ValueOwnership ((value.toRaw () & Ownership) >> OwnershipShift);
2150+ // / Get the spelling of the parameter specifier used on the parameter.
2151+ ParamSpecifier getOwnershipSpecifier () const {
2152+ return ParamSpecifier ((value.toRaw () & Specifier) >> SpecifierShift);
21282153 }
21292154
2155+ ValueOwnership getValueOwnership () const ;
2156+
21302157 ParameterTypeFlags withVariadic (bool variadic) const {
21312158 return ParameterTypeFlags (variadic ? value | ParameterTypeFlags::Variadic
21322159 : value - ParameterTypeFlags::Variadic);
21332160 }
21342161
21352162 ParameterTypeFlags withInOut (bool isInout) const {
2136- return withValueOwnership (isInout ? ValueOwnership ::InOut
2137- : ValueOwnership ::Default);
2163+ return withOwnershipSpecifier (isInout ? ParamSpecifier ::InOut
2164+ : ParamSpecifier ::Default);
21382165 }
21392166
21402167 ParameterTypeFlags withCompileTimeConst (bool isConst) const {
@@ -2143,18 +2170,18 @@ class ParameterTypeFlags {
21432170 }
21442171
21452172 ParameterTypeFlags withShared (bool isShared) const {
2146- return withValueOwnership (isShared ? ValueOwnership::Shared
2147- : ValueOwnership ::Default);
2173+ return withOwnershipSpecifier (isShared ? ParamSpecifier::LegacyShared
2174+ : ParamSpecifier ::Default);
21482175 }
21492176
21502177 ParameterTypeFlags withOwned (bool isOwned) const {
2151- return withValueOwnership (isOwned ? ValueOwnership::Owned
2152- : ValueOwnership ::Default);
2178+ return withOwnershipSpecifier (isOwned ? ParamSpecifier::LegacyOwned
2179+ : ParamSpecifier ::Default);
21532180 }
21542181
2155- ParameterTypeFlags withValueOwnership (ValueOwnership ownership ) const {
2156- return (value - ParameterTypeFlags::Ownership )
2157- | ParameterFlags (uint8_t (ownership ) << OwnershipShift );
2182+ ParameterTypeFlags withOwnershipSpecifier (ParamSpecifier specifier ) const {
2183+ return (value - ParameterTypeFlags::Specifier )
2184+ | ParameterFlags (uint8_t (specifier ) << SpecifierShift );
21582185 }
21592186
21602187 ParameterTypeFlags withAutoClosure (bool isAutoClosure) const {
@@ -2217,8 +2244,8 @@ enum class ParameterFlagHandling {
22172244class YieldTypeFlags {
22182245 enum YieldFlags : uint8_t {
22192246 None = 0 ,
2220- Ownership = 7 ,
2221- OwnershipShift = 0 ,
2247+ Specifier = 7 ,
2248+ SpecifierShift = 0 ,
22222249
22232250 NumBits = 3
22242251 };
@@ -2234,42 +2261,44 @@ class YieldTypeFlags {
22342261 return YieldTypeFlags (OptionSet<YieldFlags>(raw));
22352262 }
22362263
2237- YieldTypeFlags (ValueOwnership ownership )
2238- : value(uint8_t (ownership ) << OwnershipShift ) {}
2264+ YieldTypeFlags (ParamSpecifier specifier )
2265+ : value(uint8_t (specifier ) << SpecifierShift ) {}
22392266
22402267 bool isInOut () const { return getValueOwnership () == ValueOwnership::InOut; }
22412268 bool isShared () const { return getValueOwnership () == ValueOwnership::Shared;}
22422269 bool isOwned () const { return getValueOwnership () == ValueOwnership::Owned; }
22432270
2244- ValueOwnership getValueOwnership () const {
2245- return ValueOwnership ((value.toRaw () & Ownership ) >> OwnershipShift );
2271+ ParamSpecifier getOwnershipSpecifier () const {
2272+ return ParamSpecifier ((value.toRaw () & Specifier ) >> SpecifierShift );
22462273 }
2274+
2275+ ValueOwnership getValueOwnership () const ;
22472276
22482277 YieldTypeFlags withInOut (bool isInout) const {
2249- return withValueOwnership (isInout ? ValueOwnership ::InOut
2250- : ValueOwnership ::Default);
2278+ return withOwnershipSpecifier (isInout ? ParamSpecifier ::InOut
2279+ : ParamSpecifier ::Default);
22512280 }
22522281
22532282 YieldTypeFlags withShared (bool isShared) const {
2254- return withValueOwnership (isShared ? ValueOwnership::Shared
2255- : ValueOwnership ::Default);
2283+ return withOwnershipSpecifier (isShared ? ParamSpecifier::LegacyShared
2284+ : ParamSpecifier ::Default);
22562285 }
22572286
22582287 YieldTypeFlags withOwned (bool isOwned) const {
2259- return withValueOwnership (isOwned ? ValueOwnership::Owned
2260- : ValueOwnership ::Default);
2288+ return withOwnershipSpecifier (isOwned ? ParamSpecifier::LegacyOwned
2289+ : ParamSpecifier ::Default);
22612290 }
22622291
2263- YieldTypeFlags withValueOwnership (ValueOwnership ownership) const {
2264- return (value - YieldTypeFlags::Ownership )
2265- | YieldFlags (uint8_t (ownership) << OwnershipShift );
2292+ YieldTypeFlags withOwnershipSpecifier (ParamSpecifier ownership) const {
2293+ return (value - YieldTypeFlags::Specifier )
2294+ | YieldFlags (uint8_t (ownership) << SpecifierShift );
22662295 }
22672296
22682297 // / Return these flags interpreted as parameter flags.
22692298 ParameterTypeFlags asParamFlags () const {
22702299 return ParameterTypeFlags (/* variadic*/ false ,
22712300 /* autoclosure*/ false ,
2272- /* nonEphemeral*/ false , getValueOwnership (),
2301+ /* nonEphemeral*/ false , getOwnershipSpecifier (),
22732302 /* isolated*/ false , /* noDerivative*/ false ,
22742303 /* compileTimeConst*/ false );
22752304 }
@@ -7087,16 +7116,16 @@ inline TupleTypeElt TupleTypeElt::getWithType(Type T) const {
70877116// / Create one from what's present in the parameter decl and type
70887117inline ParameterTypeFlags ParameterTypeFlags::fromParameterType (
70897118 Type paramTy, bool isVariadic, bool isAutoClosure, bool isNonEphemeral,
7090- ValueOwnership ownership, bool isolated, bool isNoDerivative,
7119+ ParamSpecifier ownership, bool isolated, bool isNoDerivative,
70917120 bool compileTimeConst) {
70927121 // FIXME(Remove InOut): The last caller that needs this is argument
70937122 // decomposition. Start by enabling the assertion there and fixing up those
70947123 // callers, then remove this, then remove
70957124 // ParameterTypeFlags::fromParameterType entirely.
70967125 if (paramTy->is <InOutType>()) {
7097- assert (ownership == ValueOwnership ::Default ||
7098- ownership == ValueOwnership ::InOut);
7099- ownership = ValueOwnership ::InOut;
7126+ assert (ownership == ParamSpecifier ::Default ||
7127+ ownership == ParamSpecifier ::InOut);
7128+ ownership = ParamSpecifier ::InOut;
71007129 }
71017130 return {isVariadic, isAutoClosure, isNonEphemeral, ownership, isolated,
71027131 isNoDerivative, compileTimeConst};
0 commit comments