Commit Graph

753 Commits

Author SHA1 Message Date
Doug Gregor
fa183b3639 [GenericSignatureBuilder] Rewrite sanity check to avoid warning in no-asserts builds. 2018-08-15 13:08:50 -07:00
swift-ci
be0e1643d6 Merge pull request #18720 from DougGregor/kill-type-resolver-context-generic-signature 2018-08-15 10:55:08 -07:00
Doug Gregor
7f759145c7 [GSB] Make requirement-signature computation more robust for nested protocols.
Add all of the generic parameters from outer contexts as well. This only
occurs in ill-formed code, but maintains a GenericSignatureBuilder
invariant that it knows about all of the generic parameters in play.
2018-08-15 09:26:23 -07:00
Doug Gregor
0a26e333bb Switch two simple callers over to decl-based lookupQualified. 2018-08-14 02:39:24 -07:00
Doug Gregor
b947a47a5d [AST] Reimplement ProtocolDecl::getInheritedProtocols() on decl name lookup.
Use the declaration-based name lookup facilities to re-implement
ProtocolDecl::getInheritedProtocols(), rather than dynamically selecting
between the requirement signature and the inherited types. This reduces
dependencies for this computation down to basic name lookup (no semantic
analysis) and gives us a stable result.
2018-08-06 16:12:09 -07:00
Doug Gregor
b421d08955 [GSB] Use resolved type when looking for a representative constraint.
When looking for a representative superclass constraint, take into
account other same-type constraints by comparing against the resolved
superclass constraint type rather than the type as spelled.

Fixes SR-8179 / rdar://problem/41851224.
2018-07-26 12:42:29 -07:00
Huon Wilson
c12bb46145 Merge pull request #18004 from huonw/sr8240
[AST] Member lookup in the GSB needs to understand equivalence classes with concrete types.
2018-07-18 12:46:08 +10:00
Huon Wilson
4faa0da99b [AST] Fix a few incorrectly indented lines. NFC. 2018-07-17 23:01:21 +10:00
Huon Wilson
ea1560f43b [AST] Member lookup in the GSB needs to understand equivalence classes with concrete types.
A constraint like `Parameter == SomethingConcrete` means references to
`Parameter` in that context behave like `SomethingConcrete`, including for name
resolution. Handling the parameter as just a parameter type means that it won't
find any non-protocol nested types (i.e. things other than associated types and
protocol typealiases are invisible).

Fixes rdar://problem/42136457 and SR-8240.
2018-07-17 22:54:22 +10:00
Slava Pestov
45fb11ce3c AST: Add ExistentialLayout::getSuperclass(), rename superclass to explicitSuperclass
More groundwork for protocols with superclass constraints.
In several places we need to distinguish between existential
types that have a superclass term (MyClass & Proto) and
existential types containing a protocol with a superclass
constraint.

This is similar to how I can write 'AnyObject & Proto', or
write 'Proto1 & Proto2' where Proto1 has an ': AnyObject'
in its inheritance clause.

Note that some of the usages will be revisited later as
I do more refactoring and testing. This is just a first pass.
2018-07-02 22:06:33 -07:00
Huon Wilson
92189c6079 Merge pull request #17356 from huonw/lazier-conditional-requirements
More errors instead of crashes for conditional conformances that are invalid or involve hard-to-resolve recursion
2018-06-21 11:59:49 +10:00
Huon Wilson
10b30fef78 [GSB] Explicit error on unsupported conditional conformance recursion.
This doesn't fix the fundamental problem of correctly handling such cases, but
it is better than the "error message" that occurred previously:

    Assertion failed: ((bool)typeSig == (bool)extensionSig && "unexpected generic-ness mismatch on conformance").

Fixes the crash rdar://problem/41281406 (that in
https://bugs.swift.org/browse/SR-6569 (rdar://problem/36068136)),
https://bugs.swift.org/browse/SR-8019 (rdar://problem/41216423) and
https://bugs.swift.org/browse/SR-7989 (rdar://problem/41126254).
2018-06-21 10:53:30 +10:00
Huon Wilson
1ba49949f9 [NFC]/[GSB] Move addConditionalRequirements to be a method. 2018-06-20 18:30:27 +10:00
Huon Wilson
175192fd7b [NFC] 'static Type' is more conventional than 'Type static'. 2018-06-20 11:32:11 +10:00
Doug Gregor
2b2e143f59 [Request-Evaluator] Introduce a request for getting an "inherited type". 2018-06-14 15:29:57 -07:00
Doug Gregor
d9c0ca951a Merge pull request #16997 from DougGregor/resolve-fewer-decl-signatures
[AST] Resolve fewer decl signatures
2018-06-06 13:08:55 -07:00
Doug Gregor
bc0445d1f7 Narrow a few LazyResolver::resolveDeclSignature() calls to what they really need.
Specifically, introduce entrypoints for "resolve overridden decl" and "is @objc". These can
be computed cheaply in many more cases.
2018-06-04 18:15:39 -07:00
Huon Wilson
ec1ed4ca57 Merge pull request #16893 from huonw/errors-are-unresolved-equivalence-class
[GSB] Error types end up as unresolved equivalence classes.
2018-06-04 16:27:48 -07:00
Huon Wilson
10c3e6cea9 [GSB] Error types end up as unresolved equivalence classes.
We need to make sure they don't end up as "concrete" equivalence
classes, because they behave more like unresolved ones.

