Skip to content

[AutoDiff upstream] Add @differentiable ASTScope support. #29171

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

Merged

Conversation

dan-zheng
Copy link
Contributor

@differentiable attributes may contain where clauses referencing
generic parameters from an outer scope, just like @_specialize attributes.

@differentiable attribute where clauses may refer to generic parameters from
some generic context, just like @_specialize attribute.

Without special ASTScope support for @differentiable attributes,
ASTScopeLookup.cpp logic tries to resolve the generic parameter DeclNames 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 type-checking mega-patch: #29091


Tests exist on tensorflow branch and will be upstreamed later.
Currently, not enough code has been upstreamed for meaningful testing.

`@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.
@dan-zheng dan-zheng requested review from davidungar and rxwei January 13, 2020 21:56
@dan-zheng
Copy link
Contributor Author

Let's see if tests pass. They should!
@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 0ab9598

@dan-zheng
Copy link
Contributor Author

@swift-ci Please smoke test macOS platform

@dan-zheng
Copy link
Contributor Author

Merging now to unblock progress, happy to address feedback later!

@davidungar previously reviewed #29171 (this patch) in an email discussion on #25263 and said it looked fine.

@dan-zheng dan-zheng merged commit 6c29939 into swiftlang:master Jan 14, 2020
@dan-zheng dan-zheng deleted the autodiff-upstream-diff-attr-scope branch January 14, 2020 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants