Commit Graph

583 Commits

Author SHA1 Message Date
Huon Wilson
9aed3e83a8 [GSB] Infer requirements from parents of types.
A type Foo<...>.Bar may only exist conditionally (i.e. constraints on the
generic parameters of Foo), in which case those conditional requirements
should be implied when Foo<...>.Bar is mentioned.

Fixes SR-6850.
2018-02-02 08:44:30 +11:00
David Zarzycki
c5dc6ceb4d Merge pull request #14303 from davezarzycki/nfc_do_not_reinterpret_cast_into_CanTypeWrappers
[AST] NFC: Do not reinterpret_cast pointers into CanTypeWrappers
2018-02-01 07:17:03 -05:00
Doug Gregor
9c395a47bd [AST] Report generic signature minimization errors through diagnostics.
Rather than crashing when a generic signature is found to be non-minimal,
report the non-minimal requirement via the normal diagnostics machinery so
we can properly test for it.

Fixes rdar://problem/36912347 by letting us track which cases are
non-minimal in the standard library explicitly, so we can better
decide whether it's worth implementing a complete solution.
2018-01-31 17:14:19 -08:00
David Zarzycki
3da6fe9c0d [AST] NFC: Do not reinterpret_cast pointers into CanTypeWrappers
This also introduces 'TypeArrayView' for when a 'Type' is statically
known to be a given TypeBase subclass.
2018-01-31 11:20:05 -05:00
Doug Gregor
d18ecda796 [GSB] Ensure that we don't build an invalid potential archetype.
Queries against the generic signature might use types that are
ill-formed for that generic signature, e.g., because they refer to
associated types of unrelated protocols. Detect such conditions to
maintain GSB invariants that all potential archetypes in a well-formed
generic signature are well-formed.

Fixes the crash in SR-6797 / rdar://problem/36673825.
2018-01-23 13:52:06 -08:00
Doug Gregor
879b1802f0 [GSB] Downgrade "neither type in same-type has a generic param" error to warning.
There is nothing specifically wrong with uttering a same-type
constraint in a where clause where both sides are concrete
types. Downgrade this to a warning; we'll check that the concrete
types match (of course), and such a well-formed constraint will simply
be canonicalized away.

This aids the migration of IndexDistance from an associated type to
Int.
2017-12-07 14:44:35 -08:00
Doug Gregor
5431400367 [Name lookup] Allow where clauses to find typealiases declared in a protocol.
Within the where clause of (e.g.) an extension, unqualified name lookup is
permitted to find associated types. Extend this to also include finding
typealiases declared within the protocol itself.

This is service of the IndexDistance change (SE-0191), and
fixes rdar://problem/35490504.
2017-12-07 13:46:33 -08:00
Doug Gregor
5d5e6122f3 [GSB] Add verification of all generic signatures within a module.
Add a verification pass to ensure that all of the generic signatures in
a module are both minimal and canonical. The approach taken is quite
direct: for every (canonical) generic signature in the module, try
removing a single requirement and forming a new generic signature from
the result. If that new generic signature that provide the removed
requirement, then the original signature was not minimal.

Also canonicalize each resulting signature, to ensure that it meets the
requirements for a canonical signature.

Add a test to ensure that all of the generic signatures in the Swift
module are minimal and canonical, since they are ABI.
2017-11-07 15:20:38 -08:00
Doug Gregor
b673e5d113 [GSB] Simplify resolveDependentMemberTypes().
Make sure that we always get the underlying concrete type or the anchor
of a particular equivalence class.
2017-11-06 09:11:02 -08:00
Doug Gregor
6fc218ba7d [GSB] Make compareDependentTypes() visible to other translation units. 2017-11-04 22:46:01 -07:00
Doug Gregor
c845b07964 [GSB] Simplify compareDependentTypes().
Remove a crufty, unnecessary check.
2017-11-04 22:01:38 -07:00
Doug Gregor
7fff801d87 [GSB] Remove the PotentialArchetype-based compareDependentTypes().
It had one caller that could easily use the Type-based variant of this
function.
2017-11-04 21:52:57 -07:00
Doug Gregor
5ad254bf3f [GSB] Stop walking associated types of a protocol just due to a superclass req. 2017-11-02 15:17:42 -07:00
Doug Gregor
0416292e5c [GSB] Eliminate unnecessary walk over the associated types.
We lazily resolve all of this information about nested potential archetypes
anyway; there's no need to do it eagerly.
2017-11-02 14:56:43 -07:00
Davide Italiano
2b1921b207 Merge pull request #12686 from dcci/unused2
[gardening] More unused variables/lambda captures. NFCI.
2017-11-01 12:48:21 -07:00
Doug Gregor
fe54e70fce [GSB] Don't infer requirements from types in the definitions of protocols.
Previously, we were inferring requirements from types within the definitions
of protocols, e.g., given something like:

    protocol P {
      associatedtype A: Collection
      associatedtype B where A.Element == Set<B>
    }