Fixes rdar://problem/40009245.
2018-05-29 16:21:31 -07:00
Slava Pestov
a1c6f069c5 AST: Don't infer requirements from existential types 2018-05-28 19:09:33 -07:00
Doug Gregor
5ed639fec6 [GSB] Canonicalize types when checking concrete and superclass constraints.
Concrete and superclass constraints may be written involving type parameters
that are later resolved to concrete types. Perform the substitution to
ensure that type equality within constraint checking accounts for other
same-type constraints.

Fixes assertion in rdar://problem/40428709.
2018-05-23 14:49:58 -07:00
Slava Pestov
bd6281c558 AST: Change SubstitutionMap conformance lookup callbacks to take ProtocolDecl and not ProtocolType 2018-05-19 01:09:17 -07:00
Huon Wilson
ff779663b2 [GSB] Use a larger set for checking for visited requirements in 'isRecursive'.
This claws back some of the regression of
2feb830b58 on certain generics heavy code.

rdar://problem/40005262 (no-opt) goes from 7.83 -> 5.75 and
rdar://problem/40010847 (opt) goes from 90.7 -> 66.6 (both -27%).
2018-05-17 14:56:51 +10:00
Doug Gregor
539c352353 [GenericSignatureBuilder] Block recursion through getTypeInContext().
We could end up recursing through getTypeInContext() before we had time to
diagnose the recursion, so be *certain* that we can't recurse here to fix
a few crashes.
2018-05-03 18:11:35 -07:00
David Zarzycki
95473a10d7 [Misc] NFC: Fix random build warnings
Unused variables/methods, language extensions, extra semicolons, intentional
self assignment, platform specific quirks, etc.
2018-04-30 12:52:43 -04:00
Huon Wilson
7c435adc94 [GSB] withoutRedundantSubpath should leave Concrete RequirementSource as Concrete.
Fixes rdar://problem/39316039 and https://bugs.swift.org/browse/SR-7397.
2018-04-12 17:09:10 +10:00
Slava Pestov
75db43b978 AST: Replace ProtocolType::compareProtocols() with TypeDecl::compare() 2018-04-06 15:41:07 -07:00
Huon Wilson
6e39fcf98c [GSB] Use addConditionalRequirements for all conditional-requirement-adding. 2018-03-28 16:59:52 +11:00
Doug Gregor
b2b69e8abf Rename BoundNameAliasType to NameAliasType.
NameAliasType is dead! Long live NameAliasType!
2018-03-25 21:35:17 -07:00
Doug Gregor
e82e7ee908 [Type checker] Use BoundNameAliasType for all typealiases.
Rather than relying on the NameAliasType we get by default for references
to non-generic typealiases, use BoundNameAliasType consistently to handle
references to typealiases that are formed by the type checker.
2018-03-25 21:35:16 -07:00
Doug Gregor
ff5dc6081c [GSB] Infer requirements from protocol inheritance and where clauses.
Fixes rdar://problem/29231937.
2018-03-22 14:24:35 -07:00
Doug Gregor
728831b2ac [GSB] Infer requirements from uses of generic typealiases.
Generic typealiases can add requirements that aren't used by their
underlying type. For example, CountableRange in the standard library:

  public typealias CountableRange<Bound: Comparable> = Range<Bound>

Perform requirement inference based on uses of generic typealiases,
such that a generic function like this:

  func f<T>(_: CountableRange<T>) { }

will infer T: Bound from the use of CountableRange.

Note that this does not yet work for extensions.
2018-03-22 11:05:09 -07:00
Doug Gregor
59077bdfc6 [GSB] Allow redundant inheritance for all Objective-C-defined protocols.
Swift complains about redundant inheritance of a protocol, and
canonicalizes away such redundancies in its metadata. Clang does not
warn about such redundancies, nor does the Objective-C "conforms to
protocol" check take inheritance into account. Extend the existing
"redundant inheritance" hack (designed for JSExport) to cover all
protocols defined in Objective-C, so we match Clang's output of
Objective-C metadata.

