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

add FCW to warn about wasm ABI transition #138601

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Mar 17, 2025

See #122532 for context: the "C" ABI on wasm32-unk-unk will change. The goal of this lint is to warn about any function definition and calls whose behavior will be affected by the change. My understanding is the following:

  • scalar arguments are fine
    • including 128 bit types, they get passed as two i64 arguments in both ABIs
  • repr(C) structs (recursively) wrapping a single scalar argument are fine (unless they have extra padding due to over-alignment attributes)
  • all return values are fine

@bjorn3 @alexcrichton @Manishearth is that correct?

I am making this a "show up in future compat reports" lint to maximize the chances people become aware of this. OTOH this likely means warnings for most users of Diplomat so maybe we shouldn't do this?

IIUC, wasm-bindgen should be unaffected by this lint as they only pass scalar types as arguments.

Tracking issue: #138762
Transition plan blog post: rust-lang/blog.rust-lang.org#1531

@rustbot
Copy link
Collaborator

rustbot commented Mar 17, 2025

r? @wesleywiser

rustbot has assigned @wesleywiser.
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 Mar 17, 2025
LL | pub extern "C" fn my_fun(_x: MyType) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
Copy link
Member Author

Choose a reason for hiding this comment

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

It's not technically correct that this will become a hard error (we'll just do the ABI switch), but I don't know how to make an FCW that does not have this message...

@rust-log-analyzer

This comment has been minimized.

@bjorn3
Copy link
Member

bjorn3 commented Mar 17, 2025

I am a bit concerned about 128bit scalar types as wasm doesn't have those. Do we have to warn about those as well?

That doesn't seem to be necessary. Both the old abi and new abi pass it as two i64 arguments.

@hanna-kruppe
Copy link
Contributor

Re: i128, we just had an ABI break (independent of -Zwasm-c-abi) in 1.85 but it only changed alignment not the by-value ABI I believe #134165

@RalfJung RalfJung force-pushed the wasm-abi-fcw branch 2 times, most recently from aed14e4 to fe72062 Compare March 17, 2025 12:32
@rust-log-analyzer

This comment has been minimized.

@alexcrichton
Copy link
Member

... @alexcrichton ... is that correct?

Honestly I'm not actually sure. The ABI bits have always been a black box to me and I don't feel confident that I would be able to enumerate the list of differences between -Zwasm-c-abi={spec,legacy}. I think the problem is that the before state is "whatever rustc/llvm together do, pending private details".

That being said what you listed matches my rough understanding. I mostly want to clarify in that I do not have certainty on the exhaustiveness of my understanding.

Would it be possible to "run both ABIs and look for a difference"? That'd help make me more confident in the exhaustiveness of the check, but I'm not sure if that's possible given the structure of the code.

What I can perhaps clarify is that the "official definition" is this for params/results. I'm not knowledgable enough of rustc ABI internals to diff that with what the previous behavior was myself though.

"detects code relying on rustc's non-spec-compliant wasm C ABI",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
reference: "issue #122532 <https://github.com/rust-lang/rust/issues/122532>",
Copy link
Member

Choose a reason for hiding this comment

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

Before landing this I think it might be best to open a fresh issue here. This one's got ~100 comments and is quite old. I'm happy to open a fresh issue to fill in here once we're more settled on a final transition plan.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think it's 100 comments, and it is from May last year. But sure happy to update this to another issue number if you tell me the number :)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think we should have a separate issue that helps talk about mitigation strategies.

@RalfJung
Copy link
Member Author

RalfJung commented Mar 17, 2025

Would it be possible to "run both ABIs and look for a difference"? That'd help make me more confident in the exhaustiveness of the check, but I'm not sure if that's possible given the structure of the code.

No, it's not possible unfortunately. The entire issue is that the legacy ABI relies on LLVM details rustc has no knowledge about, and on rustc_codegen_llvm details the rest of rustc has no knowledge about.

@alexcrichton
Copy link
Member

Ok thanks for clarifying, in that case I think we can mitigate that by (a) adding appropriate wording to the blog post about this change and perhaps (b) calling out in the release notes for the next release of Rust "hey things are changing in wasm go read this blog post for more info". Basically just doing our best to raise awareness and get folks testing out -Zwasm-c-abi=spec. If things come up we can continue to refine the lint.

@jieyouxu jieyouxu added the O-wasm Target: WASM (WebAssembly), http://webassembly.org/ label Mar 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 17, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

These commits modify compiler targets.
(See the Target Tier Policy.)

@alexcrichton
Copy link
Member

I've filed #138762 as a landing page for this lint

@RalfJung
Copy link
Member Author

Thanks, I have updated the PR to link to that issue. The PR should be good to go then?

