-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff upstream] Add @differentiable
declaration attribute type-checking.
#29231
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -375,7 +375,9 @@ struct WhereClauseOwner { | |
|
||
/// The source of the where clause, which can be a generic parameter list | ||
/// or a declaration that can have a where clause. | ||
llvm::PointerUnion<GenericParamList *, TrailingWhereClause *, SpecializeAttr *> source; | ||
llvm::PointerUnion<GenericParamList *, TrailingWhereClause *, | ||
SpecializeAttr *, DifferentiableAttr *> | ||
source; | ||
|
||
WhereClauseOwner(GenericContext *genCtx); | ||
WhereClauseOwner(AssociatedTypeDecl *atd); | ||
|
@@ -386,6 +388,9 @@ struct WhereClauseOwner { | |
WhereClauseOwner(DeclContext *dc, SpecializeAttr *attr) | ||
: dc(dc), source(attr) {} | ||
|
||
WhereClauseOwner(DeclContext *dc, DifferentiableAttr *attr) | ||
: dc(dc), source(attr) {} | ||
|
||
SourceLoc getLoc() const; | ||
|
||
friend hash_code hash_value(const WhereClauseOwner &owner) { | ||
|
@@ -2020,6 +2025,35 @@ class PatternTypeRequest | |
} | ||
}; | ||
|
||
/// Type-checks a `@differentiable` attribute and returns the resolved parameter | ||
/// indices on success. On failure, emits diagnostics and returns `nullptr`. | ||
/// | ||
/// Currently, this request resolves other `@differentiable` attribute | ||
/// components but mutates them in place: | ||
/// - `JVPFunction` | ||
/// - `VJPFunction` | ||
/// - `DerivativeGenericSignature` | ||
class DifferentiableAttributeTypeCheckRequest | ||
: public SimpleRequest<DifferentiableAttributeTypeCheckRequest, | ||
IndexSubset *(DifferentiableAttr *), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, This works fine for now. I thought of two ways to refactor the request to avoid mutation:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. History: #28017 moved The current request approach (return |
||
CacheKind::SeparatelyCached> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using I tried changing I'm not sure why |
||
public: | ||
using SimpleRequest::SimpleRequest; | ||
|
||
private: | ||
friend SimpleRequest; | ||
|
||
// Evaluation. | ||
llvm::Expected<IndexSubset *> evaluate(Evaluator &evaluator, | ||
DifferentiableAttr *attr) const; | ||
|
||
public: | ||
// Separate caching. | ||
bool isCached() const { return true; } | ||
Optional<IndexSubset *> getCachedResult() const; | ||
void cacheResult(IndexSubset *value) const; | ||
}; | ||
|
||
// Allow AnyValue to compare two Type values, even though Type doesn't | ||
// support ==. | ||
template<> | ||
|
Uh oh!
There was an error while loading. Please reload this page.