-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Be able to parse linear
argument in @differentiable
attribute
#25228
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
Conversation
- Adds a 'linear` argument to '@differentiable' attribute - 'linear' argument is optional, but when added, needs to be the first argument in the attribute
273ffc7
to
c9ecd50
Compare
f8bfa16
to
fb20a04
Compare
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.
Could you please also create and add tests to test/AutoDiff/differentiating_attr_parse.swift
?
You can:
- Copy
differentiating_attr_type_checking.swift
- Change the RUN line to
%target-swift-frontend -parse -verify %s
- Preserve just a few
@differentiating
examples - no need to keep "original" functions since Sema isn't tested. - Add
@differentiating(linear, ...)
tests.
Thank you!
lib/Parse/ParseDecl.cpp
Outdated
// Parse 'linear' label (optional). | ||
if (Tok.is(tok::identifier) && Tok.getText() == "linear") { | ||
linear = true; | ||
consumeIdentifier(); |
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.
consumeIdentifier(); | |
consumeIdentifier(tok::identifier); |
This makes an assertion about the identifier being consumed, preventing errors in future changes just in case.
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.
consumeIdentifier()
does the following assertion inside to check if it's identifier
, but also does a couple more:
assert(Tok.isAny(tok::identifier, tok::kw_self, tok::kw_Self));
However, I think calling consumeToken(tok::identifier)
could be a better option as it internally does the following assertion to specifically only check if it's an identifier
:
SourceLoc consumeToken(tok K) {
assert(Tok.is(K) && "Consuming wrong token kind");
return consumeToken();
}
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.
Yes, it should be consumeToken()
. I didn't notice that and thought you wrote consumeToken
already :)
@dan-zheng I'll do it in my next PR for the |
For |
Sounds good! |
@swift-ci please test tensorflow |
1 similar comment
@swift-ci please test tensorflow |
Hmm seems like CI got some weird issue:
Will try again |
@swift-ci please test tensorflow |
This PR adds the ability to parse and handle a
linear
argument in the@differentiable
attribute inparseDifferentiableAttributeArguments
This PR does not handle modifying the C++ attribute class such that it handles whether the
linear
attribute is being used.