Skip to content

Refine access note descriptions in diagnostics #36865

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 11 commits into from
May 22, 2021

Conversation

beccadax
Copy link
Contributor

@beccadax beccadax commented Apr 12, 2021

This PR will finalize the way diagnostics describe when they're caused by access notes.

Specifically, the pre-existing access note remarks are now only emitted for valid attributes; for invalid attributes, the diagnostic is augmented with text explaining that it was added for an access note and has been disabled:

class MyClass: NSObject {
    // Both of these methods have ObjC: true in access notes

    func good(_: Int) {}
    // remark: implicitly added '@objc' to this method, as specified by access note for <reason string>
    // note: add '@objc' explicitly to silence this warning

    func bad(_: Int?) {}
    // remark: ignored access note: the type of the parameter cannot be represented in Objective-C;
    //         did not implicitly add '@objc' to this method, even though it was specified by access
    //         note for <reason string>
}

To accomplish this behavior, this PR makes it possible for a diagnostic to take a DiagnosticInfo * as a parameter; it then adds an InFlightDiagnostic::wrapIn() method which uses this capability. Thus, an error like diag::objc_invalid_on_func_single_param_type can be wrapped in diag::wrap_invalid_attr_added_by_access_note to add verbiage relating to access notes.

This PR also:

  • Emits one access note success remark covering all attributes added to each declaration, instead of separate ones for each attribute.
  • Softens selector conflicts caused by access notes into remarks.
  • Adds a command-line option which controls whether and how access note remarks are emitted; in particular, you can use it to strengthen ignored access notes back to errors.

I will probably be tweaking this further before I'm finished with this PR.

Fixes rdar://71872575.

@beccadax beccadax force-pushed the remarkable-notes branch 2 times, most recently from cd2c859 to 60b2836 Compare May 21, 2021 01:27
@beccadax
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 60b2836707d87fa17c1dbca3c49ec1bc6809bacc

@beccadax beccadax changed the title [WIP] Refine access note descriptions in diagnostics Refine access note descriptions in diagnostics May 21, 2021
@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 60b2836707d87fa17c1dbca3c49ec1bc6809bacc

@beccadax beccadax force-pushed the remarkable-notes branch from 60b2836 to ccf86c4 Compare May 21, 2021 06:46
@beccadax
Copy link
Contributor Author

@swift-ci please test

@beccadax beccadax requested a review from xymus May 21, 2021 06:49
@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - ccf86c46b34d9c25d8d02d93f40200c157989a76

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - ccf86c46b34d9c25d8d02d93f40200c157989a76

/// diagnostic currently in \c *this.
/// \li The location, ranges, decl, fix-its, and behavior limit of the
/// diagnostic currently in \c *this.
InFlightDiagnostic &wrapIn(const Diagnostic &wrapper);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you tell me more about the advantage of wrapping this diagnostic in the Xcode display? Should we apply the same trick to more kind of diagnostics or is this specific to access notes?

Copy link
Contributor Author

@beccadax beccadax May 21, 2021

Choose a reason for hiding this comment

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

Basically, Xcode's inline error UI doesn't display notes unless they have fix-its. Wrapping a diagnostic produces a longer message, but it's a single message that will actually be made visible to users in the UI they most often use to read diagnostics.

I've been thinking that it might be good to turn diag::module_interface_build_failed and friends into wrapping diagnostics around the underlying errors, since the underlying errors often seem to go unnoticed by users, but are usually a better way to resolve the problem. But that's a different pull request.

Copy link
Contributor

@xymus xymus left a comment

Choose a reason for hiding this comment

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

This looks good! I'll be curious to see a demo of it with all of the new diagnostics refinements.

beccadax added 5 commits May 21, 2021 16:10
Merge together several helpers and code patterns for “diagnose/fix-it/invalidate bad attribute” into helper functions in TypeChecker.h.

This requires minor test changes in some places where we’re testing ObjC interop without importing Foundation; it’s otherwise NFC.
This requires deferring emission until the end of typechecking. A future change will emit access-note-related notes when an attribute is invalidated.
This shows up better in Xcode, which unfortunately doesn’t really display notes very clearly.
@beccadax beccadax force-pushed the remarkable-notes branch from ccf86c4 to 5cd34ee Compare May 21, 2021 23:10
@beccadax
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 5cd34ee37e0250d3fad297ed7a92e5652009bffe

beccadax added 6 commits May 22, 2021 13:01
This will allow teams writing access notes to use -Raccess-note=all-validate to check that their access notes are correct, or teams working around problems to use -Raccess-note=failures or -Raccess-note=none to suppress diagnostics.
• There is now one access note success remark and fix-it per declaration, not per attribute/modifier.
• Failure remarks have been rephrased to better emphasize the cause of the failure.
• The wording of other access note remarks and notes have been changed to follow a similar formula.
When two members have the same ObjC selector, there’s a test used to make sure that we’re “giving” the selector to the more “authoritative” of the two. However, its logic is not symmetrical, which I suspect could cause misbehavior in some edge cases. This change formalizes the logic in a way that eliminates the asymmetry.
@beccadax
Copy link
Contributor Author

@swift-ci smoke test and merge

@beccadax beccadax force-pushed the remarkable-notes branch from 5cd34ee to d4cae43 Compare May 22, 2021 20:04
@beccadax
Copy link
Contributor Author

@swift-ci smoke test and merge

@swift-ci swift-ci merged commit 2f5cb80 into swiftlang:main May 22, 2021
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