Skip to content

ClangImporter: simplify logic for mutability attribute #61500

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
Oct 10, 2022

Conversation

compnerd
Copy link
Member

@compnerd compnerd commented Oct 7, 2022

Take the spellings for the attributes as parameters for the diagnostics to allow us to reference the ignored the attribute properly. Use direct pointer checks instead of an unnecessary llvm::Optional around a nullable pointer. Use llvm::StringRef to simplify the comparison. This avoids re-spelling the attribute parameters which have already been checked by isMutabilityAttr for the contradiction.

@compnerd
Copy link
Member Author

compnerd commented Oct 7, 2022

@swift-ci please test Windows platform

Take the spellings for the attributes as parameters for the diagnostics
to allow us to reference the ignored the attribute properly.  Use direct
pointer checks instead of an unnecessary `llvm::Optional` around a
nullable pointer.  Use `llvm::StringRef` to simplify the comparison.
This avoids re-spelling the attribute parameters which have already been
checked by `isMutabilityAttr` for the contradiction.
Copy link
Member

@etcwilde etcwilde left a comment

Choose a reason for hiding this comment

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

This reads better to me.

@compnerd
Copy link
Member Author

compnerd commented Oct 7, 2022

@swift-ci please test Windows platform

Copy link
Member

@etcwilde etcwilde left a comment

Choose a reason for hiding this comment

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

Err wait, it looks like the previous code would always override non mutating with mutating, so if you had both, it would resolve to mutating. Though I'm admittedly having some trouble following the original logic paths.

@etcwilde etcwilde self-requested a review October 7, 2022 23:51
@etcwilde
Copy link
Member

etcwilde commented Oct 7, 2022

Okay, so seenMutabilityAttr is always the last mutability attr we saw, so this is probably right.

Copy link
Member

@etcwilde etcwilde left a comment

Choose a reason for hiding this comment

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

Okay, I'm more confident in this approval now. The original diagnostic appears to have been misleading since it only pointed at the non-mutating attribute, but didn't change anything else. The replacement patch doesn't affect the setting of seenMutabilityAttr vs swiftAttr compared the original code.

@compnerd
Copy link
Member Author

compnerd commented Oct 9, 2022

@swift-ci please smoke test

@compnerd
Copy link
Member Author

compnerd commented Oct 9, 2022

@swift-ci please test

@compnerd
Copy link
Member Author

compnerd commented Oct 9, 2022

CC: @zoecarver @egorzhdan

Copy link
Contributor

@egorzhdan egorzhdan left a comment

Choose a reason for hiding this comment

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

LGTM!

@compnerd
Copy link
Member Author

The Windows failure is due to Interop/Cxx/class/mutability-annotations-typechecker.swift which was addressed by #61512

@compnerd compnerd merged commit 6519524 into swiftlang:main Oct 10, 2022
@compnerd compnerd deleted the mutable branch October 10, 2022 16:55
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