Skip to content
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

Improve the help message for an invalid calling convention #100488

Merged

Conversation

khyperia
Copy link
Contributor

@khyperia khyperia commented Aug 13, 2022

Fixes #93601

I mostly followed the suggestions of @nagisa in that issue, however, I wasn't sure how to check stability for the suggestion of "Do not suggest CCs that cannot be used due to them being unstable and feature not being enabled", so I did not implement that point.

I haven't contributed to rustc much, please feel free to point out suggestions! For example, the .map(|s| Symbol::intern(s)).collect::<Vec<_>>() seems pretty gross performance-wise, but maybe that's OK in error reporting code.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 13, 2022
@rust-highfive
Copy link
Collaborator

r? @michaelwoerister

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 13, 2022
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

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

I wasn't sure how to check stability

I'm not sure either, but I'd suggest compiling a crate with an unstable ABI and using -Ztreat-err-as-bug to see where the error is reported. Then you can use that same logic in the diagnostics code :)

the .map(|s| Symbol::intern(s)).collect::<Vec<_>>() seems pretty gross performance-wise, but maybe that's OK in error reporting code.

Yeah, that's fine, error reporting doesn't care about performance.

CallingConventions => {
let mut calling_conventions = rustc_target::spec::abi::all_names();
calling_conventions.sort_unstable();
println!("{}", calling_conventions.join("\n"));
Copy link
Member

Choose a reason for hiding this comment

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

Can you also add a UI test for this flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I'm not finding any tests for other --print options, e.g. --print=target-list has extremely similar code to this one. Could you point out where those are so I can add this test alongside them?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, not sure off the top of my head. Maybe it's in run-make? If I were at a laptop I'd find this with grep -r -- --print src/test, but I'm on mobile right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah thanks! Found this, but it's a bit odd as there seems to be no expected output. I'll add a similar Makefile for calling-conventions. https://github.com/rust-lang/rust/tree/master/src/test/run-make-fulldeps/print-target-list

@khyperia
Copy link
Contributor Author

I'm not sure either, but I'd suggest compiling a crate with an unstable ABI and using -Ztreat-err-as-bug to see where the error is reported. Then you can use that same logic in the diagnostics code :)

Hmm. The errors seem to be reported here

match symbol_unescaped.as_str() {

The crate rustc_ast_passes is not available in rustc_ast_lowering. Should I add a reference? Also, I'm not sure how to call that function without reporting an error - do I need to construct a dummy Session or something like that? How do I do that?

@jyn514
Copy link
Member

jyn514 commented Aug 13, 2022

The crate rustc_ast_passes is not available in rustc_ast_lowering. Should I add a reference? Also, I'm not sure how to call that function without reporting an error - do I need to construct a dummy Session or something like that?

I'd suggest taking that giant match and refactoring it a bit - add a public function in rustc_ast_lowering that only determines whether the ABI is unstable or not, then calling it from the feature gate code in rustc_ast_passes. Then you don't need a dummy session and you can make sure the diagnostic code uses the same logic as the feature gate code.

@khyperia khyperia force-pushed the invalid-calling-convention-help-message branch from 9edf69a to fb426cf Compare August 14, 2022 13:22
Copy link
Member

@jyn514 jyn514 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 great :) I'll let a compiler member review since I don't often touch target specs, but the code LGTM.

Unrecognized,
}

