Commit Graph

223 Commits

Author SHA1 Message Date
Doug Gregor
54f132c487 [GSB] Delete all of the "visited" sets, which are now unused.
Now that we detect recursion based on repetition within the potential
archetypes, we no longer rely on passing down "visited" sets to
detect/diagnose recursion. Remove them.
2017-04-17 23:13:21 -07:00
Doug Gregor
17846e2be1 [GSB] Cope with recursive requirements by delaying them.
Rather than detecting recursion and bailing early, delay requirements
that would form recursive types. Note that we aren't actually
processing them later.
2017-04-17 23:13:21 -07:00
Doug Gregor
995de881c7 [GSB] Teach addInheritedRequirements() and its callers to use UnresolvedType.
Teach addInheritedRequirements() to take an UnresolvedType, so the
requirements it adds can be delayed if needed. More importantly, teach
the primary caller (addConformanceRequirement) not to use
getNestedType directly; instead, form an appropriate Type and let the
type-resolution machinery handle it.
2017-04-17 23:13:21 -07:00
Doug Gregor
280bb3091f [GSB] Remove an unused entrypoint. 2017-04-16 23:05:55 -07:00
Doug Gregor
3b9cb5afa9 [GSB] Drop derived-from-concrete superclass/layout/etc. constraints.
Apply the same logic used for self-derived conformance constraints,
where we drop constraints derived from concrete conformances, to the
remaining kinds of constraints covered by isSelfDerivedSource().
2017-04-16 23:05:28 -07:00
Doug Gregor
0f5d561dbe [GSB] Factor out a path-walking operation visitPotentialArchetypesAlongPath().
Factor out a core operation of RequirementSource that walks the
potential archetypes from the root to the end of the path, enumerating
each partial RequirementSource along with the potential archetype to
which it applies. Use it for getting the final archetype to which the
RequirementSource refers, as well as simplifying the self-derived
check for conformance requirements.
2017-04-16 23:05:27 -07:00
Doug Gregor
8dfc25edc7 [GSB] Filter out conformance constraints derived from concrete conformance.
When an otherwise abstract conformance constraint is derived from a
concrete conformance, retain the abstract conformance by removing the
requirement source that involves the concrete conformance. This
eliminates our reliance on the concrete conformance, which is not
retained as part of the generic signature.

Fixes rdar://problem/31163470 and rdar://problem/31520386.
2017-04-16 23:05:23 -07:00
Doug Gregor
faa0401598 [GSB] Allow requirement inference for synthesized requirements. 2017-04-14 17:19:02 -07:00
Doug Gregor
8a4451dda9 [GSB] Infer requirements from concrete types in requirements.
When a requirement mentions a concrete type, that type might utter
other types (e.g., Set<T>) that infer requirements (here, T:
Hashable). Perform requirement inference for such types.

Part of rdar://problem/31520386.
2017-04-14 17:19:01 -07:00
Doug Gregor
148f6383df [GSB] Basic infrastructure for delaying and reprocessing requirements. 2017-04-11 14:15:46 -07:00
Doug Gregor
10ebdcd50a [GSB] Broaden the Boolean result of "add a constraint" operations.
Rather than true (an error occurred) or false (the constraint was
resolved), introduce ConstraintResult to better model what
happened. NFC for now, but the intent here is to report unresolved
constraints through this mechanism.
2017-04-11 14:15:45 -07:00
Doug Gregor
fb8023736f [GSB] Eliminate unnecessary "dependentType" parameters throughout.NFC
Now that ProtocolRequirement sources can compute their own stored
types, stop propagating that information through the GSB.
2017-04-10 10:14:01 -07:00
Doug Gregor
7900decb09 [GSB] Compute the dependent type for ProtocolRequirement sources.
The dependent type that is the subject of a ProtocolRequirement
source is independently computable based on the root potential
archetype of the source and the potential archetype to which the
requirement applies, i.e., it's just the dependent member type that
gets from the former to the later. Compute this directly, rather than
relying on the passed-down dependent type.

This is possible now because we no longer capriciously rebase
requirements onto the representatives of equivalence classes, nor
destroy any other structural information in the formation of potential
archetypes.
2017-04-10 09:21:44 -07:00
Doug Gregor
7b19bb4c16 [GSB] Use "direct" requirement terminology for same-type requirement handling.
NFC
2017-04-07 16:53:11 -07:00
Doug Gregor
c522bb5239 [GSB] Separate out "unresolved" and "direct" type requirement handling.
As we've done with layout requirements, introduce a new entry point
(addTypeRequirement) that handles unresolved type requirements of the
form `T: U`, resolves the types, and then can

1. Diagnose any immediate problems with the types,
2. Delay the type requirement if one of the types cannot be resolved,
or
3. Break it into one or more "direct" requirements.

This allows us to clean up and centralize a bunch of checking that was
scattered/duplicated across the GSB and type checker.
2017-04-07 16:53:11 -07:00
Doug Gregor
68efffd4b8 [GSB] Separate out the "unresolved" and "direct" layout constraint entrypoints.
More staging for delayed resolution of constraints.
2017-04-07 16:53:10 -07:00
Doug Gregor
6991a8c261 [GSB] Basic infrastructure to allow type resolution to fail.
When we resolve() a type that is being used in a constraint, allow
that resolution to fail. If it does fail, then record the constraint
we were trying to address (via a stub that, currently, just drops it)
and continue on. NFC for now; this is intended to allow us to limit
the explosion of types in recursive systems.
2017-04-07 16:53:10 -07:00
Doug Gregor
25f3b3dd4b [GSB] Remove unused "from generic typealias" hack. 2017-04-07 16:53:10 -07:00
swift-ci
ba9546dc13 Merge pull request #8312 from DougGregor/generic-sig-concrete-type-params 2017-03-24 00:22:19 -07:00
Doug Gregor
8bd863e645 [GSB] Reimplement self-derived checking for conformance constraints.
The general self-derived check doesn't really make sense for
conformance constraints, because we want to distinguish among
different protocol conformances.
2017-03-23 23:45:43 -07:00
Doug Gregor
d9fa16bccb [GSB] Diagnose explicit constraints made redundant by inferred ones. 2017-03-22 17:35:11 -07:00
Doug Gregor
ddc2775530 [GSB] Diagnose redundant same-type constraints.
Diagnose redundant same-type constraints using most of the same
machinery for diagnosing other redundant constraints. However,
same-type constraints are particularly interesting because
redundancies can be spelled in a number of different ways. Address
this using the connected components of the subgraph involving only
derived requirements (which is already used for the minimized generic
signature). Then, separate all of the non-derived requirements into
the intracomponent requirements and intercomponent requirements:

* All of the intracomponent requirements are redundant by definition,
  because the components are defined by derived constraints.

* For the intercomponent requirements, form a spanning tree among the
  various components and diagnose as redundant any edges that do not
  extend the spanning tree.
2017-03-21 23:02:04 -07:00
Doug Gregor
343c99302b [GSB] Compute derived same-type components when checking same-type constraints.
It's better to compute this information once while we're sorting
through all of the same-type constraints, so we can use it later when
performing queries (e.g., enumerating requirements).
2017-03-21 16:32:51 -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
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
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
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