Skip to content

[AutoDiff upstream] @derivative attribute type-checking fixes. #28853

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 1 commit into from
Dec 18, 2019

Conversation

dan-zheng
Copy link
Contributor

Upstream @derivative attribute type-checking fixes regarding derivative
generic signatures with all concrete generic parameters.

Cherry-picked from:

@dan-zheng dan-zheng requested review from rxwei and marcrasi December 18, 2019 19:33
@marcrasi
Copy link

Could you also include the tests from #28785, which I just remembered to merge?

// before extracting the differential/pullback type from it, so that the
// derivative interface type generic signature is available for simplifying
// types.
CanType canActualResultType = derivativeInterfaceType->getCanonicalType();
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 wonder if it's possible to canonicalize derivativeInterfaceType earlier, like:

-  auto *derivativeInterfaceType = derivative->getInterfaceType()
-      ->castTo<AnyFunctionType>();
+  auto derivativeInterfaceType = dyn_cast<AnyFunctionType>(
+      derivative->getInterfaceType()->getCanonicalType());

I tried this on tensorflow branch but it didn't work out of the box:

/Users/danielzheng/swift-tf/swift/test/AutoDiff/derivative_attr_type_checking.swift:58:25: error: incorrect message found
Assertion failed: ((size_t)sys::locale::columnWidth(I->getText()) == I->getText().size()), function buildFixItLine, file /Users/danielzheng/swift-tf/llvm-project/llvm/lib/Support/SourceMgr.cpp, line 316.

I believe this error occurs when diagnostic messages contain archetypes (τ_0_0). Filed TF-1073 to track this improvement.

}))
return false;

// If required result type is not a function type, check that result types
// match exactly.
auto requiredResultFnTy = dyn_cast<AnyFunctionType>(required.getResult());
auto candidateResultTy = mapType(candidateFnTy.getResult());
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 wonder if it's possible to remap candidateFnTy once, instead of remapping its individual components.
Filed TF-1073 to track this improvement.

Upstream `@derivative` attribute type-checking fixes regarding derivative
generic signatures with all concrete generic parameters.

Cherry-picked from:
- swiftlang#28762
- swiftlang#28772
@dan-zheng dan-zheng force-pushed the derivative-attr-type-checking branch from 7fd79ed to 1d66571 Compare December 18, 2019 19:45
@dan-zheng
Copy link
Contributor Author

Could you also include the tests from #28785, which I just remembered to merge?

Thanks for the reminder! I included both of the derivative_attr_type_checking.swift tests newly added in #28785.

@dan-zheng
Copy link
Contributor Author

@swift-ci Please test and merge

@swift-ci swift-ci merged commit ddcb1d5 into swiftlang:master Dec 18, 2019
@dan-zheng dan-zheng deleted the derivative-attr-type-checking branch December 19, 2019 00:00
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.

4 participants