Commit Graph

212 Commits

Author SHA1 Message Date
Doug Gregor
36e1ba2cc4 [GSB] Collapse "ResolvedType" into the more general "ResolveResult".
The latter describes more directly-relevant information.
2017-10-17 21:00:23 -07:00
Doug Gregor
8753aac1fd [GSB] Eliminate resolvePotentialArchetype().
maybeResolveEquivalenceClass() can do all of this already.
2017-10-17 21:00:23 -07:00
Doug Gregor
9314e480d0 [GSB] We don't need an anchor to resolve into an equivalence class.
Any potential archetype with the lowest depth in the equivalence class
will do when we're resolving for equivalence classes, so keep the
lowest-depth potential archetype handy.
2017-10-16 23:24:35 -07:00
Doug Gregor
801ef514d2 [GSB] Resolve type into an equivalence class without building a new PA.
Teach GenericSignatureBuilder::resolveEquivalenceClass() to perform
resolution of a type into a dependent type and its equivalence class
without realizing that potential archetype. Improves type-checking
time for the standard library by ~6%.
2017-10-16 16:49:24 -07:00
Doug Gregor
8194587879 [GSB] Move several accessor functions off of PotentialArchetype.
These properties should be queried on the equivalence class itself.
2017-10-16 15:48:02 -07:00
Doug Gregor
2adfb5aac6 [GSB] Factor out the addition of a conformance to an equivalence class.
NFC refactoring to simplify the code.
2017-10-10 23:19:09 -07:00
Doug Gregor
5f4e024403 [GSB] Clean up decision-making logic for redundant-constraint warnings.
Lots of DRY violations to refactor.
2017-10-10 23:06:52 -07:00
Huon Wilson
1dee31fe2b [GSB] subst Requirements directly; no need for the extra argument. 2017-10-10 20:17:42 -07:00
Huon Wilson
5d8d3c7f84 [GSB] Include any necessary conditional requirements.
This enabled requirement inference from conditional requirements in a many
cases (but not all).
2017-10-10 20:17:40 -07:00
Doug Gregor
936a701b15 [AST] Stop uniquing canonical GSBs based on the module.
Now that the GenericSignatureBuilder is no longer sensitive to the input
module, stop uniquing the canonical GSBs based on that module. The main
win here is when deserializing a generic environment: we would end up 
creating a canonical GSB in the module we deserialized and another
canonical GSB in the module in which it is used.
2017-10-10 09:41:23 -07:00
Doug Gregor
ef542ffd8a [GSB] Eliminate the stored LookupConformanceFn to the GSB.
Implement a module-agnostic conformance lookup operation within the GSB
itself, so it does not need to be supplied by the code constructing the
generic signature builder. This makes the generic signature builder
(closer to) being module-agnostic.
2017-10-10 09:41:23 -07:00
Doug Gregor
ea1396c364 [GSB] Only build potential archetypes for associated type "anchors".
Use the "override" information in associated type declarations to provide
AST-level access to the associated type "anchor", i.e., the canonical
associated type that will be used in generic signatures, mangling,
etc.

In the Generic Signature Builder, only build potential archetypes for
associated types that are anchors, which reduces the number of
potential archetypes we build when type-checking the standard library
by 14% and type-checking time for the standard library by 16%.

There's a minor regression here in some generic signatures that were
accidentally getting (correct) same-type constraints. There were
existing bugs in this area already (Huon found some of them), while
will be addressed as a follow-up.

Fies SR-5726, where we were failing to type-check due to missed
associated type constraints.
2017-10-07 21:52:40 -07:00
Doug Gregor
d93bed5ed1 [GSB] Move a well-formed GenericSignatureBuilder to be the canonical builder.
Once we compute a generic signature from a generic signature builder,
all queries involving that generic signature will go through a separate
(canonicalized) builder, and the original builder can no longer be used.
The canonicalization process then creates a new, effectively identical
generic signature builder. How silly.

Once we’ve computed the signature of a generic signature builder, “register”
it with the ASTContext, allowing us to move the existing generic signature
builder into place as the canonical generic signature builder. The builder
requires minimal patching but is otherwise fully usable.

Thanks to Slava Pestov for the idea!
2017-09-28 16:19:08 -07:00
Doug Gregor
2f9c18639d [GSB] Kill off resolveArchetype().
This is somewhat of a pyrrhic victory, because it was just a shell over
resolvePotentialArchetype() anyway, but we now have fewer entry points that
produce potential archetypes.
2017-09-28 15:47:57 -07:00
Doug Gregor
9f580fe7ad [GSB] Move getTypeInContext() over to EquivalenceClass.
We shouldn’t need a potential archetype to map an interface type to a
contextual type. Port `getTypeInContext()` over to `EquivalenceClass`,
largely unchanged, so we don’t directly form archetypes.

