Commit Graph

583 Commits

Author SHA1 Message Date
Doug Gregor
899e68ef09 [GSB] Generalize potential archetype from "typealias" to all concrete types.
Potential archetypes can resolve to either an associated type or a
typealias. Generalize the latter to "any concrete type", both because
the current implementation is unnecessarily narrow (typealiases aren't
actually special in this regard) and to get us closer to handling
lookups via superclass constraints when resolving these types.
2017-06-01 13:52:39 -07:00
Doug Gregor
a9733cb8db [GSB] Resolve dependent member types in same-type and superclass constraints.
Once we're finalizing same-type-to-concrete and superclass
constraints, replace any unresolved DependentMemberTypes with their
resolved counterpairs. This allows us to simplify
DependentGenericTypeResolver, which only builds unresolved
DependentMemberTypes now, and eliminates the penultimate use of
ArchetypeResolutionKind::AlwaysPartial.
2017-05-30 11:43:53 -07:00
Huon Wilson
578097c2b6 [GSB] AbstractProtocol sources are explicit when computing req. sig. and not inferred.
If they're considered explicit, requirement inference will complain when
it infers X: SomeProtocol for some concrete type X.

Fixes SR-4693, rdar://problem/31819616
2017-05-24 13:32:01 -07:00
Doug Gregor
cf5424b617 [GSB] Move the Recursive(Concrete|Superclass)Type bits into EquivalenceClass.
Recursive concrete and superclass constraints are detected
per-equivalence-class; record them that way.

Use that information to drop recursive concrete and superclass
constraints from the resulting signature, which frees the canonical
generic signature builder from having to worry about such recursive
constraints. This eliminates the invalid-code crashes introduced in
the prior commit that disabled finalization for the canonical GSBs, as
well as fixing one other random crash-on-invalid.
2017-05-15 22:05:07 -07:00
Doug Gregor
fef69478f6 [GSB] Introduce computeGenericSignature() for generic signature creation.
The GenericSignatureBuilder requires `finalize()` to be called before a
generic signature can be retrieved with `getGenericSignature()`. Most of the former isn’t strictly needed unless you want a generic signature, and the 
latter is potentially expensive. `computeGenericSignature()` combines the two
operations together, since they are conceptually related. Update most of the
callers to the former two functions to use `computeGenericSignature()`.
2017-05-15 17:16:50 -07:00
Doug Gregor
0324920847 [GSB] Cache the archetype anchor of each equivalence class.
Archetype anchors are (re-)computed often, but shouldn't change all
that much. Cache them in the equivalence class for a ~15% speedup
type-checking the standard library.
2017-05-15 17:16:50 -07:00
Doug Gregor
bab127fce0 [GSB] Put archetype anchor consistency checking behind a separate #define.
Put the archetype anchor consistency checking behind a separate
it is really expensive: turning this checking off shaves 5s off the
type-checking time of the standard library in my Release+Asserts build
(~23% speedup).
2017-05-11 16:48:12 -07:00
Doug Gregor
cbccd2d7f3 [GenericSignatureBuilder] Add some simple statistics to track work done. 2017-05-11 11:37:38 -07:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
practicalswift
1924661a55 [gardening] Remove typo 2017-05-04 15:22:23 +02:00
Slava Pestov
e91ab9f978 AST: Rip out some code from GenericSignatureBuilder's inheritance clause processing
I don't fully understand why, but this logic here is redundant
because we end up adding layout constraints implied by types in
the inheritance clause anyway.
2017-05-02 19:24:03 -07:00
Slava Pestov
b0360cebfe AST: Don't build archetypes with an error type as the superclass
This breaks invariants.
2017-05-01 19:30:42 -07:00
Graydon Hoare
b5292f04f8 Add an assortment of new "always-on" metrics. 2017-04-28 13:56:13 -07:00
Doug Gregor
e858c553cb [GSB] Start inferring same-type requirements from inherited type declarations.
Infer same-type requirements among same-named associated
types/typealiases within inherited protocols. This is more staging; it
doesn't really have teeth until we stop wiring together these types as
part of lookup.
2017-04-25 16:13:48 -07:00
Doug Gregor
de66b0c25c [GSB] Warn about redeclarations of associated types from inherited protocols.
Introduce a warning about redeclaring the associated types from an
inherited protocol in the protocol being checked:

* If the new declaration is an associated type, note that the
  declaration could be replaced by requirements in the protocol's
  where clause.
* If the new declaration is a typealias, note that it could be
  replaced by a same-type constraint in the protocol's where clause.
