Commit Graph

171 Commits

Author SHA1 Message Date
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
Doug Gregor
10ebdcd50a [GSB] Broaden the Boolean result of "add a constraint" operations.
Rather than true (an error occurred) or false (the constraint was
resolved), introduce ConstraintResult to better model what
happened. NFC for now, but the intent here is to report unresolved
constraints through this mechanism.
2017-04-11 14:15:45 -07:00
Slava Pestov
d7c1d817e3 AST: Update GenericSignatureBuilder for subclass existentials 2017-04-10 17:04:38 -07:00
Doug Gregor
fb8023736f [GSB] Eliminate unnecessary "dependentType" parameters throughout.NFC
Now that ProtocolRequirement sources can compute their own stored
types, stop propagating that information through the GSB.
2017-04-10 10:14:01 -07:00
Doug Gregor
7900decb09 [GSB] Compute the dependent type for ProtocolRequirement sources.
The dependent type that is the subject of a ProtocolRequirement
source is independently computable based on the root potential
archetype of the source and the potential archetype to which the
requirement applies, i.e., it's just the dependent member type that
gets from the former to the later. Compute this directly, rather than
relying on the passed-down dependent type.

This is possible now because we no longer capriciously rebase
requirements onto the representatives of equivalence classes, nor
destroy any other structural information in the formation of potential
archetypes.
2017-04-10 09:21:44 -07:00
Doug Gregor
7b19bb4c16 [GSB] Use "direct" requirement terminology for same-type requirement handling.
NFC
2017-04-07 16:53:11 -07:00
Doug Gregor
c522bb5239 [GSB] Separate out "unresolved" and "direct" type requirement handling.
As we've done with layout requirements, introduce a new entry point
(addTypeRequirement) that handles unresolved type requirements of the
form `T: U`, resolves the types, and then can

1. Diagnose any immediate problems with the types,
2. Delay the type requirement if one of the types cannot be resolved,
or
3. Break it into one or more "direct" requirements.

This allows us to clean up and centralize a bunch of checking that was
scattered/duplicated across the GSB and type checker.
2017-04-07 16:53:11 -07:00
Doug Gregor
68efffd4b8 [GSB] Separate out the "unresolved" and "direct" layout constraint entrypoints.
More staging for delayed resolution of constraints.
2017-04-07 16:53:10 -07:00
Doug Gregor
6991a8c261 [GSB] Basic infrastructure to allow type resolution to fail.
When we resolve() a type that is being used in a constraint, allow
that resolution to fail. If it does fail, then record the constraint
we were trying to address (via a stub that, currently, just drops it)
and continue on. NFC for now; this is intended to allow us to limit
the explosion of types in recursive systems.
2017-04-07 16:53:10 -07:00
Doug Gregor
25f3b3dd4b [GSB] Remove unused "from generic typealias" hack. 2017-04-07 16:53:10 -07:00
Doug Gregor
44c2f849d6 [Type checker] Continue validating requirements after an error.
We want to validate both type in same-type or conformance constraints,
even when the first type is ill-formed, so we don't leave null types
around for later phases to crash on.

Fixes rdar://problem/31093854.
2017-04-05 14:05:59 -07:00
Doug Gregor
5c89eb84f0 [AST] Drop substitutions from type witnesses.
Nobody is using the actual substitutions, but we sure did a lot of
work to cope with them.
2017-04-05 11:21:38 -07:00
Doug Gregor
8841f04ea8 [GSB] Properly compute archetype anchor during same-type DFS.
This would cause spurious idempotency failures with generic signature canonicalization.
2017-04-04 14:07:13 -07:00