Commit Graph

753 Commits

Author SHA1 Message Date
Doug Gregor
9385849dc0 [GSB] Don't emit redundant superclass constraints.
We were emitting a superclass constraint for each connected component
of derived same-type constraints within an equivalence class, when in
fact we only need one superclass constraint for the entire equivalence
class.
2017-03-21 07:25:35 -07:00
Doug Gregor
5aa51e9532 [GSB] Keep track of all layout constraints.
As we've done with all of the other kinds of constraints, keep track
of all of the layout constraints on the equivalence class. Use the
normal mechanism to diagnose conflicts between different layout
constraints, warn about duplicate layout constraints, etc.
2017-03-21 06:59:40 -07:00
swift-ci
7811dc753d Merge pull request #8239 from DougGregor/all-same-type-constraints 2017-03-21 06:39:24 -07:00
Doug Gregor
0f4c14b22e [GSB] checkRedundantSuperclassConstraints() -> checkSuperclassConstraints() 2017-03-21 06:19:22 -07:00
Doug Gregor
094b0f8f54 [GSB] Rename checkRedundantConcreteTypeConstraints() to checkConcreteTypeConstraints() 2017-03-21 06:18:46 -07:00
Doug Gregor
4686801c2f Remove the now-unused GenericSignatureBuilder::updateRequirementSource(). 2017-03-21 06:14:37 -07:00
Doug Gregor
f429712253 [GSB] Track all same-type constraint requirement sources.
As we've been doing with other kinds of constraints, track *all* of
the requirement sources for deriving same-type constraints within the
equivalence class, then remove self-derived constraints at the end.

There is no checking for duplicated same-type constraints yet.
2017-03-21 06:11:05 -07:00
Hugh Bellamy
d9879522fb Fix top of tree Clang unused lambda capture warnings 2017-03-21 19:15:08 +07:00
Doug Gregor
9aed438f27 [GSB] Use isDerivedRequirement() for same-type connected components 2017-03-19 22:26:39 -07:00
Doug Gregor
eaee4add8a [GSB] Track all conformance constraint sources.
Move the storage for the protocols to which a particular potential
archetype conforms into EquivalenceClass, so that it is more easily
shared. More importantly, keep track of *all* of the constraint
sources that produced a particular conformance requirement, so we can
revisit them later, which provides a number of improvements:

* We can drop self-derived requirements at the end, once we've
  established all of the equivalence classes
* We diagnose redundant conformance requirements, e.g., "T: Sequence"
  is redundant if "T: Collection" is already specified.
* We can choose the best path when forming the conformance access
  path.
2017-03-16 23:15:37 -10:00
Doug Gregor
c443739d68 [GSB] Centralize reporting of same-type conflicts.
This eliminates a bunch of code repetition and handles "typealias"
conflict diagnostics more uniformly.
2017-03-15 22:33:38 -10:00
Doug Gregor
3c9f7a4c83 [GSB] Don't recursively resolve concrete types.
Resolving to a potential archetype with a concrete type maintains more
useful information in the GenericSignatureBuilder.
2017-03-15 22:33:38 -10:00
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
Huon Wilson
ca3a398b4a Merge pull request #8021 from huonw/protocol-where-clause
Parse/typecheck/print where clauses on protocols
2017-03-15 11:00:46 -07:00
swift-ci
2ba4f03d8a Merge pull request #8023 from huonw/tweak 2017-03-10 17:06:39 -08:00
Huon Wilson
a9299802bb Factor out first = true; ... if (first) first = false; else ....
There's an `interleave` function for this: let's use it.
2017-03-10 15:44:12 -08:00
Doug Gregor
3e80a616c4 [GSB] Hack the ordering of adding requirements for a signature.
This hack is papering over other issues in the generic signature
builder, where canonicalizing an existing generic signature---in which
we already know the specific associated type declarations---could
introduce "inferred" requirements, breaking the resulting requirement
signatures by producing too-short paths. By delaying same-type
requirements, we make this case less likely.

The correct solution is to eliminate
PotentialArchtype::getNestedType()'s injection of an inferred
requirement, but doing so requires a bit more surgery.
2017-03-09 21:57:54 -08:00
Doug Gregor
7809118f5e [GSB] Insert superclass constraints into the right place. 2017-03-09 21:55:40 -08:00
Doug Gregor
bca51d1186 [GSB] Fix a broken assertion. 2017-03-09 21:55:39 -08:00
Huon Wilson
5d89786031 [Sema] Feed protocol where clauses into the places that need to reason about them. 2017-03-09 16:23:31 -08:00
Slava Pestov
848076946d AST: Remove gatherAllSubstitutions() usages 2017-03-08 13:54:30 -08:00
Hugh Bellamy
7b2b1039be Fix Windows build as a result of recent GSB changes 2017-03-08 17:56:39 +07:00
Slava Pestov
5b48acf78e Merge pull request #7857 from slavapestov/fix-circular-deserialization-with-extensions
Re-apply "AST: Fix excessive deserialization in GenericSignatureBuilder"
2017-03-07 17:03:43 -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
58f794449e [GSB] Prefer shorter requirement sources to longer ones. 2017-03-07 10:23:24 -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
Slava Pestov
822b7f650f Re-apply "AST: Fix excessive deserialization in GenericSignatureBuilder"
This got reverted because it made our non-deterministic deserialization
crasher come up more often. Re-applying this patch to test the theory
that @jrose-apple's fix addressed the issue.
2017-03-01 18:14:12 -08: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
9d9cfe280b [AST/Sema] Eliminate a few unused 'depth' local variables. 2017-02-27 14:40:32 -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