Commit Graph

12650 Commits

Author SHA1 Message Date
Slava Pestov
69f2aba2ff Merge pull request #22158 from pschuh/s-2
NilLiteralExpr now is lowered directly into SIL.
2019-01-28 15:40:10 -05:00
Pavel Yaskevich
462cb1ffb1 Merge pull request #22124 from xedin/diagnose-partial-applies
[CSDiagnostics] Diagnose invalid partial application
2019-01-28 10:44:56 -08:00
Slava Pestov
ac557c53b2 Merge pull request #22143 from theblixguy/fix/look-through-reference-storage-type-equatable
[Sema] Allow weak/unowned types when checking Hashable/Equatable conformance
2019-01-28 13:12:46 -05:00
Parker Schuh
6ca70c6720 NilLiteralExpr now is lowered directly into SIL.
Instead of constructing calls to
ExpressibleByNilLiteral.init(nilLiteral: ()) in CSApply.cpp, just
annotate NilLiteralExpr with the selected construtor and do the actual
construction during SILGen.

For context, StringLiteralExpr already behaves this way.
2019-01-28 10:00:52 -08:00
Karoy Lorentey
587a9a824c Merge pull request #22081 from lorentey/hashvalue-fixit
[Sema] Add dedicated fix-it for NSObject.hashValue overrides
2019-01-28 07:50:20 -08:00
Pavel Yaskevich
1c79380a12 [CSFix] Couple of small cleanups related to ForceOptional
* Make sure that base and unwrapped types aren't null
* Don't allocate `ForceOptional` fix if nothing has been unwrapped
  in `simplifyApplicableFnConstraint`
* Add sugar reconstitution support to `FailureDiagnostic::resolveType`
* Format diagnostics a bit better
2019-01-26 00:48:01 -08:00
Pavel Yaskevich
b4fb25f66d Merge pull request #22050 from theblixguy/fix/SR-9201
[Diag] Fix incorrect diagnostic when unwrapping double optional
2019-01-25 23:07:09 -08:00
Suyash Srijan
8928431cbe [sema] support weak/unowned variables when checking for conformance 2019-01-26 02:57:45 +00:00
Suyash Srijan
614f72f85d [cs] use simplifyLocatorToAnchor and revert changes to some test diagnostic messages 2019-01-26 00:29:46 +00:00
Pavel Yaskevich
6134533580 [MiscDiagnostics] Remove obsolete invalid partial application diagnostics
Diagnostics for cases like these has been moved to new diagnostic framework.
2019-01-25 14:18:19 -08:00
Pavel Yaskevich
174fd14090 [CSDiagnostics] Diagnose invalid partial application of init delegation 2019-01-25 14:18:04 -08:00
Pavel Yaskevich
315a0adc93 [CSDiagnostics] Add invalid partial apply diagnostic for mutating methods 2019-01-25 14:17:54 -08:00
Suyash Srijan
8845fcbbfe [cs] use anchor from locator when creating a ForceOptional fix 2019-01-25 21:41:05 +00:00
Suyash Srijan
6a0a1dec05 [cs] use anchor instead of locator, etc 2019-01-25 21:36:07 +00:00
Pavel Yaskevich
7d830cee8b [ConstraintSystem] Add a fix to detect invalid partial application
Currently supported only partial applications of instance methods
marked as `mutating`.
2019-01-25 13:29:11 -08:00
Pavel Yaskevich
df0616a206 [CSDiag] Mark all sub-expressions which are about to be re-typechecked
Currently that has been limited only to expressions which aren't
flagged as `TCC_ForceRecheck`, but it should be extended to all
sub-expressions, otherwise we might produce invalid diagnostics
in `PreCheckExpression`.
2019-01-25 12:04:07 -08:00
Suyash Srijan
76b8209b25 [cs] store base type and unwrapped type in the fix 2019-01-25 10:13:37 +00:00
David Ungar
323c42c532 Fomat 2019-01-24 18:46:49 -08:00
Pavel Yaskevich
fe9376dd78 Merge pull request #22082 from xedin/move-weights-to-cs
[ConstraintSystem] Track AST depth information directly
2019-01-24 11:53:17 -08:00
Pavel Yaskevich
4342de969c Merge pull request #22084 from dingobye/sr9732
[Sema] Improve diagnostics for `variable_never_mutated` in case of for-each loop's binding.
2019-01-24 10:04:56 -08:00
Ding Ye
421d6b065a [Sema] Improve diagnostics for variable_never_mutated in case of for-each loop's binding.
The diagnostics for `variable_never_mutated` always suggests
changing `var` to `let`, which is misleading in case of
for-each loops where explicitly immutable context applies.
This patch adds some variety to the message to make it appropriate.

