Commit Graph

15871 Commits

Author SHA1 Message Date
Suyash Srijan
8f44a0bd66 [TypeChecker] Diagnose key paths with contextual type but no leading dot
If a Swift key path has root type inferred but does not have a leading dot,
then diagnose it, because it's not valid.

For example:

```swift
struct Foo {
  let property: [Int] = []
  let kp: KeyPath<Foo, Int> = \property.count // error
}
```

Resolves SR-12290
Resolves rdar://problem/59874355
2020-04-07 16:59:23 -07:00
Pavel Yaskevich
3accb65a5c [AST] Track whether key path expression has a leading dot
This is going to be useful to detect whether contextual root
is really expected during key path resolution in Sema.
2020-04-07 16:16:34 -07:00
Holly Borla
ece84b176c [Diagnostics] Adjust ConstraintFix::diagnoseForAmbiguity to take an array
ref of pairs rather than two parallel arrays.
2020-04-07 13:38:26 -07:00
Ravi Kandhadai
4264b39b23 Merge pull request #26969 from ravikandhadai/oslog-user-model
[Sema Diagnostics] Add Miscellaneous Sema diagnostics to enforce that the new os log APIs and atomics are passed constants for certain arguments
2020-04-07 13:23:10 -07:00
Dan Zheng
5d8d8dab2d Merge pull request #30852 from dan-zheng/autodiff-cleanup
[AutoDiff] NFC: gardening.
2020-04-07 13:13:58 -07:00
Doug Gregor
78880ffc1a Merge pull request #27776 from owenv/catch_revamp_take_4
[SE-0276] Support multiple patterns in catch clauses
2020-04-07 12:31:33 -07:00
Dan Zheng
77d0d99f81 [AutoDiff] NFC: move isDifferentiableProgrammingEnabled.
Move `isDifferentiableProgrammingEnabled` to AutoDiff.h so it's more accessible.
2020-04-07 11:01:00 -07:00
Pavel Yaskevich
bd44fb3ef3 Merge pull request #30838 from xedin/rdar-61347993
[ConstraintSystem] Don't bind result type of an empty closure too early
2020-04-07 10:40:12 -07:00
Marc Rasi
78ac5eb0a3 add PointerUnion for parsed vs deserialized derivative attr 2020-04-07 10:25:30 -07:00
Ravi Kandhadai
b57a1d7c0e [Sema] Add miscellaneous sema diagnostics to check that the new os log
APIs and atomic operations are passed compile-time constants for
certain arguments.
2020-04-06 18:41:13 -07:00
Holly Borla
6375481ea4 [Diagnostics] In DefineMemberBasedOnUse::diagnoseForAmbiguity, use
the base type from each solution instead of only the base type from
the first solution.
2020-04-06 17:35:31 -07:00
Marc Rasi
be9d35cece Merge branch 'master' into derivative-attr-serialization 2020-04-06 16:58:08 -07:00
Pavel Yaskevich
04e2795a03 [ConstraintSystem] Don't bind result type of an empty closure too early
Instead of setting empty closure (`{}`) result type to be `Void`
while generating constraints, let's allocate a new type variable
instead and let it be bound to `Void` once the body is opened.

This way we can support an interaction with function builders which
would return a type different from `Void` even when applied to empty closure.

