Commit Graph

583 Commits

Author SHA1 Message Date
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
Slava Pestov
4f0ea8417d AST: Re-implement EquivalenceClassVizIterator::operator!= in terms of operator== to avoid warning 2017-09-11 21:50:33 -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
c1cf112939 [GSB] Eliminate redundant code in self-derived source checking.
Reimplement isSelfDerivedSource() in terms of
getMinimalConformanceSource(), because they're fundamentally the same
thing. Also, replace the custom removeSelfDerived() implementation
within checkConformanceConstraints() by improving the common
checkConformanceConstraints() and teaching it to work on top of
getMinimalConformanceSource().

There is some hackery in here to make getMinimalConformanceSource()
behave like the now-removed isSelfDerivedSource(). It's all marked
with FIXMEs while I sort out the general form of "self-derived" for
same-type constraints. It's not as easy as I had hoped ;)
2017-08-15 17:10:00 -07:00
Doug Gregor
fb7f4b26d1 [GSB] Maintain written requirement location when removing redundant subpaths. 2017-08-15 17:02:36 -07:00
Doug Gregor
1d1d21fa2c [GSB] Always initialize out variable derivedViaConcrete.
Fixes a problem with undefined behavior rdar://problem/33849926.
2017-08-15 10:30:55 -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
Doug Gregor
b3abb5591d [GSB] Eliminate unnecessary check in self-derived source computation.
Although this isn't triggering problems right now, it's incorrect.
2017-08-10 10:17:28 -07:00
Slava Pestov
eb46696baa AST: Fix bogus diagnostic with bad conformance requirements in generic signature
Fixes <rdar://problem/33604221>.
2017-07-31 14:19:19 -07:00
Doug Gregor
ed87c343bd [GSB] Detect self-derived conformances within same-type requirement sources.
Detect requirement sources that are internally self-derived for
(e.g.) handling of requirement sources for same-type constraints and
superclass constraints. This eliminates some incorrect warnings about
redundant same-type constraints involving recursive protocols, which
(more importantly) were a symptom of incorrect generic signature
minimization.

Fixes SR-5473.
2017-07-27 15:02:33 -07:00
Doug Gregor
d589cb720f [GSB] Retain minimal conformance sources within self-derived sources.
More correctly fix SR-5485: we were retaining self-derived conformance
sources when we shouldn't, which led to spurious "redundant
conformance" diagnostics and (much worse) incorrect minimized generic
signatures. Now, when we detect a self-derived conformance source,
return the minimal source that will derive the same conformance... and
retain that one if it's new.
2017-07-27 11:06:48 -07:00
Doug Gregor
469e9e08a5 SE-0157: Enable recursive protocol constraints by default.
We don't know if they work in general, but specific cases of recursive
protocol constraints are working, and enabling them doesn't break
anything.
2017-07-26 20:57:24 -07:00
Doug Gregor
e7077b10de [GSB] Allow reprocessed requirements to go back into the equivalence classes.
processDelayedRequirements() was putting reprocessed-but-still-unresolved
requirements directly into the global delayed-requirements queue,
which meant that they didn't benefit from the optimization of putting
delayed requirements into the appropriate equivalence class.

Revise the meaning of UnresolvedHandlingKind::ReturnUnresolved (and
change its name to GenerateUnresolved) to still generate the
unresolved constraint, but notify the caller that it remained
unresolved. That way, we can track what happens when reprocessing
requirements (the statistics are *really* useful), but we still get
the optimization from putting delayed requirements onto the
equivalence class that can resolve them.

With this change, type checking the standard library is now only 1%
slower with ``enable-recursive-constraints`.
2017-07-26 16:41:42 -07:00
Doug Gregor
c1eb47ff35 [GSB] Add delayed requirements to the equivalence class that can resolve them.
When a requirement is delayed, we know the equivalence class that
would have to change to make the requirement potentially
resolvable. Record the delayed requirement on that equivalence class.

When an equivalence class is modified for any reason, move all of the
delayed requirements to the global delayed-requirements queue so
they'll be reprocessed. This cuts the number of
reprocessed-but-still-unresolved requirements in half when
type-checking the standard library, taking us from 4x slower to 3x
slower.
2017-07-26 16:41:42 -07:00
Doug Gregor
ceab6ae10f [GSB] Route modifications through EquivalenceClass.
Replace the overly-general bumpGeneration() with a "modified()"
operation on EquivalenceClass, indicating that the given
EquivalenceClass has been modified in some way. There are no
modifications in the system that do not directly affect an equivalence
class.
2017-07-26 16:41:42 -07:00
Doug Gregor
d132f50c9d [GSB] Track the affected equivalence class for an unresolved type.
When we fail to resolve a particular type to a potential archetype,
track which equivalence class would have to change for the resolution
of that type to succeed. For now, this is "just" more bookkeeping.
2017-07-26 16:41:42 -07:00
Doug Gregor
83642c6dd9 [GSB] Suppress redundant diagnostics for circular protocol inheritance. 2017-07-25 16:07:24 -07:00