Commit Graph

194 Commits

Author SHA1 Message Date
Doug Gregor
372d7bbf60 [GSB] Rework construction of nested types.
Our handling of nested types was scattered in several places, and
(worse) correct computation of archetype anchors required us to
"explode" out all of the potential archetypes for every associated
type with the given name to ensure that we get the right one.

Make nested type construction somewhat more lazy: if asked for a
nested type for a specific associated type, just create the nested
type for that associated type (instead of *all* of them). If asked for
a nested type by name, either return the one we already have or create
the one that's most likely to be the archetype anchor. Overall, this
should result in many fewer potential archetypes being constructed.
2017-03-15 22:33:38 -10:00
Doug Gregor
ce106bc98f [GSB] Abstract the storage for the nested types of a potential archetype
NFC so far; we're going to track more information here.
2017-03-15 22:33:38 -10:00
Doug Gregor
1f8b0f9b85 Canonicalize conformance access paths for sources pre-requirement-signature.
When a requirement source involving a ProtocolRequirement element is
built prior to the requirement signature of the protocol it
references, we can end up with a requirement source whose steps don't
reflect was is actually available via the requirement signatures. When
building a conformance access path from such requirement sources,
canonicalize on-the-fly using the requirement signatures (which have
been/can be computed by this point) to produce a correct access path.
2017-03-08 16:14:55 -08:00
Doug Gregor
81ed11ccfa Merge pull request #7959 from DougGregor/inferred-requirements-are-not-redundant
[GSB] Don't complain about redundant requirements with inferred sources.
2017-03-07 11:26:45 -08:00
Doug Gregor
23184497e2 [GSB] Don't complain about redundant requirements with inferred sources.
If a requirement is made redundant due to another requirement that was
inferred from the signature of a generic declaration, don't diagnose
the former as redundant. The user has likely written the requirement
explicitly for clarity purposes (e.g., to emphasize the Hashable
requirement on a function that takes a Set<T>). Removing the
requirement to silence the warning would make the code less clear.

This eliminates all of the annoying, spurious warnings from the build
of the overlays.
2017-03-07 10:41:06 -08:00
Doug Gregor
cd93126b4f [GSB] Teach requirement inference to use SubstitutionMaps.
The ad hoc substitution functions here were really odd; use
SubstitutionMap directly, and pass it through to
GenericSignatureBuilder::addRequirement().
2017-03-07 09:09:49 -08:00
Doug Gregor
908123ac11 [GSB] Fix requirement sources from protocol requirement signature.
The stored dependent types in ProtocolRequirement elements within
requirement sources were incorrect for requirements created from the
requirement signature of another protocol, because we picked up the
already-substituted subject type. Thread the optional substitution map
through addRequirement(Requirement) as well, so we maintain the
original spelling of the stored dependent type.

This is a temporary fix; we should be able to recover the stored
dependent types from the potential archetypes in the requirement
source, so that we don't need to specify them explicitly at
construction time.
2017-03-07 08:55:17 -08:00
Doug Gregor
370550f472 [GSB] Abstract ConcreteConstraint to a more-general Constraint<T>. 2017-03-06 16:31:30 -08:00
Doug Gregor
730ecfe610 [GSB] Start tracking the owning dependent type in requirement sources.
For a protocol requirement element within a requirement source, track
both the protocol in which the requirement was introduced as well as
the dependent type (relative to that protocol) on which the
requirement was introduced. This information is important when
reconstructing the path from a requirement-as-written to the location
of a desired protocol conformance.
2017-03-06 11:53:39 -08:00
Doug Gregor
84c5d3ee28 [GSB] Start tracking source locations for requirements within protocols.
Start reshuffling RequirementSource to store more information about
requirements in protocols. As a small step, track the source locations
for requirements written within the protocols themselves.

