Commit Graph

9116 Commits

Author SHA1 Message Date
Pavel Yaskevich
695baccc3e Revert "[ConstraintSolver] Prioritize certain type variables while looking for bindings"
This reverts commit 001b09747a.
2017-10-02 17:30:18 -07:00
Jordan Rose
49b7b75422 Merge pull request #12217 from jrose-apple/tomb-of-the-unknown-object
Continue removing Builtin.UnknownObject
2017-10-02 15:18:16 -07:00
Pavel Yaskevich
8f14126b0e [CSGen] Give a correct locator to each type var representing closure parameter
Fixes a bug where all of the type variables related to closure parameters
without type would be attached to the same locator.
2017-10-02 13:58:54 -07:00
Pavel Yaskevich
3100088217 Merge pull request #12198 from xedin/rdar-22898292
[ConstraintSolver] Prioritize certain type variables while looking for bindings
2017-10-02 11:34:39 -07:00
Jordan Rose
31f97cf93c Use AnyObject instead of Builtin.UnknownObject
...for addressors and for dynamic self.
2017-10-02 09:05:35 -07:00
Greg Spiers
c5d6e17d85 Do not allow ‘weak’ and ‘unowned’ keywords for property declarations in protocols. 2017-10-01 12:43:48 +01:00
Doug Gregor
45ef8cfbcc Requirement environment: adopt the conformance's generic signature when we can.
Noticed by Slava: when the requirement is non-generic, the requirement
signature's generic signature is always going to be the same as the
conformance declaration context's generic signature, so use that immediately.

This eliminates a large number of generic signature builders created due to
requirement signatures (e.g., from 4893 -> 569 when measured against
the standard library work for SE-0157).

Short-circuit build of requirement environment.

This is all Slava and it’s magnificent.

FIXUP for “the Slava change”
2017-09-30 23:44:57 -07:00
swift-ci
2545af6d4b Merge pull request #12203 from DougGregor/requirement-environment-fewer-gsbs 2017-09-30 22:40:37 -07:00
Doug Gregor
27e4333923 Form a GenericSignatureBuilder for a RequirementEnvironment as needed.
In a number of cases, we would form a `GenericSignatureBuilder` as part
of computing the RequirementEnvironment, only to throw it away when we
realized we didn’t need it. Stop doing that.
2017-09-30 22:20:03 -07:00
Pavel Yaskevich
001b09747a [ConstraintSolver] Prioritize certain type variables while looking for bindings
Presence of some constraints (Subtype at least) requires a certain
contextual ranking of the type variables associated with them when
it comes to picking bindings, otherwise it might lead to no or
invalid solutions, because only a set of the bindings for the best
type variable is attempted.

Resolves: rdar://problem/22898292
2017-09-30 14:36:16 -07:00
Pavel Yaskevich
3c8c880b8e Merge pull request #12173 from xedin/rdar-34670592
[ConstraintSolver] Fix handling of defaultable constraint in `getPotentialBindings`
2017-09-29 13:07:18 -07:00
swift-ci
a8083a08eb Merge pull request #12187 from DougGregor/sr-5579 2017-09-29 12:26:01 -07:00
Doug Gregor
fa0c986c25 [Type checker] Make sure we fully validate ‘where’ clauses in protocols.
Fixes SR-5579 and an existing crash.
2017-09-29 11:23:45 -07:00
Doug Gregor
34847c5ff5 [Type checker] Introduce validateRequirements() rather than writing the same loop in three other places. 2017-09-29 10:57:27 -07:00
Pavel Yaskevich
4e7a089717 [ConstraintSolver] Fix handling of defaultable constraint in getPotentialBindings
While trying to find a fixed type for a given type variable, check if
it has representative and if it does, reflect that in the returned type.