Resolves: rdar://problem/61347993
2020-04-06 15:55:55 -07:00
Hamish Knight
d6a6df2cf6 [CS] Fix invalid key path crasher (#30832)
[CS] Fix invalid key path crasher
2020-04-06 12:14:38 -07:00
Pavel Yaskevich
cbf3cab966 Merge pull request #30746 from ismetanin/fix-it-for-removing-escaping-from-optional-closure-parameter
Add new error diagnostic for escaping optional closures
2020-04-06 12:03:42 -07:00
Slava Pestov
549f630c40 Merge pull request #30809 from slavapestov/curry-thunk-source-range-fix
Sema: Fix source range for curry thunks
2020-04-06 13:37:01 -04:00
Luciano Almeida
08904ffe3f [SR-12242] Apply to Arg involving ConstraintLocator::GenericArgument diagnostics improvement (#30814)
* [CSDiagnostics] Handle arg to param generic when locator points to ConstraintLocator::GenericArgument

* [test] Add SR-12242 test case

* [CSDiagnostics] Handle arg to param on Generic mismatch as a fallback diagnostic

* [CSDiagnostics] Make assign diagnostics in GenericMismatchFailure handle more cases

* [test] Adding test cases for assign expr in GenericMismatch diagnostics

* [CSDiagnostics] Improving inout to pointer argument conversions with optionals diagnostics
2020-04-06 10:25:02 -07:00
Hamish Knight
3339ea4f91 [CS] Fix invalid key path crasher
Previously we were bailing early on encountering
an optional chain in the key path. However this
could cause us to miss invalid components further
down the line. Instead, set a flag and force the
key path to be read-only if we encountered an
optional chain.

Resolves SR-12519.
2020-04-06 10:14:19 -07:00
Dan Zheng
83f6714334 [AutoDiff] Start fixing SR-12526.
Start fixing SR-12526: `@derivative` attribute cross-module deserialization
crash. Remove original `AbstractFunctionDecl *` from `DerivativeAttr` and store
`DeclID` instead, mimicking `DynamicReplacementAttr`.
2020-04-06 06:37:23 -07:00
Dan Zheng
0c1d4b5adf [AutoDiff] Enable cross-file derivative registration.
Lift temporary cross-file derivative registration restriction.

`@derivative` attribute type-checking simplications coming soon: TF-1099.
Original function and derivative function must have same access level, with one
exception: public original functions may have internal `@usableFromInline`
derivatives.
2020-04-06 02:36:02 -07:00
Brent Royal-Gordon
121fa9a058 Ignore transitive ObjC imports when cross-importing
This behavior change reduces the chance of unexpected and unwanted cross-imports being performed.

Fixes rdar://problem/60554019.
2020-04-05 19:06:59 -07:00
Holly Borla
bbfcb55e9e [Property Wrappers] Inject the opaque value placeholder for a property
wrapper original wrapped value expression inside of CSApply.

This prevents type checking the synthesized backing storage initializer
twice - once with the original expression and again with the placeholder.
2020-04-05 19:02:37 -07:00
Ivan Smetanin
0beddca9e9 Unify diagnose invalid attr producing 2020-04-05 19:31:51 +03:00
Ivan Smetanin
f9b1a524da Fix escaping_optional_type_argument producing behavior 2020-04-04 20:22:04 +03:00
Owen Voorhees
43e2d107e1 [SE-0276] Implement multi-pattern catch clauses
Like switch cases, a catch clause may now include a comma-
separated list of patterns. The body will be executed if any
one of those patterns is matched.

This patch replaces `CatchStmt` with `CaseStmt` as the children
of `DoCatchStmt` in the AST. This necessitates a number of changes
throughout the compiler, including:
- Parser & libsyntax support for the new syntax and AST structure
- Typechecking of multi-pattern catches, including those which
  contain bindings.
- SILGen support
- Code completion updates
- Profiler updates
- Name lookup changes
2020-04-04 09:28:26 -07:00
Robert Widmann
b78ed5319b Merge pull request #30800 from CodaFi/erase-install
[Serialization] Lazily Resolve the Eraser Type of @ _typeEraser
2020-04-03 22:32:40 -07:00
Pavel Yaskevich
5eea0ae0fc Merge pull request #30803 from xedin/rdar-60961087
[CSGen] Bring back performance hack for named patterns with an initializer expression
2020-04-03 22:16:16 -07:00
Slava Pestov
5f51546480 Sema: Fix source range for curry thunks
Fixes <rdar://problem/61117301> / <https://bugs.swift.org/browse/SR-12496>.
2020-04-03 23:26:04 -04:00
Slava Pestov
e5a7fd3114 Merge pull request #30802 from slavapestov/var-decl-usage-checker-fixes
VarDeclUsageChecker fixes
2020-04-03 23:25:19 -04:00
Pavel Yaskevich
5c58bb8432 [CSGen] Bring back performance hack for named patterns with an initializer expression
Unfortunately we still need this performance hack because otherwise
e.g. if initializer returns a tuple its type is going to be connected
to a type variable representing a pattern type, which means all of the
tuple element types are going to form a single constraint system component.

Resolves: rdar://problem/60961087
2020-04-03 15:56:27 -07:00
Pavel Yaskevich
80ac793ecd [CSGen] Adjust locators for some patterns
In each of the following situations `getTypeForPattern` would
add a new pattern element to the path:

- Element of a tuple pattern
- Sub-pattern of a typed pattern
- Sub-pattern of optional .some
2020-04-03 15:56:27 -07:00
Slava Pestov
319a026a9a Sema: Always compute captures when we type check a function body 2020-04-03 18:14:36 -04:00
Holly Borla
c301176ca6 [ConstraintSystem] Allow SolutionApplicationTarget to store the
innermost call to init(wrappedValue:) if the target is for initialization
of a property wrapper's backing storage.
2020-04-03 15:12:12 -07:00
Slava Pestov
2c2d087242 Sema: More accurate VarDeclUsageChecker analysis with local functions
We used to take all the captures of a local function and treat them all
as read and write usages of vars from an outer scope. Instead, let's
refactor the analysis to walk into local functions.
2020-04-03 18:07:08 -04:00
Robert Widmann
27b211c1f9 Lazy-load the eraser of @_typeEraser where possible
Type erasure requires a circular construction by its very nature:

@_typeEraser(AnyProto)
protocol Proto { /**/ }
public struct AnyProto : Proto {}

If we eagerly resolve AnyProto, the chain of resolution steps that
deserialization must make goes a little something like this:

Lookup(Proto)
    -> Deserialize(@_typeEraser(AnyProto))
    -> Lookup(AnyProto)
    -> DeserializeInheritedStuff(AnyProto)
    -> Lookup(Proto)

This cycle could be broken if the order of incremental inputs was
such that we had already cached the lookup of Proto.

Resolve this cycle in any case by suspending the deserialization of the
type eraser until the point it's demanded by adding
ResolveTypeEraserTypeRequest.

rdar://61270195
2020-04-03 14:52:21 -07:00
Slava Pestov
93f0faf109 Sema: Fix false-positive var => let warning in VarUsageDeclChecker
Fixes <rdar://problem/60563962>.
2020-04-03 17:27:43 -04:00
Hamish Knight
6a7b2e0040 [Sema] Handle metatypes in buildSelfReference
Before attempting to get the superclass of a
self parameter type, check to see if we have a
metatype, and perform the necessary unwrapping and
re-wrapping if needed.
2020-04-03 09:18:58 -07:00
Hamish Knight
c926da1b07 [Sema] Adjust property wrapper mutability application
Only apply the relevant property wrapper mutability
when we're performing an access via the wrapped
value.
2020-04-03 08:26:36 -07:00
Artem Chikin
b679fd8738 Add -Rcross-import option
It is an optional, user-accessible mechanism to have the compiler tell you what it’s cross-importing.

Resolves rdar://problem/60381893
2020-04-02 19:45:39 -07:00
Joe Groff
a87369b53c Merge pull request #30763 from jckarter/protocol-infer-objc-error-convention
Sema: Infer error convention from @objc protocol requirements.
2020-04-02 16:04:37 -07:00
Ivan Smetanin
5f68f7a717 Make escaping_optional_type_argument to be an error, use it instead of original message when object type is a function type 2020-04-02 18:08:19 +03:00
Dan Zheng
1308fc69c5 [AutoDiff] Simplify conditions enabling differentiable programming. (#30765)
Previously, two conditions were necessary to enable differentiable programming:
- Using the `-enable-experimental-differentiable-programming` frontend flag.
- Importing the `_Differentiation` module.

Importing the `_Differentiation` module is the true condition because it
contains the required compiler-known `Differentiable` protocol. The frontend
flag is redundant and cumbersome.

Now, the frontend flag is removed.
Importing `_Differentiation` is the only condition.
2020-04-02 03:24:03 -07:00
Joe Groff
90062f1839 Sema: Infer error convention from @objc protocol requirements.
When a Swift declaration witnesses an ObjC protocol requirement, its error convention needs to
match the requirement. Furthermore, if there are different protocol requirements that the
Swift method can witness, with different error conventions, we need to bail out because we
can't simultaneously match all of them. Fixes rdar://problem/59496036 | SR-12201.
2020-04-01 18:26:38 -07:00
Slava Pestov
7b4786e723 Sema: Contextualize closures for function builder bodies also
The ContextualizeClosures walker re-parents and assigns discriminators to
autoclosures. We weren't doing this walk for function builder bodies,
which meant that proper invariants were not being established for the
implicit autoclosures synthesized for partially applied method references.

This is a recent regression from my change to build curry thunks for
unapplied method references in Sema.

Fixes <rdar://problem/61039516>.
2020-04-01 15:42:25 -04:00
Slava Pestov
391fc45559 Sema: Return value of TypeChecker::contextualizeInitializer() was unused 2020-04-01 15:08:12 -04:00
swift-ci
cf608c0c9a Merge pull request #30752 from DougGregor/codable-iuo-crash 2020-04-01 11:54:13 -07:00
Pavel Yaskevich
d922041ac5 Merge pull request #30740 from xedin/rdar-61084565
[ConstraintSystem] Don't include self-recursive dynamic member result…
2020-04-01 10:27:53 -07:00
Doug Gregor
9a37a2a62c [Codable] Fix crash-on-invalid with codable synthesis and implicitly unwrapped optionals
Fixes rdar://problem/60985179.
2020-04-01 10:15:32 -07:00
Slava Pestov
61bf796e41 Merge pull request #30745 from slavapestov/final-static-property-wrapper-fix
Sema: Property wrapper storage wrappers ($foo) inherit 'final' bit from original property
2020-04-01 12:12:32 -04:00
Robert Widmann
630d0f631a Merge pull request #30606 from AnthonyLatsis/rename-getfullname
[NFC] Preparations to address the «Rename to getName?» TODO on ValueDecl::getFullName
2020-04-01 09:00:04 -07:00