Resolves: SR-9732
2019-01-24 16:54:57 +11:00
Karoy Lorentey
df8eba480e [Sema] Add dedicated fix-it for NSObject.hashValue overrides
NSObject.hashValue used to be declared `@objc open` by historical accident. This has been corrected to `@nonobjc public` in Swift 5’s SDK overlays, to catch accidental overrides. (These never did work correctly, and shouldn’t have been allowed.)

Help migration by adding a dedicated error message for NSObject.hashValue overrides, with a nice fix-it.

rdar://problem/45674813
2019-01-23 19:43:04 -08:00
Pavel Yaskevich
e604261805 [ConstraintSystem] Track AST depth information directly
Instead of storing information about expression depths in the
solver state (which gets recomputed for salvage) let's track
it directly in constraint system, which also gives solver
access to it when needed e.g. for fixes.
2019-01-23 18:44:53 -08:00
Pavel Yaskevich
49c40d92f6 [AST] Augment getDepthMap with information about parent expressions
Which is very useful for the solver because otherwise it'd have to
compute and store this information twice.
2019-01-23 18:21:07 -08:00
Jordan Rose
aee0b4e675 Merge pull request #22006 from theblixguy/fix/SR-7601
[Typechecker] Allow @objc functions to return dynamic self
2019-01-23 13:41:57 -08:00
David Ungar
b7f3697387 Merge pull request #21907 from davidungar/A-defaultTypeReq-1-15-10
Use Request to getDefaultType & move cache to SourceFile.
2019-01-22 21:39:31 -08:00
Harlan Haskins
015b159ec1 Merge pull request #21996 from harlanhaskins/la-z-boy
[ParseableInterfaces] Handle lazy vars
2019-01-22 15:26:37 -08:00
Suyash Srijan
f5264b9779 [diag] fix incorrect diagnostic when unwrapping double optional 2019-01-22 22:03:40 +00:00
Pavel Yaskevich
8944665650 Merge pull request #22015 from theblixguy/fix/SR-2688
[Typechecker] allow @autoclosure closure to be a typealias
2019-01-22 12:49:32 -08:00
Jordan Rose
37c30b1710 Merge pull request #21999 from jrose-apple/from-exponential-expletives-to-quadratic-quality
Cut down on exponential growth in checking switch exhaustivity.
2019-01-22 11:49:51 -08:00
Harlan Haskins
dd5a6772f4 [ParseableInterfaces] Handle lazy vars
For lazy vars, we need to make public the top-level entry point, and the fact
that the lazy storage contributes to the layout of a type (if it’s fixed
layout, or if the type is not resilient.) We also shouldn’t ever print `lazy`
in a parseable interface.

Since we need to parse these identifiers, give them a new name,
`$__lazy_storage_$_{propname}`, which is parseable only in parseable interfaces
so it doesn’t conflict with other properties.
2019-01-22 11:03:12 -08:00
Suyash Srijan
843539b801 [typechecker] simplify code 2019-01-22 16:21:04 +00:00
Suyash Srijan
7dcb14f86c [typechecker] allow @autoclosure closure to be a typealias 2019-01-21 13:30:46 +00:00
Pavel Yaskevich
57a9d3fc6d [ConstraintSystem] Warning fixes shouldn't affect solution ranking 2019-01-21 01:07:56 -08:00
Pavel Yaskevich
33cff97ab2 [Sema] Fix resolveDependentMemberType to properly handle nested types found in enum/struct/class
Currently if member has been found through same-type constraint
it would only be properly handled when it comes from a class type,
because that's the only time when base type gets replaced with
"concrete" type from equivalence class, but nested types could also
come from structs, enums and sometimes protocols (e.g. typealias)
which `resolveDependentMemberType` has to handle.

