Skip to content

[AutoDiff] factor derivative typechecking helper out of AttributeChecker #28879

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 20, 2019

Conversation

marcrasi
Copy link

@marcrasi marcrasi commented Dec 19, 2019

In order to allow a @derivative in one file to define the derivative of a function in another file, we nned to calculate the derivative configurations of all the @derivative attributes in the module, not just those in the primary file (see #28790 for a work in progress of this).

AttributeChecker::visitDerivativeAttr is the function that does the necessary calculation, so this PR factors it into a separate function that others can call to do the calculation. This PR makes a few changes to the logic:

  • ASTContext::DerivativeAttrs now stores a set of all attributes per configuration, because otherwise you get buggy order-dependent behavior in the duplicate attr check when you call typeCheckDerivativeAttr multiple times per attribute.
  • typeCheckDerivativeAttr returns a boolean indicating error instead of calling attr->setInvalid() so that non-AttributeChecker callers can leave attr->setInvalid() to the AttributeChecker.

Note: This PR makes the AttributeChecker no longer use diagnoseAndRemoveAttr(), so you don't get a "fixItRemove" on the diagnostics any more. Keeping it would make the refactoring a bit more complicated, and I don't think it's that valuable to keep, because in many of the error cases removing the attribute isn't really the right way to fix things.

@marcrasi marcrasi requested a review from dan-zheng December 19, 2019 20:07
@marcrasi marcrasi force-pushed the less-mutating-typechecking branch from b5e4b60 to 7592fbd Compare December 19, 2019 20:10
@marcrasi marcrasi force-pushed the less-mutating-typechecking branch from 7592fbd to 962c3d8 Compare December 19, 2019 20:20
@marcrasi
Copy link
Author

@swift-ci please test and merge

1 similar comment
@marcrasi
Copy link
Author

@swift-ci please test and merge

@marcrasi marcrasi force-pushed the less-mutating-typechecking branch from 962c3d8 to 637314a Compare December 20, 2019 01:28
@marcrasi
Copy link
Author

@swift-ci please test and merge

1 similar comment
@marcrasi
Copy link
Author

@swift-ci please test and merge

@swift-ci swift-ci merged commit e47543c into swiftlang:master Dec 20, 2019
dan-zheng added a commit to dan-zheng/swift that referenced this pull request Dec 20, 2019
Fix build error introduced in swiftlang#28892.

Caused by not re-running CI after swiftlang#28879
was merged.
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