Kills a few more uses of `GenericSignatureBuilder::resolveArchetype()`.
2017-09-28 15:47:57 -07:00
Doug Gregor
6374a17df9 [GSB] Introduce EquivalenceClass::getAnchor().
The anchor of an equivalence class canonically represents that equivalence
class. Add API for computing the anchor directly, and switch a few more
clients off of `resolveArchetype()`.
2017-09-28 15:47:57 -07:00
Doug Gregor
54864f858c [Type checker] Replace a use of GenericSignatureBuilder::resolveArchetype().
The type checker shouldn’t know about potential archetypes. Use
GenericSignatureBuilder::resolveEquivalenceClass() and perform the lookup
into that instead.

The test case change highlights an existing problem with generic signature
minimization.
2017-09-28 14:27:42 -07:00
Doug Gregor
f08a85ab11 [GSB] Cache the nested types of an equivalence class.
The GSB performs repeated lookups of the same nested type (by name) within
a given equivalence class. Cache the results of this lookup.
2017-09-28 14:27:16 -07:00
Doug Gregor
24780d9c95 [GSB] Inline getGenericSignature() into it’s only caller.
It’s small and straightforward. NFC
2017-09-28 14:27:15 -07:00
Doug Gregor
0a1583fb87 [GSB] Tighten up interfaces for computing a generic signature.
Funnel all places where we create a generic signature builder to compute
the generic signature through a single entry point in the GSB
(`computeGenericSignature()`), and make `finalize` and `getGenericSignature`
private so no new uses crop up.

Tighten up the signature of `computeGenericSignature()` so it only works on
GSB rvalues, and ensure that all clients consider the GSB dead after that
point by clearing out the internal representation of the GSB.
2017-09-28 14:27:15 -07:00
Doug Gregor
c9761fc821 [GSB] Simplify some interfaces. NFC 2017-09-28 14:27:14 -07:00
Doug Gregor
71deb0d928 [GSB] Centralize lookup of nested types.
We had two similar loops that performed name lookup for nested types on a
potential archetype, so consolidate those into a single implementation on
the equivalence class itself.
2017-09-28 14:27:14 -07:00
Doug Gregor
4df2958eea [GSB] Track equivalence classes in an intrusive linked list.
Managing equivalence classes via the implicit structure of potential
archetypes is silly, and leads to weird patterns where we visit all
potential archetypes just to find the equivalence classes. Teach the
GSB implementation to manage equivalence classes in a linked list, so we
can easily iterate over them, and switch most uses of
`visitPotentialArchetypes()` over to that iteration.
2017-09-28 14:27:09 -07:00
Doug Gregor
f6ad2a06d7 [GSB] Initialize FloatingPointSource's "as written" field consistently.
Eliminates a use of uninitialized memory.
2017-09-27 10:37:36 -07:00
Doug Gregor
684a484d81 SR-5753: Don't warn about constraints redundant with inferred constraints. 2017-09-26 17:22:43 -07:00
Doug Gregor
8f5d8aa7f9 Revert "[GSB] Centralize, clean up, and cache nested type name lookup" 2017-09-25 13:43:10 -07:00
Doug Gregor
896e0925e6 [Type checker] Replace a use of GenericSignatureBuilder::resolveArchetype().
The type checker shouldn’t know about potential archetypes. Use
GenericSignatureBuilder::resolveEquivalenceClass() and perform the lookup
into that instead.

The test case change highlights an existing problem with generic signature
minimization.
2017-09-25 09:39:08 -07:00
Doug Gregor
44d444c556 [GSB] Cache the nested types of an equivalence class.
The GSB performs repeated lookups of the same nested type (by name) within
a given equivalence class. Cache the results of this lookup.
2017-09-25 08:49:04 -07:00
Doug Gregor
f5e9ca57dd [GSB] Inline getGenericSignature() into it’s only caller.
It’s small and straightforward. NFC
2017-09-25 08:47:40 -07:00
Doug Gregor
a048194041 [GSB] Tighten up interfaces for computing a generic signature.
Funnel all places where we create a generic signature builder to compute
the generic signature through a single entry point in the GSB
(`computeGenericSignature()`), and make `finalize` and `getGenericSignature`
private so no new uses crop up.

Tighten up the signature of `computeGenericSignature()` so it only works on
GSB rvalues, and ensure that all clients consider the GSB dead after that
point by clearing out the internal representation of the GSB.
2017-09-25 08:47:40 -07:00
Doug Gregor
32260c8d00 [GSB] Simplify some interfaces. NFC 2017-09-25 08:47:39 -07:00
Doug Gregor
122d07b063 [GSB] Centralize lookup of nested types.
We had two similar loops that performed name lookup for nested types on a
potential archetype, so consolidate those into a single implementation on
the equivalence class itself.
2017-09-25 08:47:39 -07:00
Joe Shajrawi
00f44ce24a Revert "Create fewer generic signature builders" 2017-09-22 21:57:53 -07:00
Doug Gregor
3a3e8874d5 [GSB] Cache the nested types of an equivalence class.
The GSB performs repeated lookups of the same nested type (by name) within
a given equivalence class. Cache the results of this lookup.
2017-09-22 17:11:06 -07:00
Doug Gregor
76a532b3af [GSB] Move a well-formed GenericSignatureBuilder to be the canonical builder.
Once we compute a generic signature from a generic signature builder,
all queries involving that generic signature will go through a separate
(canonicalized) builder, and the original builder can no longer be used.
The canonicalization process then creates a new, effectively identical
generic signature builder. How silly.

