@@ -410,12 +410,10 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
410410 );
411411
412412 SWIFT_INLINE_BITFIELD (ParamDecl, VarDecl, 1 +2 +NumDefaultArgumentKindBits,
413- // / Whether we've computed the specifier yet.
414- SpecifierComputed : 1 ,
415-
416- // / The specifier associated with this parameter. This determines
417- // / the storage semantics of the value e.g. mutability.
418- Specifier : 2 ,
413+ // / The specifier associated with this parameter + 1, or zero if the
414+ // / specifier has not been computed yet. This determines
415+ // / the ownership semantics of the parameter.
416+ OwnershipSpecifier : 3 ,
419417
420418 // / Information about a symbolic default argument, like #file.
421419 defaultArgumentKind : NumDefaultArgumentKindBits
@@ -5993,10 +5991,17 @@ enum class ParamSpecifier : uint8_t {
59935991 // / duration of a call.
59945992 InOut = 1 ,
59955993
5994+ // / `borrowing`, indicating nonexclusive access to the argument for the
5995+ // / duration of a call.
5996+ Borrowing = 2 ,
5997+ // / `consuming`, indicating ownership transfer of the argument from caller
5998+ // / to callee.
5999+ Consuming = 3 ,
6000+
59966001 // / `__shared`, a legacy spelling of `borrowing`.
5997- Shared = 2 ,
5998- // / `__owned`, a legacy spelling of `consuming`.
5999- Owned = 3 ,
6002+ LegacyShared = 4 ,
6003+ // / `__owned`, a legacy spelling of `consuming`.
6004+ LegacyOwned = 5 ,
60006005};
60016006
60026007// / A function parameter declaration.
@@ -6285,8 +6290,8 @@ class ParamDecl : public VarDecl {
62856290 using Specifier = ParamSpecifier;
62866291
62876292 Optional<Specifier> getCachedSpecifier () const {
6288- if (Bits.ParamDecl .SpecifierComputed )
6289- return Specifier (Bits.ParamDecl .Specifier );
6293+ if (Bits.ParamDecl .OwnershipSpecifier != 0 )
6294+ return Specifier (Bits.ParamDecl .OwnershipSpecifier - 1 );
62906295
62916296 return None;
62926297 }
@@ -6297,20 +6302,18 @@ class ParamDecl : public VarDecl {
62976302
62986303 // / Is the type of this parameter 'inout'?
62996304 bool isInOut () const { return getSpecifier () == Specifier::InOut; }
6300- // / Is this an immutable 'shared' property?
6301- bool isShared () const { return getSpecifier () == Specifier::Shared; }
6302- // / Is this an immutable 'owned' property?
6303- bool isOwned () const { return getSpecifier () == Specifier::Owned; }
63046305
6305- bool isImmutable () const {
6306- return isImmutableSpecifier (getSpecifier ());
6306+ bool isImmutableInFunctionBody () const {
6307+ return isSpecifierImmutableInFunctionBody (getSpecifier ());
63076308 }
6308- static bool isImmutableSpecifier (Specifier sp) {
6309+ static bool isSpecifierImmutableInFunctionBody (Specifier sp) {
63096310 switch (sp) {
63106311 case Specifier::Default:
6311- case Specifier::Shared:
6312- case Specifier::Owned:
6312+ case Specifier::Borrowing:
6313+ case Specifier::LegacyShared:
6314+ case Specifier::LegacyOwned:
63136315 return true ;
6316+ case Specifier::Consuming:
63146317 case Specifier::InOut:
63156318 return false ;
63166319 }
@@ -6323,29 +6326,32 @@ class ParamDecl : public VarDecl {
63236326
63246327 static ValueOwnership getValueOwnershipForSpecifier (Specifier specifier) {
63256328 switch (specifier) {
6326- case Specifier::Default:
6327- return ValueOwnership::Default;
6328- case Specifier::InOut:
6329+ case ParamSpecifier::InOut:
63296330 return ValueOwnership::InOut;
6330- case Specifier::Shared:
6331+ case ParamSpecifier::Borrowing:
6332+ case ParamSpecifier::LegacyShared:
63316333 return ValueOwnership::Shared;
6332- case Specifier::Owned:
6334+ case ParamSpecifier::Consuming:
6335+ case ParamSpecifier::LegacyOwned:
63336336 return ValueOwnership::Owned;
6337+ case ParamSpecifier::Default:
6338+ return ValueOwnership::Default;
63346339 }
6335- llvm_unreachable (" unhandled specifier " );
6340+ llvm_unreachable (" invalid ParamSpecifier " );
63366341 }
63376342
63386343 static Specifier
63396344 getParameterSpecifierForValueOwnership (ValueOwnership ownership) {
6345+ #warning "todo: switch over to consuming/borrowing once they're fully supported"
63406346 switch (ownership) {
63416347 case ValueOwnership::Default:
63426348 return Specifier::Default;
63436349 case ValueOwnership::Shared:
6344- return Specifier::Shared;
6350+ return Specifier::LegacyShared; // should become Borrowing
63456351 case ValueOwnership::InOut:
63466352 return Specifier::InOut;
63476353 case ValueOwnership::Owned:
6348- return Specifier::Owned;
6354+ return Specifier::LegacyOwned; // should become Consuming
63496355 }
63506356 llvm_unreachable (" unhandled ownership" );
63516357 }
@@ -6358,6 +6364,9 @@ class ParamDecl : public VarDecl {
63586364 static bool classof (const Decl *D) {
63596365 return D->getKind () == DeclKind::Param;
63606366 }
6367+
6368+ // / Get the source code spelling of a parameter specifier value as a string.
6369+ static StringRef getSpecifierSpelling (Specifier spec);
63616370};
63626371
63636372// / Describes the kind of subscripting used in Objective-C.
0 commit comments