Resolves: rdar://problem/47334176
2019-01-20 01:59:40 -08:00
Suyash Srijan
e65014e1ce [typechecker] allow @objc functions to return dynamic self 2019-01-20 03:49:50 +00:00
David Ungar
06356e64c9 Fixes. 2019-01-19 17:03:54 -08:00
Pavel Yaskevich
837385cb14 Merge pull request #21987 from xedin/add-behavior-to-fixes
[CSFix] Introduce non-fatal "warning" fixes
2019-01-18 22:25:46 -08:00
Jordan Rose
671944df0c Cut down on exponential growth in checking switch exhaustivity.
The problem Assume 'A' and 'B' are enums with cases .a1, .a2, etc. and
.b1, .b2, etc. If we try to typecheck this switch:

    switch (a, b) {
    case (.a1, .b1),
         (.a1, .b2):
      break
    ...

The compiler is going to try to perform the following series of
operations:

    > var s = (A, B)
    > s -= (.a1, .b1)
    ((A - .a1, B) | (A, B - .b1))
    > s -= (.a1, .b2)
    (((A - .a1, B) | (A - .a1, B - .b2)) |
     ((A - .a1, B - .b1) | (A, B - .b1 - .b2)))
    ...

As you can see, the disjunction representing the uncovered space is
growing exponentially. Eventually some of these will start
disappearing (for instance, if B only has .b1 and .b2, that last term
can go away), and if the switch is exhaustive they can /all/ start
disappearing. But several of them are also redundant: the second and
third cases are fully covered by the first.

I exaggerated a little: the compiler is already smart enough to know
that the second case is redundant with the first, because it already
knows that (.a1, .b2) isn't a subset of (A - .a1, B). However, the
third and fourth cases are generated separately from the first two,
and so nothing ever checks that the third case is also redundant.

This patch changes the logic for subtracting from a disjunction so
that

1. any resulting disjunctions are flattened, and
2. any later terms that are subspaces of earlier terms are dropped

This is a quadratic algorithm in the worst case (compare every space
against every earlier space), but because it saves us from exponential
growth (or at least brings down the exponent) it's worth it. For the
test case now committed in the repository, we went from 40 seconds
(using -switch-checking-invocation-threshold=20000000 to avoid cutting
off early) to 0.2 seconds.

I'll admit I was only timing this one input, and it's possible that
other complex switches will not see the same benefit, or may even see
a slowdown. But I do think this kind of switch is common in both
hand-written and auto-generated code, and therefore this is likely to
be a benefit in many places.

rdar://problem/47365349
2019-01-18 18:36:58 -08:00
Jordan Rose
f5a8f26e58 Don't bother forming a Space just to check if a case is redundant
Saves a few copies of linked lists. No real impact expected,
certainly no user-facing changes.
2019-01-18 18:36:58 -08:00
David Ungar
cb340af0f2 Format 2019-01-18 16:39:19 -08:00
David Ungar
d1fe7ca9a9 First cut at removing DeclContextWrapper 2019-01-18 16:38:46 -08:00
Robin Kunde
09f1bf8a40 [Diagnostics] Diagnose unresolved and typoed labels when using labeled break or continue statements inside loops (#21915)
Adds proper diagnostics when using unresolved labels on break statements inside loops. In case of simple typos, also provides suggestions and fixits. Right now, the misleading "error: 'break' is only allowed inside a loop, if, do, or switch" is emitted in 4.2 and master.

Resolves SR-9677.
2019-01-18 15:06:59 -08:00
Robert Widmann
d7a406dbc2 Merge pull request #20950 from CodaFi/christmas-declarations
[NFC] Upgrade EnumElementDecl to a DeclContext
2019-01-18 17:25:22 -05:00
David Ungar
12e7501561 Format 2019-01-18 14:19:29 -08:00
David Ungar
681fda399e Eliminate const char* 2019-01-18 14:18:10 -08:00
Pavel Yaskevich
aa8ccfd57d [CSFix] Introduce non-fatal "warning" fixes
The intention here is to be able to detect warnings earlier and
move some of the logic from CSApply and MiscDiagnostics to solver.

Warning fixes still lead to solution being applied to AST.
2019-01-18 14:08:08 -08:00
Brian King
3c6fc86c5a Check for getter by member reference 2019-01-18 09:49:23 -05:00
Slava Pestov
1b27618e3e Sema: Teach rethrows checking about OtherConstructorDeclRefExpr
Fixes <https://bugs.swift.org/browse/SR-8788>.
2019-01-18 00:35:03 -05:00
David Ungar
a8abaadd65 Minor 2019-01-17 17:37:24 -08:00