Commit Graph

1216 Commits

Author SHA1 Message Date
Hamish Knight
f045350266 [CS] Clean up dynamic member overload choice checking
Add `OverloadChoice::isAnyDynamicMemberLookup`,
and use it to clean up a couple of places.
2021-10-01 12:54:08 +01:00
Pavel Yaskevich
de35114171 [Diagnostics] Add a tailored diagnostic for Swift -> C pointer conversion
Diagnose situations where Swift -> C pointer implicit conversion
is attempted on a Swift function instead of one imported from C header.

```swift
func test(_: UnsafePointer<UInt8>) {}

func pass_ptr(ptr: UnsafeRawPointer) {
  test(ptr) // Only okay if `test` was an imported C function.
}
```
2021-09-20 17:22:26 -07:00
Pavel Yaskevich
3a41f7af5f [ConstraintSystem] Add a new conversion - Swift to C pointers
Following pointer conversions are supported in argument positions (when referencing C/ObjC functions):

- Unsafe[Mutable]RawPointer -> Unsafe[Mutable]Pointer<[U]Int>
- Unsafe[Mutable]Pointer<Int{8, 16, ...}> -> Unsafe[Mutable]Pointer<UInt{8, 16, ...}>
2021-09-20 17:22:25 -07:00
swift-ci
28d0de56a5 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-20 14:33:29 -07:00
Pavel Yaskevich
a061a966d1 Merge pull request #39251 from xedin/classof-for-fixes
[CSFix] Add support for `classof` for all fixes
2021-09-20 14:33:06 -07:00
swift-ci
b03e896a3d Merge remote-tracking branch 'origin/main' into rebranch 2021-09-16 10:33:40 -07:00
Pavel Yaskevich
bd7d2125b7 Merge pull request #39261 from JiarenWang/wjr
[Compiler] add 'value' label for `NSNumber` to prevent roundabout err…
2021-09-16 10:17:38 -07:00
jiaren wang
391c6e07ad [Compiler] add 'value' label for NSNumber to prevent roundabout error message. 2021-09-15 23:23:41 +08:00
Pavel Yaskevich
0a425480d0 [CSFix] NFC: Rename fix/diagnostic for checked casts that always succeed 2021-09-10 13:55:15 -07:00
swift-ci
a459ff3a77 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-08 16:15:39 -07:00
Pavel Yaskevich
d798d3f711 Merge pull request #39190 from xedin/diagnostics-for-weak-patterns
[ResultBuilders] Properly diagnose `weak` declarations with non-optional type
2021-09-08 16:08:25 -07:00
Pavel Yaskevich
3bbde55052 [ConstraintSystem] Detect and diagnose incorrectly typed weak declarations
All `weak` declarations are supposed to have an optional type.
Detect situations when is not an optional, wrap it as a fix,
and diagnose the problem.
2021-09-08 09:39:54 -07:00
swift-ci
87204b48f9 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-08 04:12:46 -07:00
Hamish Knight
b5bc5141e5 Merge pull request #39192 from hamishknight/a-range-of-arguments
[CS] Store argument list mappings on solutions
2021-09-08 12:00:48 +01:00
Pavel Yaskevich
60d931612c [Dignostics] Diagnose weak declarations with non-optional types
Diagnose situations where `weak` attribute is used with a non-optional type
in declaration e.g. `weak var x: <Type>`:

```swift
class X {
}

weak var x: X = ...
```

`weak` declaration is required to use an optional type e.g. `X?`.
2021-09-07 17:36:56 -07:00
swift-ci
08f1ddb51e Merge remote-tracking branch 'origin/main' into rebranch 2021-09-07 11:34:13 -07:00
Holly Borla
03777c3fc9 [Diagnostics] Remove ContextualFailure::diagnoseMissingFunctionCall.
Instead, always diagnose missing call errors via MissingCallFailure.
2021-09-06 20:05:13 -07:00
Holly Borla
9d0d521457 [Diagnostics] Diagnose associated value pattern matching errors separately
from missing function call errors in `ContextualFailure`.

