-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add ASTScope support for @differentiable
attribute.
#27451
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
Add ASTScope support for @differentiable
attribute.
#27451
Conversation
`@differentiable` attribute where clauses may refer to generic parameters from some generic context. Without special ASTScope support for `@differentiable` attributes, ASTScopeLookup.cpp logic tries to resolve the generic parameter DeclNames in the where clause based on source location alone (`ASTScopeImpl::findChildContaining`) and fails. The fix is to add a special `DifferentiableAttributeScope`, mimicking `SpecializeAttributeScope`. Every `@differentiable` attribute has its own scope, derived from the declaration on which it is declared. Unlike `@_specialize`, `@differentiable` may also be declared on `AbstractStorageDecl` declarations (subscripts and variables). Resolves TF-815.
`Decl::getSourceRangeIncludingAttrs` should not consider implicit `@differentiable` attributes generated during `@differentiating` attribute type-checking. TF-835 tracks robust lowering for `@differentiating` attributes that does not involve generating implicit `@differentiable` attributes, circumventing this issue.
cc @davidungar: your review would be appreciated!
@differentiable(where T: Differentiable)
func id<T>(_ x: T) -> T { x } I mostly copied logic from |
@swift-ci Please test tensorflow |
if ((false)) { | ||
// if (useASTScopesForLookup()) { | ||
// SWIFT_ENABLE_TENSORFLOW END | ||
if (useASTScopesForLookup()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this reverts an earlier workaround hack.
There's one remaining test failure, which is known and orthogonal.
EDIT: macOS has one additional failure:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the detailed comments! From what I can see, this looks reasonable.
`@differentiable` attributes may contain `where` clauses referencing generic parameters from some generic context, just like `@_specialize` attributes. Without special ASTScope support for `@differentiable` attributes, ASTScopeLookup.cpp logic tries to resolve the generic parameter `DeclName`s in `where` clauses based on source location alone (`ASTScopeImpl::findChildContaining`) and fails. The fix is to add a special `DifferentiableAttributeScope`, mimicking `SpecializeAttributeScope`. Every `@differentiable` attribute has its own scope, derived from the declaration on which it is declared. Unlike `@_specialize`, `@differentiable` may also be declared on `AbstractStorageDecl` declarations (subscripts and variables). Upstreams swiftlang#27451. Progress towards TF-828: upstream `@differentiable` attribute type-checking.
`@differentiable` attributes may contain `where` clauses referencing generic parameters from some generic context, just like `@_specialize` attributes. Without special ASTScope support for `@differentiable` attributes, ASTScopeLookup.cpp logic tries to resolve the generic parameter `DeclName`s in `where` clauses based on source location alone (`ASTScopeImpl::findChildContaining`) and fails. The fix is to add a special `DifferentiableAttributeScope`, mimicking `SpecializeAttributeScope`. Every `@differentiable` attribute has its own scope, derived from the declaration on which it is declared. Unlike `@_specialize`, `@differentiable` may also be declared on `AbstractStorageDecl` declarations (subscripts and variables). Upstreams #27451. Progress towards TF-828: upstream `@differentiable` attribute type-checking.
@differentiable
attribute where clauses may refer to genericparameters from some generic context.
Without special ASTScope support for
@differentiable
attributes,ASTScopeLookup.cpp
logic tries to resolve the generic parameterDeclNames in the where clause based on source location alone
(
ASTScopeImpl::findChildContaining
) and fails.The fix is to add a special
DifferentiableAttributeScope
, mimickingSpecializeAttributeScope
. Every@differentiable
attribute has itsown scope, derived from the declaration on which it is declared.
Unlike
@_specialize
,@differentiable
may also be declared onAbstractStorageDecl
declarations (subscripts and variables).Resolves TF-815.
Decl::getSourceRangeIncludingAttrs
should not consider implicit@differentiable
attributes generated during@differentiating
attribute type-checking.
TF-835 tracks robust lowering for
@differentiating
attributesthat does not involve generating implicit
@differentiable
attributes,circumventing this issue.
Unblocks
swift-DEVELOPMENT-SNAPSHOT-2019-09-24-a
merge intotensorflow
.