Note: there's a QoI regression here where we get duplicated
diagnostics (due to multiple generic signature builders being built
from a bad signature).
2017-03-06 10:11:18 -08:00
Doug Gregor
6c9394a2b5 [GSB] Always build "via protocol requirements" sources through floating sources.
The use of floating sources allows us to carry through the protocol
information (i.e., "in which protocol do we look for this
information?") without immediately forming a new
RequirementSource. Yet more NFC refactoring for protocol-requirement
sources to carry more pertinent information.
2017-03-06 10:11:18 -08:00
Doug Gregor
2aa2d3ea4d [GSB] Teach the addRequirement(RequirementRepr*) to use a floating source.
NFC cleanup for now, which is staging for a change to provide more
information for "abstract protocol requirement" path elements.
2017-03-06 10:11:18 -08:00
Hugh Bellamy
33f5f89912 Update unreachable control path annotations 2017-03-03 20:21:49 +07:00
Doug Gregor
d1627dcc83 [GSB] Check superclass constraints against concrete constraints.
Centralize the checking of a superclass constraint against a
same-type-to-concrete constraint. Additionally, produce a warning if
the superclass constraint is satisfied but is made redundant by an
existing same-type constraint.
2017-02-28 16:39:58 -08:00
Doug Gregor
cdb38c1e97 [GSB] Check all superclass constraints during finalization.
Use the same infrastructure we have for same-type-to-concrete
constraints to check superclass constraints. Specifically,

* Track all superclass constraints; never "update" a requirement source
* Remove self-derived superclass constraints
* Pick the best superclass constraint within each connected component
  of an equivalence class and use that for requirement generation.
* Diagnose conflicting superclass requirements during finalization
* Diagnose redundant superclass requirements (during finalization)
2017-02-28 16:14:30 -08:00
Doug Gregor
a97fa06744 [GSB] Factor out the checking of of the concrete-type constraints.
This checking will also be used for other kinds of constraints (e.g.,
superclass constraints), so factor it out in advance.
2017-02-28 14:52:51 -08:00
Doug Gregor
5ec385797f [GSB] Remove self-derived same-type-to-concrete constraints.
Introduce an operation on RequirementSource to determine whether a
constraint with such a source, when it lands on a given potential
archetype, is "self-derived": e.g., the final constraint is derived
from the original constraint. Remove such constraints from the system
during finalization, because otherwise they would make the original
constraint redundant.

Fixes rdar://problem/30478915, although we still need to apply this
same logic to other kinds of constraints in the system.
2017-02-28 09:47:30 -08:00
Doug Gregor
c2da97172b [GSB] Store the root potential archetype in RequirementSource.
Use TrailingObjects to help us efficiently store the root potential
archetype within requirement sources, so we can reconstruct the
complete path from the point where a requirement was created to the
potential archetype it affects.

The test changes are because we are now dumping the root potential
archetype as part of -debug-generic-signatures.
2017-02-28 09:47:11 -08:00
Doug Gregor
2d430d8324 [GSB] Always pass a root potential archetype to a requirement source.
Whenever we create a (root) requirement source, associate it with the
potential archetype on which the requirement is written. This lets us
follow a requirement source from the (stated or implied) requirement on
the root potential archetype to the effective requirement on the
resulting potential archetype.

Introduce FloatingRequirementSource for the cases where we need to
state what the root source is, but don't yet have a potential
archetype to attach it to. These get internally resolved to
RequirementSources as soon as possible.
2017-02-28 09:47:02 -08:00
Doug Gregor
dbf5782d56 [GSB] Provide a root potential archetype for requirement-signature sources. 2017-02-28 09:42:06 -08:00
Doug Gregor
f7bc907d23 [GSB] Provide a root potential archetype for nested-type-name-match sources. 2017-02-28 09:41:52 -08:00
Doug Gregor
40a813bc8d [GenericSigBuilder] Sink RequirementSource into GenericSignatureBuilder. 2017-02-28 09:41:23 -08:00
Doug Gregor
6adeb2db5d [GenericSigBuilder] Track associated type declarations in RequirementSource. 2017-02-28 09:37:06 -08:00
Doug Gregor
5c2fe3496f Merge pull request #7740 from huonw/parse-assoc-type-where
(Mostly) Type-check where clauses on associated types
2017-02-27 22:06:51 -08:00
Doug Gregor
00efc8b93a [GenericSigBuilder] Remove unused min/max depth for inference.
We know the depth from the generic signature.
2017-02-27 11:21:08 -08:00
Doug Gregor
0c0de0adf4 [AST] Move storage of same-type-to-concrete constraints to EquivalenceClass.
Most clients that will be considering same-type-to-concrete
constraints will need to look at all of the constraints within the
equivalence class together. Store the same-type-to-concrete
constraints on the EquivalenceClass itself, which fits this use case
better, and should reduce the storage requirements by making potential
archetypes two pointers smaller. NFC
2017-02-27 10:26:47 -08:00
practicalswift
99ceb78c7d Merge pull request #7723 from practicalswift/gardening-20170223
[gardening] Shell fixes. Consistent headers. a-vs-an typos. Python fixes. Unused variables and methods.
2017-02-27 14:05:05 +01:00
Huon Wilson
d9441a04ed [GenericSignatureBuilder] Consume where clauses on associated types. 2017-02-24 19:24:14 -08:00
swift-ci
41c6247b26 Merge pull request #7755 from DougGregor/all-same-type-to-concrete 2017-02-24 16:39:12 -08:00
Doug Gregor
29256e526c [GenericSigBuilder] Track all same-type-to-concrete constraints.
When we see a second same-type-to-concrete constraint on a particular
potential archetype, record it. Previously, we were checking it and
then updating the requirement source eagerly. That won't work with
proper recursion detection, and meant that we missed out on some
obvious redundant-same-type-constraint diagnostics.

The scheme here is to build up the equivalence classes without losing
any information, and then determine which information is redundant at
the end.
2017-02-24 15:43:17 -08:00
Doug Gregor
ba81b66f26 [GenericSigBuilder] Migrate the concrete type into to EquivalenceClass. 2017-02-24 14:47:59 -08:00
Doug Gregor
04ba576e3f [GenericSig Builder] Introduce an equivalence-class abstraction.
Introduce an equivalence-class abstraction that captures all of the
members of the equivalence class in a separate type that will maintain
the "truth" about the meaning of the equivalence class, rather than
having that information distributed amongst the potential archetypes
within the class.

For now, use it to capture the members of the equivalence classes, so
we have one SmallVector per equivalence class rather than N
SmallVectors.
2017-02-24 14:25:03 -08:00
swift-ci
fc0b3dd570 Merge pull request #7747 from DougGregor/same-type-to-concrete-redundancy 2017-02-24 11:51:08 -08:00
Doug Gregor
d697c2fdcb [GenericSig Builder] Diagnose redundant same-typeo-t-concrete constraints.
Diagnose when a same-type constraint (to a concrete type) is made
redundant by another same-type constraint. Slightly improve the
diagnostic that handles collisions between two same-type constraints.
2017-02-24 10:44:30 -08:00
practicalswift
98d2254073 [gardening] Fix a-vs-an typos 2017-02-24 09:38:00 +01:00
practicalswift
33a5601ad1 [gardening] Fix typos 2017-02-23 22:46:40 +01:00
Doug Gregor
23f3ba53f8 [GenericSig Builder] Track and canonicalize same-type-to-concrete constraints.
Track each same-type-to-concrete constraint on the potential archetype
against which it was written, and ensure that the requirement sources
for such same-type constraints stay with the potential archetypes on
which they were described. This is similar to the way we track
same-type constraints among potential archetypes.

Use this information to canonicalize same-type-to-concrete constraints
appropriately. For each connected component within an equivalence
class of potential archetypes, select the best requirement source to
the concrete type, or substitute in an abstract requirement source if
none exists. This approach ensures that components that would be
equivalent to that concrete type anyway get a derived source, while
components that get the concrete-type equivalence by being tied to
another

To get here, we also needed to change the notion of the archetype
anchor so that potential archetypes with no same-type constraints
directly in their path are preferred over potential archetypes that do
have a same-type constraint in their path. Otherwise, the anchor might
be something that is always concrete and is, therefore, not terribly
interesting.

Fixes the new case that popped up in rdar://problem/30478915.
2017-02-21 22:19:18 -08:00
Huon Wilson
d671a6527b [Generic signature builder] paper over problems with generic typealiases in protocols.
Generic typealiases are entirely broken as archetypes, but some things
mostly worked with them before introducing ResolvedType, so let's
restore that behaviour.
2017-02-20 11:48:07 -08:00
Huon Wilson
f64ef03235 [Generic signature builder] resolve types deeper in same type requirements.
This adds the concept of an "unresolved type" and a "resolved type",
where the latter involves stripping away any typealias archetype layers
from the former, to get to the "true" potential archetype or concrete
type that something refers to.
2017-02-20 11:48:06 -08:00
Doug Gregor
d017fe3ab4 [GenericSigBuilder] Clean up handling of "inheritance" clauses.
Unify the handling of the "inheritance" clauses of a generic type
parameter, associated type, or protocol, walking them in a
TypeRepr-preserving manner and adding requirements as they are
discovered. This sets the stage for providing better source-location
information [*].

This eliminates a redundant-but-different code path for protocol
"inheritance" clauses, which was using
ProtocolDecl::getInheritedProtocols() rather than looking at the
actual TypeReprs, and unifies the logic with that of associated types
and type parameters. This eliminates a near-DRY violation, sets us up
for simplifying the "inherited protocols" part of ProtocolDecl, and
sets us up better for the soon-to-be-proposed

  class C { }
  protocol P: C { }

[*] We still drop it, but now we have a FIXME!
2017-02-17 17:39:10 -08:00
Doug Gregor
da39d9b17b [GenericSig Builder] Rework RequirementSource to describe requirement path.
Reimplement the RequirementSource class, which captures how
a particular requirement is satisfied by a generic signature. The
primary goal of this rework is to keep the complete path one follows
in a generic signature to get from some explicit requirement in the
generic signature to some derived requirement or type, e.g.,

1) Start at an explicit requirement "C: Collection"
2) Go to the inherited protocol Sequence,
3) Get the "Iterator" associated type
4) Get its conformance to "IteratorProtocol"
5) Get the "Element" associated type

