Commit Graph

9116 Commits

Author SHA1 Message Date
Rintaro Ishizaki
6fa84150c5 [AST] Eliminate IfConfigStmt
Resolves: https://bugs.swift.org/browse/SR-4426

* Make IfConfigDecl be able to hold ASTNodes
* Parse #if as IfConfigDecl
* Stop enclosing toplevel #if into TopLevelCodeDecl.
* Eliminate IfConfigStmt
2017-05-16 12:19:54 +09:00
Slava Pestov
03ebba50be Sema: Fix lvalue access of class existential payloads
Now that SILGen can correctly lower lvalue accesses of
class existential payloads, remove a hack in Sema that
was simply doing the wrong thing.

Fixes <rdar://problem/31858378>.
2017-05-15 20:14:48 -07:00
Pavel Yaskevich
ead1447aa1 [QoI] Extend single tuple parameter diagnostics to function/subscript calls
Properly diagnose cases of function/subscript argument tuple
structuring/destructuring related by not limited to SE-0110.

Resolves: rdar://problem/31973368
2017-05-15 18:41:41 -07:00
Joe Groff
306fce3d62 Merge branch 'master' into keypath-crashes 2017-05-15 17:18:29 -07:00
Doug Gregor
fef69478f6 [GSB] Introduce computeGenericSignature() for generic signature creation.
The GenericSignatureBuilder requires `finalize()` to be called before a
generic signature can be retrieved with `getGenericSignature()`. Most of the former isn’t strictly needed unless you want a generic signature, and the 
latter is potentially expensive. `computeGenericSignature()` combines the two
operations together, since they are conceptually related. Update most of the
callers to the former two functions to use `computeGenericSignature()`.
2017-05-15 17:16:50 -07:00
Pavel Yaskevich
7ad9cbee99 Merge pull request #9624 from xedin/rdar-32101765
[QoI] Improve diagnostics for Smart KeyPath
2017-05-15 16:51:44 -07:00
Joe Groff
faa6bc72f0 Sema: Reject unimplemented key path components during resolveKeyPathExpr.
This is a bit more robust and user-friendly than hoping more brittle recovery in SILGen or IRGen for unsupported components kicks in. rdar://problem/32200714
2017-05-15 16:10:59 -07:00
Pavel Yaskevich
8e8ead31d3 [QoI] Improve diagnostics for Smart KeyPath
Add `FailureDiagnostics::visitKeyPathExpr` to try and diagnose contextual
value type problems related to Smart KeyPath feature. If problems with
contextual value type can't be diagnosed let's walk components and see
if there are any structural problems with expression itself e.g. unknown
members and incorrect types in the path.

Resolves: rdar://problem/32101765
2017-05-15 14:43:37 -07:00
Joe Groff
ba7a5a80dd Sema: Don't crash when a tuple element is referenced in a key path.
Fixes rdar://problem/32200643. It'd be nice to have a targeted diagnostic too…
2017-05-15 14:12:41 -07:00
Mark Lacey
a1ed4e6174 Merge pull request #9606 from rudkx/revert-ecfa406fc580df48260c6ad606bfd11c10f6ad4c
Revert "Re-instate "Improve disjunction selection""
2017-05-15 13:24:11 -07:00
swift-ci
eed8f55735 Merge pull request #9613 from DougGregor/rename-nskeyedarchive-attributes 2017-05-15 12:16:47 -07:00
Mark Lacey
bc7dff5c9f Revert "Re-instate "Improve disjunction selection""
This reverts commit
ecfa406fc5, which was reinstating
3c5b393e0c.

It does not revert one test change from that commit, because
inexplicably one of the tests is still failing, probably due to some
other changes that have happened since. I'm leaving a ticket open to
investigate.

I've added one of the new cases that is failing as a result of this
change.

