Commit Graph

58361 Commits

Author SHA1 Message Date
eeckstein
df5ba9cff4 Merge pull request #30581 from eeckstein/blockargopt
SILOptimizer: a new small optimization pass to remove redundant basic block arguments.
2020-03-27 11:41:11 +01:00
marcrasi
f6562d3a67 [AutoDiff upstream] differentiable function conversion pipeline (#30660)
Add the `@differentiable` function conversion pipeline:

- New expressions that convert between `@differentiable`,
  `@differentiable(linear)`, and non-`@differentiable` functions:
  - `DifferentiableFunction`
  - `LinearFunction`
  - `DifferentiableFunctionExtractOriginal`
  - `LinearFunctionExtractOriginal`
  - `LinearToDifferentiableFunction`
- All the AST handling (e.g. printing) necessary for those expressions.
- SILGen for those expressions.
- CSApply code that inserts these expressions to implicitly convert between
  the various function types.
- Sema tests for the implicit conversions.
- SILGen tests for the SILGen of these expressions.

Resolves TF-833.
2020-03-27 01:27:39 -07:00
Pavel Yaskevich
c99c9b95d0 [ConstraintSystem] Switch availability check to use correct API
Use `TypeChecker::checkDeclarationAvailability` instead of `isDeclAvailable`,
that is a proper API endpoint which does flag checking before calling
`isDeclAvailable` internally.
2020-03-27 00:43:09 -07:00
marcrasi
eae4c5eece [AutoDiff upstream] @differentiable function type sema (#30648)
Add type checking for `@differentiable` function types:
- Check that parameters and results conform to `Differentiable`.
- Implicitly conform parameters and results whose types are generic parameters
  to `Differentiable`.
- Upstream most of the differentiable_func_type_type_checking.swift test from
  `tensorflow` branch. A few function conversion tests have not been added
   because they depend on the `@differentiable` function conversion pipeline.

Diagnose gracefully when the `Differentiable` protocol is unavailable because
`_Differentiation` has not been imported.

Resolves TF-823 and TF-1219.
2020-03-26 23:28:02 -07:00
Xi Ge
ad76c24fb6 Merge pull request #30659 from nkcsgexi/60857470
Revert "TBDGen: avoid emitting symbols with OBJC_CLASS and OBJC_METACLASS prefixes"
2020-03-26 23:14:28 -07:00
Robert Widmann
987cd55f50 [NFC] Drop llvm::Expected from Evaluation Points
A request is intended to be a pure function of its inputs. That function could, in theory, fail. In practice, there were basically no requests taking advantage of this ability - the few that were using it to explicitly detect cycles can just return reasonable defaults instead of forwarding the error on up the stack.

This is because cycles are checked by *the Evaluator*, and are unwound by the Evaluator.

Therefore, restore the idea that the evaluate functions are themselves pure, but keep the idea that *evaluation* of those requests may fail. This model enables the best of both worlds: we not only keep the evaluator flexible enough to handle future use cases like cancellation and diagnostic invalidation, but also request-based dependencies using the values computed at the evaluation points. These aforementioned use cases would use the llvm::Expected interface and the regular evaluation-point interface respectively.
2020-03-26 23:08:02 -07:00
Robert Widmann
f2a1abc5dd [NFC] Refactor Side-Effecting Requests to be Explicitly so
Introduce evaluator::SideEffect, the type of a request that performs
some operation solely to execute its side effects. Thankfully, there are
precious few requests that need to use this type in practice, but it's
good to call them out explicitly so we can get around to making them
behave much more functionally in the future.
2020-03-26 22:55:20 -07:00
Alexis Laferrière
8c61335045 Merge pull request #30661 from xymus/fix60819771
Protect against erroneous extensions in `SPIGroupsRequest`
2020-03-26 19:36:00 -07:00
Pavel Yaskevich
4af4a3d901 Merge pull request #30656 from apple/revert-29845-trailing-closure-position
Revert "[ConstraintSystem] Accept trailing closure if multiple defaulted parameters after last function parameter"
2020-03-26 17:30:51 -07:00
Robert Widmann
4accf59a3b Merge pull request #30618 from CodaFi/protocol-adoption-program
[NFC] Add LookupConformancesInContextRequest
2020-03-26 17:18:55 -07:00
Pavel Yaskevich
81dbec09fb [ConstraintSystem] Don't check -disable-availability-checking
Checking for `-disable-availability-checking` in
`ConstraintSystem::isDeclUnavailable` caused a regression with
obsolete/introduced checking. Let's rely on
`DeclAttributes::isUnavailable` and `TypeChecker::isDeclAvailable`
to do the right thing instead.

Resolves: rdar://problem/60898369
2020-03-26 16:13:32 -07:00
Doug Gregor
d282e3c1e9 [Property wrappers] NFC rename initialValue -> wrappedValue where appropriate
wrappedValue is the new name, and we only support initialValue for backward
compatibility with earlier revisions of the property wrappers proposal.
2020-03-26 15:16:28 -07:00
Arnold Schwaighofer
c9d490c5a9 Revert "Merge pull request #30612 from aschwaighofer/irgen_also_unique_ext_method_types_list"
This reverts commit f0cdd76f18, reversing
changes made to 703fe0f1a1.

Revert "IRGen: Refactor getObjCEncodingForMethod and getObjectEncodingFromClangNode into one"

This reverts commit 0082682b0d.

Revert "Merge pull request #30438 from aschwaighofer/irgen_prefer_clang_type_encoding"

This reverts commit eeb7fa52b2, reversing
changes made to 77af77fa8a.

Revert "Merge pull request #30433 from aschwaighofer/irgen_no_duplicate_objc_method_descriptor_entries"

This reverts commit 77af77fa8a, reversing
changes made to 841eeb05b0.

This reverts the changes for

rdar://60461850, rdar://60474785, rdar://60778637

There is still at least an issue that we address with PR#30654.

Revert until we have confidence that this is the right fix set.
2020-03-26 15:00:15 -07:00
Doug Gregor
5ac8d769fd [Property wrappers] Allow default initialization to infer a type.
Property wrappers are allowed to infer the type of a variable, but this
only worked when the property wrapper was provided with an explicit
initialization, e.g.,

    @WrapsAnInt() var x   // infers type Int from WrapsAnInt.wrappedValue

However, when default initialization is supported by the property wrapper,
dropping the parentheses would produce an error about the missing type
annotation

    @WrapsAnInt var x

Make this second case behave like the first, so that default initialization
works consistently with the explicitly-specified version.
Fixes rdar://problem/59471019.
2020-03-26 13:44:08 -07:00
Alexis Laferrière
56c5959872 [SPI] Protect against an erroneous extension
rdar://problem/60819771
2020-03-26 12:51:03 -07:00
Doug Gregor
38964fc360 [Type checker] Remove dead code to compute pattern checking options. 2020-03-26 12:48:47 -07:00
Erik Eckstein
93a0dfc578 SILOptimizer: a new small optimization pass to remove redundant basic block arguments.
RedundantPhiElimination eliminates block phi-arguments which have the same value as other arguments of the same block.
This also works with cycles, like two equivalent loop induction variables. Such patterns are generated e.g. when using stdlib's enumerated() on Array.

   preheader:
     br bb1(%initval, %initval)
   header(%phi1, %phi2):
     %next1 = builtin "add" (%phi1, %one)
     %next2 = builtin "add" (%phi2, %one)
     cond_br %loopcond, header(%next1, %next2), exit
   exit:

is replaced with

   preheader:
     br bb1(%initval)
   header(%phi1):
     %next1 = builtin "add" (%phi1, %one)
     %next2 = builtin "add" (%phi1, %one) // dead: will be cleaned-up later
     cond_br %loopcond, header(%next1), exit
   exit:

Any remaining dead or "trivially" equivalent instructions will then be cleaned-up by DCE and CSE, respectively.

rdar://problem/33438123
2020-03-26 19:30:01 +01:00
Holly Borla
febcbf6d1c Merge pull request #30655 from hborla/missing-conformance-operator-ref
[Diagnostics] Support diagnosing references to operators without argument application
2020-03-26 11:13:12 -07:00
Xi Ge
31afb3f692 Revert "TBDGen: avoid emitting symbols with OBJC_CLASS and OBJC_METACLASS prefixes"
For clang decls marked with SWIFT_CLASS, these explicit class initializer symbols turn
out to be necessary in the TBD files.

rdar://60857470
2020-03-26 10:46:53 -07:00
Robert Widmann
4de729fffc [NFC] Add LookupConformancesInContextRequest
Add a request to lookup all implied conformances for use while
typechecking the primary. This provides a cache-point for
evaluator-based dependency tracking.
2020-03-26 10:26:25 -07:00
ematejska
75691d641e [AutoDiff upstream] Add linear function SIL instructions (#30638)
Add `linear_function` and `linear_function_extract` instructions.

`linear_function` creates a `@differentiable(linear)` function-typed value from
an original function operand and a transpose function operand (optional).

`linear_function_extract` extracts either the original or transpose function
value from a `@differentiable(linear)` function.

Resolves TF-1142 and TF-1143.
2020-03-26 09:41:14 -07:00
Pavel Yaskevich
2fa4fbb7a9 Merge pull request #30646 from xedin/rdar-60225883
[CSApply] Support dynamic member lookup as component of key path dyna…
2020-03-26 09:33:12 -07:00
Nathan Hawes
4ccc95f9b2 Merge pull request #30636 from nathawes/cross-import-indexing
[Index] Add index support for cross import overlays.
2020-03-26 09:22:07 -07:00
Pavel Yaskevich
f75996839a Revert "[ConstraintSystem] Accept trailing closure if multiple defaulted parameters after last function parameter" 2020-03-26 09:19:57 -07:00
Rintaro Ishizaki
1985cfdd0b Merge pull request #30652 from rintaro/ide-completion-func-in-closure-rdar60838686
[CodeCompletion] Don't run second pass for decls in closures
2020-03-26 09:12:44 -07:00
Holly Borla
da715f87c5 [Diagnostics] Support diagnosing references to operators without argument
application in MissingConformanceFailure::diagnoseAsAmbiguousOperatorRef
2020-03-26 08:40:32 -07:00
Xi Ge
ffe8a2b74a Merge pull request #30650 from nkcsgexi/60857172
PrintAsObjC: use header path relative to usr/include when importing non-framework headers
2020-03-26 07:59:20 -07:00
Rintaro Ishizaki
7b7599a28d [CodeCompletion] Don't run second pass for decls in closures
For instance:
--
let globalVar = {
    func something(arg: Int) -> Int {
        #^HERE^#
    }
    return something(12)
}()
--
We want to consider this as a top-level completion, not a function body
completion.

rdar://problem/60838686
2020-03-26 00:42:39 -07:00
Xi Ge
ebe0a45583 PrintAsObjC: use header path relative to usr/include when importing non-framework headers
We could assume usr/include belongs to header search paths. If a header
is located in a deeper location inside this directory, we need to print
the additional path components.

rdar://60857172
2020-03-25 23:30:28 -07:00
Anthony Latsis
3b3eadef05 Merge pull request #30488 from AnthonyLatsis/ast-printer-se-0267
[ASTPrinter] Account for contextual where clauses when printing gen. requirements
2020-03-26 07:32:37 +03:00
Slava Pestov
e06661d0c4 Merge pull request #30644 from slavapestov/fix-member-type-of-concrete-generic-param-crash
GSB: Fix maybeResolveEquivalenceClass() with member type of concrete type
2020-03-25 22:25:07 -04:00
Anthony Latsis
403004b4c7 [ASTPrinter] Account for contextual where clauses when printing requirements 2020-03-26 04:48:39 +03:00
Pavel Yaskevich
95be170e46 [CSApply] Support dynamic member lookup as component of key path dynamic member lookup
Previously solution application only supported references to
key path dynamic member lookup as components but it should support both kinds.

Resolves: rdar://problem/60225883
Resolves: [SR-12313](https://bugs.swift.org/browse/SR-12313)
2020-03-25 15:21:52 -07:00
David Ungar
db141af397 Merge pull request #30639 from davidungar/rdar-60840456-custom-attr-on-extension
Start lookup *outside* of D when D is, e.g. an ExtensionDecl
2020-03-25 15:12:48 -07:00
Nathan Hawes
a785fa6cee [Frontend][Index] Add frontend option to skip indexing the stdlib (for test performance)
Several tests related to indexing system modules were taking a considerable
amount of time (100+ seconds in the worst case) indexing the standard library.
This adds a frontend option to skip it and updates those tests to pass it.
2020-03-25 14:36:23 -07:00
Slava Pestov
53ab30044c GSB: Fix maybeResolveEquivalenceClass() with member type of concrete type
Fixes <rdar://problem/55401811>, <https://bugs.swift.org/browse/SR-11475>.
2020-03-25 16:53:57 -04:00
swift-ci
3e32a4cd57 Merge pull request #30641 from dan-zheng/fix-typo 2020-03-25 13:28:10 -07:00
Pavel Yaskevich
b73b7c20c4 Merge pull request #30592 from xedin/fallback-diag-for-holes
[ConstraintSystem] Avoid applying invalid solution with fixes
2020-03-25 11:54:08 -07:00
Arnold Schwaighofer
440acea981 Merge pull request #30633 from aschwaighofer/arm64e_does_not_backdeploy
arm64e does not back-deploy
2020-03-25 11:44:48 -07:00
Dan Zheng
7d1341e21c [Sema] NFC: fix typo.
`let` stored -> `let` stored property
2020-03-25 18:40:38 +00:00
David Ungar
44cc14a051 Start lookup *outside* of D when D is, e.g. an ExtensionDecl, since the attribute is outside of it. 2020-03-25 11:17:13 -07:00
Dan Zheng
76ad4abd0a [AutoDiff upstream] Fill in derivative witness table/vtable thunks. (#30634)
Generate `differentiable_function` and `differentiable_function_extract` in
derivative witness table/vtable thunks.

`differentiation_function` is later canonicalized by the differentiation
transform.

Add SIL FileCheck tests.
2020-03-25 11:15:58 -07:00
Dan Zheng
e5cb871428 [AutoDiff upstream] Add flag-gated AdditiveArithmetic derivation. (#30628)
Add `AdditiveArithmetic` derived conformances for structs, gated by the
`-enable-experimential-additive-arithmetic-derivation` flag.

Structs whose stored properties all conform to `AdditiveArithmetic` can derive
`AdditiveArithmetic`:
- `static var zero: Self`
- `static func +(lhs: Self, rhs: Self) -> Self`
- `static func -(lhs: Self, rhs: Self) -> Self`
- An "effective memberwise initializer":
  - Either a synthesized memberwise initializer or a user-defined initializer
    with the same type.

Effective memberwise initializers are used only by derived conformances for
`Self`-returning protocol requirements like `AdditiveArithmetic.+`, which
require memberwise initialization.

Resolves TF-844.
Unblocks TF-845: upstream `Differentiable` derived conformances.
2020-03-25 10:31:50 -07:00
Nathan Hawes
8b03b05f1d [Index] Add index support for cross import overlays.
Resolves rdar://problem/59445445
2020-03-25 10:04:41 -07:00
Pavel Yaskevich
5f328ad003 [ConstraintSystem] Don't increase SK_Fix score when looking through holes
`SK_Fix` was used to indicate that solver has encountered a hole
along the current path but since there is `SK_Hole` now, increasing
`SK_Fix` no longer makes sense.
2020-03-25 09:34:00 -07:00
Arnold Schwaighofer
a6c6ddccf1 arm64e does not back-deploy
rdar://60438869
2020-03-25 09:02:14 -07:00
Pavel Yaskevich
7410c09c56 [CSGen] No longer allow _ allow to be a hole directly
Problems related to incorrect use of `_` where previously diagnosed
by syntactic diagnostics which meant that it could only happen on
type-checked AST. This is no longer a case so we don't have to allow
incorrect uses of `_` to form solution without any fixes.
2020-03-25 08:33:36 -07:00
Dan Zheng
07596cbc9b [AutoDiff upstream] Relax @differentiable for protocol witnesses. (#30629)
Previously, all witnesses of a `@differentiable` protocol requirement were
required to have the same attribute (or one with superset parameter indices).

However, this leads to many annotations on witnesses and is not ideal for
usability. `@differentiable` attributes are really only significant on
public witnesses, so that they are clearly `@differentiable` at a glance (in
source code, interface files, and API documentation), without looking through
protocol conformance hierarchies.

Now, only *public* witnesses of `@differentiable` protocol requirements are
required to have the same attribute (or one with superset parameter indices).
For less-visible witnesses, an implicit `@differentiable` attribute is created
with the same configuration as the requirement's.

Resolves TF-1117.
Upstreams #29771 from tensorflow branch.
2020-03-25 08:13:27 -07:00
marcrasi
025cb9a501 autodiff builtins (#30624)
Define type signatures and SILGen for the following builtins:

```
/// Applies the {jvp|vjp} of `f` to `arg1`, ..., `argN`.
func applyDerivative_arityN_{jvp|vjp}(f, arg1, ..., argN) -> jvp/vjp return type

/// Applies the transpose of `f` to `arg`.
func applyTranspose_arityN(f, arg) -> transpose return type

/// Makes a differentiable function from the given `original`, `jvp`, and
/// `vjp` functions.
func differentiableFunction_arityN(original, jvp, vjp)

/// Makes a linear function from the given `original` and `transpose` functions.
func linearFunction_arityN(original, transpose)
```

Add SILGen FileCheck tests for all builtins.
2020-03-25 02:36:42 -07:00
Pavel Yaskevich
972de2e657 Merge pull request #30627 from LucianoPAlmeida/SR-12382-improve-pointer-conversion-mismatch-diag
[SR-12382] Improve optional pointer conversion mismatch diagnostics
2020-03-25 02:22:59 -07:00