Skip to content

[Diagnostics][NFCI] Introduce Structured fix-its #26612

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
Sep 6, 2019

Conversation

owenv
Copy link
Contributor

@owenv owenv commented Aug 12, 2019

These are defined with macros like errors/warnings/notes, and make use of format strings and diagnostic arguments. The intent is to leverage diagnostic arguments in the future to disambiguate ambiguously spelled types.

Ported a few miscellaneous fix-its to the new system.

Some of the rationale for this change is explained here. This change alone isn't enough to fix e.g. SR-8668, but it's a first step towards being able to handle that kind of situation better.

If this seems like a good direction to take, the next steps I had in mind are roughly:

  • Move the formatting of fix-it arguments into the DiagnosticConsumers (Didn't want to do that as part of this PR and end up with a huge diff, it'll likely require moving DiagnosticArgument out of the DiagnosticEngine header)
  • Port more fix-its over to using format strings (This really only makes sense for the more complicated fix-its)
  • Maybe allow attaching an optional DeclContext to a diagnostic which can be used to determine if types need qualification when formatted

cc @jrose-apple (this builds on some of the argument formatting changes to diags from a few weeks back)
cc @xedin (this may eventually affect many fix-its produced during type checking)

@xedin xedin self-requested a review August 12, 2019 17:05
@owenv owenv force-pushed the formatted_fixits branch from 13e6de8 to dd3d2cf Compare August 15, 2019 01:23
@owenv
Copy link
Contributor Author

owenv commented Aug 15, 2019

Rebased and moved some of the examples over to CSDiagnostics now that those diags have been ported over 🎉

@owenv
Copy link
Contributor Author

owenv commented Aug 20, 2019

Hi @xedin / @jrose-apple , just wanted to bump this. Totally understand if this change is undesirable, but I have had some success leveraging it to fix type shadowing issues in fix-its by optionally attaching a DeclContext which can be used to determine how a fix-it’s arguments should be formatted (that would be a follow-up PR).

@xedin xedin requested a review from jrose-apple August 20, 2019 20:53
Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

This seems reasonable to me, but I'd like @jrose-apple to take a look as well.

@owenv owenv force-pushed the formatted_fixits branch 2 times, most recently from 4ca0016 to e69e73c Compare September 4, 2019 16:21
@owenv
Copy link
Contributor Author

owenv commented Sep 4, 2019

Hi @jrose-apple , I'd like to pick this back up if possible. Do you mind taking a look when you have time?

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

I like the direction; a lot of fix-its probably do fit into this model. Only small comments.

@@ -24,6 +24,11 @@ enum class swift::DiagID : uint32_t {
static_assert(static_cast<uint32_t>(swift::DiagID::invalid_diagnostic) == 0,
"0 is not the invalid diagnostic ID");

enum class swift::FixItID : uint32_t {
#define FIXIT(ID, Text, Signature) ID,
#include "swift/AST/FixIts.def"
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 make sense to have fix-its in their own file? I would have thought it'd be simplest to have them next to the diagnostics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Defining fix-its alongside the other diags complicates the macro usage by a fair amount. I'm starting to think the advantages are outweigh the tradeoffs though, so updated the PR to do this. I only added the definitions to Parse and Sema diags for now, they can be rolled out to the other headers as needed.

@owenv owenv force-pushed the formatted_fixits branch 2 times, most recently from 624f236 to 1c30c54 Compare September 5, 2019 01:02
Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Down to the nitty-gritty.

@owenv owenv force-pushed the formatted_fixits branch 2 times, most recently from 5687a76 to 873e04d Compare September 5, 2019 16:00
@owenv
Copy link
Contributor Author

owenv commented Sep 5, 2019

Thanks for bearing with me as I fix up these remaining issues!

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Only one more comment, and it's tiny. Thanks, @owenv!

@jrose-apple jrose-apple self-assigned this Sep 5, 2019
These are defined with macros like errors/warnings/notes, and
make use of format strings and diagnostic arguments. The intent
is to leverage diagnostic arguments in the future to disambiguate
ambiguously spelled types.

Ported a few miscellaneous fix-its to the new system
@jrose-apple
Copy link
Contributor

Welcome to C++. :-)

@swift-ci Please smoke test

@jrose-apple jrose-apple merged commit 94f1d2c into swiftlang:master Sep 6, 2019
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