Skip to content

[GSB] Track all same-type constraint requirement sources. #8239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions include/swift/AST/GenericSignatureBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ class GenericSignatureBuilder {
llvm::MapVector<ProtocolDecl *, std::vector<Constraint<ProtocolDecl *>>>
conformsTo;

/// Same-type constraints between each potential archetype and any other
/// archetype in its equivalence class.
llvm::MapVector<PotentialArchetype *,
std::vector<Constraint<PotentialArchetype *>>>
sameTypeConstraints;

/// Concrete type to which this equivalence class is equal.
///
/// This is the semantic concrete type; the constraints as written
Expand Down Expand Up @@ -163,14 +169,6 @@ class GenericSignatureBuilder {
GenericSignatureBuilder(const GenericSignatureBuilder &) = delete;
GenericSignatureBuilder &operator=(const GenericSignatureBuilder &) = delete;

/// Update an existing constraint source reference when another constraint
/// source was found to produce the same constraint. Only the better
/// constraint source will be kept.
///
/// \returns true if the new constraint source was better, false otherwise.
bool updateRequirementSource(const RequirementSource *&existingSource,
const RequirementSource *newSource);

/// Retrieve the constraint source conformance for the superclass constraint
/// of the given potential archetype (if present) to the given protocol.
///
Expand Down Expand Up @@ -458,15 +456,15 @@ class GenericSignatureBuilder {
Diag<Type, T> redundancyDiag,
Diag<bool, Type, T> otherNoteDiag);

/// Check for redundant concrete type constraints within the equivalence
/// Check the concrete type constraints within the equivalence
/// class of the given potential archetype.
void checkRedundantConcreteTypeConstraints(
void checkConcreteTypeConstraints(
ArrayRef<GenericTypeParamType *> genericParams,
PotentialArchetype *pa);

/// Check for redundant superclass constraints within the equivalence
/// Check the superclass constraints within the equivalence
/// class of the given potential archetype.
void checkRedundantSuperclassConstraints(
void checkSuperclassConstraints(
ArrayRef<GenericTypeParamType *> genericParams,
PotentialArchetype *pa);

Expand All @@ -476,6 +474,12 @@ class GenericSignatureBuilder {
ArrayRef<GenericTypeParamType *> genericParams,
PotentialArchetype *pa);

/// Check same-type constraints within the equivalence class of the
/// given potential archetype.
void checkSameTypeConstraints(
ArrayRef<GenericTypeParamType *> genericParams,
PotentialArchetype *pa);

public:
/// \brief Resolve the given type to the potential archetype it names.
///
Expand Down Expand Up @@ -1025,11 +1029,6 @@ class GenericSignatureBuilder::PotentialArchetype {
mutable llvm::PointerUnion<PotentialArchetype *, EquivalenceClass *>
representativeOrEquivClass;

/// Same-type constraints between this potential archetype and any other
/// archetype in its equivalence class.
llvm::MapVector<PotentialArchetype *, const RequirementSource *>
SameTypeConstraints;

/// \brief The layout constraint of this archetype, if specified.
LayoutConstraint Layout;

Expand Down Expand Up @@ -1301,12 +1300,15 @@ class GenericSignatureBuilder::PotentialArchetype {
const RequirementSource *source);

/// Retrieve the same-type constraints.
llvm::iterator_range<
std::vector<std::pair<PotentialArchetype *, const RequirementSource *>>
::const_iterator>
getSameTypeConstraints() const {
return llvm::make_range(SameTypeConstraints.begin(),
SameTypeConstraints.end());
ArrayRef<Constraint<PotentialArchetype *>> getSameTypeConstraints() const {
if (auto equivClass = getEquivalenceClassIfPresent()) {
auto known = equivClass->sameTypeConstraints.find(
const_cast<PotentialArchetype *>(this));
if (known == equivClass->sameTypeConstraints.end()) return { };
return known->second;
}

return { };
}

/// \brief Retrieve (or create) a nested type with the given name.
Expand Down
Loading