macro_rules! gate_feature_post {
Copy link
Member

Choose a reason for hiding this comment

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

nit: I would change this from a macro to a function, since it no longer affects control flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The one slight annoyance with that is that $feature is used in both $features.$feature (bool field for if it's enabled), as well as sym::$feature, so the caller would have to duplicate the name of the feature, passing in both. I guess that's okay, though, and probably worth it being a regular function over a macro?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm. I agree changing it is a pain. But I also kind of feel that if this is a macro, it's not helping enough for it to be worth it - it would be nice to find a way to simplify the giant match some more, e.g. only pass in a list of ABI names and feature gates and have it generate the match for you.

That said, it's a big change unrelated to your improvement, I'm fine with just merging as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah! @m-ou-se pointed out that Features::enabled(Symbol) exists, that makes it nicer.

@bors
Copy link
Contributor

bors commented Aug 27, 2022

☔ The latest upstream changes (presumably #101064) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

@nagisa nagisa 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 great!

src/test/ui/parser/issues/issue-8537.stderr Outdated Show resolved Hide resolved
-include ../tools.mk

all:
$(RUSTC) --print calling-conventions
Copy link
Member

Choose a reason for hiding this comment

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

Hm, wouldn’t this be better off as a UI test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure - I'm following the example set by other similar tests. If we want to change the group of them to test in a different way, that seems like a separate change IMO #100488 (comment)

@nagisa
Copy link
Member

nagisa commented Aug 28, 2022

I'll let a compiler member review since I don't often touch target specs, but the code LGTM.

r=me in that regard. This needs a rebase and this could probably benefit from fewer commits (e.g. squash in the commits that fix mistakes introduced by prior commits as well as those that add tests)

@khyperia
Copy link
Contributor Author

khyperia commented Aug 28, 2022

I'm not sure how to resolve the merge conflict from 0043d10, to be honest. I don't know how this new error reporting system works, or what this .ftl file is. Is there any documentation on how this extremely magical-seeming system works, so I can use it properly? (macros are one thing, this seems like a whole custom DSL, haha)

@JeanCASPAR do you think you could help out?

@jyn514
Copy link
Member

jyn514 commented Aug 28, 2022

cc @davidtwco , is there documentation somewhere for how to use the translation macros?

@davidtwco
Copy link
Member

cc @davidtwco , is there documentation somewhere for how to use the translation macros?

https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html primarily, #100717 links most of our resources

@jyn514 jyn514 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 30, 2022
@m-ou-se m-ou-se force-pushed the invalid-calling-convention-help-message branch from 45ea9a6 to c46abb6 Compare September 8, 2022 14:19
@rustbot rustbot added the A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic label Sep 8, 2022
@rustbot
Copy link
Collaborator

rustbot commented Sep 8, 2022

rustc_error_messages was changed

cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki

@khyperia
Copy link
Contributor Author

khyperia commented Sep 8, 2022

Sorry for taking so long for the update! @nagisa could I get another review? I (...we) changed some stuff in the rebase, it might be nice to check again. Thanks!

@jyn514
Copy link
Member

jyn514 commented Sep 8, 2022

@khyperia fyi you can use

@rustbot ready

to mark this as ready for review.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 8, 2022
@bors
Copy link
Contributor

bors commented Sep 21, 2022

☔ The latest upstream changes (presumably #101558) made this pull request unmergeable. Please resolve the merge conflicts.

@khyperia khyperia force-pushed the invalid-calling-convention-help-message branch from c46abb6 to 9a206a7 Compare September 22, 2022 20:42
@nagisa
Copy link
Member

nagisa commented Sep 22, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Sep 22, 2022

📌 Commit 9a206a7 has been approved by nagisa

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 22, 2022
@nagisa
Copy link
Member

nagisa commented Sep 22, 2022

@bors r-
@bors r=nagisa,jyn514

(/me wonders if bors can stomach this...)

@bors
Copy link
Contributor

bors commented Sep 22, 2022

📌 Commit 9a206a7 has been approved by nagisa,jyn514

It is now in the queue for this repository.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 22, 2022
@bors
Copy link
Contributor

bors commented Sep 23, 2022

⌛ Testing commit 9a206a7 with merge 77e7e88...

@bors
Copy link
Contributor

bors commented Sep 23, 2022

☀️ Test successful - checks-actions
Approved by: nagisa,jyn514
Pushing 77e7e88 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 23, 2022
@bors bors merged commit 77e7e88 into rust-lang:master Sep 23, 2022
@rustbot rustbot added this to the 1.66.0 milestone Sep 23, 2022
@khyperia khyperia deleted the invalid-calling-convention-help-message branch September 23, 2022 06:54
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (77e7e88): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
3.4% [3.4%, 3.4%] 1
Regressions ❌
(secondary)
4.1% [2.6%, 5.5%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.4% [3.4%, 3.4%] 1

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
2.1% [2.1%, 2.1%] 1
Regressions ❌
(secondary)
3.0% [3.0%, 3.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.1% [2.1%, 2.1%] 1

Footnotes

  1. the arithmetic mean of the percent change 2

  2. number of relevant changes 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The help message when an invalid calling convention is specified is getting a little unwieldy
10 participants