State of `Differentiation` in Swift 6.4 updates

Hello everyone!
Swift 6.4 released last week so it's time for another differentiable Swift update wrt the compiler!
(See our previous update back in February here)

What's new:

  • Differentiation of throwing functions is finally supported on all platforms. Previously the work for throwing functions got cherry picked onto 6.3 release branches but wasn't picked up for Darwin platforms unfortunately.
  • Work continues on autodiff-aware closure specialization. This will result in better optimized derivatives and pullbacks, no source code changes will be required, just a compiler update!
  • Fixed multiple compiler crashes
  • Many more other small improvements

Going forward

We're continuing to focus on improving performance and usability. We'll share additional updates about the swift-differentiation library, and the ongoing work we've been landing on main, targeting Swift 6.5.
From here we're hoping to do a few shorter but more frequent updates, so stay tuned for more over the next few weeks!

Thanks

Thanks to all the people who help us move forward! Be it in contributions, bug reports, code reviews, testing or any other way!

Special thanks goes out to:

Extra

For the curious ones, here is the list of important PRs in 6.4 timeframe:

Features:

  • Landed initial support for differentiating throwing functions, wrapping pullbacks in Optional and emitting the control flow needed to differentiate active try_apply results. This was already working on Linux, but the original 6.3 cherry-pick missed the Darwin releases - #82653 and #86393
  • Extended closure specialization to branch tracing enums, replacing opaque closures stored in enum payloads with their captured values so more multi-block pullbacks can be specialized into direct calls - #85757
  • Required new AST and SIL bridging for derivative functions - #84648, and for optional and enum case construction - #85756
  • Closes the long-standing request for a linear-map-aware closure optimization - #68944

Improvements/fixes:

  • Fixed a crash when differentiating generic code whose Differentiable conformance comes from a protocol's conditional conformance - #77446
  • Taught the SIL combiner to fold differentiable_function_extract inside borrowed scopes, unblocking VJP inlining under OSSA - #87826
  • Allowed implicitly generated VJPs/JVPs to be force-inlined when the original function is marked always-inline - #87859
  • Cleaned up conformance-related SIL warnings introduced by the AutoDiff closure specialization work - #86183
  • Fixed a miscompile where the closure specialization pass reused a specialized function across call sites with different non-reabstraction thunks - #91284
19 Likes

swift-differentiation-stdlib: prebuilt _Differentiation module for Apple platforms

Starting with macOS and iOS 26.4, Apple's OSes no longer ship the _Differentiation module as part of their system libraries. swift-differentiation-stdlib is a new repository that fills this gap by shipping a prebuilt _Differentiation module as an XCFramework for macOS, iOS, and the iOS simulator. This is only relevant on Apple platforms. On Linux, _Differentiation still ships with the toolchain and works as it always has. Most people will get this package through swift-differentiation, which depends on it and re-exports the module.

Here's what the package provides:
Release and dev snapshots. We have support for the latest Swift 6.4 releases, and a handful of prerelease versions from Swift 6.5 development snapshots. Swift 6.3.3 users should move to 603.3.1. Versioning still follows the swift-syntax convention, so pick the release that matches your compiler.
App Store ready packaging. The library ships as a framework bundle with dSYMs, so apps that depend on it pass App Store validation and get symbolicated crash reports.
Lightweight The XCFramework is now published as a release asset instead of being checked into git. SwiftPM downloads it and verifies it by checksum.

Please report missing symbols, SDK mismatches, or other issues here or as an issue on the repo.

3 Likes