Commit Graph

753 Commits

Author SHA1 Message Date
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
6492cc301c [GenericSigBuilder] Eliminate some redundancy in same-type-to-concrete checking. 2017-02-24 14:54:02 -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
21ebc5bff3 [gardening] Remove unused method isOuterArchetype(...) 2017-02-24 09:38:00 +01:00
practicalswift
d352652a72 Merge pull request #7727 from practicalswift/typos-20170223
[gardening] Fix typos
2017-02-24 09:15:12 +01:00
Doug Gregor
5245ecacf0 Teach RequirementSource::dump() to print a newline.
Helpful when debugging so the output doesn't get buffered.
2017-02-23 21:54:32 -08:00
practicalswift
33a5601ad1 [gardening] Fix typos 2017-02-23 22:46:40 +01:00
Doug Gregor
cbbf415435 [GenericSigBuilder] Archetypes no longer make it to this path. NFC 2017-02-23 13:43:18 -08:00
Doug Gregor
e71788d7a6 [GenericSigBuilder] Conformances due to concrete types can be abstract.
When a type parameter is made concrete via an existential type,
conformance requirements on that type parameter will be
abstract. Fixes rdar://problem/30610428.
2017-02-23 13:41:08 -08:00
swift-ci
f1231a4c49 Merge pull request #7518 from DougGregor/concrete-archetype-anchors 2017-02-22 17:55:26 -08:00
Doug Gregor
121e1aa13c [Generic signature builder] Eliminate hack that performs an extra walk of potential archetypes. 2017-02-22 16:47:03 -08:00
Doug Gregor
10fc3fa546 [GenericSig Builder] Make resolve() less representative-dependent.
`GenericSignatureBuilder::resolve()` was always jumping to the
representative, to treat typealias representatives as
special. However, doing this means that we put the same-type
constraint on the wrong potential archetype (with the wrong source).

Eliminate the use of `getRepresentative()`. This unfortunately
causes us to need recursive resolution, because we can't always depend
on jumping to the representative to avoid it.
2017-02-21 22:19:19 -08: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
Doug Gregor
e7a4fbc98b Revert "[Generic signature builder] Align the representative with the archetype anchor."
This reverts commit 0df3adb7a3.
2017-02-21 13:41:26 -08:00
Doug Gregor
ad459542a1 Revert "[Generic signature builder] Eliminate "concrete type in path" checks."
This reverts commit 58f181a470.
2017-02-21 13:41:26 -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
d514e01c06 [Generic signature builder] diagnose typealiases with the same name and different types.
At the moment, these are only done on demand, when the typealias is
actually used somewhere, because there's currently a recursive
validation loop that stops doing it more eagerly from working in many
cases.
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
2a4c8dc581 Merge pull request #7581 from DougGregor/generic-sig-builder-inheritance-cleanup
[GenericSigBuilder] Clean up handling of "inheritance" clauses.
2017-02-17 21:28:40 -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
fa21e00570 Merge pull request #7578 from DougGregor/generic-sig-builder-cleanups
Generic signature builder cleanups
2017-02-17 16:28:03 -08:00
Doug Gregor
ef4c8840e9 [GenericSigBuilder] Use addRequirement() rather than hardcoding it. DRY 2017-02-17 15:49:00 -08:00
Slava Pestov
36b2927b2c Merge pull request #7563 from slavapestov/protocol-typealias-wrong-self
AST: Fix GenericSignatureBuilder bug with protocol typealiases
2017-02-17 15:49:00 -08:00
Doug Gregor
28987ca21e [GenericSigBuilder] Remove some dead code; we don't deal with ArchetypeTypes. 2017-02-17 15:41:39 -08:00
Slava Pestov
cd893ea84a AST: Fix GenericSignatureBuilder bug with protocol typealiases
If a nested type of a generic parameter was a typealias, and the
generic parameter was not at depth 0, index 0, we would resolve
the type down to the wrong PotentialArchetype, causing bogus
diagnostics and crashes.

Make sure we apply a substitution to the typealias's underlying
type before resolving it, to map it to the correct PotentialArchetype.

