Commit Graph

12650 Commits

Author SHA1 Message Date
Rintaro Ishizaki
a54d2ff122 [AST] Don't suggest unusable values for typo correction and code completion
Filter out these cases:

- use within its own initial value
- use before declaration for local values

rdar://problem/25068938
2018-12-02 09:33:23 +09:00
Mark Lacey
de835e4710 Merge pull request #20927 from rudkx/sr9102
[TypeChecker] Fix a problem with rethrows classification.
2018-11-30 16:51:26 -08:00
Pavel Yaskevich
03d283171c [CSDiagnostics] Fix requirement source lookup to support member references
Fuzzing found a problem related to re-typecheck introducing
`MemeberRefExpr` into AST with failing requirements which
are then diagnosted via fixes, quite unlikely case to be
found in the wild.
2018-11-30 13:48:19 -08:00
Mark Lacey
5a498db041 [TypeChecker] Fix a problem with rethrows classification.
We failed to properly classify arguments that are of optional function
type, in this case leading to a verification failure due to the throws
attribute on the apply expression not being set to some value.

Fixes: SR-9102 / rdar://problem/45615204
2018-11-30 13:28:04 -08:00
Mark Lacey
1ed46b458b [ConstraintSystem] Do not infer 'nil' arguments as optional throwing function types.
I have a follow-up change to correctly classify optional arguments,
and with that fix applied we incorrectly emit rethrow diagnostics for
'nil' arguments passed in places where optional throwing functions are
expected.