We don't currently capture all of the information we want in the path,
but the basic structure is there, and should also allow us to capture
more source-location information, find the "optimal" path, etc. There are
are a number of potential uses:

* IRGen could eventually use this to dig out the witness tables and
  type metadata it needs, instead of using its own fulfillment
  strategy
* SubstitutionMap could use this to lookup conformances, rather than
  it's egregious hacks
* The canonical generic signature builder could use this to lookup
  conformances as needed, e.g., for the recursive-conformances case.

... and probably more simplifications, once we get this right.
2017-02-17 13:50:51 -08:00
practicalswift
3e40296cfa [gardening] Fix inconsistent headers 2017-02-13 15:21:52 +01:00
Huon Wilson
f1dba0e7e8 [Generic signature builder] Substitute requirements instead of threading a PA around.
This essentially undoes the implementation in 51da51dfc0, which
implicitly did a substitution of the Self type in a protocol's
requirement signature by threading around the replacement PA. This is
brittle because every part of the code needs to take and pass around the
argument. By preemptively substituting, the whole requirement is in the
right form from the time it enters `addRequirement`.

The infrastructure here also allows simplifying some code.
2017-02-10 18:58:56 -08:00
Doug Gregor
579af863c5 Rename ArchetypeBuilder -> GenericSignatureBuilder 2017-02-10 12:46:34 -08:00