2017-04-24 07:55:42 -07:00
swift-ci
930c488ff6 Merge pull request #8893 from practicalswift/gardening-20170420b 2017-04-20 16:18:09 -07:00
Doug Gregor
583d567705 Merge pull request #8888 from DougGregor/the-subsequence-of-my-subsequence
[Stdlib] For Collections, the SubSequence of a Subsequence is SubSequence
2017-04-20 15:46:37 -07:00
Doug Gregor
65c8334b99 [GSB] Hack: self-derived sources are showing up very late; ignore them.
There's a more pervasive issue here that needs further study;
essentially, we can end up with self-derived sources getting
reinjected later, and will either need to avoid that reinjection or
need to expand what this localized hack does, filtering out
self-derived constraints when we enumerate requirements.
2017-04-20 13:11:21 -07:00
practicalswift
797c2d8118 [gardening] Fix end of namespace comments 2017-04-20 22:01:01 +02:00
practicalswift
431e5a1440 [gardening] Use consistent end of namespace comments 2017-04-20 13:47:10 +02:00
Slava Pestov
16b033c111 Merge pull request #8876 from slavapestov/subclass-existentials-sema-casts
Update Sema cast checks for subclass existentials... and more!
2017-04-20 01:28:53 -07:00
Slava Pestov
f4b91cd118 AST: Remove unused 'resolver' argument from TypeBase::getSuperclass() 2017-04-20 00:37:38 -07:00
Doug Gregor
a926beab5b [GSB] Hack to limit recursion in the type graph.
This stops after 5 recurrences of the same associated type. It is a
gross hack and a terrible idea, here as a placeholder to prevent us
from running off the rails in ill-formed code. This will go away when
we get further along the path with recursive protocol constraints.
2017-04-20 00:09:23 -07:00
Doug Gregor
b91bd28aba [GSB] Use precise potential-archetype identity when forming protocol-requirement sources.
When we’re determining what type should be used to key a ProtocolRequirement based on the source’s potential archetype and the target’s potential archetype, use potential archetype identity (==) rather than equivalence-class membership to cover the basis case. This ensures that interesting identity relationships in the enclosing context (e.g., the current GenericSignatureBuilder) don’t cause us to compute incorrect stored types.
2017-04-19 23:15:32 -07:00
Doug Gregor
eba4affe3e [GSB] Don’t drop derived-via-concrete constraints too early.
When computing the connected components of within an equivalence class (based on derived same-type requirements), we might need derived-via-concrete constraints to maintain connectedness of the larger graph. Therefore, delay their removal until after we’ve computed connected components.
2017-04-19 08:42:05 -07:00
Doug Gregor
b676e43889 [GSB] Use RequirementSource::isProtocolRequirement() more. 2017-04-19 08:42:05 -07:00
Doug Gregor
e48f4191ca [GSB] Add EquivalenceClass::dump(). NFC 2017-04-19 08:42:05 -07:00
Doug Gregor
98dbd23fe2 [GSB] Add RequirementSource::isProtocolRequirement() to check both protocol-requirement kinds.
It’s too easy to forget to check both ProtocolRequirement and InferredProtocolRequirement, so abstract the check into a method.
2017-04-18 15:47:40 -07:00
Doug Gregor
54f132c487 [GSB] Delete all of the "visited" sets, which are now unused.
Now that we detect recursion based on repetition within the potential
archetypes, we no longer rely on passing down "visited" sets to
detect/diagnose recursion. Remove them.
2017-04-17 23:13:21 -07:00
Doug Gregor
a5a162a17c [GSB] Install basic recursion checking.
Recursive protocol conformances still aren't functional, so reinstate
some checking for recursive protocol conformances. It doesn't catch
everything that the previous version did---but we don't crash on such
cases anymore, either.
2017-04-17 23:13:21 -07:00
Doug Gregor
17846e2be1 [GSB] Cope with recursive requirements by delaying them.
Rather than detecting recursion and bailing early, delay requirements
that would form recursive types. Note that we aren't actually
processing them later.
2017-04-17 23:13:21 -07:00
Doug Gregor
995de881c7 [GSB] Teach addInheritedRequirements() and its callers to use UnresolvedType.
Teach addInheritedRequirements() to take an UnresolvedType, so the
requirements it adds can be delayed if needed. More importantly, teach
the primary caller (addConformanceRequirement) not to use
getNestedType directly; instead, form an appropriate Type and let the
type-resolution machinery handle it.
2017-04-17 23:13:21 -07:00
Doug Gregor
280bb3091f [GSB] Remove an unused entrypoint. 2017-04-16 23:05:55 -07:00
Doug Gregor
3b9cb5afa9 [GSB] Drop derived-from-concrete superclass/layout/etc. constraints.
Apply the same logic used for self-derived conformance constraints,
where we drop constraints derived from concrete conformances, to the
remaining kinds of constraints covered by isSelfDerivedSource().
2017-04-16 23:05:28 -07:00
Doug Gregor
a892e89922 [GSB] Simplify and clean up RequirementSource::isSelfDerivedSource().
Reimplement isSelfDerivedSource() in terms of the new
visitPotentialArchetypesAlongPath(). Aside from being clearer and
shorter, this formulation eliminates some hackery (the direct
"NestedType" lookup) that was mostly masking a bug in
updateNestedTypeForConformance() where we created a
nested-type-name-match source with an incorrect source for the
purposes of concretizing the nested type.