It doesn't make sense to diagnose pattern matching errors inside of
`diagnoseMissingFunctionCall`, and the code I added to bail out if there
is no explicit function expression broke the pattern matching diagnostics
anyway.
2021-09-06 19:50:00 -07:00
Holly Borla
dc10f60198 [ConstraintSystem] Don't attempt missing function call diagnostics if
there is no function expression explicitly written in the source code.
2021-09-06 19:50:00 -07:00
Hamish Knight
ddff9c4c9d [CS] Store argument list mappings on solutions
Roll back argument list mappings in the constraint
system at the end of solver scopes, and copy
argument list mappings into solutions.
2021-09-06 12:54:49 +01:00
swift-ci
cb32b553de Merge remote-tracking branch 'origin/main' into rebranch 2021-09-04 11:32:57 -07:00
Hamish Knight
3e28bbbd2c Update for review feedback
- Remove OriginalArguments in favor of storing the
pre-rewritten argument list, which simplifies things
nicely
- Adopt llvm::indexed_accessor_iterator
2021-09-01 18:40:29 +01:00
Hamish Knight
8c2b88abc0 [CS] Adopt ArgumentList
- Explicitly limit favoring logic to only handle
unary args, this seems to have always been the
case, but needs to be handled explicitly now that
argument lists aren't exprs
- Update the ConstraintLocator simplification to
handle argument lists
- Store a mapping of locators to argument lists
in the constraint system
- Abstract more logic into a getArgumentLocator
method which retrieves an argument-to-param locator
from an argument anchor expr
2021-09-01 18:40:25 +01:00
swift-ci
5fe1881a91 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-27 21:53:32 -07:00
Rintaro Ishizaki
49547a5378 [NFC][Basic] Import llvm::isa_and_nonnull to 'swift' namespace
Just for convenicence.

* Replace `llvm::isa_and_nonnull` with imported `isa_and_nonnull`
* Repalce some `EXPR && isa<T>(EXPR)` with `isa_and_nonnull<T>(EXPR)`
2021-08-27 11:36:21 -07:00
swift-ci
0a4b07a10c Merge remote-tracking branch 'origin/main' into rebranch 2021-08-20 09:33:58 -07:00
Frederick Kellison-Linn
5f07747cb3 [Sema] Diagnose user-specified placeholders which couldn’t be resolved 2021-08-19 14:53:33 -04:00
swift-ci
6f33655298 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-13 19:53:46 -07:00
Pavel Yaskevich
994f9a9a3d [Diagnostics] Result Builders: Improve diagnostic for unsupported observed vars 2021-08-13 13:42:13 -07:00
Pavel Yaskevich
0074adc6fe [Diagnostics] Result Builders: Extract pattern binding and var storage diagnostics into methods 2021-08-13 12:30:16 -07:00
Pavel Yaskevich
85d203cb34 [Diagnostics] Result Builders: Improve diagnostic for unsupported lazy/wrapped/computed vars 2021-08-13 12:04:06 -07:00
Pavel Yaskevich
67377216de [Diagnostics] Result Builders: Improve diagnostic for uninitialized variable declarations
Resolves: rdar://81532339
2021-08-13 10:41:13 -07:00
swift-ci
2aedbaa7ef Merge remote-tracking branch 'origin/main' into rebranch 2021-08-10 12:13:26 -07:00
Hamish Knight
e82edadee7 Remove some obsolete literal handling logic
We no longer convert literals into constructor
calls in Sema, SILGen emits the necessary calls.
2021-08-06 17:07:22 +01:00
Arnold Schwaighofer
5a83172a55 Merge remote-tracking branch 'upstream/main' into rebranch 2021-08-05 12:04:56 -07:00
Hamish Knight
21e8a320ec [CS] Better handle paren fix-its for unresolved chains
I missed this case when previously improving the
logic here. As it turns out, using the raw anchor
as the root expression from which to derive parent
information is insufficient. This is because it
may not capture relevant parent exprs not a part
of the fix locator.

