Commit Graph

15871 Commits

Author SHA1 Message Date
Brent Royal-Gordon
7df141cdad Merge pull request #29341 from brentdax/path-dependence
[MiscDiagnostics] Warn if magic identifiers don’t match
2020-01-21 20:45:47 -08:00
Devin Coughlin
082421048a [AST/Sema] Add availability attributes for macCatalyst
Add a platform kind and availability attributes for macCatalyst. macCatalyst
uses iOS version numbers and inherits availability from iOS attributes unless
a macCatalyst attribute is explicitly provided.
2020-01-21 20:27:14 -08:00
swift-ci
a6035b96bc Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-21 20:03:38 -08:00
Dan Zheng
aabc849c9e [AutoDiff] Add @differentiable fix-it for protocols/classes. (#29332)
For protocol requirements and class members with `@differentiable` attribute,
conforming types and subclasses must have the same `@differentiable` attribute
(or one with a superset of differentiability parameters) on implementing/
overriding declarations.

For implementing/overriding declarations that are missing a `@differentiable`
attribute, emit a fix-it that adds the missing attribute.

Resolves TF-1118.
2020-01-21 20:01:38 -08:00
swift-ci
25c6002331 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-21 16:43:52 -08:00
Pavel Yaskevich
1ed5794df5 Merge pull request #29322 from xedin/delay-closure-constraint-generation-is-some-cases
[ConstraintSystem] Delay closure body constraint generation in a coup…
2020-01-21 16:26:33 -08:00
Luciano Almeida
e598f6118e [ConstraintSystem] Improve check for record SpecifyObjectLiteralTypeImport and fix string description 2020-01-21 20:55:08 -03:00
Luciano Almeida
716e11f575 [Constraint System] Recording SpecifyObjectLiteralTypeImport fix when attempting literal result type variable binding and handle object literal in MissingArgumentsFailure 2020-01-21 20:39:44 -03:00
Brent Royal-Gordon
c504eb1b0a Warn if magic identifiers don’t match
When wrapping a function which is supposed to capture the caller’s location, there’s always a risk that the wrapper won’t capture the information the wrapped function wants; for instance, you might pass `(…, line, column)` where the callee expected `(…, column, line)`.

This commit emits a warning when a call passes an explicit argument to something that has a default argument, and that explicit argument is itself a parameter with a default argument, and both parameters use magic identifiers, but they use *different* magic identifiers.  This is partially in support of concise #file, but applies to all magic identifiers.

Fixes rdar://problem/58588633.
2020-01-21 14:28:16 -08:00
Brent Royal-Gordon
6c99bdac1e [NFC] Extract helper for making magic identifier strings 2020-01-21 14:28:16 -08:00
swift-ci
d4f35195fc Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-21 12:23:19 -08:00
Suyash Srijan
451074a426 [Typechecker] Remove 'NSObject.hashValue' warning now that it is an error (and because 'hashValue' is longer 'open') (#29328) 2020-01-21 20:16:54 +00:00
Pavel Yaskevich
2b8c00215f [ConstraintSystem] Delay closure body constraint generation in a couple of specific cases
* If there is a disjunction associated with closure type e.g.
  coercion to some other type `_ = { $0 } as (Int32) -> Void`

* If there is a disjunction associated with a collection which
  could provide more context to the constraint solver.
2020-01-21 12:06:32 -08:00
swift-ci
a48309f8b1 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-21 12:03:41 -08:00
Doug Gregor
d0981292ab [Constraint generation] Collect all closure body references to type variables.
Collect all references to parameters whose types involve type variables,
including in closures that aren’t single-expression. This fixes a type
checker assertion that occurs when the constraint graph can get disconnected
with the combination of delayed constraint generation for single-expression
closures and the use of function builders.

Fixes rdar://problem/58695803.
2020-01-21 10:15:28 -08:00
Doug Gregor
2b70025772 [Builder transform] Give generated pattern bindings proper source locations.
ASTScopes completely skip implicit pattern bindings, so don't mark
generated ones as implicit. Instead, give them suitable source
location information.

Fixes rdar://problem/58710568.
2020-01-21 10:12:48 -08:00
Doug Gregor
8283a67648 Revert "Revert "Reimplement function builders as statement transformations."" 2020-01-21 10:07:20 -08:00
swift-ci
e28c558c72 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-21 09:43:46 -08:00
Varun Gandhi
f6e0db5bdc Merge pull request #29239 from varungandhi-apple/vg-clang-types-in-sil
Propagate Clang types through SIL
2020-01-21 09:42:37 -08:00
swift-ci
677787741d Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-21 09:23:10 -08:00
Doug Gregor
423adbc089 Merge pull request #29292 from apple/revert-29133-generlize-function-builders
Revert "Reimplement function builders as statement transformations."
2020-01-21 09:10:20 -08:00
Luciano Almeida
94dd355604 [CSDiag] Remove FailureDiagnosis:: visitObjectLiteralExpr from CSDiag 2020-01-21 11:54:26 -03:00
Luciano Almeida
b53da3247a [ConstraintLocator] Minor indentation fixes 2020-01-21 11:54:26 -03:00
Luciano Almeida
68e09d64fd [CSFix] Creating object literal module import fix 2020-01-21 11:54:26 -03:00
swift-ci
cf405482f5 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-21 00:22:55 -08:00
Pavel Yaskevich
203a2b657b Merge pull request #29323 from LucianoPAlmeida/nfc-minor-comments
[NFC] Fixing minor comments and code
2020-01-21 00:15:50 -08:00
Luciano Almeida
fb12c09188 [NFC] Fixing minor comments that should be docs and minor call 2020-01-20 21:35:22 -03:00
swift-ci
44b7b6c0a9 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-19 12:23:32 -08:00
Dan Zheng
44d937d7c2 [AutoDiff upstream] Add @differentiable declaration attribute type-checking. (#29231)
The `@differentiable` attribute marks a function as differentiable.

Example:
```
@differentiable(wrt: x, jvp: derivativeFoo where T: Differentiable)
func id<T>(_ x: T) -> T { x }
```

The `@differentiable` attribute has an optional `wrt:` clause specifying the
parameters that are differentiated "with respect to", i.e. the differentiability
parameters. The differentiability parameters must conform to the
`Differentiable` protocol.

If the `wrt:` clause is unspecified, the differentiability parameters are
currently inferred to be all parameters that conform to `Differentiable`.

The `@differentiable` attribute also has optional `jvp:` and `vjp:` labels
for registering derivative functions. These labels are deprecated in favor of
the `@derivative` attribute and will be removed soon.

The `@differentiable` attribute also has an optional `where` clause, specifying
extra differentiability requirements for generic functions.

The `@differentiable` attribute is gated by the
`-enable-experimental-differentiable-programming` flag.

Code changes:
- Add `DifferentiableAttributeTypeCheckRequest`.
  - Currently, the request returns differentiability parameter indices, while
    also resolving `JVPFunction`, `VJPFunction`, and
    `DerivativeGenericSignature` and mutating them in-place in
    `DifferentiableAttr`. This was the simplest approach that worked without
    introducing request cycles.
- Add "is type-checked" bit to `DifferentiableAttr`.
  - Alternatively, I tried changing `DifferentiableAttributeTypeCheckRequest` to
    use `CacheKind::Cache` instead of `CacheKind::SeparatelyCached`, but it did
    not seem to work: `@differentiable` attributes in non-primary-files were
    left unchecked.

Type-checking rules (summary):
- `@differentiable` attribute must be declared on a function-like "original"
  declaration: `func`, `init`, `subscript`, `var` (computed properties only).
- Parsed differentiability parameters must be valid (if they exist).
- Parsed `where` clause must be valid (if it exists).
- Differentiability parameters must all conform to `Differentiable`.
- Original result must all conform to `Differentiable`.
- If JVP/VJP functions are specified, they must match the expected type.
  - `@differentiable(jvp:vjp:)` for derivative registration is deprecated in
    favor of `@derivative` attribute, and will be removed soon.
- Duplicate `@differentiable` attributes with the same differentiability
  parameters are invalid.
- For protocol requirements and class members with `@differentiable` attribute,
  conforming types and subclasses must have the same `@differentiable` attribute
  (or one with a superset of differentiability parameter indices) on
  implementing/overriding declarations.
2020-01-19 12:23:04 -08:00
Varun Gandhi
5f45820755 [AST] Store Clang type in SILFunctionType for @convention(c) functions. 2020-01-17 16:22:39 -08:00
Doug Gregor
86c13d3c74 Revert "Reimplement function builders as statement transformations." 2020-01-17 15:52:49 -08:00
swift-ci
3a0eb0760f Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-17 10:44:12 -08:00
Suyash Srijan
1f6714694c [Diagnostics] Emit fix-its for 'did you mean to override init(from:)/encode(to:)' diagnostics (#29259) 2020-01-17 18:43:55 +00:00
Doug Gregor
09bfd9438f Merge pull request #29133 from DougGregor/generlize-function-builders
Reimplement function builders as statement transformations.
2020-01-17 10:39:46 -08:00
swift-ci
4bc7076974 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-16 14:23:12 -08:00
Pavel Yaskevich
e4277daac7 Merge pull request #29252 from xedin/rdar-58647769
[ConstraintSystem] Fix conversion of variadic/inout closure parameter…
2020-01-16 14:09:47 -08:00
Doug Gregor
bfa6d7316d [Function builders] Fake Expr-based locators for now.
The right solution is to extend the notion of the "anchor" of a locator
to also cover statements (and TypeReprs, and Patterns, and more), so
this is a stop-gap.
2020-01-16 13:19:21 -08:00
Doug Gregor
cf96e6559a [Function builders] Minor fixes for lvalue-ness, interface types 2020-01-16 13:19:21 -08:00
Doug Gregor
9853926cb2 [Function builders] Make sure we contextualize closures with builders applied.
We used to get this contextualization "for free" because closures that
had function builders applied to them would get translated into
single-expression closures. Now, we need to check for this explicitly.
2020-01-16 13:19:21 -08:00
Doug Gregor
a49f0091cb [Constraint application] Skip error expressions when applying builders.
If we encountered an error, just skip it; there's nothing more to do.
2020-01-16 13:19:21 -08:00
Doug Gregor
f959ace180 [Function builders] Minor fixes for "load" expr generation 2020-01-16 13:18:33 -08:00
Doug Gregor
fccee4f77b [Constraint generation] Cope with odd handling of parameter types.
When generating constraints in the context of the "old" diagnostic
path that type-checks subexpressions independently, we might not have
types for closure parameters. Cope with the case with a narrower form
of the original hack.
2020-01-16 13:18:33 -08:00
Doug Gregor
c8acc0fc43 [Function builders] Minor fixes for builder transform refactoring.
A couple of trivial fixes as part of the builder transform refactoring:
* When recording captured expressions, record the source entity appropriately
* Make sure to check (and skip) #if declarations in application
* Check and diagnostic #warning/#error as part of application (not generation)
* Simplify the body result type for return coercion during application
* When checking for applicability of a function builder, don't do any
  constraint generation.
2020-01-16 13:18:33 -08:00
Doug Gregor
3a51d5b9b2 [WIP] Reimplement function builders as statement transformations. 2020-01-16 13:18:33 -08:00
Doug Gregor
71350bdb7b Generalize some mentions of closures in function builder application 2020-01-16 13:18:33 -08:00
Doug Gregor
9e6f6d8d3b Rename FunctionBuilderClosurePreCheck -> FunctionBuilderBodyPreCheck 2020-01-16 13:18:33 -08:00
swift-ci
ea899fe449 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-16 11:24:04 -08:00
Varun Gandhi
a0b0e362ac Merge pull request #29213 from varungandhi-apple/vg-fix-implicit-tupling-bug
We did the implicit untupling but forgot to do implicit tupling. Oops.
2020-01-16 11:06:22 -08:00
Pavel Yaskevich
f49d4501f8 [ConstraintSystem] Fix conversion of variadic/inout closure parameters for internal use
Delayed constraint generation for the body of the single-statement
closures regressed variadic parameter handling. Fix it by using
`FunctionType::Param::getParameterType` for "internal" version of
the parameter type which translates variadic/inout correctly.

Resolved: rdar://problem/58647769
2020-01-16 10:37:36 -08:00
Erik Eckstein
1b312a85bd Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-16 10:39:20 +01:00