Skip to content

Commit 958cea5

Browse files
authored
Merge pull request #7787 from DougGregor/same-type-to-concrete
2 parents 47b4309 + 00efc8b commit 958cea5

File tree

4 files changed

+191
-228
lines changed

4 files changed

+191
-228
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -377,17 +377,38 @@ class GenericSignatureBuilder {
377377
using RequirementRHS =
378378
llvm::PointerUnion3<Type, PotentialArchetype *, LayoutConstraint>;
379379

380+
/// Describes a constraint that is bounded on one side by a concrete type.
381+
struct ConcreteConstraint {
382+
PotentialArchetype *archetype;
383+
Type concreteType;
384+
const RequirementSource *source;
385+
};
386+
380387
/// Describes an equivalence class of potential archetypes.
381388
struct EquivalenceClass {
382389
/// Concrete type to which this equivalence class is equal.
390+
///
391+
/// This is the semantic concrete type; the constraints as written
392+
/// (or implied) are stored in \c concreteTypeConstraints;
383393
Type concreteType;
384394

395+
/// The same-type-to-concrete constraints written within this
396+
/// equivalence class.
397+
std::vector<ConcreteConstraint> concreteTypeConstraints;
398+
385399
/// The members of the equivalence class.
386400
TinyPtrVector<PotentialArchetype *> members;
387401

388402
/// Construct a new equivalence class containing only the given
389403
/// potential archetype (which represents itself).
390404
EquivalenceClass(PotentialArchetype *representative);
405+
406+
/// Find a source of the same-type constraint that maps a potential
407+
/// archetype in this equivalence class to a concrete type along with
408+
/// that concrete type as written.
409+
Optional<ConcreteConstraint>
410+
findAnyConcreteConstraintAsWritten(
411+
PotentialArchetype *preferredPA = nullptr) const;
391412
};
392413

393414
friend class RequirementSource;
@@ -602,7 +623,7 @@ class GenericSignatureBuilder {
602623
/// where \c Dictionary requires that its key type be \c Hashable,
603624
/// the requirement \c K : Hashable is inferred from the parameter type,
604625
/// because the type \c Dictionary<K,V> cannot be formed without it.
605-
void inferRequirements(TypeLoc type, unsigned minDepth, unsigned maxDepth);
626+
void inferRequirements(TypeLoc type);
606627

607628
/// Infer requirements from the given pattern, recursively.
608629
///
@@ -736,16 +757,6 @@ class GenericSignatureBuilder::PotentialArchetype {
736757
llvm::MapVector<Identifier, llvm::TinyPtrVector<PotentialArchetype *>>
737758
NestedTypes;
738759

739-
/// The concrete types to which this potential archetype has been
740-
/// constrained.
741-
///
742-
/// This vector runs parallel to ConcreteTypeSources.
743-
llvm::TinyPtrVector<Type> concreteTypes;
744-
745-
/// The source of the concrete type requirements that were written on
746-
/// this potential archetype.
747-
llvm::TinyPtrVector<const RequirementSource *> concreteTypeSources;
748-
749760
/// Whether this is an unresolved nested type.
750761
unsigned isUnresolvedNestedType : 1;
751762

@@ -973,22 +984,6 @@ class GenericSignatureBuilder::PotentialArchetype {
973984
SameTypeConstraints.end());
974985
}
975986

976-
/// Retrieve the concrete types as written on this potential archetype.
977-
const llvm::TinyPtrVector<Type>& getConcreteTypesAsWritten() const {
978-
return concreteTypes;
979-
}
980-
981-
/// Retrieve the concrete type sources as written on this potential archetype.
982-
ArrayRef<const RequirementSource *> getConcreteTypeSourcesAsWritten() const {
983-
return concreteTypeSources;
984-
}
985-
986-
/// Find a source of the same-type constraint that maps this potential
987-
/// archetype to a concrete type somewhere in the equivalence class of this
988-
/// type along with the concrete type that was written there.
989-
Optional<std::pair<Type, const RequirementSource *>>
990-
findAnyConcreteTypeSourceAsWritten() const;
991-
992987
/// \brief Retrieve (or create) a nested type with the given name.
993988
PotentialArchetype *getNestedType(Identifier Name,
994989
GenericSignatureBuilder &builder);

0 commit comments

Comments
 (0)