Commit Graph

212 Commits

Author SHA1 Message Date
Dan Zheng
3c3093db75 [AutoDiff] Clean up VJP basic block utilities.
Add a common helper function `VJPEmitter::createTrampolineBasicBlock`.

Change `VJPEmitter::buildPullbackValueStructValue` to take an original basic
block instead of a terminator instruction.
2020-05-28 12:32:15 -07:00
Saleem Abdulrasool
cebe79d482 SIL: use object libraries instead of globbing
This simplifies the handling of the subdirectories in the SIL and
SILOptimizer paths.  Create individual libraries as object libraries
which allows the analysis of the source changes to be limited in scope.
Because these are object libraries, this has 0 overhead compared to the
previous implementation.  However, string operations over the filenames
are avoided.  The cost for this is that any new sub-library needs to be
added into the list rather than added with the special local function.
2020-05-18 18:56:34 +00:00
Dan Zheng
d9c3a8497a [AutoDiff] Fix semantic member accessor linear map structs. (#31745)
Ensure that semantic member accesors have empty linear map structs.
Semantic member accessor VJPs do not accumulate any callee pullbacks.

Resolves SR-12800: SIL verification error.
2020-05-12 23:20:30 -07:00
marcrasi
619d0b0351 [AutoDiff] fix array subscript lookup when there are multiple (#31723)
Fix `PullbackEmitter::getArrayAdjointElementBuffer` to always lookup
`Array.TangentVector.subscript` from the stdlib.

Resolves compiler crash when user code also defines
`Array.TangentVector.subscript`.
2020-05-12 01:52:06 -07:00
Dan Zheng
cde1d180b4 [AutoDiff] Fix semantic member accessor pullbacks ownership errors.
Fix ownership errors in semantic member accessor pullbacks:
- Getter pullbacks: emit copy value operation before storing value.
- Setter pullbacks: track loaded value as a temporary, to be destroyed.

Add tests covering trivial, non-trivial, and address-only properties.
Resolves SR-12778 and SR-12779.
2020-05-11 01:50:51 -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
Dan Zheng
b5ccc4daf4 [AutoDiff] NFC: gardening. (#31668)
Run clang-format on all differentiation SILOptimizer files.
Remove dead commented code.
2020-05-09 07:29:29 -07:00
Arnold Schwaighofer
970c27248f Merge pull request #31470 from aschwaighofer/fix_rdar62560867
SIL: Thread type expansion context through to function convention apis
2020-05-06 11:52:19 -07:00
marcrasi
ce5e0e774c [AutoDiff] Fix SR-12641: Handle address-only types in derivative fn types (#31496)
* The update in `SILFunctionType.cpp` fixes SR-12641 by making address-only parameters/results in differentials have indirect convention.
* I updated the crasher test to use a resilient struct defined in the test, instead of `Tracked<Float>`, so that the test does not need to depend on `DifferentiationUnittest`.
* The update in `VJPEmitter.cpp` fixes a similar issue with pullbacks that I discovered while investigating.
* I added code that exposes this new issue to the SR-12641 crasher test.
2020-05-05 12:29:10 -07:00
Arnold Schwaighofer
147144baa6 SIL: Thread type expansion context through to function convention apis
This became necessary after recent function type changes that keep
substituted generic function types abstract even after substitution to
correctly handle automatic opaque result type substitution.

Instead of performing the opaque result type substitution as part of
substituting the generic args the underlying type will now be reified as
part of looking at the parameter/return types which happens as part of
the function convention apis.

rdar://62560867
2020-05-04 13:53:30 -07:00
Dan Zheng
43715e725e [AutoDiff] NFC: reorganize differentiation SILOptimizer files. (#30969)
Move differentiation-related SILOptimizer files to
{include/swift,lib}/SILOptimizer/Differentiation/.

This reduces directory nesting and gathers files together.
2020-05-04 06:19:39 -07:00