mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[AutoDiff upstream] Serialize derivative function configurations. (#30672)
Serialize derivative function configurations per module. `@differentiable` and `@derivative` attributes register derivatives for `AbstractFunctionDecl`s for a particular "derivative function configuration": parameter indices and dervative generic signature. To find `@derivative` functions registered in other Swift modules, derivative function configurations must be serialized per module. When configurations for a `AbstractFunctionDecl` are requested, all configurations from imported modules are deserialized. This module serialization technique has precedent: it is used for protocol conformances (e.g. extension declarations for a nominal type) and Obj-C members for a class type. Add `AbstractFunctionDecl::getDerivativeFunctionConfigurations` entry point for accessing derivative function configurations. In the differentiation transform: use `AbstractFunctionDecl::getDerivativeFunctionConfigurations` to implement `findMinimalDerivativeConfiguration` for canonical derivative function configuration lookup, replacing `getMinimalASTDifferentiableAttr`. Resolves TF-1100.
This commit is contained in:
@@ -36,6 +36,7 @@ class DependencyCollector;
|
||||
namespace swift {
|
||||
|
||||
class AbstractFunctionDecl;
|
||||
struct AutoDiffConfig;
|
||||
class ClangImporterOptions;
|
||||
class ClassDecl;
|
||||
class FileUnit;
|
||||
@@ -153,6 +154,23 @@ public:
|
||||
unsigned previousGeneration,
|
||||
llvm::TinyPtrVector<AbstractFunctionDecl *> &methods) = 0;
|
||||
|
||||
/// Load derivative function configurations for the given
|
||||
/// AbstractFunctionDecl.
|
||||
///
|
||||
/// \param originalAFD The declaration whose derivative function
|
||||
/// configurations should be loaded.
|
||||
///
|
||||
/// \param previousGeneration The previous generation number. The AST already
|
||||
/// contains derivative function configurations loaded from any generation up
|
||||
/// to and including this one.
|
||||
///
|
||||
/// \param results The result list of derivative function configurations.
|
||||
/// This list will be extended with any methods found in subsequent
|
||||
/// generations.
|
||||
virtual void loadDerivativeFunctionConfigurations(
|
||||
AbstractFunctionDecl *originalAFD, unsigned previousGeneration,
|
||||
llvm::SetVector<AutoDiffConfig> &results) {};
|
||||
|
||||
/// Verify all modules loaded by this loader.
|
||||
virtual void verifyAllModules() { }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user