-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Cherry-pick AutoDiff bug fixes and two features into 5.3 #32155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Mangle `@noDerivative` parameters to fix type reconstruction errors. Resolves SR-12650. The new mangling is non-breaking. When differentiation supports multiple result indices and `@noDerivative` results are added, we can reuse some of this mangling support.
…ypes (swiftlang#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.
…swiftlang#31524) In `AbstractFunctionDecl::getDerivativeFunctionConfigurations`, type-check `@differentiable` attributes. This is important to populate derivative configurations for original functions in other files. Resolves TF-1271. Exposes TF-1272: fix derivative configurations for cross-file `@derivative` attributes. This is a more difficult issue.
…ftlang#31669) For accessors: make `AbstractFunctionDecl::getDerivativeFunctionConfigurations` resolve configurations from parent storage declaration `@differentiable` attributes. Fixes "no `@differentiable` attribute" non-differentiability error for accessors whose parent storage declaration `@differentiable` attributes have not been type-checked (e.g. because the storage declarations are in another file). Add protocol requirement and class member storage declaration tests. Resolves TF-1234.
…mizer pass (swiftlang#30984) Add DifferentiabilityWitnessDevirtualizer: an optimization pass that devirtualizes `differentiability_witness_function` instructions into `function_ref` instructions. Co-authored-by: Dan Zheng <[email protected]>
…lang#30969) Move differentiation-related SILOptimizer files to {include/swift,lib}/SILOptimizer/Differentiation/. This reduces directory nesting and gathers files together.
Make commutative diagrams pretty using Unicode box characters. Use lowercase letters for arrow names.
…iftlang#30580) Adding JVP and VJP function derivatives for pow function defined in stdlib. Resolves TF-1200.
…s. (swiftlang#31527) Require `@derivative` functions and their original functions to have the same access level. Public original functions may also have internal `@usableFromInline` derivatives, as a special case. Diagnose access level mismatches. Produce a fix-it to change the derivative function's access level. This simplifies derivative registration rules, and may enable simplification of AutoDiff symbol linkage rules. Resolves TF-1099 and TF-1160.
Run clang-format on all differentiation SILOptimizer files. Remove dead commented code.
Differentiable conformance derivation now "peers through" property wrappers. Synthesized TangentVector structs contain wrapped properties' TangentVectors as stored properties, not wrappers' TangentVectors. Property wrapper types are not required to conform to `Differentiable`. Property wrapper types are required to provide `wrappedValue.set`, which is needed to synthesize `mutating func move(along:)`. ``` import _Differentiation @propertyWrapper struct Wrapper<Value> { var wrappedValue: Value } struct Struct: Differentiable { @wrapper var x: Float = 0 // Compiler now synthesizes: // struct TangentVector: Differentiable & AdditiveArithmetic { // var x: Float // ... // } } ``` Resolves SR-12638.
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.
Add SR-12642 negative test: crash regarding `Differentiable` derived conformances and redeclared properties.
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`).
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.
…ang#31723) Fix `PullbackEmitter::getArrayAdjointElementBuffer` to always lookup `Array.TangentVector.subscript` from the stdlib. Resolves compiler crash when user code also defines `Array.TangentVector.subscript`.
Make derivative forwarding thunks use original function's linkage instead of the derivative function's, stripping external. This is consistent with the linkage of differentiability witnesses. Clarify AutoDiff linkage-related comments. Resolves TF-1160: TBDGen error due to incorrect derivative thunk linkage.
…g#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.
The module name is not specified but the test explicitly overfits to an expected name. Adjust the test invocation to accommodate the expectation.
…erty wrappers. (swiftlang#32003) In `Differentiable` derived conformances, determine whether a property-wrapped property is mutable by checking whether a setter exists, instead of calling `VarDecl::getPropertyWrapperMutability()`. Resolves rdar://63577692 (SR-12873) where class-typed property wrappers with a mutable `wrappedValue` are rejected by synthesis (not included in the `TangentVector`). Also improve the property-wrapper-spe cific immutability warning message.
Add a common helper function `VJPEmitter::createTrampolineBasicBlock`. Change `VJPEmitter::buildPullbackValueStructValue` to take an original basic block instead of a terminator instruction.
This test was disabled in SR-12741 due to iphonesimulator-i386 failures. Enabling the test on other platforms is important to prevent regressions.
Support differentiation of `is` and `as?` operators. These operators lower to branching cast SIL instructions, requiring control flow differentiation support. Resolves SR-12898.
@swift-ci please smoke test |
@swift-ci please smoke test macOS |
18:34:16 --
18:34:16 Exit Code: 2
18:34:16
18:34:16 Command Output (stderr):
18:34:16 --
18:34:16 <unknown>:0: warning: using sysroot for 'MacOSX' but targeting 'iPhone'
18:34:16
/Users/buildnode/jenkins/workspace/swift-PR-osx-smoke-test/branch-release/5.3/swift/test/IRGen/framepointer_arm64.sil:13:8: error: no such module 'Swift'
18:34:16 import Swift
18:34:16 ^
18:34:16 FileCheck error: '-' is empty.
18:34:16 FileCheck command line: /Users/buildnode/jenkins/workspace/swift-PR-osx-smoke-test/branch-release/5.3/buildbot_incremental/llvm-macosx-x86_64/bin/FileCheck /Users/buildnode/jenkins/workspace/swift-PR-osx-smoke-test/branch-release/5.3/swift/test/IRGen/framepointer_arm64.sil --check-prefix=CHECK The test failure seems unrelated to this change. |
@swift-ci please test |
Build failed |
@swift-ci Please test linux |
Build failed |
@swift-ci Please test linux |
Build failed |
@swift-ci Please test linux |
This looks fine to me. @DougGregor any concerns about taking this patch into 5.3? Most of it exclusively touches autodiff. |
This PR attempts to cherry-pick the latest differentiable programming changes into release/5.3, including various bug fixes and two notable features:
Since the entire differentiable programming feature is gated by
import _Differentiation
, merging this into 5.3 should be low-risk.