@@ -484,31 +484,27 @@ bool GenericSignature::requiresClass(Type type, ModuleDecl &mod) {
484
484
if (!type->isTypeParameter ()) return false ;
485
485
486
486
auto &builder = *getGenericSignatureBuilder (mod);
487
- auto pa =
488
- builder.resolveArchetype (type, ArchetypeResolutionKind::CompleteWellFormed);
489
- if (!pa) return false ;
490
-
491
- if (pa-> isConcreteType () ) return false ;
487
+ auto equivClass =
488
+ builder.resolveEquivalenceClass (
489
+ type,
490
+ ArchetypeResolutionKind::CompleteWellFormed);
491
+ if (!equivClass ) return false ;
492
492
493
493
// If this type was mapped to a concrete type, then there is no
494
494
// requirement.
495
- pa = pa->getRepresentative ();
496
-
497
- if (pa->isConcreteType ()) return false ;
495
+ if (equivClass->concreteType ) return false ;
498
496
499
497
// If there is a layout constraint, it might be a class.
500
- if (auto layout = pa->getLayout ()) {
501
- if (layout->isClass ()) return true ;
502
- }
498
+ if (equivClass->layout && equivClass->layout ->isClass ()) return true ;
503
499
504
500
// If there is a superclass bound, then obviously it must be a class.
505
501
// FIXME: We shouldn't need this?
506
- if (pa-> getSuperclass () ) return true ;
502
+ if (equivClass-> superclass ) return true ;
507
503
508
504
// If any of the protocols are class-bound, then it must be a class.
509
505
// FIXME: We shouldn't need this?
510
- for (auto proto : pa-> getConformsTo () ) {
511
- if (proto ->requiresClass ()) return true ;
506
+ for (const auto &conforms : equivClass-> conformsTo ) {
507
+ if (conforms. first ->requiresClass ()) return true ;
512
508
}
513
509
514
510
return false ;
@@ -519,37 +515,41 @@ Type GenericSignature::getSuperclassBound(Type type, ModuleDecl &mod) {
519
515
if (!type->isTypeParameter ()) return nullptr ;
520
516
521
517
auto &builder = *getGenericSignatureBuilder (mod);
522
- auto pa =
523
- builder.resolveArchetype (type, ArchetypeResolutionKind::CompleteWellFormed);
524
- if (!pa) return nullptr ;
518
+ auto equivClass =
519
+ builder.resolveEquivalenceClass (
520
+ type,
521
+ ArchetypeResolutionKind::CompleteWellFormed);
522
+ if (!equivClass) return nullptr ;
525
523
526
524
// If this type was mapped to a concrete type, then there is no
527
525
// requirement.
528
- if (pa-> isConcreteType () ) return nullptr ;
526
+ if (equivClass-> concreteType ) return nullptr ;
529
527
530
528
// Retrieve the superclass bound.
531
- return pa-> getSuperclass () ;
529
+ return equivClass-> superclass ;
532
530
}
533
531
534
532
// / Determine the set of protocols to which the given dependent type
535
533
// / must conform.
536
- SmallVector<ProtocolDecl *, 2 > GenericSignature::getConformsTo (Type type,
537
- ModuleDecl &mod) {
534
+ SmallVector<ProtocolDecl *, 2 >
535
+ GenericSignature::getConformsTo (Type type, ModuleDecl &mod) {
538
536
if (!type->isTypeParameter ()) return { };
539
537
540
538
auto &builder = *getGenericSignatureBuilder (mod);
541
- auto pa =
542
- builder.resolveArchetype (type, ArchetypeResolutionKind::CompleteWellFormed);
543
- if (!pa) return { };
539
+ auto equivClass =
540
+ builder.resolveEquivalenceClass (
541
+ type,
542
+ ArchetypeResolutionKind::CompleteWellFormed);
543
+ if (!equivClass) return { };
544
544
545
545
// If this type was mapped to a concrete type, then there are no
546
546
// requirements.
547
- if (pa-> isConcreteType () ) return { };
547
+ if (equivClass-> concreteType ) return { };
548
548
549
549
// Retrieve the protocols to which this type conforms.
550
550
SmallVector<ProtocolDecl *, 2 > result;
551
- for (auto proto : pa-> getConformsTo () )
552
- result.push_back (proto );
551
+ for (const auto &conforms : equivClass-> conformsTo )
552
+ result.push_back (conforms. first );
553
553
554
554
// Canonicalize the resulting set of protocols.
555
555
ProtocolType::canonicalizeProtocols (result);
@@ -563,19 +563,17 @@ bool GenericSignature::conformsToProtocol(Type type, ProtocolDecl *proto,
563
563
if (!type->isTypeParameter ()) return false ;
564
564
565
565
auto &builder = *getGenericSignatureBuilder (mod);
566
- auto pa =
567
- builder.resolveArchetype (type, ArchetypeResolutionKind::CompleteWellFormed);
568
- if (!pa) return false ;
566
+ auto equivClass =
567
+ builder.resolveEquivalenceClass (
568
+ type,
569
+ ArchetypeResolutionKind::CompleteWellFormed);
570
+ if (!equivClass) return false ;
569
571
570
572
// FIXME: Deal with concrete conformances here?
571
- if (pa-> isConcreteType () ) return false ;
573
+ if (equivClass-> concreteType ) return false ;
572
574
573
575
// Check whether the representative conforms to this protocol.
574
- if (auto equivClass = pa->getEquivalenceClassIfPresent ())
575
- if (equivClass->conformsTo .count (proto) > 0 )
576
- return true ;
577
-
578
- return false ;
576
+ return equivClass->conformsTo .count (proto) > 0 ;
579
577
}
580
578
581
579
// / Determine whether the given dependent type is equal to a concrete type.
@@ -590,23 +588,27 @@ Type GenericSignature::getConcreteType(Type type, ModuleDecl &mod) {
590
588
if (!type->isTypeParameter ()) return Type ();
591
589
592
590
auto &builder = *getGenericSignatureBuilder (mod);
593
- auto pa =
594
- builder.resolveArchetype (type, ArchetypeResolutionKind::CompleteWellFormed);
595
- if (!pa) return Type ();
591
+ auto equivClass =
592
+ builder.resolveEquivalenceClass (
593
+ type,
594
+ ArchetypeResolutionKind::CompleteWellFormed);
595
+ if (!equivClass) return Type ();
596
596
597
- return pa-> getConcreteType () ;
597
+ return equivClass-> concreteType ;
598
598
}
599
599
600
600
LayoutConstraint GenericSignature::getLayoutConstraint (Type type,
601
601
ModuleDecl &mod) {
602
602
if (!type->isTypeParameter ()) return LayoutConstraint ();
603
603
604
604
auto &builder = *getGenericSignatureBuilder (mod);
605
- auto pa =
606
- builder.resolveArchetype (type, ArchetypeResolutionKind::CompleteWellFormed);
607
- if (!pa) return LayoutConstraint ();
605
+ auto equivClass =
606
+ builder.resolveEquivalenceClass (
607
+ type,
608
+ ArchetypeResolutionKind::CompleteWellFormed);
609
+ if (!equivClass) return LayoutConstraint ();
608
610
609
- return pa-> getLayout () ;
611
+ return equivClass-> layout ;
610
612
}
611
613
612
614
bool GenericSignature::areSameTypeParameterInContext (Type type1, Type type2,
@@ -618,21 +620,21 @@ bool GenericSignature::areSameTypeParameterInContext(Type type1, Type type2,
618
620
return true ;
619
621
620
622
auto &builder = *getGenericSignatureBuilder (mod);
621
- auto pa1 =
622
- builder.resolveArchetype (type1,
623
+ auto equivClass1 =
624
+ builder.resolveEquivalenceClass (
625
+ type1,
623
626
ArchetypeResolutionKind::CompleteWellFormed);
624
- assert (pa1 && " not a valid dependent type of this signature?" );
625
- pa1 = pa1->getRepresentative ();
626
- assert (!pa1->isConcreteType ());
627
+ assert (equivClass1 && " not a valid dependent type of this signature?" );
628
+ assert (!equivClass1->concreteType );
627
629
628
- auto pa2 =
629
- builder.resolveArchetype (type2,
630
+ auto equivClass2 =
631
+ builder.resolveEquivalenceClass (
632
+ type2,
630
633
ArchetypeResolutionKind::CompleteWellFormed);
631
- assert (pa2 && " not a valid dependent type of this signature?" );
632
- pa2 = pa2->getRepresentative ();
633
- assert (!pa2->isConcreteType ());
634
+ assert (equivClass2 && " not a valid dependent type of this signature?" );
635
+ assert (!equivClass2->concreteType );
634
636
635
- return pa1 == pa2 ;
637
+ return equivClass1 == equivClass2 ;
636
638
}
637
639
638
640
bool GenericSignature::isCanonicalTypeInContext (Type type, ModuleDecl &mod) {
@@ -772,9 +774,10 @@ ConformanceAccessPath GenericSignature::getConformanceAccessPath(
772
774
773
775
// Resolve this type to a potential archetype.
774
776
auto &builder = *getGenericSignatureBuilder (mod);
775
- auto pa =
776
- builder.resolveArchetype (type, ArchetypeResolutionKind::CompleteWellFormed);
777
- auto equivClass = pa->getOrCreateEquivalenceClass ();
777
+ auto equivClass =
778
+ builder.resolveEquivalenceClass (
779
+ type,
780
+ ArchetypeResolutionKind::CompleteWellFormed);
778
781
779
782
// Dig out the conformance of this type to the given protocol, because we
780
783
// want its requirement source.
@@ -873,11 +876,10 @@ ConformanceAccessPath GenericSignature::getConformanceAccessPath(
873
876
Type storedType = eraseAssociatedTypes (source->getStoredType ());
874
877
875
878
// Dig out the potential archetype for this stored type.
876
- auto pa =
877
- inProtoSigBuilder.resolveArchetype (
879
+ auto equivClass =
880
+ inProtoSigBuilder.resolveEquivalenceClass (
878
881
storedType,
879
882
ArchetypeResolutionKind::CompleteWellFormed);
880
- auto equivClass = pa->getOrCreateEquivalenceClass ();
881
883
882
884
// Find the conformance of this potential archetype to the protocol in
883
885
// question.
0 commit comments