we would infer that B: Hashable. The code for doing this was actually
incorrect due to its mis-use of requirement sources, causing a few
crashers. Plus, it's not a good idea in general because it hides the
actual requirements on B. Stop doing this.

Also stop trying to infer requirements from conditional
requirements---those have already been canonicalized and minimized, so
there's nothing to infer from.
2017-10-31 15:28:19 -07:00
Davide Italiano
87de4637fc [gardening] More unused variables/lambda captures. NFCI. 2017-10-31 10:35:24 -07:00
Doug Gregor
832a154b08 [GSB] Make sure we wire up same-named type declarations consistently.
Fixes a former crasher that included well-formed code that was rejected
by my previous refactoring. Said crasher now passes, and IRGen's properly
as well. Also, account for three more fixed crashers.
2017-10-27 22:17:45 -07:00
Doug Gregor
5b8c914582 [GSB] Reimplement equivalence class "anchor" logic.
Replace the pair of PotentialArchetype's getArchetypeAnchor() and
getNestedArchetypeAnchor() with a straightforward, more-efficient
computation based on equivalence classes. This reduces the number of
times we query the archetype anchor cache by 88% when building the
standard library, as well as eliminating some
PotentialArchetype-specific APIs.
2017-10-27 21:46:45 -07:00
Doug Gregor
d731a948f4 [GSB] Simplify enumeration of the subject types for requirements.
The first step in enumerating the minimal, canonical set of requirements for
a generic signature is identifying which "subject" types will show up in
the left-hand side of the requirements. Previously, this would require us
to realize all of the potential archetypes, and perform a number of
archetype-anchor computations and comparisons.

Replace that with a simpler walk over the equivalence classes,
identifying the anchor types within each derived same-type component
of those equivalence classes, which form the subject types. This is
more straightforward, doesn't rely on potential archetypes, simplifies
the code, and eliminates a silly O(n^2)-for-small-n that's been
bothering me for a while.
2017-10-27 16:10:02 -07:00
Doug Gregor
4ff05fa51b [GSB] Eliminate a bunch of unnecessary PotentialArchetype* interfaces.
All of these constraint-checking functions work on the equivalence class.
2017-10-27 14:00:43 -07:00
Doug Gregor
1117eff2a8 [GSB] Eliminate PotentialArchetype from enumerateRequirements(). 2017-10-27 13:49:18 -07:00
Doug Gregor
29390e095a [GSB] Switch the anchor of a derived same-type component to UnresolvedType.
It was a PotentialArchetype*, but we don't want to have to realize a
potential archetype to model this.
2017-10-27 13:32:59 -07:00
Doug Gregor
16ea8aedf2 [GSB] Switch some more APIs away from PotentialArchetype. 2017-10-27 12:58:42 -07:00
Doug Gregor
3452dda95c [GSB] Stop warning about 'bare' associated type redeclarations.
Associated type redeclarations occasionally occur to push around
associated type witness inference. Suppress the warning about redeclarations
that add no requirements (i.e., have neither an inheritance nor a
where clause).
2017-10-26 14:58:00 -07:00
swift-ci
652edc93f8 Merge pull request #12607 from DougGregor/gsb-less-potential-archetype-realization 2017-10-24 17:30:57 -07:00
Doug Gregor
d2f0df4b3b [GSB] Eliminate unused Constraint<T>::realizeSubjectPotentialArchetype(). 2017-10-24 16:18:07 -07:00
Graydon Hoare
30b6fdce83 Merge pull request #12429 from graydon/named-lazy-member-loading
Named lazy member loading 1/N
2017-10-24 14:27:04 -07:00
Doug Gregor
f5e44a4968 [GSB] Don't realize potential archetypes for same-type-to-concrete constraints. 2017-10-24 11:11:21 -07:00
Doug Gregor
a33dee4844 [GSB] Switch potential archetype -> component index mapping to CanType.
Switch the mapping from types to components used by the same-type
connected-components computation to be indexed by CanType instead,
eliminating a few more places where we force realization of a potential
archetype.
2017-10-24 10:18:35 -07:00
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