Fixes SR-7130 / rdar://problem/38394637.
2018-03-19 10:07:07 -07:00
Doug Gregor
4a358bafb5 [GSB] Merge layout constraints when merging equivalence classes.
Fixes SR-7168 / rdar://problem/38394648.
2018-03-16 13:11:49 -07:00
Doug Gregor
5b03b8da3e Merge pull request #15220 from DougGregor/gsb-cleanups
[GSB] Cleanups regarding potential archetypes
2018-03-14 17:48:14 -07:00
Doug Gregor
acef21be66 [GSB] When merging equivalence classes, only merge each named nested type once.
Eliminate some redundant work in the GenericSignatureBuilder by only merging
one nested type per name, rather than all nested types that have that same
name.
2018-03-13 16:23:38 -07:00
Doug Gregor
9031fc3228 [GSB] More cleanup now that nested potential archetypes don't contain concrete types. 2018-03-13 15:46:31 -07:00
Huon Wilson
0e337acae0 Revert "[AST] Ensure requirements are correctly identified as conditional." 2018-03-14 08:12:37 +11:00
Doug Gregor
31792ac3f7 [GSB] Eliminate potential archetypes from the same-type constraint representation.
Same-type constraints are one of the primary places where potential
archetypes are used explicitly in the GenericSignatureBuilder. Switch
the representation over to a dependent type (represented by a `Type`)
instead, furthering the demise of PotentialArchetype.
2018-03-12 10:33:39 -07:00
Doug Gregor
4481a42c49 [GSB] Push potential archetype realization slightly deeper.
Same-type constraints are (still) described in terms of potential
archetypes, so push the "realization" operation for potential
archetypes down into the function that adds a same-type constraint
between type parameters.
2018-03-11 23:55:23 -07:00
Doug Gregor
0f7c822371 [GSB] Add same-type rewrite rules via dependent types.
GenericSignatureBuilder::addSameTypeRewriteRule() was described in
terms of an equivalence class and a potential archetype. Rework it in
terms of two dependent types (i.e., the anchors of their equivalence
classes), so we don't need to rely on the PotentialArchetype
mechanism.
2018-03-11 23:55:23 -07:00
Doug Gregor
9552692cd3 [GSB] Eliminate equivalence-class lookup from type canonicalization.
Make GenericSignatureBuilder::getCanonicalTypeParameter() independent of
equivalence classes. This is primarily cleanup, because all of these
equivalence-class resolution calls were actually dead from the point
where we changed the key for the rewrite-roots DenseMap over to
dependent types.
2018-03-11 23:55:23 -07:00
Doug Gregor
0eedacf183 [GSB] Use anchors for the keys in the mapping to rewrite tree roots.
Rather than keying the rewrite tree roots on equivalence classes,
which imply a mapping through potential archetypes, key on (canonical)
types that are currently the anchors of equivalence classes.
2018-03-11 23:55:23 -07:00
Doug Gregor
35902bbee2 [GSB] Simplifying via the term rewriting system cannot fail.
Now that we no longer have DependentMemberTypes within the GSB that don't
have associated type declarations, we can no longer fail when
unpacking type into a RewritePath, so remove a bunch of optionals and
null Type checks that are now superfluous.
2018-03-11 23:55:22 -07:00
Huon Wilson
be28f6830c Merge pull request #15094 from huonw/conditional-requirement-order
[AST] Ensure requirements are correctly identified as conditional.
2018-03-12 09:53:02 +11:00
Doug Gregor
455cb60a9e [GSB] Don't eagerly minimize the term-rewriting system.
It's not worth the cost in compile times.
2018-03-09 10:42:15 -08:00
Doug Gregor
624f2ba7b0 [GSB] Eliminate redundant rules from the rewrite tree.
As part of minimization, example each rule to determine whether
minimizing the left-hand-side (while ignoring the rule under question)
still produces the right-hand side. If so, the rule is redundant and
will be eliminated from the rewrite tree.
2018-03-09 10:42:14 -08:00
Doug Gregor
91aa964714 [GSB] Minimize the right-hand sides of rules in the term-rewriting system.
Introduce the first step of a minimization algorithm for the
term-rewriting system used to produce anchors of equivalence
classes. This step simplifies the right-hand sides of each rewrite
rule, so that each rewrite step goes to the minimal result.

This code is currently not enabled; it *can* be enabled by minimizing
before computing anchors, but it ends up pessimizing compile times to
do so.
2018-03-09 10:42:14 -08:00
Doug Gregor
8346917b8f [GSB] RewriteTreeNode::bestMatch -> RewriteTreeNode::bestRewritePath. 2018-03-09 10:42:14 -08:00
Doug Gregor
e12abf5363 [GSB] Generalize traversal of all rewrite rules in a rewrite tree.
Use the generalized traversal to implement the mergeInto() operation.
2018-03-09 10:42:14 -08:00