This change ensures that we strip the throwing bit off of the nested
function type so that we don't consider 'nil' arguments in these
positions as potentially throwing functions.
2018-11-30 13:28:04 -08:00
Mark Lacey
0ffc988a66 Merge pull request #20907 from rudkx/refactor-checkTypeOfBinding
Refactor checkTypeOfBinding
2018-11-30 12:21:40 -08:00
Mark Lacey
e0847c5a98 [ConstraintSystem] More cleanup of nil literal handling. 2018-11-29 23:25:11 -08:00
Mark Lacey
56a636066b [ConstraintSystem] Make checkTypeOfBinding do one job rather than two.
Hoist the call to hasNilLiteralConstraint into the one caller that
cares about this.
2018-11-29 21:00:32 -08:00
Mark Lacey
1bcb29d608 [ConstraintSystem] Hoist out code checking for nil literal conformance. 2018-11-29 21:00:32 -08:00
Mark Lacey
4d76d308c9 [ConstraintSystem] Move checkTypeOfBinding into CSBindings.cpp.
This is the only place that it's actually used from.
2018-11-29 21:00:32 -08:00
Jordan Rose
859e2b0d84 Limit access of implicit typealiases for associated type witnesses (#20817)
When conformance checking infers an associated type, it makes a new
typealias to represent that type. Unfortunately, the access of that
typealias was always the same as the conforming type's, which (1)
might have leaked implementation details if the protocol wasn't as
public as the conforming type, and (2) might have been straight-up
incorrect if the /inferred type/ wasn't as public as the conforming
type.

Fix this in pre-Swift-5 modes by limiting the access to fit the
underlying type (technically source-breaking, but most code that
relied on this would have failed to link anyway), and in Swift 5 mode
by using the minimum possible access (the intersection of the protocol
and conforming type).

rdar://problem/46143405
2018-11-29 16:37:22 -08:00
Pavel Yaskevich
8a79fa1a9f [TypeChecker] Improve error about mutating self capture by escaping closure
Closures can't explicitly capture a mutating self parameter, so
let's re-word diagnostic to point what what actual problem here
is, and add a note about ways to fix the code.

Thanks to Cory Benfield for message suggestion.

Resolves: [SR-9314](https://bugs.swift.org/browse/SR-9314)
Resolves: rdar://problem/46322943
2018-11-28 16:22:05 -08:00
Pavel Yaskevich
1c82d4977d Merge pull request #20786 from xedin/rdar-44816848
[CSSimplify] Delay binding metatype instance types if one side is type variable
2018-11-28 10:53:44 -08:00
Pavel Yaskevich
28a66a23eb [CSSimplify] Delay binding metatype instance types if one side is type variable
While matching two metatypes where one side is a class (which could have
supertypes) and another is a type variable use `subtype` constraint to
delay binding types together because there is a real possibility that
there exists a superclass associated with yet free type variable which
would be a better match when attempted.

Resolves: rdar://problem/44816848
2018-11-27 14:36:46 -08:00
Harlan Haskins
245109d909 Merge pull request #20250 from harlanhaskins/accessorizing
[ParseableInterface] Standardize printing for accessors
2018-11-27 10:31:17 -08:00
Harlan Haskins
90489545b0 [Sema] Allow explicit @_hasStorage attribute outside of SIL 2018-11-26 18:42:02 -08:00
Harlan Haskins
a64a4e1940 [Sema] Add implicit @_hasStorage attribute for printing 2018-11-26 18:42:02 -08:00
John McCall
b9f4b17a33 Mark lazy properties as having mutating getters immediately.
We were trying to do this when synthesizing the getter prototype, but
we don't do that immediately when we're just type-checking a reference
to the storage, which could lead to the reference thinking that the
getter was non-mutating.

Fixes rdar://45712204.
2018-11-26 17:36:13 -05:00
Pavel Yaskevich
783f0345f7 Merge pull request #20693 from xedin/forward-autoclosure-diagnostic
[CSDiagnostics] Add custom diagnostic for invalid @autoclosure forwarding
2018-11-22 11:52:03 -08:00
Rintaro Ishizaki
5df5711b67 [CodeCompletion] Rework getOperatorCompletions() (#20632)
In postfix completion, for operator completion, we do:

  1. Type check the operand without applying it, but set the resolved
     type to the root of the expression.
  2. For each possible operators:
      i. Build temporary binary/postfix expression
      ii. Perform type checking to see whether the operator is applicable 

This could be very slow especially if the operand is complex.

* Introduce `ReusePrecheckedType` option to constraint system. With
  this option, CSGen respects pre-stored types in expressions and doesn't
  take its sub-expressions into account.
  * Improve type checking performance because type variables aren't
     generated for sub-expressions of LHS (45511835)
  * Guarantee that the operand is not modified by the type checker because
     expression walkers in `CSGen` doesn't walk into the operand.

* Introduce `TypeChecker::findLHS()` to find LHS for a infix operator from
  pre-folded expression. We used to `foldSequence()` temporary
  `SequenceExpr` and find 'CodeCompletionExpr' for each attempt.
  * No need to flatten folded expression after initial type-checking.
  * Save memory of temporary `BinaryExpr` which used to be allocated by
    `foldSequence()`.
  * Improve accuracy of the completion. `foldSequence()` recovers invalid
    combination of operators by `left` associative manner (with
    diagnostics). This used to cause false-positive results. For instance,
    `a == b <HERE>` used to suggest `==` operator. `findLHS()` returns
    `nullptr` for such invalid combination.

rdar://problem/45511835
https://bugs.swift.org/browse/SR-9061
2018-11-22 21:20:51 +09:00
Pavel Yaskevich
07e5d54855 [CSDiagnostics] Add custom diagnostic for invalid @autoclosure forwarding
Suggest to add `()` (form a call) to correctly forward argument function
originated from `@autoclosure` parameter to function parameter itself
marked as `@autoclosure`.
2018-11-21 12:17:25 -08:00
Pavel Yaskevich
cc780e3292 [ConstraintSystem] Make sure that @autoclosure argument detection works for subscripts/members
Currently logic in `matchCallArguments` could only detect argument
being an @autoclosure parameter for normal calls and operators.

This patch extends it to support subscripts and unresolved member calls.
2018-11-21 12:17:25 -08:00
Pavel Yaskevich
f9dae942f8 [CSFix] Add fix to track invalid @autoclosure forwarding 2018-11-21 12:17:25 -08:00
Mark Lacey
256284cf83 Merge pull request #20664 from rudkx/conditionalize-disjunction-selection-on-designated-types
[ConstraintSystem] Enable disjunction ordering change when use of des…
2018-11-17 18:17:55 -08:00
Mark Lacey
a1be08230f [ConstraintSystem] Enable disjunction ordering change when use of designated types are enabled.
We try to work more-or-less bottom up in the expression when we
attempt apply disjunctions first. This is very helpful to get good
results with designated types enabled in the solver. Rather than
forcing tests to specify both `-swift-version 5` (which also enables
this bottom-up behavior) and enabling designated types, allow them to
just enable the later to get the behavior.

We'll eventually have to revisit this when we decide the specific
conditions that we'll enable the use of designated types under.
2018-11-16 22:01:04 -08:00
Slava Pestov
0a8ee10621 AST: Refactor AbstractStorageDecl::getAccessStrategy() for keypath resilience
Instead of passing in a DeclContext, which we don't have when emitting a keypath
accessor, pass in a ModuleDecl and ResilienceExpansion.

Keypaths now work well enough in inlinable contexts that we can check in an
end-to-end resilience test.
2018-11-16 23:18:30 -05:00
Mark Lacey
2c15dc2d1c Merge pull request #20625 from rudkx/designated-types-array
[ConstraintSystem] Add Array as a designated type for `+` and `+=`.
2018-11-16 15:28:34 -08:00
Jordan Rose
81bcf9d5d6 Revert "[ParseableInterfaces] Skip value witnesses of resilient conformances" (#20637)
This reverts commit 61dd307b3b,
the effective part of #20419.

rdar://problem/43824088
2018-11-16 11:21:14 -08:00
Mark Lacey
018498fb2f Merge pull request #16942 from bjhomer/bjhomer/optional-try-flattening
Flatten nested optionals resulting from try? and optional sub-expressions
2018-11-16 11:14:05 -08:00
Slava Pestov
dd12206c0b Merge pull request #20626 from slavapestov/more-small-fixes
More small fixes
2018-11-16 10:56:05 -05:00
Mark Lacey
a5d627844a Merge pull request #20618 from rudkx/favor-equality
[ConstraintSystem] When we have multiple conversions/fixes, make equa…
2018-11-16 06:27:42 -08:00
Slava Pestov
7ffe361709 Sema: Clean up generic signature checking 2018-11-16 01:18:18 -05:00
Slava Pestov
6903e716fd Sema: Diagnose unsupported existential types in more places
Fixes <rdar://problem/23427259>, <https://bugs.swift.org/browse/SR-4207>.
2018-11-16 01:18:18 -05:00
Mark Lacey
d7cf830842 [ConstraintSystem] Add Array as a designated type for + and +=.
Also add overloads for these operators to an extension of Array.

This allows us to typecheck array concatenation quickly with
designated type support enabled and the remaining type checker hacks
disabled.
2018-11-15 21:42:33 -08:00
Suyash Srijan
0d9f63474a [Sema] Emit a diagnostic when extending a protocol with a redundant requirement (#20503)
* Emit a warning diagnostic if an extension contains a redundant requirement

* Updates diagnostic message and checks if the extension type is a protocol

* Updates indentation and extracts self type

* [ast] Updates diagnostic message

* [ast] fix indentation

* [ast] Change ':' to 'to' in 'protocol_extension_redundant_requirement'

* [sema] Adds protocol extension redundant requirement check

Moved from TypeCheckRequests to TypeCheckGeneric

* [ast] fix some crashes related to null ptrs, check self type before emitting a diagnostic, update tests

* [ast] renames 'owner' to 'ext'

* [sema] fix style

* [test] Add another test case for redundant requirement

Co-Authored-By: theblixguy <suyashsrijan@outlook.com>

* [test] fix failing test

The test was failing because A has already been declared as a typealias.
2018-11-15 19:18:51 -08:00
Mark Lacey
347b060322 [ConstraintSystem] When we have multiple conversions/fixes, make equality favored.
This allows us to skip attempting actual conversions.

This speeds up one of our slow test cases, and perturbs the output of
another test. In the latter case, we stop emitting conversions as part
of the non-semantic piece of the array_expr. The fact that we're not
putting conversions in on that path is something I've seen before in
other instances. I'll open a bug if I cannot find one for it, although
I believe it's entirely cosmetic in this case since we don't rely on
the conversion being there.
2018-11-15 18:41:53 -08:00
Mark Lacey
33b6e43efa [ConstraintSystem] When we have multiple conversions/fixes, make equality favored.
This allows us to skip attempting actual conversions.

This speeds up one of our slow test cases, and perturbs the output of
another test. In the latter case, we stop emitting conversions as part
of the non-semantic piece of the array_expr. The fact that we're not
putting conversions in on that path is something I've seen before in
other instances. I'll open a bug if I cannot find one for it, although
I believe it's entirely cosmetic in this case since we don't rely on
the conversion being there.
2018-11-15 17:38:22 -08:00
Jordan Rose
bda28ffb9b Require @usableFromInline on witnesses for non-type requirements too (#20485)
Follow-up to f33bf67dc9 for non-type requirements. We use non-type
witnesses for optimization purposes, so if we didn't enforce this we
might end up with something silently performing worse with parseable
interfaces than it would with swiftmodules. There's also a tricky case
where the client of the interface infers a different implementation:

    public protocol Foo {
      func foo()
    }
    extension Foo {
      public func foo() { print("default") }
    }
    @usableFromInline struct FooImpl: Foo {
      internal func foo() { print("actual") }
    }

There might be another solution to this in the future, but for now
this is the simplest answer. Like f33bf67dc9, it'll be a warning in
Swift 4 mode and an error in Swift 5 mode.

rdar://problem/43824161
2018-11-15 16:59:39 -08:00
John McCall
6ffeb4d839 [NFC] Add PrettyStackTraceConformance and use it
Also allow the printFooDescription functions to suppress
the trailing newline.
2018-11-15 18:39:35 -05:00
Arnold Schwaighofer
b255b8aac8 Fix compile error 2018-11-15 13:30:33 -08:00
Arnold Schwaighofer
07eec26ead Move the isImplicitDynamicEnabled into addImplicitDynamicAttribute 2018-11-15 12:05:26 -08:00
Arnold Schwaighofer
edd4f2ca6a Don't implicitly add dynamic to stored properties
This can introduce an exclusivity check failure.
2018-11-15 09:50:00 -08:00
Arnold Schwaighofer
a9aad0ff98 Don't add implicit dynamic to variables to local and implicit vars 2018-11-15 07:39:09 -08:00
Arnold Schwaighofer
619673e1fa Merge pull request #20570 from aschwaighofer/synthesize_accessors_dynamic_globals
Synthesize accessors for dynamic global variables
2018-11-14 14:35:47 -08:00
Arnold Schwaighofer
40f0c43e31 Add isNativeDynamic() and use it 2018-11-14 12:04:41 -08:00
Arnold Schwaighofer
c3230dfc5c Add the implicit dynamic attribute in the IsDynamicRequest query 2018-11-14 12:04:17 -08:00
Pavel Yaskevich
caa01ea96e Merge pull request #20542 from xedin/small-bindings-cleanups
[CSBindings] Couple of small `PotentialBindings` cleanups
2018-11-14 11:25:10 -08:00
Graydon Hoare
f212d185c5 Merge pull request #20458 from graydon/text-interface-format-version
Text interface format version
2018-11-14 09:19:27 -08:00
Arnold Schwaighofer
f7d8515d79 Add the dynamic replacement attribute before we add the accessors 2018-11-14 09:08:05 -08:00
Arnold Schwaighofer
081bb95bee Synthesize accessors for dynamic global variables 2018-11-14 07:57:45 -08:00