Commit Graph

12650 Commits

Author SHA1 Message Date
Slava Pestov
003a9a47b2 Parse: Remove obsolete @autoclosure(escaping) and @noescape type attributes
Some diagnostics got worse, but I think the reduction in compiler complexity
is worth it, and copy-and-pasting Swift 2 code is not likely to produce great
results anyway.

Also, this corrects an oversight where we did not reject @pseudogeneric on
function types in AST parsing.
2019-04-09 15:02:14 -04:00
Slava Pestov
1c17ccfd3c AST: Add TypeBase::isNoEscape() 2019-04-09 15:02:14 -04:00
Slava Pestov
e214156abf Sema: Remove escaping capture diagnostics
I'm about to replace all of this with a SIL pass.
2019-04-09 15:02:14 -04:00
John Holdsworth
afba3d4772 Move off diagnostic path 2019-04-09 15:49:35 +01:00
John McCall
94be707c5a Merge pull request #23867 from rjmccall/var-is-too-mutated
Various improvements to the variable-is-never-mutated diagnostic
2019-04-09 10:43:47 -04:00
Saleem Abdulrasool
ead2a28383 Sema: move is_convertible outside of class decl
Ensure the class is fully defined before performing the `is_convertible`
check which may trigger a compiler builtin.  Before the class is
complete, the compiler can not technically perform the check on it.
This fixes the build with `cl`.
2019-04-08 16:25:19 -07:00
John Holdsworth
8b64cd4031 Only so much is possible 2019-04-09 00:21:41 +01:00
John McCall
4f4d64b93e Various improvements to the variable-is-never-mutated diagnostic.
The main fixes here are:
- we weren't looking through open-existentials in the l-value
- we weren't handling mutating gets correctly unless CSApply wrapped
  the base in an InOutExpr, which seems to be multifile-sensitive
- we were missing diagnostics in some cases involving subscripts

A better fix would be to re-introduce LValueAccessKind, but I wanted
a workable short-term fix that I could try to get into 5.1.

Fixes rdar://49482742, which is specific to the lazy-getter problem.
2019-04-08 18:43:24 -04:00
Jordan Rose
be48d64697 Merge pull request #23722 from jrose-apple/type-disadvantage
Implementation-only import checking for types used in decls
2019-04-08 09:18:11 -07:00
John Holdsworth
c89ce55c9e Ban Self in typealias for now https://bugs.swift.org/browse/SR-10334 2019-04-08 10:44:09 +01:00
Sam Lazarus
ebdb3cf346 Sema: Re-allowed coercion for existentials that have already been opened 2019-04-06 15:54:50 -04:00
Sam Lazarus
8ee220a560 Merge branch 'master' into slazarus/allow-access-through-existential-metatype 2019-04-06 09:03:33 -04:00
Sam Lazarus
390c6357b1 Sema: Prevented an invalid coercion when handling member access in accesses through metatypes 2019-04-05 23:34:15 -04:00
Jordan Rose
4972351b3c Fix implementation-only checking for members of frozen structs/classes
...which I had exactly backwards.
2019-04-05 20:10:10 -07:00
Jordan Rose
a9b0a6661a Implementation-only import checking for types used in decls
Based on the existing access checker for types used in decls. There's
a common skeleton here but we can't seem to get it out, so for now
add a third DeclVisitor to this file. On the plus side, checking this
alongside access is an easy way to make sure everything gets checked.

Part of rdar://problem/48991061
2019-04-05 20:10:10 -07:00
Jordan Rose
0f0ae58469 Factor out Type-in-Requirement visiting from access checking
I wish there was more we could share with the upcoming
implementation-only checker, but I don't see an obvious way to do it.
All the call sites want to know what kind of declaration they're
visiting in order to customize the diagnostic, or downgrade something
to a warning, or something else.

