@@ -507,7 +507,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
507
507
);
508
508
509
509
SWIFT_INLINE_BITFIELD (FuncDecl, AbstractFunctionDecl,
510
- 1 +1 +2 +1 +1 +NumSelfAccessKindBits+1 ,
510
+ 1 +1 +2 +1 +1 +NumSelfAccessKindBits+1 + 1 ,
511
511
// / Whether we've computed the 'static' flag yet.
512
512
IsStaticComputed : 1 ,
513
513
@@ -529,7 +529,10 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
529
529
// / Whether this is a top-level function which should be treated
530
530
// / as if it were in local context for the purposes of capture
531
531
// / analysis.
532
- HasTopLevelLocalContextCaptures : 1
532
+ HasTopLevelLocalContextCaptures : 1 ,
533
+
534
+ // / Set to true if this FuncDecl has a transferring result.
535
+ HasTransferringResult : 1
533
536
);
534
537
535
538
SWIFT_INLINE_BITFIELD (AccessorDecl, FuncDecl, 4 + 1 + 1 ,
@@ -6457,8 +6460,6 @@ class ParamDecl : public VarDecl {
6457
6460
SourceLoc ArgumentNameLoc;
6458
6461
SourceLoc SpecifierLoc;
6459
6462
6460
- TypeRepr *TyRepr = nullptr ;
6461
-
6462
6463
struct alignas (1 << StoredDefaultArgumentAlignInBits) StoredDefaultArgument {
6463
6464
PointerUnion<Expr *, VarDecl *> DefaultArg;
6464
6465
@@ -6477,7 +6478,9 @@ class ParamDecl : public VarDecl {
6477
6478
// / argument without triggering a request.
6478
6479
llvm::Optional<Initializer *> getCachedDefaultArgumentInitContext () const ;
6479
6480
6480
- enum class Flags : uint8_t {
6481
+ // / NOTE: This is stored using bits from TyReprAndFlags and
6482
+ // / DefaultValueAndFlags.
6483
+ enum class Flag : uint8_t {
6481
6484
// / Whether or not this parameter is vargs.
6482
6485
IsVariadic = 1 << 0 ,
6483
6486
@@ -6489,12 +6492,66 @@ class ParamDecl : public VarDecl {
6489
6492
6490
6493
// / Whether or not this paramater is '_resultDependsOn'
6491
6494
IsResultDependsOn = 1 << 3 ,
6495
+
6496
+ // / Whether or not this parameter is 'transferring'.
6497
+ IsTransferring = 1 << 4 ,
6492
6498
};
6493
6499
6494
- // / The default value, if any, along with flags.
6495
- llvm::PointerIntPair<StoredDefaultArgument *, 3 , OptionSet<Flags>>
6500
+ // / The type repr and 3 bits used for flags.
6501
+ llvm::PointerIntPair<TypeRepr *, 3 , std::underlying_type<Flag>::type>
6502
+ TyReprAndFlags;
6503
+
6504
+ // / The default value, if any, along with 3 bits for flags.
6505
+ llvm::PointerIntPair<StoredDefaultArgument *, 3 ,
6506
+ std::underlying_type<Flag>::type>
6496
6507
DefaultValueAndFlags;
6497
6508
6509
+ OptionSet<Flag> getOptions () const {
6510
+ uint8_t result = 0 ;
6511
+ result |= TyReprAndFlags.getInt ();
6512
+ result |= DefaultValueAndFlags.getInt () << 3 ;
6513
+ return OptionSet<Flag>(result);
6514
+ }
6515
+
6516
+ // / Set the current set of options to \p newFlags.
6517
+ void setOptions (OptionSet<Flag> newFlags) {
6518
+ uint8_t bits = newFlags.toRaw ();
6519
+ TyReprAndFlags.setInt (bits & 0x7 );
6520
+ DefaultValueAndFlags.setInt (bits >> 3 );
6521
+ }
6522
+
6523
+ void setOptionsAndPointers (TypeRepr *tyRepr,
6524
+ StoredDefaultArgument *storedArgs,
6525
+ OptionSet<Flag> newFlags) {
6526
+ uint8_t bits = newFlags.toRaw ();
6527
+ TyReprAndFlags.setPointerAndInt (tyRepr, bits & 0x7 );
6528
+ DefaultValueAndFlags.setPointerAndInt (storedArgs, bits >> 3 );
6529
+ }
6530
+
6531
+ void addFlag (Flag newFlag) {
6532
+ auto flagBits = uint8_t (newFlag);
6533
+ if (uint8_t (newFlag) < (1 << 3 )) {
6534
+ flagBits &= 0x7 ;
6535
+ TyReprAndFlags.setInt (TyReprAndFlags.getInt () | flagBits);
6536
+ return ;
6537
+ }
6538
+
6539
+ flagBits >>= 3 ;
6540
+ DefaultValueAndFlags.setInt (DefaultValueAndFlags.getInt () | flagBits);
6541
+ }
6542
+
6543
+ void removeFlag (Flag newFlag) {
6544
+ auto flagBits = uint8_t (newFlag);
6545
+ if (uint8_t (newFlag) < (1 << 3 )) {
6546
+ flagBits &= 0x7 ;
6547
+ TyReprAndFlags.setInt (TyReprAndFlags.getInt () & ~flagBits);
6548
+ return ;
6549
+ }
6550
+
6551
+ flagBits >>= 3 ;
6552
+ DefaultValueAndFlags.setInt (DefaultValueAndFlags.getInt () & ~flagBits);
6553
+ }
6554
+
6498
6555
friend class ParamSpecifierRequest ;
6499
6556
6500
6557
public:
@@ -6540,8 +6597,8 @@ class ParamDecl : public VarDecl {
6540
6597
SourceLoc getSpecifierLoc () const { return SpecifierLoc; }
6541
6598
6542
6599
// / Retrieve the TypeRepr corresponding to the parsed type of the parameter, if it exists.
6543
- TypeRepr *getTypeRepr () const { return TyRepr ; }
6544
- void setTypeRepr (TypeRepr *repr) { TyRepr = repr; }
6600
+ TypeRepr *getTypeRepr () const { return TyReprAndFlags. getPointer () ; }
6601
+ void setTypeRepr (TypeRepr *repr) { TyReprAndFlags. setPointer ( repr) ; }
6545
6602
6546
6603
bool isDestructured () const {
6547
6604
auto flags = ArgumentNameAndFlags.getInt ();
@@ -6663,30 +6720,44 @@ class ParamDecl : public VarDecl {
6663
6720
// / Whether or not this parameter is old-style variadic.
6664
6721
bool isVariadic () const ;
6665
6722
void setVariadic (bool value = true ) {
6666
- auto flags = DefaultValueAndFlags.getInt ();
6667
- DefaultValueAndFlags.setInt (value ? flags | Flags::IsVariadic
6668
- : flags - Flags::IsVariadic);
6723
+ if (value)
6724
+ addFlag (Flag::IsVariadic);
6725
+ else
6726
+ removeFlag (Flag::IsVariadic);
6669
6727
}
6670
6728
6671
6729
// / Whether or not this parameter is marked with `@autoclosure`.
6672
6730
bool isAutoClosure () const {
6673
- return DefaultValueAndFlags. getInt ().contains (Flags ::IsAutoClosure);
6731
+ return getOptions ().contains (Flag ::IsAutoClosure);
6674
6732
}
6733
+
6675
6734
void setAutoClosure (bool value = true ) {
6676
- auto flags = DefaultValueAndFlags.getInt ();
6677
- DefaultValueAndFlags.setInt (value ? flags | Flags::IsAutoClosure
6678
- : flags - Flags::IsAutoClosure);
6735
+ if (value)
6736
+ addFlag (Flag::IsAutoClosure);
6737
+ else
6738
+ removeFlag (Flag::IsAutoClosure);
6679
6739
}
6680
6740
6681
6741
// / Whether or not this parameter is marked with 'isolated'.
6682
- bool isIsolated () const {
6683
- return DefaultValueAndFlags.getInt ().contains (Flags::IsIsolated);
6684
- }
6742
+ bool isIsolated () const { return getOptions ().contains (Flag::IsIsolated); }
6685
6743
6686
6744
void setIsolated (bool value = true ) {
6687
- auto flags = DefaultValueAndFlags.getInt ();
6688
- DefaultValueAndFlags.setInt (value ? flags | Flags::IsIsolated
6689
- : flags - Flags::IsIsolated);
6745
+ if (value)
6746
+ addFlag (Flag::IsIsolated);
6747
+ else
6748
+ removeFlag (Flag::IsIsolated);
6749
+ }
6750
+
6751
+ // / Whether or not this parameter is marked with 'transferring'.
6752
+ bool isTransferring () const {
6753
+ return getOptions ().contains (Flag::IsTransferring);
6754
+ }
6755
+
6756
+ void setTransferring (bool value = true ) {
6757
+ if (value)
6758
+ addFlag (Flag::IsTransferring);
6759
+ else
6760
+ removeFlag (Flag::IsTransferring);
6690
6761
}
6691
6762
6692
6763
// / Whether or not this parameter is marked with '_const'.
@@ -6765,7 +6836,7 @@ class ParamDecl : public VarDecl {
6765
6836
return true ;
6766
6837
case Specifier::Consuming:
6767
6838
case Specifier::InOut:
6768
- case Specifier::Transferring :
6839
+ case Specifier::ImplicitlyCopyableConsuming :
6769
6840
return false ;
6770
6841
}
6771
6842
llvm_unreachable (" unhandled specifier" );
@@ -6783,7 +6854,7 @@ class ParamDecl : public VarDecl {
6783
6854
case ParamSpecifier::LegacyShared:
6784
6855
return ValueOwnership::Shared;
6785
6856
case ParamSpecifier::Consuming:
6786
- case ParamSpecifier::Transferring :
6857
+ case ParamSpecifier::ImplicitlyCopyableConsuming :
6787
6858
case ParamSpecifier::LegacyOwned:
6788
6859
return ValueOwnership::Owned;
6789
6860
case ParamSpecifier::Default:
@@ -7708,6 +7779,7 @@ class FuncDecl : public AbstractFunctionDecl {
7708
7779
Bits.FuncDecl .IsStaticComputed = false ;
7709
7780
Bits.FuncDecl .IsStatic = false ;
7710
7781
Bits.FuncDecl .HasTopLevelLocalContextCaptures = false ;
7782
+ Bits.FuncDecl .HasTransferringResult = false ;
7711
7783
}
7712
7784
7713
7785
void setResultInterfaceType (Type type);
@@ -7864,6 +7936,16 @@ class FuncDecl : public AbstractFunctionDecl {
7864
7936
Bits.FuncDecl .ForcedStaticDispatch = flag;
7865
7937
}
7866
7938
7939
+ // / Returns true if this FuncDecl has a transferring result... returns false
7940
+ // / otherwise.
7941
+ bool hasTransferringResult () const {
7942
+ return Bits.FuncDecl .HasTransferringResult ;
7943
+ }
7944
+
7945
+ void setTransferringResult (bool newValue = true ) {
7946
+ Bits.FuncDecl .HasTransferringResult = newValue;
7947
+ }
7948
+
7867
7949
static bool classof (const Decl *D) {
7868
7950
return D->getKind () == DeclKind::Func ||
7869
7951
D->getKind () == DeclKind::Accessor;
0 commit comments