Once we’ve computed the signature of a generic signature builder, “register”
it with the ASTContext, allowing us to move the existing generic signature
builder into place as the canonical generic signature builder. The builder
requires minimal patching but is otherwise fully usable.

Thanks to Slava Pestov for the idea!
2017-09-22 17:11:05 -07:00
Doug Gregor
ca4b83b40e [GSB] Inline getGenericSignature() into it’s only caller.
It’s small and straightforward. NFC
2017-09-22 11:32:26 -07:00
Doug Gregor
115d81a327 [GSB] Tighten up interfaces for computing a generic signature.
Funnel all places where we create a generic signature builder to compute
the generic signature through a single entry point in the GSB
(`computeGenericSignature()`), and make `finalize` and `getGenericSignature`
private so no new uses crop up.

Tighten up the signature of `computeGenericSignature()` so it only works on
GSB rvalues, and ensure that all clients consider the GSB dead after that
point by clearing out the internal representation of the GSB.
2017-09-22 11:32:26 -07:00
Doug Gregor
56a3ea8d10 [GSB] Simplify some interfaces. NFC 2017-09-22 11:32:25 -07:00
Doug Gregor
9bdeff2e3d [GSB] Centralize lookup of nested types.
We had two similar loops that performed name lookup for nested types on a
potential archetype, so consolidate those into a single implementation on
the equivalence class itself.
2017-09-22 11:32:25 -07:00
Doug Gregor
0d53a73f41 [GSB] Collapse same-type components using delayed requirements.
Perform the actual "collapse" of same-type components by looking
through the delayed requirements of an equivalence class.
2017-09-12 06:20:38 -07:00
Doug Gregor
43f3833b96 [GSB] Process same-type requirements needed to collapse same-type components.
Same-type constraints are rederived based on the potential archetypes
within an equivalence class and the same-type constraints that link
them. In some cases, there may be parts that connect those same-type
constraints that are stored in "delayed" requirements (for which one
or both end-points have not been realized in a potential archetype);
consider those as well for connectedness.

In a sense, this is an artifact of the generic signature builder's
approach of realizing potential archetypes too readily, and this can
likely be simplified in the future. For now, it's important for the
minimization of same-type constraints in generic signatures.
2017-09-12 06:14:25 -07:00
Doug Gregor
9b54f6a585 [GSB] Dump delayed requirements to aid in debugging. NFC 2017-09-12 06:14:25 -07:00
Doug Gregor
56a07d2e73 [GSB] Split out the operation to expand the requirement signature of a conformance.
NFC for now; we are going to re-use this code.
2017-09-12 06:14:25 -07:00
Doug Gregor
70d4e12285 [GSB] Introduce resolveEquivalenceClass() and start using it.
Queries through the GenericSignatureBuilder about a particular type
parameter only really need information about the equivalence class in which that type parameter resides. Introduce a new entry point
GenericSignatureBuilder::resolveEquivalenceClass() that only

For now, resolveEquivalanceClass() is a thin layer over
resolveArchetype().
2017-09-08 21:45:09 -07:00
Doug Gregor
71eaa5d773 [GSB] Add visualization of same-type constraints in an equivalence class.
Introduce support for writing a GraphViz graph describing the
same-type constraints within an equivalence class. This visualization
helps debugging the minimization algorithm.

LLVM's GraphWriter is actually kinda awful, so there is some hackery
here both to dodge an overzealous static assertion and to munge the
output into an undirected graph.

NFC except for debugging.
2017-08-16 20:29:04 -07:00
Doug Gregor
bb0595b1a2 [GSB] Drop unused parameter to FloatingRequirementSource::forNestedTypeNameMatch. 2017-08-16 11:07:46 -07:00
Doug Gregor
ac5d9fbe53 [GSB] Factor out the introduction of nested-type-name-match constraints. 2017-08-16 11:05:16 -07:00
Doug Gregor
fb7f4b26d1 [GSB] Maintain written requirement location when removing redundant subpaths. 2017-08-15 17:02:36 -07:00
Doug Gregor
bebac49cee [GSB] Form minimal requirement sources by removing redundant subpaths.
When we detect that a requirement source is self-derived, identify the
redundant subpath and remove it to produce a new, smaller requirement
source that computes the same result. We were doing this form the
limited case where the redundant subpath ended at the end of the
requirement source; generalize that notion.

Fixes SR-5601.
2017-08-10 17:00:07 -07:00
Doug Gregor
9d71b152fe [GSB] Add a requirement source modeling the binding of a concrete type.
When a potential archetype refers to a concrete (non-associated) type
declaration, we bind to that concrete type. Add a new requirement
source kind for this case that is always derived, separating it from
the nested-type-name-match source.

One important aspect of this is that typealiases in protocols that
"override" an associated type an inherited protocol will generate the
same requirement signature as the equivalent protocol that uses a
same-type constraint, making the suppression of the "hey, this is
equivalent to a same-type constraint now!" warning an ABI-preserving
change.

With this, remove a now-unnecessary hack for nested-name-match
requirement sources.
2017-08-10 10:38:13 -07:00