Commit Graph

134 Commits

Author SHA1 Message Date
ematejska
fbec91a1b5 [Autodiff] Derivative Registration for the Get and Set Accessors (#32614)
* initial changes

* Add tests, undo unnecessary changes.

* Fixing up computed properties accessors and adding tests for getters.

* Adding nested type testcase

* Fixing error message for when accessor is referenced but not acutally found.

* Cleanup.

- Improve diagnostic message.
- Clean up code and tests.
- Delete unrelated nested type `@derivative` attribute tests.

* Temporarily disable class subscript setter derivative registration test.

Blocked by SR-13096.

* Adding libsyntax integration and fixing up an error message.

* Added a helper function for checking if the next token is an accessor label.

* Update utils/gyb_syntax_support/AttributeNodes.py

Co-authored-by: Dan Zheng <danielzheng@google.com>

* Update lib/Parse/ParseDecl.cpp

Co-authored-by: Dan Zheng <danielzheng@google.com>

* Add end-to-end derivative registration tests.

* NFC: run `git clang-format`.

* NFC: clean up formatting.

Re-apply `git clang-format`.

* Clarify parsing ambiguity FIXME comments.

* Adding couple of more testcases and fixing up error message for when accessor is not found on functions resolved.

* Update lib/Sema/TypeCheckAttr.cpp

Co-authored-by: Dan Zheng <danielzheng@google.com>

Co-authored-by: Dan Zheng <danielzheng@google.com>
2020-07-01 20:14:58 -07:00
Robert Widmann
b766544327 Merge pull request #32642 from CodaFi/ossignpost
[Gardening] Clean Up OS Conditionals With canImport and Vendor=apple
2020-07-01 12:08:15 -07:00
Robert Widmann
cddf73ecdb [Gardening] Clean Up OS-Test Patterns Across The Codebase
Clean up a few general patterns that are now obviated by canImport

This aligns more generally with the cleanup that the Swift Package
Manager has already done in their automated XCTest-plumbing tool in
apple/swift-package-manager#1826.
2020-06-30 22:55:58 -07:00
Dan Zheng
1bc9159e4f [AutoDiff] Support differentiation of functions with multiple results in SIL. (#32629)
Reverse-mode differentiation now supports `apply` instructions with multiple
active "semantic results" (formal results or `inout` parameters).

The "cannot differentiate through multiple results" non-differentiability error
is lifted.

Resolves TF-983.
2020-06-30 17:33:25 -07:00
Dan Zheng
46c2073784 [AutoDiff] Start supporting loadable types with address-only tangents. (#32540)
Previously, PullbackEmitter assumed that original values' value category
matches their `TangentVector` types' value category. This was problematic
for loadable types with address-only `TangentVector` types.

Now, PullbackEmitter starts to support differentiation of loadable types with
address-only `TangentVector` types. This patch focuses on supporting and testing
class types, more support can be added incrementally.

Resolves TF-1149.
2020-06-25 08:27:03 -07:00
Dan Zheng
bcae5016dd [AutoDiff] NFC: garden test. (#32209)
Clarify test name and contents.
2020-06-05 16:26:42 -07:00
Dan Zheng
756788eb95 [AutoDiff upstream] Add forward-mode differentiation runtime tests. (#32106)
Forward-mode differentiation development isn't currently prioritized, but
upstreaming tests allows us to prevent regressions.
2020-05-30 21:37:50 -07:00
Dan Zheng
a6bb9742fe [AutoDiff] NFC: garden tests. (#32102)
Remove extraneous code.
Clarify test name: test/AutoDiff/SIL/Serialization/differentiable_function_type.swift.
2020-05-30 11:51:49 -07:00
Dan Zheng
f9c5d7ae6c [AutoDiff] Derive Differentiable.zeroTangentVectorInitializer. (#31823)
`Differentiable` conformance derivation now supports
`Differentiable.zeroTangentVectorInitializer`.

There are two potential cases:
1. Memberwise derivation: done when `TangentVector` can be initialized memberwise.
2. `{ TangentVector.zero }` derivation: done as a fallback.

`zeroTangentVectorInitializer` is a closure that produces a zero tangent vector,
capturing minimal necessary information from `self`.

It is an instance property, unlike the static property `AdditiveArithmetic.zero`,
and should be used by the differentiation transform for correctness.

Remove `Differentiable.zeroTangentVectorInitializer` dummy default implementation.

Update stdlib `Differentiable` conformances and tests.
Clean up DerivedConformanceDifferentiable.cpp cruft.

Resolves TF-1007.
Progress towards TF-1008: differentiation correctness for projection operations.
2020-05-29 01:59:52 -07:00
Dan Zheng
d5d076db6a [AutoDiff] Support differentiation of branching cast instructions.
Support differentiation of `is` and `as?` operators.

These operators lower to branching cast SIL instructions, requiring control
flow differentiation support.

Resolves SR-12898.
2020-05-28 12:54:38 -07:00
Dan Zheng
24de636822 [AutoDiff] Re-enable control_flow.swift test.
This test was disabled in SR-12741 due to iphonesimulator-i386 failures.
Enabling the test on other platforms is important to prevent regressions.
2020-05-28 12:41:55 -07:00
Dan Zheng
e3938b5c7d [AutoDiff] Fix Array.append(_:) pullback.
The derivative wrt `self` should drop the last element from the incoming seed.

Example:
- Incoming seed: [1, 2, 3, 4]
- Derivative wrt `self`: [1, 2, 3]
- Derivative wrt appended element: 4
2020-05-14 09:27:50 -07:00
Dan Zheng
2e690e2d5e [AutoDiff] NFC: garden array differentiation.
Use consistent variable naming. Reorganize code.
2020-05-14 09:27:50 -07:00
Dan Zheng
212c89d869 [AutoDiff] NFC: add clarifying comments to test. 2020-05-11 01:43:43 -07:00
Dan Zheng
96f3f6fbcb [AutoDiff] Finish wrapped property differentiation support.
Add special-case VJP generation support for "semantic member accessors".
This is necessary to avoid activity analysis related diagnostics and simplifies
generated code.

Fix "wrapped property mutability" check in `Differentiable` derived conformnances.
This resolves SR-12642.

Add e2e test using real world property wrappers (`@Lazy` and `@Clamping`).
2020-05-10 15:55:29 -07:00
Dan Zheng
1f5818a5e9 [AutoDiff] Support property wrapper differentiation.
Support differentiation of property wrapper wrapped value getters and setters.

Create new pullback generation code path for "semantic member accessors".
"Semantic member accessors" are attached to member properties that have a
corresponding tangent stored property in the parent `TangentVector` type.

These accessors have special-case pullback generation based on their semantic
behavior. Currently, only getters and setters are supported.

This special-case pullback generation is currently used for stored property
accessors and property wrapper wrapped value accessors. In the future, it can
also be used to support `@differentiable(useInTangentVector)` computed
properties: SR-12636.

User-defined accesors cannot use this code path because they may use custom
logic that does not semantically perform a member access.

Resolves SR-12639.
2020-05-09 16:43:06 -07:00
Andrew Trick
4150dbd2ed SR-12741: disable AutoDiff/validation-test/control_flow.swift. 2020-05-06 01:08:06 -07:00
Dan Zheng
bab23d8298 SILOptimizer: fix partial_apply optimization. (#31552)
`partial_apply` can be rewritten to `thin_to_thick_function` only if the
specialized callee is `@convention(thin)`.

This condition is newly exercised by the differentiation transform:
`{JVP,VJP}Emitter::visitApplyInst` generates argument-less `partial_apply`
with `@convention(method)` callees.

Resolves SR-12732.
2020-05-05 09:09:42 -07:00
Andrew Trick
2f1b21d64c Temporarily disable 3 AutoDiff tests: SR-12732
https://bugs.swift.org/browse/SR-12732
3 AutoDiff test failures: crashing in SIL verification

Failing Tests (3):
06:26:12     Swift(macosx-x86_64) :: AutoDiff/validation-test/derivative_registration.swift
06:26:12     Swift(macosx-x86_64) :: AutoDiff/validation-test/custom_derivatives.swift
06:26:12     Swift(macosx-x86_64) :: AutoDiff/stdlib/derivative_customization.swift

Possibly from:

commit 738ef730e8
Author: Dan Zheng <danielzheng@google.com>
Date:   Mon May 4 00:44:48 2020 -0700

    [AutoDiff] Fix `@differentiable` attribute derivative configurations. (#31524)
2020-05-04 14:34:51 -07:00
Saleem Abdulrasool
debc627ce5 Merge pull request #31332 from compnerd/custom-derivative
test: repair the `custom_derivative` test
2020-04-26 16:11:56 -07:00
Saleem Abdulrasool
fef09af0b1 Merge pull request #31330 from compnerd/autodiff-module
test: repair the `separate_tangent_type` test on Windows
2020-04-26 16:10:45 -07:00
Saleem Abdulrasool
54e4994f6f test: repai the custom_derivative test
The test imports the C library for the math library.  Add a case for
Windows.
2020-04-26 11:56:03 -07:00
Saleem Abdulrasool
e18a61f1a4 test: repair the cross_module_derivative_attr test
Convert to dynamic libraries, fix the run lines, remove the workaround
for the TBD validation.
2020-04-26 11:53:03 -07:00
Saleem Abdulrasool
281d5198ce test: repair the separate_tangent_type test on Windows 2020-04-26 11:44:41 -07:00
marcrasi
a48880d13f [AutoDiff upstream] add more validation tests (#31190) 2020-04-22 17:31:11 -07:00
marcrasi
433821b7d1 [AutoDiff upstream] add more validation tests (#31112) 2020-04-21 15:30:25 -07:00
marcrasi
99356cd9f4 [AutoDiff upstream] add more differentiation tests (#30933) 2020-04-13 09:40:45 -07:00
Saleem Abdulrasool
abd4b12d21 Merge pull request #30951 from compnerd/cross-module-differentiation-win
AutoDiff: repair the cross-module-differentiation on Windows
2020-04-10 14:42:48 -07:00
Dan Zheng
486e667904 [AutoDiff] Support direct init reference differentiation. (#30946)
Support `@differentiable` function conversion for `init` references, in
addition to `func` references and literal closures. Minor usability improvement.

Resolves SR-12562.
2020-04-10 12:23:19 -07:00
Saleem Abdulrasool
26c61f5183 AutoDiff: repair the cross-module-differentiation on Windows
Make the cross-module differentiation test work on Windows by converting
to a shared library to run the test.
2020-04-10 11:25:40 -07:00
Saleem Abdulrasool
ccdc8efa95 AutoDiff: repair the test on Windows
The name of the module is encoded into the type name.  The module name
is not `null` on Windows, which would fail to match the name.  It is
possible to make the test less overly-constricted, but setting the
module name to null is simpler and avoids more regex matching.
2020-04-10 08:14:54 -07:00
Dan Zheng
b4fa7e0027 [AutoDiff] Support direct init reference differentiation.
Support `@differentiable` function conversion for `init` references, in
addition to `func` references and literal closures. Minor usability improvement.

Resolves SR-12562.
2020-04-10 01:26:34 -07:00
marcrasi
ddef9292a6 [AutoDiff upstream] DifferentiationUnittest and some e2e tests (#30915)
Adds 2 simple e2e tests and some lit subsitutions and unittest libraries
necessary to support them.
2020-04-09 14:25:31 -07:00
Dan Zheng
c142fcf6e2 [AutoDiff] Add SynthesizedFileUnit TBDGen/serialization tests.
Upstream `SynthesizedFileUnit` failing tests from TF-1239.
2020-04-08 21:22:06 -07:00