-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Allow rustdoc to handle asm! of foreign architectures #82838
Conversation
r? @davidtwco (rust-highfive has picked a reviewer for you, use r? to override) |
Why does this make it to rustdoc at all? Special casing it with Lines 396 to 405 in 51748a8
|
if self.sess.asm_arch.is_none() && !self.sess.opts.actually_rustdoc { | ||
struct_span_err!(self.sess, sp, E0472, "asm! is unsupported on this target").emit(); | ||
} | ||
if asm.options.contains(InlineAsmOptions::ATT_SYNTAX) | ||
&& !matches!( | ||
self.sess.asm_arch, | ||
Some(asm::InlineAsmArch::X86 | asm::InlineAsmArch::X86_64) | ||
) | ||
&& !self.sess.opts.actually_rustdoc | ||
{ | ||
self.sess | ||
.struct_span_err(sp, "the `att_syntax` option is only supported on x86") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this check done so early? I would expect it to be in codegen somewhere, or at least in MIR lowering.
Also, I'm not sure how this change helps with the stdarch failure:
|
I've fixed the other issues in the stdarch PR. The latest CI results show the problem. The main issue is the representation of register and register class constraints:
Even though rustdoc doesn't run the HIR passes it still performs AST lowering so we need to lower registers and register classes to a dummy type so we can still produce a valid HIR. |
bd60df1
to
4131e86
Compare
I've simplified the code: it turns out that rustdoc is happy enough if I just lower the entire |
32cda4a
to
d5d6408
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems unfortunate to keep special-casing rustdoc everywhere, but I don't know how hard it would be move this later in the compiler. This seems no worse than the other hacks for rustdoc.
LGTM from the compiler impl standpoint. @bors r+ I, too, agree that having to special-case rustdoc here is unfortunate, IMHO the best way to fix this would be to make it possible for rustdoc itself to entirely skip any handling of function bodies in any part of the compiler it ends up invoking. A most straightforward way would probably be walking the AST and replacing all the bodies with |
@bors r+ |
📌 Commit 4d2413296e5d849f75001128b2a9df026df6acdb has been approved by |
This broke quite a lot of rustdoc, it was changed about a year ago: #73566. The way to do this properly is to move the error checking to after AST desugaring, when typechecking is being done, then rustdoc should ignore it automatically. |
Now that you mention it, could this change cause issues since we aren't lowering the |
I think so, yes. Try this test case: #![feature(decl_macro)]
#![feature(asm)]
pub unsafe fn aarch64(a: f64, b: f64) {
let c;
asm!("add {:d}, {:d}, d0", out(vreg) c, in(vreg) a, in("d0") {
|| {
macro m() {}
};
b
});
c
} |
lol that causes rustc itself to fail, even without these changes: thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_middle/src/hir/map/mod.rs:300:29
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
Here's an example that compiles when you add #![feature(decl_macro)]
#![feature(asm)]
pub unsafe fn aarch64(a: f64, b: f64) -> f64 {
let c;
asm!("add {:d}, {:d}, d0", out(vreg) c, in(vreg) a, in("d0") {
|| {
macro m() {}
};
b
});
c
} |
kind of thing? Yeah, not lowering this would most likely be prone to causing all the same issues as what @bors r- |
I think the root cause is probably linked to #82869, so let's figure that out first. |
I can see 2 ways of solving this properly:
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should also fix #82869.
Can you please add a regression test for this as well? Overall LGTM! r=me.
compiler/rustc_target/src/asm/mod.rs
Outdated
@@ -309,6 +313,7 @@ impl InlineAsmReg { | |||
Self::RiscV(r) => r.emit(out, arch, modifier), | |||
Self::Hexagon(r) => r.emit(out, arch, modifier), | |||
Self::Mips(r) => r.emit(out, arch, modifier), | |||
Self::Err => unreachable!(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many of these unreachable!
s here and in {modifier,reg}_to_llvm
feel like they should be a bug!
instead. These aren't very obviously unreachable and in the future it might be the case that somebody does change some code in a way that would cause this to become reached too (thus introducing a bug).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bug!
is defined in rustc_middle
which rustc_target
can't depend on since that would result in a circular dependency. I've added a message to the unreachable
though.
8f76dda
to
ba00ddc
Compare
@bors r=nagisa |
📌 Commit ba00ddc has been approved by |
Allow rustdoc to handle asm! of foreign architectures This allows rustdoc to process code containing `asm!` for architectures other than the current one. Since this never reaches codegen, we just replace target-specific registers and register classes with a dummy one. Fixes rust-lang#82869
☀️ Test successful - checks-actions |
This allows rustdoc to process code containing
asm!
for architectures other than the current one. Since this never reaches codegen, we just replace target-specific registers and register classes with a dummy one.Fixes #82869