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

Implement Display for rustc_target::callconv::Conv #135808

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tiif
Copy link
Contributor

@tiif tiif commented Jan 21, 2025

Follow up of #133103 (comment)

@rustbot
Copy link
Collaborator

rustbot commented Jan 21, 2025

r? @fmease

rustbot has assigned @fmease.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 21, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jan 21, 2025

Some changes occurred to the CTFE machinery

cc @rust-lang/wg-const-eval

The Miri subtree was changed

cc @rust-lang/miri

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

@tiif
Copy link
Contributor Author

tiif commented Jan 21, 2025

It's miri related, and Ralf looks busy, so r? @oli-obk

@rustbot rustbot assigned oli-obk and unassigned fmease Jan 21, 2025
@oli-obk
Copy link
Contributor

oli-obk commented Jan 21, 2025

@bors r+ rollup

has no test changes as for almost all cases the Debug impl has the same output as the Display impl, adding a new test just for risc doesn't really bring much value imo, so shipping as is

@bors
Copy link
Contributor

bors commented Jan 21, 2025

📌 Commit bbde683 has been approved by oli-obk

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 Jan 21, 2025
@@ -920,8 +920,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn check_abi<'a>(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, exp_abi: Conv) -> InterpResult<'a, ()> {
if fn_abi.conv != exp_abi {
throw_ub_format!(
"calling a function with ABI {:?} using caller ABI {:?}",
exp_abi,
"calling a function with ABI {exp_abi} using caller ABI {}",
Copy link
Member

@workingjubilee workingjubilee Jan 21, 2025

Choose a reason for hiding this comment

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

@oli-obk This error is user-facing, correct?

If so, the proposed formatting is not desirable, it should be using ExternAbi's formatting instead.

Copy link
Member

Choose a reason for hiding this comment

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

This isn't about ExternAbi though, it is about the underlying calling convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hope it'd help by providing more context. Initially we indeed used ExternAbi here for check_abi, but after #133103 we passed FnAbi instead of ExternAbi, so we can check the number of fixed args like what is done in rust-lang/miri#4122.

Copy link
Member

Choose a reason for hiding this comment

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

Also, this is how we allow e.g. calling a C function through a C-unwind fn pointer.

Copy link
Member

@workingjubilee workingjubilee Jan 21, 2025

Choose a reason for hiding this comment

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

This isn't about ExternAbi though, it is about the underlying calling convention.

The underlying calling convention is still mappable to one of the ExternAbi strings, and we can still express conflicts in terms of that. Dropping data randomly, like erasing "rust-cold" to "Cold", or "x86-interrupt" to "X86Intr", will mostly be confusing.

Copy link
Member

@RalfJung RalfJung Jan 22, 2025

Choose a reason for hiding this comment

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

The concrete error this comment is attached to does not have a ui test; the other one changed in this PR is tested at

//~^ ERROR: calling a function with calling convention C using calling convention Rust

and

https://github.com/rust-lang/rust/blob/e8ff9b1836fc8e69ab4fe78c35a6799277c8e700/src/tools/miri/tests/fail/function_calls/exported_symbol_abi_mismatch.rs

Copy link
Member

Choose a reason for hiding this comment

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

huh, those two say "calling convention" but this error says "ABI"? is that what you mean by "the concrete error"... does not have a UI test?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah this one here is triggered when you call a built-in shim the wrong way (rather than some normal Rust function), which we don't have a test for. We should add one.

And indeed it should say "calling convention".

Copy link
Contributor Author

@tiif tiif Jan 22, 2025

Choose a reason for hiding this comment

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

So we should change the error message in check_abito use "calling convention" and add a test that will invoke the check_abi here.

Other than that, should we continue with impl Display for Conv or map the calling convention to ExternAbi?

Copy link
Member

Choose a reason for hiding this comment

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

Please implement Display by mapping Conv back to the matching ExternAbi variant (without unwind). This will sometimes give a surprising result, but it will still be comprehensible. If this is properly tested, then I can elaborate on the error message in a followup that gives the rest of the information necessary to fix the problem.

Of course, if even this is considered impossible by my peers, then I can relent for now and simply make possible the impossible later.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 21, 2025

@bors r-

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

7 participants