Nowhere in the blog post or the tracking issue do we mention that -Zwasm-c-abi=legacy suppresses the lint. That seemed to be a key part of Diplomat's transition plan, or is that not the case any more? This PR becomes simpler if we don't have that flag suppress the lint.

@alexcrichton
Copy link
Member

Oh that's just an oversight on my part. @Manishearth I know you said it would be nice for -Zwasm-c-abi=legacy to suppress the lint, but can you confirm that it's desirable enough for the extra complexity in this PR?

@Manishearth
Copy link
Member

Having spec turn off the lint is desirable, having legacy turn off the lint is ... only somewhat a benefit, so it's fine if you don't.

Ultimately it's just a warning

@RalfJung
Copy link
Member Author

Ultimately I already wrote the code so it doesn't need to be a huge benefit. ;) But it if provides a benefit, it should probably occur somewhere in our recommended transition plan.

@alexcrichton
Copy link
Member

Ok I've updated both #138762 and rust-lang/blog.rust-lang.org#1531 to mention the lint-silencing nature of -Zwasm-c-abi=legacy, and in that case...

@bors: r+

@bors
Copy link
Contributor

bors commented Mar 21, 2025

📌 Commit 3301e0e has been approved by alexcrichton

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 Mar 21, 2025
tgross35 added a commit to tgross35/rust that referenced this pull request Mar 22, 2025
add FCW to warn about wasm ABI transition

See rust-lang#122532 for context: the "C" ABI on wasm32-unk-unk will change. The goal of this lint is to warn about any function definition and calls whose behavior will be affected by the change. My understanding is the following:
- scalar arguments are fine
  - including 128 bit types, they get passed as two `i64` arguments in both ABIs
- `repr(C)` structs (recursively) wrapping a single scalar argument are fine (unless they have extra padding due to over-alignment attributes)
- all return values are fine

`@bjorn3` `@alexcrichton` `@Manishearth` is that correct?

I am making this a "show up in future compat reports" lint to maximize the chances people become aware of this. OTOH this likely means warnings for most users of Diplomat so maybe we shouldn't do this?

IIUC, wasm-bindgen should be unaffected by this lint as they only pass scalar types as arguments.

Tracking issue: rust-lang#138762
Transition plan blog post: rust-lang/blog.rust-lang.org#1531
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 22, 2025
Rollup of 10 pull requests

Successful merges:

 - rust-lang#137736 (Don't attempt to export compiler-builtins symbols from rust dylibs)
 - rust-lang#138236 (uefi: Add OwnedEvent abstraction)
 - rust-lang#138321 ([bootstrap] Distribute split debuginfo if present)
 - rust-lang#138410 (Couple mir building cleanups)
 - rust-lang#138490 (Forward `stream_position` in `Arc<File>` as well)
 - rust-lang#138535 (Cleanup `LangString::parse`)
 - rust-lang#138536 (stable_mir: Add `MutMirVisitor`)
 - rust-lang#138580 (resolve: Avoid some unstable iteration 2)
 - rust-lang#138601 (add FCW to warn about wasm ABI transition)
 - rust-lang#138631 (Update test for SGX now implementing `read_buf`)

r? `@ghost`
`@rustbot` modify labels: rollup
@matthiaskrgr
Copy link
Member

@bors r-
#138827 (comment)

@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 Mar 22, 2025
@RalfJung
Copy link
Member Author

RalfJung commented Mar 22, 2025 via email

@RalfJung
Copy link
Member Author

I just allowed the lint in the proc_macro bridge. I hope that makes sense?
Not sure whom to ping for that bridge... @eddyb and @petrochenkov maybe?

@hanna-kruppe
Copy link
Contributor

Why’s the bridge being compiled for wasm32-unknown-unknown anyway?

@alexcrichton
Copy link
Member

@bors: r+

I believe the comment Ralf left is right, both sides of the bridge are rustc and JS isn't involved, so it doesn't matter what the exact ABI is. I believe this is built for wasm32-unknown-unknown as a standard part of any std-containing sysroot for a target. For example extern crate proc_macro; is valid on wasm32-unknown-unknown

@bors
Copy link
Contributor

bors commented Mar 22, 2025

📌 Commit a75a841 has been approved by alexcrichton

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 22, 2025
@bjorn3
Copy link
Member

bjorn3 commented Mar 22, 2025

I believe the comment Ralf left is right, both sides of the bridge are rustc and JS isn't involved, so it doesn't matter what the exact ABI is.

While both sides of the bridge are rustc, they can be different versions of rustc. That is why the bridge exists in the first place and uses the C ABI rather than the Rust ABI. That said as rustc doesn't even support loading proc-macros when it is itself compiled to wasm, it doesn't really matter that the ABI changes just on wasm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-wasm Target: WASM (WebAssembly), http://webassembly.org/ 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.