Commit Graph

753 Commits

Author SHA1 Message Date
Doug Gregor
642b45835c [GSB] Use result of recordSameTypeConstraint() to short-circuit.
Centralizes the logic for short-circuiting based on same-type
constraints.
2017-10-23 21:51:54 -07:00
Doug Gregor
bd0625f083 [GSB] Flatten list of same-type requirements.
Equivalence classes stored their same-type constraints in a MapVector
keyed on the source potential archetype, which allowed traversal along the
paths of the graph. However, this capability isn't required, because we
end up walking all of the edges each time. Flatten the list of same-type
constraints to a single vector, eliminating constraint duplication between
the source and the target out-edge lists.

This cuts down on the number of same-type constraints we record by 50%,
but performance gains are limited (6% of stdlib type-checking time)
because most of the time these same-type constraints were skipped
anyway.
2017-10-23 21:33:41 -07:00
Doug Gregor
d1206e45a1 [GSB] Replace depth-first search connected components with union-find.
When computing connected components for the graph of derived same-type
constraints within an equivalence, replace the depth-first search with
union-find. The latter does not require us to have an out-edges list
for each node in the graph.
2017-10-23 20:54:35 -07:00
Doug Gregor
e8c9b3ffa2 [GSB] Eliminate the GenericSignatureBuilder from PotentialArchetype.
Now that getBuilder() is gone, stash an ASTContext into root
PotentialArchetypes instead of a GenericSignatureBuilder. This eliminates
some ickiness where we had to re-root potential archetypes when moving a
GenericSignatureBuilder.
2017-10-23 14:21:43 -07:00
Doug Gregor
2f3b2dfc7b [GSB] Plumb generic params through getDependentType() fully.
This allows us to eliminate `getBuilder()`.
2017-10-23 14:11:38 -07:00
Doug Gregor
214f9d54ca [GSB] Eliminate the penultimate caller to PotentialArchetype::getBuilder(). 2017-10-23 11:38:36 -07:00
Doug Gregor
a510e9b56d [GSB] Eliminate most uses of PotentialArchetype::getBuilder().
The remaining two uses after this refactor are... stubborn.
2017-10-23 10:39:21 -07:00
Graydon Hoare
d538519544 [NamedLazyMemberLoading] Skip some type-member logic for ObjC protocols. 2017-10-20 22:48:44 -07:00
Doug Gregor
42c1619088 [GSB] Eliminate a debugging-only source of potential archetype realization. 2017-10-20 21:57:23 -07:00
Doug Gregor
972f04832b [GSB] Teach expandConformanceRequirement() to use a resolved type.
Eliminates another too-early source of realization of potential archetypes.
2017-10-20 21:52:40 -07:00
Doug Gregor
28e3e5cf40 [GSB] Eliminate potential archetypes from requirement sources entirely. 2017-10-20 21:38:12 -07:00
Doug Gregor
1f09f3bc10 [GSB] Eliminate potential archetypes from minimizing requirement sources.
Refactor the interfaces that involve “walking” a requirement source
(e.g., minimization, computation of the affected type, etc.) to rely
only on interface types and not potential archetypes.
2017-10-20 16:42:39 -07:00
Doug Gregor
aa9755d149 [GSB] Start moving RequirementSource off of potential archetypes.
Eliminate potential archetypes from most of the public interface of
RequirementSource.
2017-10-20 15:18:36 -07:00
Doug Gregor
fd191fe59c [GSB] Switch Constraint's "subject" over to an unresolved type.
We're still eagerly resolving the subject to a potential archetype
everywhere, but this refactoring allows us to start introducing laziness.
2017-10-20 13:37:47 -07:00
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