Commit Graph

16 Commits

Author SHA1 Message Date
Anton Korobeynikov
2943d63ce5 Update tests not to use Tracked<T> for now. Also XFAIL SIMD tests 2025-10-12 19:48:52 -07:00
Daniil Kovalev
1e403ecf5c [AutoDiff] Support custom derivatives for @_alwaysEmitIntoClient functions (#78908)
Consider an `@_alwaysEmitIntoClient` function and a custom derivative
defined
for it. Previously, such a combination resulted different errors under
different
circumstances.

Sometimes, there were linker errors due to missing derivative function
symbol -
these occurred when we tried to find the derivative in a module, while
it
should have been emitted into client's code (and it did not happen).

Sometimes, there were SIL verification failures like this:

```
SIL verification failed: internal/private function cannot be serialized or serializable: !F->isAnySerialized() || embedded
```

Linkage and serialization options for the derivative were not handled
properly,
and, instead of PublicNonABI linkage, we had Private one which is
unsupported
for serialization - but we need to serialize `@_alwaysEmitIntoClient`
functions
so the client's code is able to see them.

This patch resolves the issue and adds proper handling of custom
derivatives
of `@_alwaysEmitIntoClient` functions. Note that either both the
function and
its custom derivative or none of them should have
`@_alwaysEmitIntoClient`
attribute, mismatch in this attribute is not supported.

The following cases are handled (assume that in each case client's code
uses
the derivative).

1. Both the function and its derivative are defined in a single file in
   one module.

2. Both the function and its derivative are defined in different files
which
   are compiled to a single module.

3. The function is defined in one module, its derivative is defined in
another
   module.

4. The function and the derivative are defined as members of a protocol
extension in two separate modules - one for the function and one for the
   derivative. A struct conforming the protocol is defined in the third
   module.

5. The function and the derivative are defined as members of a struct
extension in two separate modules - one for the function and one for the
   derivative.

The changes allow to define derivatives for methods of `SIMD`.

Fixes #54445
<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->
2025-05-25 09:47:15 -04:00
Richard Wei
b9fed629bd [AutoDiff] Disable tests on use_os_stdlib or back_deployment_runtime
AutoDiff is not ABI-stable and not shipped in any OS. We disable all AutoDiff runtime tests with `use_os_stdlib` or `back_deployment_runtime`.
2022-05-03 14:04:58 -07:00
Slava Pestov
b57be6dbf1 Revert "AutoDiff: Disable requirement machine when building or testing Differentiation library"
This reverts commit 4f6ba29715.
2021-09-23 13:24:40 -04:00
Slava Pestov
4f6ba29715 AutoDiff: Disable requirement machine when building or testing Differentiation library
The SIL type lowering logic for AutoDiff gets the substituted generic signature
mixed up with the invocation generic signature, so it tries to ask questions
about DependentMemberTypes in a signature with no requirements. This triggers
assertions when the requirement machine is enabled.

Disable the requirement machine until this is fixed.
2021-07-30 19:42:31 -04:00
Nate Chandler
b3997be85b [Test] Disabled several AutoDiff tests for back_deployment_runtime.
rdar://76566029
2021-04-13 15:18:05 -07:00
Richard Wei
0b53a02544 [AutoDiff] Rename 'in:' to 'of:' in differential operators.
Rename the argument label `in:` in `gradient(at:in:)`, `pullback(at:in:)`, etc to `of:`, as suggested in the [pitch thread](https://forums.swift.org/t/differentiable-programming-for-gradient-based-machine-learning/42147).
2021-02-24 01:33:42 -05:00
Arnold Schwaighofer
27a4e824c2 The runtime function swift_autoDiffCreateLinearMapContext was recently added
So these tests fail with missing symbols if the test is deployed with stdlib's on older OSes

rdar://71900166
2020-12-02 11:45:22 -08:00
Dan Zheng
c28d9cd7ea [AutoDiff] NFC: fix typos. (#33002) 2020-07-20 11:41:39 -07:00
Dan Zheng
fcfacddbf2 [AutoDiff] Register VJPs for SIMD subscript(_: Int) setters. (#32747) 2020-07-16 07:48:12 -07:00
Dan Zheng
cb9e134587 [AutoDiff] NFC: fix "pullback" abbrevation. (#32745)
"bp" -> "pb"
2020-07-07 17:39:55 -07:00
Dan Zheng
4495f6b87d Fix tests for 32-bit platforms.
- Remove unnecessary imports from test/AutoDiff/stdlib/simd.swift.
- Use platform-correct `Builtin` integer type in
  `PullbackEmitter::getArrayAdjointElementBuffer`.
2020-04-08 19:16:00 -07:00
Dan Zheng
d599105715 [AutoDiff upstream] Fix stdlib differentiation tests.
Temporarily disable not-yet-supported differentiation tests:

- Forward-mode differentiation.
  - TF-1237: to be upstreamed.
- `Differentiable.zeroTangentVector`.
  - TF-1238: to be upstreamed.
- `SIMD.sum` differentiation.
  - TF-1103: `@_alwaysEmitIntoClient` derivative registration.
2020-04-08 02:50:43 -07:00
Dan Zheng
da36555aa5 [AutoDiff upstream] Gardening.
- Standardize filenames: `XXXDifferentiation.swift`.
  - Use Pascal or snake case consistently.
- Formatting changes.
2020-04-08 02:49:12 -07:00
Ewa Matejska
36cf56651f fixing up some tests and turning off SIMD extension which uses @_alwaysEmitIntoClient since that's not supported yet. 2020-04-03 12:59:47 -07:00
Ewa Matejska
f07ae89636 First pass at upstreaming Differentiable conformances and derivatives 2020-04-02 19:55:26 -07:00