@@ -366,9 +366,9 @@ class ArchetypeBuilder::PotentialArchetype {
366
366
llvm::MapVector<Identifier, llvm::TinyPtrVector<PotentialArchetype *>>
367
367
NestedTypes;
368
368
369
- // / \brief The actual archetype, once it has been assigned, or the concrete
370
- // / type that the parameter was same-type constrained to .
371
- ArchetypeType::NestedType ArchetypeOrConcreteType ;
369
+ // / The concrete type to which a this potential archetype has been
370
+ // / constrained.
371
+ Type ConcreteType ;
372
372
373
373
// / \brief Recursively conforms to itself.
374
374
unsigned IsRecursive : 1 ;
@@ -377,10 +377,6 @@ class ArchetypeBuilder::PotentialArchetype {
377
377
// / be resolved.
378
378
unsigned Invalid : 1 ;
379
379
380
- // / Whether we are currently substituting into the concrete type of
381
- // / this potential archetype.
382
- unsigned SubstitutingConcreteType : 1 ;
383
-
384
380
// / Whether we have detected recursion during the substitution of
385
381
// / the concrete type.
386
382
unsigned RecursiveConcreteType : 1 ;
@@ -403,7 +399,7 @@ class ArchetypeBuilder::PotentialArchetype {
403
399
// / associated type.
404
400
PotentialArchetype (PotentialArchetype *Parent, Identifier Name)
405
401
: ParentOrParam(Parent), NameOrAssociatedType(Name), Representative(this ),
406
- IsRecursive (false ), Invalid(false ), SubstitutingConcreteType( false ),
402
+ IsRecursive (false ), Invalid(false ),
407
403
RecursiveConcreteType(false ), RecursiveSuperclassType(false ),
408
404
DiagnosedRename(false )
409
405
{
@@ -415,7 +411,7 @@ class ArchetypeBuilder::PotentialArchetype {
415
411
PotentialArchetype (PotentialArchetype *Parent, AssociatedTypeDecl *AssocType)
416
412
: ParentOrParam(Parent), NameOrAssociatedType(AssocType),
417
413
Representative(this ), IsRecursive(false ), Invalid(false ),
418
- SubstitutingConcreteType( false ), RecursiveConcreteType(false ),
414
+ RecursiveConcreteType(false ),
419
415
RecursiveSuperclassType(false ), DiagnosedRename(false )
420
416
{
421
417
assert (Parent != nullptr && " Not an associated type?" );
@@ -426,7 +422,7 @@ class ArchetypeBuilder::PotentialArchetype {
426
422
PotentialArchetype (PotentialArchetype *Parent, TypeAliasDecl *TypeAlias)
427
423
: ParentOrParam(Parent), NameOrAssociatedType(TypeAlias),
428
424
Representative(this ), IsRecursive(false ), Invalid(false ),
429
- SubstitutingConcreteType( false ), RecursiveConcreteType(false ),
425
+ RecursiveConcreteType(false ),
430
426
RecursiveSuperclassType(false ), DiagnosedRename(false )
431
427
{
432
428
assert (Parent != nullptr && " Not an associated type?" );
@@ -438,7 +434,7 @@ class ArchetypeBuilder::PotentialArchetype {
438
434
Identifier Name)
439
435
: ParentOrParam(GenericParam),
440
436
NameOrAssociatedType(Name), Representative(this ), IsRecursive(false ),
441
- Invalid(false ), SubstitutingConcreteType( false ),
437
+ Invalid(false ),
442
438
RecursiveConcreteType(false ), RecursiveSuperclassType(false ),
443
439
DiagnosedRename(false )
444
440
{
@@ -448,6 +444,14 @@ class ArchetypeBuilder::PotentialArchetype {
448
444
// / \brief Recursively build the full name.
449
445
void buildFullName (bool forDebug, SmallVectorImpl<char > &result) const ;
450
446
447
+ // / Retrieve the generic parameter at the root of this potential archetype.
448
+ GenericTypeParamType *getRootParam () const {
449
+ if (auto parent = getParent ())
450
+ return parent->getRootParam ();
451
+
452
+ return getGenericParam ();
453
+ }
454
+
451
455
public:
452
456
~PotentialArchetype ();
453
457
@@ -466,14 +470,6 @@ class ArchetypeBuilder::PotentialArchetype {
466
470
return ParentOrParam.dyn_cast <PotentialArchetype *>();
467
471
}
468
472
469
- // / Retrieve the generic parameter at the root of this potential archetype.
470
- GenericTypeParamType *getRootParam () const {
471
- if (auto parent = getParent ())
472
- return parent->getRootParam ();
473
-
474
- return getGenericParam ();
475
- }
476
-
477
473
// / Retrieve the associated type to which this potential archetype
478
474
// / has been resolved.
479
475
AssociatedTypeDecl *getResolvedAssociatedType () const {
@@ -487,10 +483,31 @@ class ArchetypeBuilder::PotentialArchetype {
487
483
488
484
// / Retrieve the generic type parameter for this potential
489
485
// / archetype, if it corresponds to a generic parameter.
486
+ // /
487
+ // / FIXME: We should weaken this to just a depth/index key.
490
488
GenericTypeParamType *getGenericParam () const {
491
489
return ParentOrParam.dyn_cast <GenericTypeParamType *>();
492
490
}
493
-
491
+
492
+ // / Determine whether this is a generic parameter.
493
+ bool isGenericParam () const {
494
+ return ParentOrParam.is <GenericTypeParamType *>();
495
+ }
496
+
497
+ // / Retrieve the generic parameter key for a potential archetype that
498
+ // / represents this potential archetype.
499
+ // /
500
+ // / \pre \c isGenericParam()
501
+ GenericParamKey getGenericParamKey () const {
502
+ return getGenericParam ();
503
+ }
504
+
505
+ // / Retrieve the generic parameter key for the generic parameter at the
506
+ // / root of this potential archetype.
507
+ GenericParamKey getRootGenericParamKey () const {
508
+ return getRootParam ();
509
+ }
510
+
494
511
// / Retrieve the type alias.
495
512
TypeAliasDecl *getTypeAliasDecl () const {
496
513
return NameOrAssociatedType.dyn_cast <TypeAliasDecl *>();
@@ -550,33 +567,38 @@ class ArchetypeBuilder::PotentialArchetype {
550
567
PotentialArchetype *getNestedType (Identifier Name,
551
568
ArchetypeBuilder &builder);
552
569
570
+
553
571
// / \brief Retrieve (or build) the type corresponding to the potential
554
- // / archetype.
555
- ArchetypeType::NestedType getType (ArchetypeBuilder &builder);
572
+ // / archetype within the given generic environment.
573
+ ArchetypeType::NestedType getTypeInContext (ArchetypeBuilder &builder,
574
+ GenericEnvironment *genericEnv);
556
575
557
576
// / Retrieve the dependent type that describes this potential
558
577
// / archetype.
559
578
// /
579
+ // / \param genericParams The set of generic parameters to use in the resulting
580
+ // / dependent type.
581
+ // /
560
582
// / \param allowUnresolved If true, allow the result to contain
561
583
// / \c DependentMemberType types with a name but no specific associated
562
584
// / type.
563
- Type getDependentType (bool allowUnresolved);
585
+ Type getDependentType (ArrayRef<GenericTypeParamType *> genericParams,
586
+ bool allowUnresolved);
564
587
565
588
// / True if the potential archetype has been bound by a concrete type
566
589
// / constraint.
567
590
bool isConcreteType () const {
568
591
if (Representative != this )
569
592
return Representative->isConcreteType ();
570
593
571
- return ArchetypeOrConcreteType. isConcreteType ( );
594
+ return static_cast < bool >(ConcreteType );
572
595
}
573
596
574
597
// / Get the concrete type this potential archetype is constrained to.
575
598
Type getConcreteType () const {
576
- assert (isConcreteType ());
577
599
if (Representative != this )
578
600
return Representative->getConcreteType ();
579
- return ArchetypeOrConcreteType. getAsConcreteType () ;
601
+ return ConcreteType ;
580
602
}
581
603
582
604
void setIsRecursive () { IsRecursive = true ; }
0 commit comments