Commit Graph

539 Commits

Author SHA1 Message Date
Doug Gregor
81d35d3f78 [GSB] Abstract away the PotentialArchetype stored in a constraint. 2017-10-20 13:16:59 -07:00
Doug Gregor
b046a35994 [GSB] Eliminate visitPotentialArchetypes().
Walking all of the potential archetypes is expensive. Instead, walk the
equivalence classes, which are the fundamental unit.
2017-10-17 21:00:24 -07:00
Doug Gregor
3177edc911 [GSB] Eliminate an unnecessary archetype-anchor computation. 2017-10-17 21:00:24 -07:00
Doug Gregor
c346b812f4 [GSB] Eliminate the "local archetype anchor" hack.
We're now getting the right set of potential archetypes, so this hack is
just extraneous work. Reduces the number of lookups into the
equivalence class nested type cache by ~24%, but only improves
type-checking performance of the standard library by ~3%.
2017-10-17 21:00:24 -07:00
Doug Gregor
476a557e55 [GSB] Eliminate some now-unused API on PotentialArchetype. 2017-10-17 21:00:24 -07:00
Doug Gregor
0d42fbf691 [GSB] Delay realization of potential archetypes for conformance requirements.
While here, consolidate PotentialArchetype::addConformance() into
EquivalenceClass::recordConformanceConstraint().
2017-10-17 21:00:24 -07:00
Doug Gregor
3ac1b3b14b [GSB] Push potential archetype realization into addConformanceRequirement(). 2017-10-17 21:00:24 -07:00
Doug Gregor
504911971a [GSB] Only concrete the immediate type from its concrete parent.
Spinning through all of its equivalence-class members is just busywork.
2017-10-17 21:00:24 -07:00
Doug Gregor
708412672e [GSB] Teach resolveConcreteConformance() to use ResolvedType. 2017-10-17 21:00:24 -07:00
Doug Gregor
760f23af7c [GSB] Teach much of superclass-constraint handling to use ResolvedType.
We're still realizing potential archetypes far too often, but it's a start.
2017-10-17 21:00:24 -07:00
Doug Gregor
4f339eb0ca [GSB] Push potential archetype realization layout-constraint handling.
We want to delay the realization of potential archetypes as late as
possible; for layout constraints, push realization of potential archetypes
down past the point where we know whether we’re learning anything new
about the equivalence class.

No functionality change, yet.
2017-10-17 21:00:24 -07:00
Doug Gregor
de5e0470ce [GSB] Rename ResolveResult to ResolvedType.
The old name was the better one; now we have a better (single)
representation.
2017-10-17 21:00:24 -07:00
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
2f1e74be9a [GSB] Minor simplification to resolve(). 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
9c85324670 [GSB] Switch the core "resolve" over to maybeResolveEquivalenceClass(). 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
9a563ce200 [GSB] Extend ResolveResult to describe resolved types that were not realized.
We want to be able to resolve a type to a particular known equivalence class
without realizing the corresponding potential archetype. Represent this in
ResolveResult, even though we're not using this state yet.
2017-10-16 15:48:02 -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
929c6423c6 [GSB] Make resolveEquivalenceClass() not build extra potential archetypes.
When we're only resolving the equivalence class in which a dependent type
occurs, always use the archetype anchor for the equivalence class to
find the equivalence class of the next nested type. This means that,
for example, determining the equivalence class of
C.SubSequence.SubSequence.SubSequence.SubSequence for a Collection C
will only resolve potential archetypes up to
C.SubSequence.SubSequence.

Not much benefit from this because the GenericSignatureBuilder itself
isn't using resolveEquivalenceClass() when expanding requirements.
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
Doug Gregor
fb2b070ab9 [GSB] Don't complain about redundant superclass constraints in derived reqs.
Fixes SR-5862.
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
27239469ea [GSB] Mark conformances used by the GenericSignatureBuilder as “used”.
Prior to the removal of the “lookup conformance function”, whenever
the type checker created a GenericSignatureBuilder, its lookup conformance
function would mark any referenced conformance as “used”. Do so now via
a LazyResolver callback, which fixes a regression in multi-file type
checking scenarios.
2017-10-10 10:01:40 -07:00
Doug Gregor
a92d8d5760 [Cleanup] Reduce dependencies on swift/AST/LazyResolver.h. 2017-10-10 10:01:39 -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
d3de4f2321 Merge pull request #12321 from DougGregor/assoc-type-overrides
Track "overrides" of associated types
2017-10-09 12:59:21 -07:00
Doug Gregor
1763a2c391 [GSB] Stop collapsing "structurally equivalent" potential archetypes.
Now that we only record potential archetypes involving the "anchor"
archetypes, there is no need to collapse structurally-equivalent potential
archetypes. Delete some temporary code.
2017-10-07 21:52:40 -07:00
Doug Gregor
e65f74d46f [GSB] Infer same-type constraints among same-named associated types.
When we have an equivalence class that contains two unrelated
associated types with the same name, infer a same-type constraint
between those two associated types. This is a more principled way to
introduce these constraints that we had before, fixing a
recently-introduced regression.
2017-10-07 21:52:40 -07:00
Doug Gregor
3cdf7cc08d [GSB] Don't introduce same-type constraints with overridden associated types.
Since overriding associated types aren't recorded as potential archetypes,
there is no point in introducing inferred same-type constraints involving
them.
2017-10-07 21:52:40 -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
Slava Pestov
f2582e1311 AST: Replace a few mapTypeOutOfContext() calls with ArchetypeType::getInterfaceType() 2017-10-07 05:44:57 -07:00
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