26
26
#ifndef SWIFT_SIL_SILDIFFERENTIABILITYWITNESS_H
27
27
#define SWIFT_SIL_SILDIFFERENTIABILITYWITNESS_H
28
28
29
+ #include " swift/AST/Attr.h"
29
30
#include " swift/AST/AutoDiff.h"
30
31
#include " swift/AST/GenericSignature.h"
31
32
#include " swift/SIL/SILAllocated.h"
@@ -60,6 +61,11 @@ class SILDifferentiabilityWitness
60
61
// / Whether or not this differentiability witness is serialized, which allows
61
62
// / devirtualization from another module.
62
63
bool serialized;
64
+ // / The AST `@differentiable` or `@differentiating` attribute from which the
65
+ // / differentiability witness is generated. Used for diagnostics.
66
+ // / Null if the differentiability witness is parsed from SIL or if it is
67
+ // / deserialized.
68
+ DeclAttribute *attribute = nullptr ;
63
69
64
70
static AutoDiffConfig *
65
71
getAutoDiffConfig (SILModule &module , IndexSubset *parameterIndices,
@@ -72,18 +78,18 @@ class SILDifferentiabilityWitness
72
78
IndexSubset *resultIndices,
73
79
GenericSignature *derivativeGenSig,
74
80
SILFunction *jvp, SILFunction *vjp,
75
- bool isSerialized)
81
+ bool isSerialized, DeclAttribute *attribute )
76
82
: module (module ), linkage(linkage), originalFunction(originalFunction),
77
83
parameterIndices (parameterIndices), resultIndices(resultIndices),
78
84
derivativeGenericSignature(derivativeGenSig), jvp(jvp), vjp(vjp),
79
- serialized(isSerialized) {}
85
+ serialized(isSerialized), attribute(attribute) {}
80
86
81
87
public:
82
88
static SILDifferentiabilityWitness *create (
83
89
SILModule &module , SILLinkage linkage, SILFunction *originalFunction,
84
90
IndexSubset *parameterIndices, IndexSubset *resultIndices,
85
91
GenericSignature *derivativeGenSig, SILFunction *jvp, SILFunction *vjp,
86
- bool isSerialized);
92
+ bool isSerialized, DeclAttribute *attribute = nullptr );
87
93
88
94
SILDifferentiabilityWitnessKey getKey () const ;
89
95
SILModule &getModule () const { return module ; }
@@ -114,6 +120,7 @@ class SILDifferentiabilityWitness
114
120
}
115
121
}
116
122
bool isSerialized () const { return serialized; }
123
+ DeclAttribute *getAttribute () const { return attribute; }
117
124
118
125
// / Verify that the differentiability witness is well-formed.
119
126
void verify (const SILModule &M) const ;
0 commit comments