Resolves: rdar://problem/34670592
2017-09-29 00:08:07 -07:00
Slava Pestov
b232b8f604 Fix some warnings 2017-09-29 00:24:22 -06:00
Doug Gregor
d93bed5ed1 [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-28 16:19:08 -07:00
Doug Gregor
d924233ba3 Merge pull request #12144 from DougGregor/gsb-nested-type-lookup-redux
[GSB] Centralize, clean up, and cache nested type name lookup
2017-09-28 15:47:25 -07:00
Doug Gregor
9f255e3f96 Merge pull request #12152 from DougGregor/csgen-dereference-end
[Constraint system] Eliminate some dead code in constraint optimization.
2017-09-28 14:50:33 -07:00
Doug Gregor
54864f858c [Type checker] Replace a use of GenericSignatureBuilder::resolveArchetype().
The type checker shouldn’t know about potential archetypes. Use
GenericSignatureBuilder::resolveEquivalenceClass() and perform the lookup
into that instead.

The test case change highlights an existing problem with generic signature
minimization.
2017-09-28 14:27:42 -07:00
Doug Gregor
0a1583fb87 [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-28 14:27:15 -07:00
Doug Gregor
b7a511a5ee Stop dumping the full state of the GSB in testing.
The full state of the GSB isn’t all that useful for testing, creates a ton of noise and gets in the way of some cleanups we’d like to make in the interface.
Stop dumping it as part of `-debug-generic-signatures`.
2017-09-28 14:27:15 -07:00
Doug Gregor
46e4c6d365 [Constraint system] Eliminate some dead code in constraint optimization.
The code is mistakenly dereferencing an "end" iterator and currently
has no effect. Remove it to make valgrind happier.
2017-09-28 13:47:37 -07:00
Slava Pestov
a1aaa4e141 Sema: Remove a bogus assertion
Fixes <rdar://problem/32727557>.
2017-09-28 13:06:58 -07:00
swift-ci
cf801104dd Merge pull request #12153 from xedin/pretty-potentinal-bindings-output 2017-09-27 21:16:57 -07:00
Pavel Yaskevich
c08610bb0b [ConstraintSolver] NFC: Prettify output of bindings in PotentialBindings 2017-09-27 20:47:20 -07:00
Slava Pestov
044af751f3 Sema: Fix a failure to emit a diagnostic
CSDiag was misinterpreting the result of checkGenericArguments().

A result of SubstitutionFailure does not mean a diagnostic was
emitted, only a result of Failure means that. This fixes a case
where we did not emit a diagnostic, result in a crash on invalid.

The diagnostic is still poor, but that's better than crashing.

Fixes <https://bugs.swift.org/browse/SR-5932>,
<rdar://problem/34522739>.
2017-09-27 16:39:06 -07:00
Jordan Rose
ec5c145835 Merge pull request #11465 from KingOfBrian/bugfix/SR-964
Warn if the getter is used, but the setter argument is not used
2017-09-27 10:11:05 -07:00
Brian King
a5a6684fce Improve diagnostic language 2017-09-26 20:47:09 -04:00
Brian King
c5397ba41b Clean up implementation 2017-09-26 20:46:40 -04:00
Doug Gregor
684a484d81 SR-5753: Don't warn about constraints redundant with inferred constraints. 2017-09-26 17:22:43 -07:00
Pavel Yaskevich
3b06f2e897 Merge pull request #12072 from xedin/rdar-33429010
[ConstraintGraph] Don't try to contract edge of parameter bindings with `inout` attribute
2017-09-26 11:51:09 -07:00
Mark Lacey
da87b83e7f Merge pull request #12116 from rudkx/move-add-potential-binding
[Constraint system] Move addPotentialBinding implementation back to CSBdinings.cpp.
2017-09-25 20:18:23 -07:00
Michael Gottesman
0c74e485a3 Merge pull request #12107 from apple/revert-12097-gsb-nested-type-lookup
Revert "[GSB] Centralize, clean up, and cache nested type name lookup"
2017-09-25 18:58:01 -07:00
swift-ci
2129101485 Merge pull request #12113 from xedin/rdar-33613329 2017-09-25 18:56:03 -07:00
Pavel Yaskevich
9d9a6c6231 [Diagnostics] Restore inout ParamDecl types properly after type-check
We are currently in process of removing `InOutType`
so `VarDecl::get{Interface}Type` is going to wrap base
type into `InOutType` if its flag indicates that it's
an `inout` parameter declaration. But such type can't
be restored directly using `VarDecl::set{Interface}Type`
caller needs additional logic to extract base type.

Resolves: rdar://problem/33613329
2017-09-25 17:38:28 -07:00
Brian King
4f20f670e7 Generate a fix-it to change the first getter usage into the setter parameter. 2017-09-25 20:19:36 -04:00
Mark Lacey
e46d2a7216 [Constraint system] Move addPotentialBinding implementation back to CSBdinings.cpp.
The method is logically part of PotentialBindings, but the
implementation doesn't need to live in the header.
2017-09-25 16:52:41 -07:00
Slava Pestov
02204f08c3 Sema: Synthesized delegating initializers inherit the @_inlineable attribute
Also add a test that deinits can be declared @_inlineable, but this is not
 a new feature, it was just previously untested.
2017-09-25 16:23:07 -07:00
Brian King
b894bd038b Update error message 2017-09-25 19:21:16 -04:00
Brian King
f1f64ce8a6 Change warning to only be reported if the parameter is unused but the getter is used. 2017-09-25 19:20:58 -04:00
Brian King
a79d2a8c44 Generate a warning if the implicit setter argument 'newValue' is not used. 2017-09-25 19:20:50 -04:00
Slava Pestov
835b4f8bf6 Sema: Destructors inherit @_versioned from their containing class 2017-09-25 15:38:58 -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
896e0925e6 [Type checker] Replace a use of GenericSignatureBuilder::resolveArchetype().
The type checker shouldn’t know about potential archetypes. Use
GenericSignatureBuilder::resolveEquivalenceClass() and perform the lookup
into that instead.

The test case change highlights an existing problem with generic signature
minimization.
2017-09-25 09:39:08 -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
9f063e9657 Stop dumping the full state of the GSB in testing.
The full state of the GSB isn’t all that useful for testing, creates a ton of noise and gets in the way of some cleanups we’d like to make in the interface.
Stop dumping it as part of `-debug-generic-signatures`.
2017-09-25 08:47:40 -07:00
Doug Gregor
e53fa3f721 Make unconstrained extensions use the generic signature of extended type.
An unconstrained extension will always have the same generic signature as the
nominal type it extends. Rather can constructing a new generic signature
builder to tell us that, just re-use the generic signature. Improves
type-checking performance of the standard library by 15%.
2017-09-24 22:23:01 -07:00
Doug Gregor
9fa2a8bdca Don’t create a new generic signature builder for non-generic members.
When type-checking a function or subscript that itself does not have generic
parameters (but is within a generic context), we were creating a generic
signature builder which will always produce the same generic signature as
the enclosing context. Stop creating that generic signature builder.

Instead, teach the CompleteGenericTypeResolver to use the generic signature
+ the canonical generic signature builder for that signature to resolve
types, which also eliminates some extraneous re-type-checking.

Improves type-checking performance of the standard library by 36%.
2017-09-24 22:23:00 -07:00
Tony Allevato
f74b3fb3c1 [Sema] Only emit warnings for implicit self use in getters
This fixes a pre-existing bug where implicit DeclRefExprs involving
*any* expression of the same type within a getter were flagged with
warnings, even if they were references to something other than "self".
2017-09-24 17:31:19 -07:00