Commit Graph

15871 Commits

Author SHA1 Message Date
John McCall
faee21b626 Implement Swift serialization and deserialization of Clang types.
As part of this, we have to change the type export rules to
prevent `@convention(c)` function types from being used in
exported interfaces if they aren't serializable.  This is a
more conservative version of the original rule I had, which
was to import such function-pointer types as opaque pointers.
That rule would've completely prevented importing function-pointer
types defined in bridging headers and so simply doesn't work,
so we're left trying to catch the unsupportable cases
retroactively.  This has the unfortunate consequence that we
can't necessarily serialize the internal state of the compiler,
but that was already true due to normal type uses of aggregate
types from bridging headers; if we can teach the compiler to
reliably serialize such types, we should be able to use the
same mechanisms for function types.

This PR doesn't flip the switch to use Clang function types
by default, so many of the clang-function-type-serialization
FIXMEs are still in place.
2020-02-06 22:09:00 -05:00
swift-ci
ac3ce0d3c4 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-06 13:43:41 -08:00
Hamish Knight
2b8583581d Merge pull request #29664 from hamishknight/inout-decls
Create a new module and SourceFile for REPL completion
2020-02-06 13:43:00 -08:00
swift-ci
ce39ec797e Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-06 13:24:23 -08:00
Pavel Yaskevich
02a676b3d1 Merge pull request #29672 from xedin/eliminate-leftover-contextual-diagnostics
[Diagnostics] Fix all of the edge cases and remove `diagnoseContextualConversionError`
2020-02-06 13:10:48 -08:00
Pavel Yaskevich
17f7598fdb [Diagnostics] NFC: Remove obsolete diagnoseContextualConversionError 2020-02-06 09:32:22 -08:00
Pavel Yaskevich
2875aa8e2b [Diagnostics] Diagnose an attempt to init/use dictionary with array literal in CSGen
It's much easier to detect that contextual type is a dictionary
but expression is an array literal while generating constraints.
2020-02-06 09:32:07 -08:00
Pavel Yaskevich
96441c1129 [CSFix] Account for nested structural errors related to function argument mismatches
When it comes to contextual mismatches `ContextualType` is not guaranteed
to be the last element in the patch since contextual type could be a function
too which could would have `contextual type -> function argument` path.
2020-02-06 09:30:19 -08:00
swift-ci
b276e72ceb Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-05 18:44:45 -08:00
Slava Pestov
ead5b9586c Merge pull request #29668 from slavapestov/fix-throws-in-defer-diagnostics
Sema: Only diagnose 'throws' in 'defer' as part of TypeCheckError
2020-02-05 21:43:23 -05:00
swift-ci
70ebdb7629 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-05 17:44:45 -08:00
Holly Borla
0cdaeb5708 Merge pull request #29649 from hborla/function-builder-syntactic-diags
[MiscDiagnostics] Walk into the body of a non single-statement closure if the closure had a function builder transform applied.
2020-02-05 17:43:03 -08:00
swift-ci
cf3c4aa3f5 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-05 16:06:28 -08:00
Slava Pestov
db6eb27ac7 Sema: Only diagnose 'throws' in 'defer' as part of TypeCheckError
We had a similar check in TypeCheckStmt but it did not account for the
possibility of the 'throw' being contained inside a 'do'/'catch' inside
a 'defer'. Remove it and just diagnose everything in one place.

Fixes <rdar://problem/57360567>.
2020-02-05 18:48:10 -05:00
Hamish Knight
9208f5bd88 Remove StartElem params from various entry points
Now that REPL code completion no longer injects
temporary decls into source files, this parameter
is no longer needed.
2020-02-05 14:01:21 -08:00
Hamish Knight
8037f2feb0 Merge pull request #29619 from hamishknight/a-buffet-of-tokens
Parse Swift decls in one shot
2020-02-05 13:58:31 -08:00
swift-ci
b713e90ffb Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-05 12:23:45 -08:00
Pavel Yaskevich
c5ae6c96a9 [ConstraintSystem] Detect missing/extraneous arguments even if there is optional injection required
If parameter type is optional let's ignore that since argument could
be either optional itself or be injected into optional implicitly.

```swift
func foo(_: ((Int, Int) -> Void)!) {}

foo { _ in } // Missing second closure parameter
```
2020-02-05 12:11:01 -08:00
Pavel Yaskevich
506cd7d858 [ConstraintSystem] Let optional chaining infer a type from sub-expression even with contextual mismatch
Just like in case of `try?` it makes it easier to distinguish between
missing optional unwrap and contextual type mismatch.
2020-02-05 12:11:01 -08:00
Pavel Yaskevich
fb0a484a08 [ConstraintSystem] Let try? infer type from sub-expression even with contextual mismatch
This helps to diagnose contextual mismatches like `Int? vs. Bool`
instead of suggesting to unwrap the optional which would still
produce an incorrect type.
2020-02-05 12:11:01 -08:00
Pavel Yaskevich
0103041a30 [ConstraintSystem] Tidy up restriction handling in contextual failures
Delay "fixing" contextual conversion failures until restriction is applied
this helps to tidy up logic for superclass and existential conversions.

