Commit Graph

753 Commits

Author SHA1 Message Date
Slava Pestov
9579c9e12f AST: Archetypes store an interface type instead of an Identifier or AssociatedTypeDecl 2017-10-07 04:46:37 -07:00
Slava Pestov
4ac0aecaef AST: Fix a problem with superclass constraints
If the class itself is generic and we're looking up a nested type
from a conformance, we would pass an interface type to
mapTypeOutOfContext() and crash.
2017-10-06 18:56:13 -07:00
Graydon Hoare
51d759e0f1 [AST] Add dedicated lazier-path to getting protocol associated types. 2017-10-06 01:55:47 -04:00
Doug Gregor
e39935f37e [GSB] Delay requirements involving unresolved dependent types.
Tightens up invariants, but is effectively NFC.
2017-09-29 10:35:38 -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
8c8d19218b [GSB] Switch resolveDependentMemberTypes() off of resolveArchetype().
We want to do the lookup into the parent equivalence class here.
2017-09-28 15:47:57 -07:00
Doug Gregor
7867c6940f [GSB] Stop using resolveArchetype() to detect recursive types.
Use resolveEquivalenceClass() instead, which will be more lightweight in the
future. This is effectively NFC because we were already alway working on
the representatives of the equivalence classes in this code.
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
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
c4093105fb [GSB] Silence errors at unknown locations.
These only occur with canonicalized builders in invalid code; it’s not worth
having them slip out.
2017-09-28 14:27:15 -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
9d6a716dbd [GSB] BumpPtrAllocate internal data structure.
RequirementSources, PotentialArchetypes, and EquivalenceClasses live as
long as the GenericSignatureBuilder. BumpPtrAllocate them all, introducing
a free list for equivalence classes because those can be transient.
2017-09-28 14:27:09 -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
98e88bc015 Merge pull request #12135 from DougGregor/sr-5753
SR-5753: Don't warn about constraints redundant with inferred constraints
2017-09-27 09:03:50 -07:00
Slava Pestov
fe33453177 Revert "[GSB] Hack the ordering of adding requirements for a signature."
I don't think this is necessary anymore.

This reverts commit 3e80a616c4.
2017-09-26 21:26:56 -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
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
3e1737ef3b [GSB] Silence errors at unknown locations.
These only occur with canonicalized builders in invalid code; it’s not worth
having them slip out.
2017-09-25 08:49:01 -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
eccdedaf97 Merge pull request #12062 from DougGregor/make-fewer-gsbs
Create fewer generic signature builders
2017-09-22 18:38:27 -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
db44cf5805 [GSB] Silence errors at unknown locations.
These only occur with canonicalized builders in invalid code; it’s not worth
having them slip out.
2017-09-22 17:11:05 -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
Slava Pestov
ab242bd448 AST: Fix some warnings 2017-09-20 12:56:44 -07:00
Doug Gregor
63504e4099 [GSB] Recognize self-derived protocol requirements within a protocol.
When computing the requirement signature of a protocol, eliminate requirement
sources that are self-derived by virtual of using a given requirement of
that protocol to prove that same constraint.
2017-09-18 16:40:03 -07:00
Doug Gregor
ca4c5253d0 [GSB] Don’t record invalid concrete types via parent conformances. 2017-09-14 09:16:13 -07:00
Davide Italiano
d74dd7df74 [gardening] Remove more unused lambda captures. NFCI. (#11908) 2017-09-13 17:16:31 -07:00
Slava Pestov
824d4950c3 Merge pull request #11812 from slavapestov/divorce-clang-importer-from-sema-part-3
Reworking ClangImporter to not depend on Sema, part 3
2017-09-12 10:13:03 -07:00
Doug Gregor
41ff0585fb [GSB] Collapse structurally-equivalent potential archetypes.
When there are to "structurally" equivalent potential archetypes in
different components of an equivalence class, as determined by their
nested-name structure, collapse the two components. This addresses the
remaining known issues due to the eager explosion of potential
archetypes in the generic signature builder.
2017-09-12 06:20:38 -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
1e21d8df8a [GSB] Eliminate self-derived nested-type-name-match constraints..
Nested-type-name-match constraints are odd because they are
effectively artifacts of the GenericSignatureBuilder's algorithm,
i.e., they occur when we have two PotentialArchetypes representing the
same type, and each of those PA's has a nested type based on the same
associated type. Because of this, nested-type-name-match constraints
have no useful requirement sources, so the normal means of detecting
self-derived constraints doesn't suffice, and we end up with
self-derived nested-type-name-match constraints eliminating the
constraints they depend on, causing spurious "redundant same-type
constraint" diagnostics and minimized generic signatures that drop
important requirements.

Handle nested-type-name-match constraints by first keeping them out of
the connected-components algorithm used to compute same-type
constraints within an equivalence class. Then, detect self-derived
nested-type-name-match constraints by determining whether any of the
ancestor potential archetypes are in the same equivalence class... and
redundant with the edge that makes the ancestor potential archetypes
equivalent. Remove such self-derived edges, and treat all other
nested-type-name-match edges as derived, providing a minimized
signature.

Fixes SR-5841, SR-5601, and SR-5610
2017-09-12 06:11:53 -07:00
Doug Gregor
39c36ea8ca [GSB] Remove a spurious variable update. NFC 2017-09-12 06:11:53 -07:00
Doug Gregor
4dee0d9cc7 [GSB] Infer equivalence of same-named nested types of the same potential archetype.
When we have two nested types of a given potential archetype that have
the same name, introduce a (quietly) inferred constraint. This is
a future-proofing step for canonicalization, for a possible future
where we no longer require all of the nested types of a given name
to be equivalent, e.g., because we have a proper disambiguation
mechanism.
2017-09-12 06:11:39 -07:00