This is being reverted not because of bugs in this particular commit,
but because it seems to be exposing other bugs in the type checker that
are resulting in source compatibility problems. We need to shake these
other bugs out of the type checker before bringing this change back.
2017-05-15 11:27:11 -07:00
Doug Gregor
7955aa13e6 Rename @NSKeyedArchive* attributes.
@NSKeyedArchiveLegacy -> @NSKeyedArchiverClassName
@NSKeyedArchiveSubclassesOnly -> @NSKeyedArchiverEncodeNonGenericSubclassesOnly

Fixes rdar://problem/32178796.
2017-05-15 11:02:31 -07:00
Mark Lacey
70c0e85581 Diagnose Substring-to-String conversions resulting from subscripting.
When we have a Substring-to-String conversion as a result of
subscripting in a context expecting String, we emit the rather generic
and unactionable availability diagnostic.

Instead, to aid in migration, emit a highly specialized diagnostic and
fixit when we're compiling for -swift-version 4.
2017-05-14 23:28:36 -07:00
Ben Cohen
ea2f64cad2 [stdlib] Add Sequence.Element, change ExpressibleByArrayLiteral.Element to ArrayLiteralElement (#8990)
* Give Sequence a top-level Element, constrain Iterator to match

* Remove many instances of Iterator.

* Fixed various hard-coded tests

* XFAIL a few tests that need further investigation

* Change assoc type for arrayLiteralConvertible

* Mop up remaining "better expressed as a where clause" warnings

* Fix UnicodeDecoders prototype test

* Fix UIntBuffer

* Fix hard-coded Element identifier in CSDiag

* Fix up more tests

* Account for flatMap changes
2017-05-14 06:33:25 -07:00
David Farler
2e275e3a13 Merge pull request #9583 from bitjammer/rdar-32143617-void-tuple-input-type
Migrator/QoI: Function input type: Don't fix Void to (Void), but fix …
2017-05-13 18:43:07 -07:00
David Farler
0c48f71384 Migrator/QoI: Function input type: Don't fix Void to (Void), but fix (Void) to ()
```swift
func foo(f: Void) -> ()) {}
```

This compiler currently suggests we change this to:

```swift
func foo(f: (Void) -> ()) {}
```

That's `(()) -> ()`, almost certainly not what someone wants in Swift
4. We should suggest changing that to:
```swift
func foo(f: () -> ()) {}
```

Additionally,

```swift
func foo(f: (Void) -> ()) {}
```

Should trigger a warning that the `(Void)` input type is `(())`, and you
can't supply `()` to it in Swift 4, and suggest a fix-it change it to:

```swift
func foo(f: () -> ()) {}
```

rdar://problem/32143617
2017-05-13 17:36:28 -07:00
Xi Ge
b6d753067b FixCode: Add a new line between switch label and the code placeholder. rdar://32121847 (#9576) 2017-05-13 12:21:48 -07:00
Joe Groff
4e9851b032 Don't classify bridging casts as WillSucceed if the object-to-value cast can fail.
When casting from an object type to a bridged Swift value type, classifyDynamicCast would use the cast classification for the target type's bridged object type, which would be trivially WillSucceed for thinks like NSNumber-to-Int or NSError-to-SomeError, even though the bridging itself could fail. Fixing this fixes SR-2920|rdar://problem/31404281.
2017-05-12 10:39:39 -07:00
swift-ci
44a86cb374 Merge pull request #9507 from DougGregor/redundant-conformance-warnings-imported 2017-05-11 12:25:06 -07:00
Pavel Yaskevich
756136b286 Merge pull request #9497 from xedin/rdar-31898542
[QoI] Improve diagnostics for unresolved member with incorrect arguments
2017-05-11 11:52:33 -07:00
Doug Gregor
a43fbedd1c [Type checker] Extend redundant-conformance warning to imported types.
Fix a silly gap in my fix for rdar://problem/31104415, where imported
types that gain conformances through their overlays were still getting
errors. Fixes SR-4820 / rdar://problem/32134724.
2017-05-11 10:53:51 -07:00
swift-ci
cd61cf6d1b Merge pull request #9494 from DougGregor/common-return-type-cleanup 2017-05-11 09:46:49 -07:00
Doug Gregor
badffdc9c3 [Constraint solver] Tune the "skip generic operators" heuristic.
The "skip generic operators" heuristic within the constraint solver is
fairly awful, because it is known to miss reasonable solutions. Make
is slightly more narrow by only skipping generic operators when the
concrete operator we found was symmetric.
2017-05-11 08:57:29 -07:00
Doug Gregor
ecdc993881 [Type checker] Tolerate invalid expressions in the error-handling checker.
When errors occur in the processing of expressions, we can end up with
invalid ASTs where the application of an operator declared within a
type is missing its "self" argument. Tolerate such ASTs in the
error-handling checker.
2017-05-11 08:57:29 -07:00
Jordan Rose
2ecfee3c46 Merge pull request #9438 from jrose-apple/no-subclass-for-you
Disallow subclassing when a class is missing vtable entries.
2017-05-11 08:47:32 -07:00
Pavel Yaskevich
c0bc4f20be [QoI] Improve diagnostics for unresolved member with incorrect arguments
`FailureDiagnosis::visitUnresolvedMemberExpr` tries to use the same logic
as `diagnoseSingleCandidateFailures` so instead of doing that let's remove
some of the special handling and use `diagnoseSingleCandidateFailures`
directly instead, which improves label diagnostics and handles more erroneous
cases as well.

Resolves: rdar://problem/31898542
2017-05-11 01:31:33 -07:00
swift-ci
e305259ef0 Merge pull request #9384 from xedin/rdar-31724211 2017-05-11 00:37:15 -07:00
Slava Pestov
787cec31c7 Merge pull request #9488 from slavapestov/kill-non-enum-inheritance-clause-outer-layer
Fix source compatibility issue with protocol compositions in protocol inheritance clauses
2017-05-11 00:08:45 -07:00
Doug Gregor
5349486ca4 [Constraint solver] Shore up "common return type" optimization.
The "common return type" optimization that occurs at
constraint-generation time was overly complicated and wrong in a
couple of places. Fix up these issues:

* Don't cache information about this optimization in the decls
  themselves; it ignores visibility as well as invalidation that
  occurs in script mode and playgrounds. Just do the the work again
* Don't map type into context; we can bail out when there are type
  parameters present
* Skip the "self" parameters of operators in types (since this only
  ever occurs for operators).

Longer term, this optimization should move into the solver itself. But
for now, at least it's cleaner/more correct.
2017-05-10 23:20:07 -07:00
swift-ci
e987d04a21 Merge pull request #9487 from DougGregor/nscoding-objc-interop 2017-05-10 23:01:04 -07:00
Slava Pestov
6548ad709b Sema: Remove TR_NonEnumInheritanceClauseOuterLayer
This was added at some point with the associated type where
clause work, but it appears to be unnecessary, because all
the tests passed with this removed.

It also introduced a source compatibility issue where we
stopped accepting typealiases to protocol compositions in
protocol inheritance clauses.

Add a test for this case too, since it wasn't tested before.

Fixes <https://bugs.swift.org/browse/SR-4855>.
2017-05-10 22:12:25 -07:00
Slava Pestov
6c443113ae Sema: Generic parameters can only bind to materializable types
I don't have a test case for this, so it might be a no-op.
But it's clearly "correct".
2017-05-10 22:01:15 -07:00
Slava Pestov
5cf9716d65 Merge pull request #9484 from slavapestov/lift-nested-typealias-restriction
Sema: Allow nested typealiases to reference protocols with associated type of Self requirements
2017-05-10 21:48:28 -07:00
Doug Gregor
5a67ecceb4 Only enable NSCoding-related runtime name warnings with Objective-C interop 2017-05-10 21:06:11 -07:00
swift-ci
7b927e55e8 Merge pull request #9483 from DougGregor/has-failable-inits-lies 2017-05-10 20:12:21 -07:00
Slava Pestov
3f723e799a Sema: Allow nested typealiases to reference protocols with associated type or Self requirements
Previously we allowed this:

protocol HasSelf {
  func foo(_: Self)
}

typealias Alias = HasSelf

But not this:

struct Outer {
  typealias Alias = HasSelf
}

Lift this restriction since the new String implementation
wants to make use of it.
2017-05-10 17:21:11 -07:00
Doug Gregor
91951c8068 [Type checker] Delete unnecessary, bogus optimization for initializers.
An early optimization in constraint generation attempted to simplify
type construction (e.g., X(...)) when the type in question has no
failable initializers. However, the optimization didn't appropriately
clear out the cached bit when new information became available (e.g.,
new conformances, new extensions), and didn't seem to help anything
performance-wise (type-checking times didn't increase at all when I
turned this off).

Fixes rdar://problem/30588177.
2017-05-10 17:06:55 -07:00
Jordan Rose
a1b9304c37 Mention version mismatches for non-implementable protocols as well. 2017-05-10 17:04:09 -07:00
Jordan Rose
48fca56342 Specifically mention version mismatches for non-subclassable classes.
That is, if a Swift 4 class has members that cannot be loaded in Swift
3 mode and that's why it can't be subclassed, mention that in the
diagnostic.
2017-05-10 17:03:32 -07:00
Jordan Rose
8a314d9440 Disallow subclassing when a class is missing vtable entries.
This isn't an inherent limitation of the language---in fact, it would
be a problem for library evolution if you had to know a superclass's
full vtable contents to generate the vtable for a subclass. However,
that's exactly where we are today, and that's not going to change for
Swift 4.

One small hole in the Swift 3 / Swift 4 story.

More rdar://problem/31878396
2017-05-10 17:03:32 -07:00
Jordan Rose
df26b25f3a Merge pull request #9360 from jrose-apple/VTablePlaceholder
Add a new MissingMemberDecl and use it to handle non-deserializable class members
2017-05-10 17:02:16 -07:00
Doug Gregor
30482a0f8e Merge pull request #9473 from DougGregor/nskeyedarchivelegacy-fixits
[Type checker] Provide actual ObjC runtime name in @NSKeyedArchiveLegacy Fix-Its.
2017-05-10 16:26:53 -07:00
Doug Gregor
2986e816c7 Add a note about deliberate use of the Swift 3 mangling. 2017-05-10 15:11:32 -07:00
Doug Gregor
6ceb47bd6c [Type checker] Provide actual ObjC runtime name in @NSKeyedArchiveLegacy Fix-Its. 2017-05-10 14:47:11 -07:00
Jordan Rose
4cdb597b23 Rename VTablePlaceholderDecl to MissingMemberDecl.
As such, we no longer insert two placeholders for initializers that
need two vtable slots; instead we record that in the
MissingMemberDecl. I can see MissingMemberDecl growing to be something
we'd actually show to users, that can be used for other kinds of
declarations that don't have vtable entries, but for now I'm not going
to worry about any of that.
2017-05-10 11:55:55 -06:00
Jordan Rose
82930033d2 Add VTablePlaceholderDecl (but don't hook it up to anything yet). 2017-05-10 11:55:54 -06:00
Robert Widmann
7ae2d94062 Short circuit subspace check with empty subjects
When determining whether one constructor pattern is a subspace of
another, we only checked if the right-hand subspace was larger than the
left.  If the left is larger than the right then we can short-circuit
the comparison once more because it cannot be a subspace.

This also takes care of refutable casts in patterns tripping the
duplicate case warning.
2017-05-10 13:26:53 -04:00
Robert Widmann
0a0ab124e8 Merge pull request #9449 from CodaFi/the-rISA
Treat irrefutable casts as irrefutable patterns.
2017-05-10 12:10:29 -04:00
Robert Widmann
5ff2161d2e Treat irrefutable casts as irrefutable patterns. 2017-05-10 11:02:28 -04:00