Skip to content

[AutoDiff] Check @noDerivative for function type comparison #67121

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
merged 2 commits into from
Jul 6, 2023

Conversation

asavonic
Copy link
Contributor

@asavonic asavonic commented Jul 5, 2023

As described in the issue #62922, the compiler should not allow to discard @noDerivative attribute and keep @differentiable. The patch adds a diagnostic for this case.

differentiation_diagnostics.swift LIT test already had this pattern, but I was unable to add an expected-error for it, because the compiler exits early and does not emit other diagnostics in this file.

Resolves #62922.

As described in the issue swiftlang#62922, the compiler should not allow to discard
@noDerivative attribute and keep @differentiable. The patch adds a diagnostic
for this case.

differentiation_diagnostics.swift LIT test already had this pattern, but I was
unable to add an expected-error for it, because the compiler exits early and
does not emit other diagnostics in this file.
@asavonic asavonic requested review from hborla and xedin as code owners July 5, 2023 13:35
@asl
Copy link
Contributor

asl commented Jul 5, 2023

@swift-ci please test

@asl asl requested review from rxwei and dan-zheng July 5, 2023 15:54
@@ -741,7 +741,7 @@ struct TF_675 : Differentiable {
let _: @differentiable(reverse) (Float) -> Float = TF_675().method

// TF-918: Test parameter subset thunk + partially-applied original function.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can no longer find TF-918... Is there a GitHub issue for it?

Copy link
Contributor

@asl asl Jul 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid all TF issues gone long time ago. And if they were not converted to normal Swift JIRA issues, then they cannot be found anywhere...

@shahmishal will you please confirm?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably go over all TF- bugs in comments and remove them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And rewrite to present issues when the issue was migrated (there are few of them IIRC). Some of the TF's refer to some design decisions made in the past. It would be good to document them somehow while there are some memories on them :) I'll check what are the most important / interesting ones

@@ -741,7 +741,7 @@ struct TF_675 : Differentiable {
let _: @differentiable(reverse) (Float) -> Float = TF_675().method

// TF-918: Test parameter subset thunk + partially-applied original function.
let _: @differentiable(reverse) (Float, Float) -> Float = (+) as @differentiable(reverse) (Float, @noDerivative Float) -> Float
let _: @differentiable(reverse) (Float, @noDerivative Float) -> Float = (+) as @differentiable(reverse) (Float, @noDerivative Float) -> Float
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this test was there! Maybe it was meant to test function conversions to a function with more @noDerivative. That should be possible with "subset parameter thunks".

let _: @differentiable(reverse) (Float, @noDerivative Float) -> Float = (+) as @differentiable(reverse) (Float, Float) -> Float

Is the above possible today?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the above example is also possible. I think it is the same as test1 in the new LIT test, but we can add it to differentiation_diagnostics.swift as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it actually work in a runtime test?

@asl
Copy link
Contributor

asl commented Jul 6, 2023

@swift-ci please test

@asl asl merged commit b6acb6f into swiftlang:main Jul 6, 2023
@@ -0,0 +1,25 @@
// RUN: %target-typecheck-verify-swift

import _Differentiation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the test is not in the test/AutoDiff folder, it needs REQUIRES: differentiable_programming or people that build without that feature will fail this test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asavonic Please submit a follow-up PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry for causing this issue. I've submitted a PR to fix it: #67190

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.

Don't allow stripping of @noDerivative if @differentiable is not stripped
4 participants