Fixes SR-4458 / rdar://problem/31375569.
2017-04-16 23:05:28 -07:00
Doug Gregor
0f5d561dbe [GSB] Factor out a path-walking operation visitPotentialArchetypesAlongPath().
Factor out a core operation of RequirementSource that walks the
potential archetypes from the root to the end of the path, enumerating
each partial RequirementSource along with the potential archetype to
which it applies. Use it for getting the final archetype to which the
RequirementSource refers, as well as simplifying the self-derived
check for conformance requirements.
2017-04-16 23:05:27 -07:00
Doug Gregor
8dfc25edc7 [GSB] Filter out conformance constraints derived from concrete conformance.
When an otherwise abstract conformance constraint is derived from a
concrete conformance, retain the abstract conformance by removing the
requirement source that involves the concrete conformance. This
eliminates our reliance on the concrete conformance, which is not
retained as part of the generic signature.

Fixes rdar://problem/31163470 and rdar://problem/31520386.
2017-04-16 23:05:23 -07:00
practicalswift
b8ca098949 Merge pull request #8742 from practicalswift/gardening-20170413
[gardening] Use consistent headers. Remove redundant includes. Remove unused methods. Fix typos, etc.
2017-04-15 18:59:30 +02:00
Doug Gregor
faa0401598 [GSB] Allow requirement inference for synthesized requirements. 2017-04-14 17:19:02 -07:00
Doug Gregor
c3b507f462 [Type checker] Use GenericSignatureBuilder's substitution logic.
Rather than hardcoding all of the substitution logic for requirements
in the RequirementEnvironment constructor, harden and re-use the
GenericSignatureBuilder's substitution logic instead.
2017-04-14 17:19:02 -07:00
Doug Gregor
336ff7721b [GSB] Delete some redundant computation. NFC 2017-04-14 17:19:01 -07:00
Doug Gregor
8a4451dda9 [GSB] Infer requirements from concrete types in requirements.
When a requirement mentions a concrete type, that type might utter
other types (e.g., Set<T>) that infer requirements (here, T:
Hashable). Perform requirement inference for such types.

Part of rdar://problem/31520386.
2017-04-14 17:19:01 -07:00
practicalswift
6a570226a0 [gardening] Fix a vs an typos 2017-04-14 17:33:24 +02:00
practicalswift
1d96be9a9e [gardening] Remove unused methods 2017-04-14 17:33:24 +02:00
Slava Pestov
3cf613a5d8 AST: Teach GenericSignatureBuilder about layout constraints that come from inheritance clauses
For now, NFC, but soon this will be <T : AnyObject>.
2017-04-13 21:17:06 -07:00
Slava Pestov
db58e02cb2 Sema: Hook up layout constraints to the solver
There were various problems with layout constraints either
being ignored or handled incorrectly. Now that I've exercised
this support with an upcoming patch, there are some fixes
here.

Also, introduce a new ExistentialLayout::getLayoutConstriant()
which returns a value for existentials which are class-constrained
but don't have a superclass or any class-constrained protocols;
an example would be AnyObject, or AnyObject & P for some
non-class protocol P.

NFC for now, since these layout-constrained existentials cannot
be constructed yet.
2017-04-13 21:17:05 -07:00
Slava Pestov
d49f8fb6d9 AST: Introduce primitive AnyObject type
Add a 'hasExplicitAnyObject()' bit to ProtocolCompositionType
to represent canonical composition types containing '& AnyObject'.

Serialize this bit and take it into account when building
ExistentialLayouts.

Rename ProtocolCompositionType::getProtocols() to getMembers()
since it can contain classes now, and update a few usages that
need further attention with FIXMEs or asserts.

For now, nothing actually constructs these types, and they will
trigger arounds asserts. Upcoming patches will introduce support
for this.
2017-04-13 21:17:05 -07:00
Doug Gregor
0f0a5906d7 [GSB] Put conformance requirements on the proper potential archetype.
We were putting conformance requirements on the representative of the
equivalence class, rather than directly on the potential archetype on
which the conformance requirement was specified. This violates the
invariant used when forming protocol-requirement sources that we never
reseat a requirement onto the representative (which would
have become a problem when implementing recursive protocol
constreaints) as well as masking a GSB idempotency issue that comes
from same-type requirements where the right-hand side was not
guaranteed to refer to the archetype anchor *within* that subcomponent.
2017-04-11 14:15:46 -07:00
Doug Gregor
e4d2e37115 [GSB] Eliminate always-true condition. 2017-04-11 14:15:46 -07:00
Doug Gregor
148f6383df [GSB] Basic infrastructure for delaying and reprocessing requirements. 2017-04-11 14:15:46 -07:00