Too bad we have to "fix" in `simplifyRestrictedConstraintImpl` now but
we can't really do much about that because diagnostics need both top-level
types to be useful.
2020-02-05 12:11:01 -08:00
Pavel Yaskevich
9a058274ae [TypeChecker] ForEach: Don't diagnose unrelated errors if type doesn't conform to Sequence
If the type used in for-each loop doesn't conform to `Sequence`
let's not try to diagnose anything about its element since such
diagnostics would include unresolved types and actual problem
(missing conformance) would already be diagnosed.
2020-02-05 12:11:01 -08:00
Pavel Yaskevich
95d0d14a29 [ConstraintLocator] Add accessors for assignemnt and coerce expression 2020-02-05 12:11:01 -08:00
Pavel Yaskevich
99856ed42c Merge pull request #29655 from xedin/rdar-41416758
[ConstraintSystem] Make variadics work with anonymous closure parameters
2020-02-05 12:10:25 -08:00
Pavel Yaskevich
07a69c425f [ConstraintSystem] Make variadics work with anonymous closure parameters
Since opening closure body is now delayed until contextual type becomes
available it's possible to infer anonymous parameters as being variadic
based on context and propagate that information down to the closure body.

Resolves: rdar://problem/41416758
2020-02-05 09:35:49 -08:00
swift-ci
8c265fd15a Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-05 05:44:33 -08:00
Slava Pestov
6c295411f6 Merge pull request #29652 from slavapestov/fix-selector-conflict-regression
Sema: Fix performance regression by only checking for selector conflicts in primary files
2020-02-05 08:35:24 -05:00
Kelvin
19a8759cee Merge branch 'master' into comparable-enums 2020-02-04 22:08:40 -06:00
Slava Pestov
c59bcfa683 Sema: Fix performance regression by only checking for selector conflicts in primary files 2020-02-04 22:16:24 -05:00
Holly Borla
778f8941ee [MiscDiagnostics] Walk into the body of a non single-statement closure
if the closure had a function builder transform applied.

This way, function builder closures can have syntactic restrictions
diagnosed the same way as other expressions.
2020-02-04 16:29:02 -08:00
Hamish Knight
312f7ddc50 Parse Swift decls in one shot
Instead of interleaving typechecking and parsing
for SIL files, first parse the file for Swift
decls by skipping over any intermixed SIL decls.
Then we can perform type checking, and finally SIL
parsing where we now skip over Swift decls.

This is an intermediate step to requestifying the
parsing of a source file for its Swift decls.
2020-02-04 13:04:50 -08:00
swift-ci
20124f3397 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-04 12:22:51 -08:00
Suyash Srijan
543d649278 [Diagnostics] Warn when the result of a Void-returning function is ignored (by assigning into '_') (#29576) 2020-02-04 20:19:37 +00:00
swift-ci
6ab5fec4f2 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-04 11:44:06 -08:00
Slava Pestov
d0205d897b Merge pull request #26975 from slavapestov/nlml-fixes
Implement lazy member loading for mirrored protocol members in imported types
2020-02-04 11:39:56 -08:00
swift-ci
712d7829d1 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-04 09:03:29 -08:00
Pavel Yaskevich
956b9f27b4 Merge pull request #29628 from owenv/condition_diags
[Diagnostics] Improve diagnostics for optional/integer as boolean condition
2020-02-04 08:49:36 -08:00
Slava Pestov
8280b20d81 Sema: Trigger lazy loading when recording potential selector conflicts 2020-02-04 09:54:06 -05:00
swift-ci
48c4eebbf1 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-04 02:42:48 -08:00
swift-ci
08dca4666e Merge pull request #29635 from DougGregor/simplify-solution-target 2020-02-04 02:36:15 -08:00
swift-ci
7e295cd4c2 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-03 23:22:53 -08:00
Doug Gregor
3981a68a76 Merge pull request #29626 from DougGregor/function-builders-single-expr-closures-return
[Constraint solver] Fix function builders with single-expression closures
2020-02-03 23:10:51 -08:00
Doug Gregor
bbc0a95723 [Constraint system] Simplify creation of contextual conversion constraint.
We were storing more state than necessary in the constraint system.
2020-02-03 22:38:24 -08:00
Doug Gregor
9569714334 Clarify method names in SolutionApplicationTarget. 2020-02-03 22:11:03 -08:00
Doug Gregor
36366bc3e4 [Constraint solver] One SolutionApplicationTarget instance to rule them all.
Capture the peculiarities of contextual types vs. types used to generate
conversion constraints, as well as the behavior of “optional some” patterns
as used by if let / while let, within SolutionApplicationTarget. This allows
us to use a single target throughout setup / solving / application, rather
than mapping between two similar-but-disjoint targets.
2020-02-03 22:02:21 -08:00
Owen Voorhees
166555c34f [Diagnostics] Better diagnostic for integer used as a boolean condition 2020-02-03 21:20:41 -08:00
Doug Gregor
f8eee50310 [Constraint solver] Fix function builders with single-expression closures
Fix a few related issues involving the interaction with
single-expression closures:

* A single-expression closure can have a "return" in it; in such
cases, disable the function-builder transform.
* Have the function builder constraint generator look through the
"return" statement in a single-expression closure the same way as
solution application does

Fixes rdar://problem/59045763, where we rejected some well-formed code
involving a single-expression closure with a "return" keyword.
2020-02-03 17:52:44 -08:00
Doug Gregor
77da6bd3a7 [Constraint graph] Don't drop unidirectional constraints.
Ye olde "break should have been continue" bug. This undoubtedly has
problems elsewhere, but I don't have a specific case until the next
commit.
2020-02-03 17:51:54 -08:00
Owen Voorhees
4aca39e18e [Diagnostics] Provide a better fix-it when trying to boolean-negate an optional 2020-02-03 17:40:03 -08:00
swift-ci
5220905ec1 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-03 15:02:53 -08:00