Instead, pass down a function that can be used to
derive the parent expressions from the constraint
system's own parent map. Also make sure to assign
to `expr` for the UnresolvedMemberChainResultExpr
case to make sure we correctly check for it as a
sub-expression.

Finally, now that we're looking at more parent
exprs, add logic to handle `try` and `await`
parents, as well as ClosureExprs and
CollectionExprs. I couldn't come up with a test
case for CollectionExpr, as we emit different
diagnostics in that case, but it's probably better
to tend on the side of being more future proof
there.

rdar://81512079
2021-08-04 14:34:24 +01:00
willtunnels
319b3e64aa Add support for opaque result types in structural positions (#38392)
* [TypeResolver][TypeChecker] Add support for structural opaque result types

* [TypeResolver][TypeChecker] Clean up changes that add structural opaque result types
2021-08-03 23:45:02 -04:00
Hamish Knight
84a2c5c2c1 [Sema] Improve extra trailing closure diagnostic
Emit the specialized extraneous trailing closure
diagnostic for multiple trailing closures and
unlabelled unary argument lists, and add a
specialized trailing closure version for the multiple
extraneous case.
2021-08-02 12:59:43 +01:00
swift-ci
1fc44750c3 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-28 13:54:07 -07:00
Doug Gregor
7c0bdff052 Improve misleading diagnostics regarding implicit Sendable conformances 2021-07-28 10:41:59 -07:00
swift-ci
a2a6e5a7e8 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-27 02:53:21 -07:00
Hamish Knight
5d1fea24ad [CS] Don't consider implicit TupleExprs in exprNeedsParensOutsideFollowingOperator
Such implicit tuples may be used to represent
argument lists for e.g binary expressions, and as
such shouldn't be considered as parent exprs that
satisfy the role of parentheses.

Also fix the callers to use the raw anchor as the
root expression they pass to provide an accurate
parent map. This requires sinking the
UnresolvedMemberChainResultExpr handling logic into
`getPrecedenceParentAndIndex`.

rdar://81109287
2021-07-26 18:17:01 +01:00
swift-ci
fd87ebc401 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-23 07:13:34 -07:00
Robert Widmann
d86551de67 Lift Requirement and Parameter Accessors up to GenericSignature
Start treating the null {Can}GenericSignature as a regular signature
with no requirements and no parameters. This not only makes for a much
safer abstraction, but allows us to simplify a lot of the clients of
GenericSignature that would previously have to check for null before
using the abstraction.
2021-07-22 23:27:05 -07:00
swift-ci
a3ebc9a069 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-12 10:51:07 -07:00
Doug Gregor
29f5d7a64a [SE-0302] Implement '@unchecked Sendable' syntax.
Parse and provide semantic checking for '@unchecked Sendable', for a
Sendable conformance that doesn't perform additional semantic checks
for correctness.

Part of rdar://78269000.
2021-07-11 12:29:53 -07:00
swift-ci
e0e2634b84 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-06 09:35:07 -07:00
OneUpWallStreet
25df5d2c48 Fixed some common grammatical errors in the comments. (#38248) 2021-07-05 01:00:48 -07:00
Evan Wilde
42ff140171 llvm::StringRef equals_lower -> equals_insensitive
The `equals_lower` API was replaced with `equals_insensitive` in llvm
commit 2e4a2b8430aca6f7aef8100a5ff81ca0328d03f9 and
3eed57e7ef7da5eda765ccc19fd26fb8dfcd8d41.

Ran git clang-format.

(cherry picked from commit e21e70a6bf)
2021-07-02 10:55:17 -07:00
Luciano Almeida
7f085082dd Merge pull request #38153 from JiarenWang/wjr
[SR-14824] Improve diagnostic for multi-statement closures instead of…
2021-07-01 08:56:10 -03:00