@@ -55,6 +55,7 @@ namespace swift {
55
55
class GenericSignature ;
56
56
class Identifier ;
57
57
class InOutType ;
58
+ class OpenedArchetypeType ;
58
59
enum class ReferenceCounting : uint8_t ;
59
60
enum class ResilienceExpansion : unsigned ;
60
61
class SILModule ;
@@ -548,7 +549,7 @@ class alignas(1 << TypeAlignInBits) TypeBase {
548
549
549
550
// / Determine whether the type involves the given opened existential
550
551
// / archetype.
551
- bool hasOpenedExistential (ArchetypeType *opened);
552
+ bool hasOpenedExistential (OpenedArchetypeType *opened);
552
553
553
554
// / Determine whether the type is an opened existential type.
554
555
// /
@@ -561,11 +562,11 @@ class alignas(1 << TypeAlignInBits) TypeBase {
561
562
562
563
// / Retrieve the set of opened existential archetypes that occur
563
564
// / within this type.
564
- void getOpenedExistentials (SmallVectorImpl<ArchetypeType *> &opened);
565
+ void getOpenedExistentials (SmallVectorImpl<OpenedArchetypeType *> &opened);
565
566
566
567
// / Erase the given opened existential type by replacing it with its
567
568
// / existential type throughout the given type.
568
- Type eraseOpenedExistential (ArchetypeType *opened);
569
+ Type eraseOpenedExistential (OpenedArchetypeType *opened);
569
570
570
571
// / Erase DynamicSelfType from the given type by replacing it with its
571
572
// / underlying type.
@@ -672,7 +673,7 @@ class alignas(1 << TypeAlignInBits) TypeBase {
672
673
bool isClassExistentialType ();
673
674
674
675
// / Opens an existential instance or meta-type and returns the opened type.
675
- Type openAnyExistentialType (ArchetypeType *&opened);
676
+ Type openAnyExistentialType (OpenedArchetypeType *&opened);
676
677
677
678
// / Break an existential down into a set of constraints.
678
679
ExistentialLayout getExistentialLayout ();
@@ -4571,6 +4572,8 @@ DEFINE_EMPTY_CAN_TYPE_WRAPPER(SubstitutableType, Type)
4571
4572
template<typename Base, typename...AdditionalTrailingObjects>
4572
4573
using ArchetypeTrailingObjects = llvm::TrailingObjects<Base,
4573
4574
ProtocolDecl *, Type, LayoutConstraint, AdditionalTrailingObjects...>;
4575
+
4576
+ class PrimaryArchetypeType ;
4574
4577
4575
4578
// / An archetype is a type that represents a runtime type that is
4576
4579
// / known to conform to some set of requirements.
@@ -4612,81 +4615,17 @@ class ArchetypeType : public SubstitutableType,
4612
4615
}
4613
4616
4614
4617
public:
4615
- // / getNew - Create a new nested archetype with the given associated type.
4616
- // /
4617
- // / The ConformsTo array will be copied into the ASTContext by this routine.
4618
- // /
4619
- // / TODO: Move to NestedArchetypeType
4620
- static CanTypeWrapper<ArchetypeType>
4621
- getNew (const ASTContext &Ctx, ArchetypeType *Parent,
4622
- DependentMemberType *InterfaceType,
4623
- SmallVectorImpl<ProtocolDecl *> &ConformsTo,
4624
- Type Superclass, LayoutConstraint Layout);
4625
-
4626
- // / getNew - Create a new primary archetype with the given name.
4627
- // /
4628
- // / The ConformsTo array will be minimized then copied into the ASTContext
4629
- // / by this routine.
4630
- // /
4631
- // / TODO: Move to PrimaryArchetypeType
4632
- static CanTypeWrapper<ArchetypeType>
4633
- getNew (const ASTContext &Ctx,
4634
- GenericEnvironment *GenericEnv,
4635
- GenericTypeParamType *InterfaceType,
4636
- SmallVectorImpl<ProtocolDecl *> &ConformsTo,
4637
- Type Superclass, LayoutConstraint Layout);
4638
-
4639
- // / Create a new archetype that represents the opened type
4640
- // / of an existential value.
4641
- // /
4642
- // / \param existential The existential type to open.
4643
- // /
4644
- // / \param knownID When non-empty, the known ID of the archetype. When empty,
4645
- // / a fresh archetype with a unique ID will be opened.
4646
- static CanTypeWrapper<ArchetypeType>
4647
- getOpened (Type existential,
4648
- Optional<UUID> knownID = None);
4649
-
4650
- // / Create a new archetype that represents the opened type
4651
- // / of an existential value.
4652
- // /
4653
- // / \param existential The existential type or existential metatype to open.
4654
- static CanType getAnyOpened (Type existential);
4655
-
4656
4618
// / Retrieve the name of this archetype.
4657
4619
Identifier getName () const ;
4658
4620
4659
4621
// / Retrieve the fully-dotted name that should be used to display this
4660
4622
// / archetype.
4661
4623
std::string getFullName () const ;
4662
4624
4663
- // / Retrieve the parent of this archetype, or null if this is a
4664
- // / primary archetype.
4665
- ArchetypeType *getParent () const ;
4666
-
4667
- // / Retrieve the opened existential type.
4668
- // / TODO: Remove and leave on only OpenedArchetypeType
4669
- Type getOpenedExistentialType () const ;
4670
-
4671
- // / Retrieve the generic environment in which this archetype resides.
4672
- // /
4673
- // / Note: opened archetypes currently don't have generic environments.
4674
- // /
4675
- // / TODO: Remove and leave only on PrimaryArchetypeType
4676
- GenericEnvironment *getGenericEnvironment () const ;
4677
-
4678
4625
// / Retrieve the interface type of this associated type, which will either
4679
4626
// / be a GenericTypeParamType or a DependentMemberType.
4680
4627
Type getInterfaceType () const { return InterfaceType; }
4681
4628
4682
- // / Retrieve the associated type to which this archetype (if it is a nested
4683
- // / archetype) corresponds.
4684
- // /
4685
- // / This associated type will have the same name as the archetype and will
4686
- // / be a member of one of the protocols to which the parent archetype
4687
- // / conforms.
4688
- AssociatedTypeDecl *getAssocType () const ;
4689
-
4690
4629
// / getConformsTo - Retrieve the set of protocols to which this substitutable
4691
4630
// / type shall conform.
4692
4631
ArrayRef<ProtocolDecl *> getConformsTo () const {
@@ -4759,18 +4698,8 @@ class ArchetypeType : public SubstitutableType,
4759
4698
// / Register a nested type with the given name.
4760
4699
void registerNestedType (Identifier name, Type nested);
4761
4700
4762
- // / isPrimary - Determine whether this is the archetype for a 'primary'
4763
- // / archetype, e.g., one that is not nested within another archetype and is
4764
- // / not an opened existential.
4765
- bool isPrimary () const ;
4766
-
4767
4701
// / getPrimary - Return the primary archetype parent of this archetype.
4768
- ArchetypeType *getPrimary () const ;
4769
-
4770
- // / Retrieve the ID number of this opened existential.
4771
- // /
4772
- // / TODO: Remove and place on OpenedArchetypeType only
4773
- UUID getOpenedExistentialID () const ;
4702
+ PrimaryArchetypeType *getPrimary () const ;
4774
4703
4775
4704
// Implement isa/cast/dyncast/etc.
4776
4705
static bool classof (const TypeBase *T) {
@@ -4786,9 +4715,6 @@ class ArchetypeType : public SubstitutableType,
4786
4715
Type Superclass, LayoutConstraint Layout);
4787
4716
};
4788
4717
BEGIN_CAN_TYPE_WRAPPER (ArchetypeType, SubstitutableType)
4789
- CanArchetypeType getParent() const {
4790
- return CanArchetypeType (getPointer ()->getParent ());
4791
- }
4792
4718
END_CAN_TYPE_WRAPPER(ArchetypeType, SubstitutableType)
4793
4719
4794
4720
// / An archetype that represents a primary generic argument inside the generic
@@ -4802,6 +4728,17 @@ class PrimaryArchetypeType final : public ArchetypeType,
4802
4728
GenericEnvironment *Environment;
4803
4729
4804
4730
public:
4731
+ // / getNew - Create a new primary archetype with the given name.
4732
+ // /
4733
+ // / The ConformsTo array will be minimized then copied into the ASTContext
4734
+ // / by this routine.
4735
+ static CanTypeWrapper<PrimaryArchetypeType>
4736
+ getNew (const ASTContext &Ctx,
4737
+ GenericEnvironment *GenericEnv,
4738
+ GenericTypeParamType *InterfaceType,
4739
+ SmallVectorImpl<ProtocolDecl *> &ConformsTo,
4740
+ Type Superclass, LayoutConstraint Layout);
4741
+
4805
4742
// / Retrieve the generic environment in which this archetype resides.
4806
4743
GenericEnvironment *getGenericEnvironment () const {
4807
4744
return Environment;
@@ -4830,6 +4767,23 @@ class OpenedArchetypeType final : public ArchetypeType,
4830
4767
TypeBase *Opened;
4831
4768
UUID ID;
4832
4769
public:
4770
+ // / Create a new archetype that represents the opened type
4771
+ // / of an existential value.
4772
+ // /
4773
+ // / \param existential The existential type to open.
4774
+ // /
4775
+ // / \param knownID When non-empty, the known ID of the archetype. When empty,
4776
+ // / a fresh archetype with a unique ID will be opened.
4777
+ static CanTypeWrapper<OpenedArchetypeType>
4778
+ get (Type existential,
4779
+ Optional<UUID> knownID = None);
4780
+
4781
+ // / Create a new archetype that represents the opened type
4782
+ // / of an existential value.
4783
+ // /
4784
+ // / \param existential The existential type or existential metatype to open.
4785
+ static CanType getAny (Type existential);
4786
+
4833
4787
// / Retrieve the ID number of this opened existential.
4834
4788
UUID getOpenedExistentialID () const { return ID; }
4835
4789
@@ -4860,11 +4814,22 @@ class NestedArchetypeType final : public ArchetypeType,
4860
4814
ArchetypeType *Parent;
4861
4815
4862
4816
public:
4817
+ // / getNew - Create a new nested archetype with the given associated type.
4818
+ // /
4819
+ // / The ConformsTo array will be copied into the ASTContext by this routine.
4820
+ static CanTypeWrapper<NestedArchetypeType>
4821
+ getNew (const ASTContext &Ctx, ArchetypeType *Parent,
4822
+ DependentMemberType *InterfaceType,
4823
+ SmallVectorImpl<ProtocolDecl *> &ConformsTo,
4824
+ Type Superclass, LayoutConstraint Layout);
4825
+
4863
4826
// / Retrieve the parent of this archetype, or null if this is a
4864
4827
// / primary archetype.
4865
4828
ArchetypeType *getParent () const {
4866
4829
return Parent;
4867
4830
}
4831
+
4832
+ AssociatedTypeDecl *getAssocType () const ;
4868
4833
4869
4834
static bool classof (const TypeBase *T) {
4870
4835
return T->getKind () == TypeKind::NestedArchetype;
@@ -4878,29 +4843,11 @@ class NestedArchetypeType final : public ArchetypeType,
4878
4843
Type Superclass, LayoutConstraint Layout);
4879
4844
};
4880
4845
BEGIN_CAN_TYPE_WRAPPER (NestedArchetypeType, ArchetypeType)
4846
+ CanArchetypeType getParent() const {
4847
+ return CanArchetypeType (getPointer ()->getParent ());
4848
+ }
4881
4849
END_CAN_TYPE_WRAPPER (NestedArchetypeType, ArchetypeType)
4882
4850
4883
- inline bool ArchetypeType::isPrimary() const {
4884
- return isa<PrimaryArchetypeType>(this );
4885
- }
4886
-
4887
- inline UUID ArchetypeType::getOpenedExistentialID () const {
4888
- return cast<OpenedArchetypeType>(this )->getOpenedExistentialID ();
4889
- }
4890
-
4891
- inline Type ArchetypeType::getOpenedExistentialType () const {
4892
- if (auto child = dyn_cast<OpenedArchetypeType>(this ))
4893
- return child->getOpenedExistentialType ();
4894
- return nullptr ;
4895
- }
4896
-
4897
- inline ArchetypeType *ArchetypeType::getParent () const {
4898
- if (auto child = dyn_cast<NestedArchetypeType>(this ))
4899
- return child->getParent ();
4900
-
4901
- return nullptr ;
4902
- }
4903
-
4904
4851
template<typename Type>
4905
4852
const Type *ArchetypeType::getSubclassTrailingObjects() const {
4906
4853
if (auto contextTy = dyn_cast<PrimaryArchetypeType>(this )) {
@@ -5256,20 +5203,17 @@ inline bool TypeBase::isOpenedExistential() const {
5256
5203
return false ;
5257
5204
5258
5205
CanType T = getCanonicalType ();
5259
- if (auto archetype = dyn_cast<ArchetypeType>(T))
5260
- return !archetype->getOpenedExistentialType ().isNull ();
5261
- return false ;
5206
+ return isa<OpenedArchetypeType>(T);
5262
5207
}
5263
5208
5264
5209
inline bool TypeBase::isOpenedExistentialWithError () {
5265
5210
if (!hasOpenedExistential ())
5266
5211
return false ;
5267
5212
5268
5213
CanType T = getCanonicalType ();
5269
- if (auto archetype = dyn_cast<ArchetypeType >(T)) {
5214
+ if (auto archetype = dyn_cast<OpenedArchetypeType >(T)) {
5270
5215
auto openedExistentialType = archetype->getOpenedExistentialType ();
5271
- return (!openedExistentialType.isNull () &&
5272
- openedExistentialType->isExistentialWithError ());
5216
+ return openedExistentialType->isExistentialWithError ();
5273
5217
}
5274
5218
return false ;
5275
5219
}
0 commit comments