@@ -72,6 +72,7 @@ class InOutType;
72
72
class OpaqueTypeDecl ;
73
73
class OpenedArchetypeType ;
74
74
class PackType ;
75
+ enum class ParamSpecifier : uint8_t ;
75
76
class PlaceholderTypeRepr ;
76
77
enum class ReferenceCounting : uint8_t ;
77
78
enum class ResilienceExpansion : unsigned ;
@@ -2069,6 +2070,29 @@ class TypeAliasType final
2069
2070
}
2070
2071
};
2071
2072
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
+
2072
2096
// / Provide parameter type relevant flags, i.e. variadic, autoclosure, and
2073
2097
// / escaping.
2074
2098
class ParameterTypeFlags {
@@ -2077,8 +2101,8 @@ class ParameterTypeFlags {
2077
2101
Variadic = 1 << 0 ,
2078
2102
AutoClosure = 1 << 1 ,
2079
2103
NonEphemeral = 1 << 2 ,
2080
- OwnershipShift = 3 ,
2081
- Ownership = 7 << OwnershipShift ,
2104
+ SpecifierShift = 3 ,
2105
+ Specifier = 7 << SpecifierShift ,
2082
2106
NoDerivative = 1 << 6 ,
2083
2107
Isolated = 1 << 7 ,
2084
2108
CompileTimeConst = 1 << 8 ,
@@ -2096,19 +2120,19 @@ class ParameterTypeFlags {
2096
2120
}
2097
2121
2098
2122
ParameterTypeFlags (bool variadic, bool autoclosure, bool nonEphemeral,
2099
- ValueOwnership ownership , bool isolated, bool noDerivative,
2123
+ ParamSpecifier specifier , bool isolated, bool noDerivative,
2100
2124
bool compileTimeConst)
2101
2125
: value((variadic ? Variadic : 0 ) | (autoclosure ? AutoClosure : 0 ) |
2102
2126
(nonEphemeral ? NonEphemeral : 0 ) |
2103
- uint8_t (ownership ) << OwnershipShift |
2127
+ uint8_t (specifier ) << SpecifierShift |
2104
2128
(isolated ? Isolated : 0 ) |
2105
2129
(noDerivative ? NoDerivative : 0 ) |
2106
2130
(compileTimeConst ? CompileTimeConst : 0 )){}
2107
2131
2108
2132
// / Create one from what's present in the parameter type
2109
2133
inline static ParameterTypeFlags
2110
2134
fromParameterType (Type paramTy, bool isVariadic, bool isAutoClosure,
2111
- bool isNonEphemeral, ValueOwnership ownership,
2135
+ bool isNonEphemeral, ParamSpecifier ownership,
2112
2136
bool isolated, bool isNoDerivative,
2113
2137
bool compileTimeConst);
2114
2138
@@ -2123,18 +2147,21 @@ class ParameterTypeFlags {
2123
2147
bool isCompileTimeConst () const { return value.contains (CompileTimeConst); }
2124
2148
bool isNoDerivative () const { return value.contains (NoDerivative); }
2125
2149
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);
2128
2153
}
2129
2154
2155
+ ValueOwnership getValueOwnership () const ;
2156
+
2130
2157
ParameterTypeFlags withVariadic (bool variadic) const {
2131
2158
return ParameterTypeFlags (variadic ? value | ParameterTypeFlags::Variadic
2132
2159
: value - ParameterTypeFlags::Variadic);
2133
2160
}
2134
2161
2135
2162
ParameterTypeFlags withInOut (bool isInout) const {
2136
- return withValueOwnership (isInout ? ValueOwnership ::InOut
2137
- : ValueOwnership ::Default);
2163
+ return withOwnershipSpecifier (isInout ? ParamSpecifier ::InOut
2164
+ : ParamSpecifier ::Default);
2138
2165
}
2139
2166
2140
2167
ParameterTypeFlags withCompileTimeConst (bool isConst) const {
@@ -2143,18 +2170,18 @@ class ParameterTypeFlags {
2143
2170
}
2144
2171
2145
2172
ParameterTypeFlags withShared (bool isShared) const {
2146
- return withValueOwnership (isShared ? ValueOwnership::Shared
2147
- : ValueOwnership ::Default);
2173
+ return withOwnershipSpecifier (isShared ? ParamSpecifier::LegacyShared
2174
+ : ParamSpecifier ::Default);
2148
2175
}
2149
2176
2150
2177
ParameterTypeFlags withOwned (bool isOwned) const {
2151
- return withValueOwnership (isOwned ? ValueOwnership::Owned
2152
- : ValueOwnership ::Default);
2178
+ return withOwnershipSpecifier (isOwned ? ParamSpecifier::LegacyOwned
2179
+ : ParamSpecifier ::Default);
2153
2180
}
2154
2181
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 );
2158
2185
}
2159
2186
2160
2187
ParameterTypeFlags withAutoClosure (bool isAutoClosure) const {
@@ -2217,8 +2244,8 @@ enum class ParameterFlagHandling {
2217
2244
class YieldTypeFlags {
2218
2245
enum YieldFlags : uint8_t {
2219
2246
None = 0 ,
2220
- Ownership = 7 ,
2221
- OwnershipShift = 0 ,
2247
+ Specifier = 7 ,
2248
+ SpecifierShift = 0 ,
2222
2249
2223
2250
NumBits = 3
2224
2251
};
@@ -2234,42 +2261,44 @@ class YieldTypeFlags {
2234
2261
return YieldTypeFlags (OptionSet<YieldFlags>(raw));
2235
2262
}
2236
2263
2237
- YieldTypeFlags (ValueOwnership ownership )
2238
- : value(uint8_t (ownership ) << OwnershipShift ) {}
2264
+ YieldTypeFlags (ParamSpecifier specifier )
2265
+ : value(uint8_t (specifier ) << SpecifierShift ) {}
2239
2266
2240
2267
bool isInOut () const { return getValueOwnership () == ValueOwnership::InOut; }
2241
2268
bool isShared () const { return getValueOwnership () == ValueOwnership::Shared;}
2242
2269
bool isOwned () const { return getValueOwnership () == ValueOwnership::Owned; }
2243
2270
2244
- ValueOwnership getValueOwnership () const {
2245
- return ValueOwnership ((value.toRaw () & Ownership ) >> OwnershipShift );
2271
+ ParamSpecifier getOwnershipSpecifier () const {
2272
+ return ParamSpecifier ((value.toRaw () & Specifier ) >> SpecifierShift );
2246
2273
}
2274
+
2275
+ ValueOwnership getValueOwnership () const ;
2247
2276
2248
2277
YieldTypeFlags withInOut (bool isInout) const {
2249
- return withValueOwnership (isInout ? ValueOwnership ::InOut
2250
- : ValueOwnership ::Default);
2278
+ return withOwnershipSpecifier (isInout ? ParamSpecifier ::InOut
2279
+ : ParamSpecifier ::Default);
2251
2280
}
2252
2281
2253
2282
YieldTypeFlags withShared (bool isShared) const {
2254
- return withValueOwnership (isShared ? ValueOwnership::Shared
2255
- : ValueOwnership ::Default);
2283
+ return withOwnershipSpecifier (isShared ? ParamSpecifier::LegacyShared
2284
+ : ParamSpecifier ::Default);
2256
2285
}
2257
2286
2258
2287
YieldTypeFlags withOwned (bool isOwned) const {
2259
- return withValueOwnership (isOwned ? ValueOwnership::Owned
2260
- : ValueOwnership ::Default);
2288
+ return withOwnershipSpecifier (isOwned ? ParamSpecifier::LegacyOwned
2289
+ : ParamSpecifier ::Default);
2261
2290
}
2262
2291
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 );
2266
2295
}
2267
2296
2268
2297
// / Return these flags interpreted as parameter flags.
2269
2298
ParameterTypeFlags asParamFlags () const {
2270
2299
return ParameterTypeFlags (/* variadic*/ false ,
2271
2300
/* autoclosure*/ false ,
2272
- /* nonEphemeral*/ false , getValueOwnership (),
2301
+ /* nonEphemeral*/ false , getOwnershipSpecifier (),
2273
2302
/* isolated*/ false , /* noDerivative*/ false ,
2274
2303
/* compileTimeConst*/ false );
2275
2304
}
@@ -7087,16 +7116,16 @@ inline TupleTypeElt TupleTypeElt::getWithType(Type T) const {
7087
7116
// / Create one from what's present in the parameter decl and type
7088
7117
inline ParameterTypeFlags ParameterTypeFlags::fromParameterType (
7089
7118
Type paramTy, bool isVariadic, bool isAutoClosure, bool isNonEphemeral,
7090
- ValueOwnership ownership, bool isolated, bool isNoDerivative,
7119
+ ParamSpecifier ownership, bool isolated, bool isNoDerivative,
7091
7120
bool compileTimeConst) {
7092
7121
// FIXME(Remove InOut): The last caller that needs this is argument
7093
7122
// decomposition. Start by enabling the assertion there and fixing up those
7094
7123
// callers, then remove this, then remove
7095
7124
// ParameterTypeFlags::fromParameterType entirely.
7096
7125
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;
7100
7129
}
7101
7130
return {isVariadic, isAutoClosure, isNonEphemeral, ownership, isolated,
7102
7131
isNoDerivative, compileTimeConst};
0 commit comments