No functionality change.
2019-04-05 20:10:10 -07:00
Jordan Rose
6c0538988d Access checking: Separate TypeDecl-finding from access scope checking
...for planned reuse in implementation-only import logic.
No intended functionality change.
2019-04-05 20:10:10 -07:00
John McCall
6ef5fb57f0 Merge pull request #23702 from rjmccall/implementation-only-diagnostics
[WIP] implementation-only import checking
2019-04-05 22:07:45 -04:00
David Ungar
cf5d81c889 Merge pull request #23735 from davidungar/tracking-primary
[Batch mode] Cope with bugs that cause error  suppression.
2019-04-05 17:45:20 -07:00
Sam Lazarus
3a089ccc24 Merge branch 'master' into slazarus/allow-access-through-existential-metatype 2019-04-05 16:33:33 -04:00
Sam Lazarus
efc3e5ff48 Sema: Allow for same-type coercion between existential metatypes 2019-04-05 16:32:45 -04:00
John McCall
ae6561c32c Checks for implementation-only imports in @inlinable code.
Part of rdar://48991061
2019-04-05 16:30:25 -04:00
Arnold Schwaighofer
e50af98cc4 Merge pull request #23790 from aschwaighofer/dynamic_replacement_final
Allow final on dynamic members
2019-04-05 10:09:39 -07:00
Jordan Rose
d36a7393b0 Fix issue with expression patterns in switch exhaustivity checking (#23804)
Expression patterns (and cast patterns) don't actually contribute to
the exhaustivity of a switch statement---if you're matching against a
String, matching "abc" doesn't meaningfully reduce the full space of
the values you have to match. This was already handled, but didn't do
the right thing in a particular case involving a tuple payload in an
enum after the Space Engine (exhaustivity checker) optimizations that
went out in Swift 5.

https://bugs.swift.org/browse/SR-10301
2019-04-05 09:14:54 -07:00
Arnold Schwaighofer
90fe435f25 Don't constrain to swift-version 5 2019-04-05 07:09:57 -07:00
Pavel Yaskevich
16b65018b4 Merge pull request #23436 from xedin/keypath-dynamic-lookup
[SE-0252][TypeChecker] Keypath Dynamic Member Lookup
2019-04-05 00:10:53 -07:00
David Ungar
c8cd0f3bc0 Move location lookup to RAII object. 2019-04-04 22:41:53 -07:00
David Ungar
240b573966 WIP 2019-04-04 21:55:25 -07:00
Michael Gottesman
564b4fc11a [silgenpattern] Fix some stack-use-after-free errors caused by iterating over an Optional<ArrayRef<T>>.
Specifically the bad pattern was:

```
   for (auto *vd : *caseStmt->getCaseBodyVariables()) { ... }
```

The problem is that the optional is not lifetime extended over the for loop. To
work around this, I changed the API of CaseStmt's getCaseBodyVariable methods to
never return the inner Optional<MutableArrayRef<T>>. Now we have the following 3
methods (ignoring const differences):

1. CaseStmt::hasCaseBodyVariables().

2. CaseStmt::getCaseBodyVariables(). Asserts if the case body variable array was
   never specified.

3. CaseStmt::getCaseBodyVariablesOrEmptyArray(). Returns either the case body
   variables array or an empty array if we were never given any case body
   variable array.

This should prevent anyone else in the future from hitting this type of bug.

radar://49609717
2019-04-04 13:34:36 -07:00
Arnold Schwaighofer
1b863d6787 Allow final on dynamic members
Dynamic is about dynamically replacing a method implementiation not
overriding.

rdar://49535048
2019-04-04 07:26:43 -07:00
Michael Gottesman
7b0d8455ca [ast][silgen] Wire up the case body var decls and use them in SILGenPattern emission to fix the evil fallthrough bug.
rdar://47467128
2019-04-03 23:51:06 -07:00
Pavel Yaskevich
b388d83426 [ConstraintSystem] Make sure that keypath dynamic member lookup could be used recursively
For example if there a structure which requires multiple implicit
dynamic member calls to get the members:

```swift
struct Point { var x, y: Int }

@dynamicMemberLookup
struct Lens<T> {
   var obj: T

   subscript<U>(dynamicMember member: KeyPath<T, U>) -> U {
     get { return obj[keyPath: member] }
   }
}

func foo(_ lens: Lens<Lens<Point>>) {
  _ = lens.x
  _ = lens.obj.x
  _ = lens.obj.obj.x
}

_ = \Lens<Lens<Point>>.x
```
2019-04-03 19:20:04 -07:00
Azoy
7c75836d77 context cleanup part 1 2019-04-03 20:50:58 -05:00
Michael Gottesman
ed94b13d3f [ast] Add a helper method for checking if a pattern contains a var decl and adopt it. 2019-04-03 13:38:03 -07:00
David Ungar
44daa88ebd Format 2019-04-03 12:53:31 -07:00
David Ungar
9cc3a4a9d8 Rename defaultDiagnosticLoc to bufferIndirectlyCausingDiagnostic. 2019-04-03 12:52:49 -07:00
Pavel Yaskevich
2e8d163655 [ConstraintSystem] Special case keypath dynamic member lookup in disjunction filtering
Since filtering currently runs as part of the `applicable function`
constraint processing, "keypath dynamic member lookup" choice can't
be attempted in-place because that would also try to operate on that
constraint, so instead let's keep the disjunction, but disable all
unviable choices.

Resolves: rdar://problem/49533404
2019-04-03 12:23:23 -07:00
Pavel Yaskevich
e3ad92fbfb [ConstraintSystem] Allow to use keypath dynamic member lookup inside keypath expressions 2019-04-03 11:01:48 -07:00
David Ungar
c139c5909a Pass defaultDiagnosticLoc to handleDiagnostic, not currentPrimaryInput. 2019-04-02 22:27:55 -07:00
Slava Pestov
560d3ad529 Sema: Simplify simplifyLocator() 2019-04-02 20:37:01 -04:00
Slava Pestov
998e62005a Sema: Don't diagnose availability errors twice in non-single-expression closures 2019-04-02 20:37:01 -04:00
Slava Pestov
6bb36b5c01 Sema: Subscript default arguments
Fixes <https://bugs.swift.org/browse/SR-6118>.
2019-04-02 20:37:01 -04:00
Slava Pestov
043d76a3bf Sema: Don't type check enum element default args in non-primary files
Move the checking from validateDecl() to typeCheckDecl() since there's no
need to do it unless we're going to be emitting the enum declaration.
2019-04-02 20:37:01 -04:00
Slava Pestov
8292cbe3b3 AST: Remove 'default argument resilience expansion'
This was a Swift 3 mode holdover.
2019-04-02 20:37:01 -04:00
Brent Royal-Gordon
dd95a63e5b Merge pull request #23724 from brentdax/static-start
[NFC] Correct assumptions about static AbstractStorageDecls
2019-04-02 17:16:27 -07:00
Slava Pestov
016cb690ae Merge pull request #23730 from slavapestov/assorted-bug-fixes
Assorted bug fixes
2019-04-02 17:38:29 -04:00
David Ungar
c90d9e69b6 Format 2019-04-02 00:43:59 -07:00
David Ungar
7a0e0ffc8a Store current primary in diagnostic engine, pass it down via handleDiagnostic. Unformmated. 2019-04-02 00:43:28 -07:00
Slava Pestov
1caf2c7544 Sema: Fix code completion crash when a ParamDecl hasn't had its type set yet
We set the type of ParamDecls when applying solutions in the normal path, but
sometimes code completion will type check an expression inside a closure without
checking the outer expression. In this case, we may have inferred a type for
the ParamDecl, but we don't write it back.

Instead, just look at the DeclRefExpr's type.

Fixes <rdar://problem/42098113>.
2019-04-02 00:25:24 -04:00
Slava Pestov
88e41231cc Sema: Skip non-single-expression closure bodies in MiscDiagnostics
This is a defensive move to avoid duplicated work and guard against crashes
when a multi-expression closure body or TapExpr has not been type checked yet.

Fixes <rdar://problem/48852402>.
2019-04-02 00:25:24 -04:00