Note that the original test case in the radar works now, but the more
comprehensive test I added exposes an existing problem where generic
signature canonicalization is not idempotent. When this is fixed,
the RUN: line in the test can be changed from -typecheck to -emit-ir.

Fixes <rdar://problem/30248571>.
2017-02-17 14:53:18 -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
Doug Gregor
2cb23fb8d7 Revert "Reinstate "AST: Fix excessive deserialization in GenericSignatureBuilder""
This reverts commit 464dac7c51.
2017-02-16 13:38:12 -08:00
Doug Gregor
464dac7c51 Reinstate "AST: Fix excessive deserialization in GenericSignatureBuilder"
This reverts commit d3926d1b09.
2017-02-16 10:59:24 -08:00
Jordan Rose
d3926d1b09 Revert "AST: Fix excessive deserialization in GenericSignatureBuilder" 2017-02-16 09:17:24 -08:00
Slava Pestov
62b650af83 AST: Fix excessive deserialization in GenericSignatureBuilder
When we're looking up all associated types with the same name in order
to find the right archetype anchor, skip extension members to avoid
circular deserialization.

Discovered while investigating <rdar://problem/30248571>.
2017-02-15 17:01:44 -08:00
Slava Pestov
41eba98902 Gardening: Fix some unused variable warnings in no-assert builds 2017-02-15 12:57:35 -08:00
practicalswift
65b0219f7b [gardening] Fix typos 2017-02-14 20:04:08 +01:00
Doug Gregor
58f181a470 [Generic signature builder] Eliminate "concrete type in path" checks.
We no longer need the "concrete type in path" checks to correctly
order potential archetypes, and they prohibit us from making the
representative always the archetype anchor.
2017-02-13 13:59:17 -08:00
Doug Gregor
9118a0488c [Generic signature builder] Eliminate isBetterArchetypeAnchor.
It's just a wrapper around compareDependentTypes() that was only used
for assertions.
2017-02-13 13:03:14 -08:00
Doug Gregor
0df3adb7a3 [Generic signature builder] Align the representative with the archetype anchor.
Make the representative of an equivalence class also be the archetype
anchor, so we don't need to walk through the equivalence class each
time we need the archetype anchor.
2017-02-13 13:03:13 -08:00
Doug Gregor
189f8a7843 [Generic signature builder] Align isBetterArchetypeAnchor and compareDependentTypes.
The latter was also performing the concrete-type-in-path check; do
that within compareDependentTypes(); we don't want a different here.
2017-02-13 13:03:13 -08:00
Doug Gregor
e3479e25fc [Generic signature builder] Concrete constraints across equivalence classes.
When emitting a requirement for a same-type-to-concrete constraint,
use the known concrete source for just the first of the component
anchors. For the rest, we need to explicitly model the constraint lest
it get lost. Fixes rdar://problem/30478915.
2017-02-13 12:49:09 -08:00
Doug Gregor
f6915546a2 [Generic signature builder] Ordering of nested types doesn't matter.
... so don't treat typealias-bound nested types as special.
2017-02-13 12:48:54 -08:00
practicalswift
3e40296cfa [gardening] Fix inconsistent headers 2017-02-13 15:21:52 +01:00
Slava Pestov
e8bd2cb367 AST: Targeted fix to prevent 0059-sr3321.swift from regressing 2017-02-12 00:51:25 -08:00
Doug Gregor
b6d54431cb Merge pull request #7398 from huonw/gsb-cleanups
[Generic signature builder] Substitute requirements instead of threading a PA around.
2017-02-11 18:48:05 -08:00
Doug Gregor
416d935df6 [Generic signature builder] Use addSameTypeRequirementBetweenArchetypes consistently.
Rather than trying to set the representative directly when adding
implicit requirements, use addSameTypeRequirementBetweenArchetypes()
consistently.
2017-02-11 00:04:12 -08:00
Huon Wilson
923113d912 [Generic signature builder] switch (...), not chained if (... ==). 2017-02-10 18:59:11 -08: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