Skip to content

Fix the wasm32-unknown-unknown target feature/cfg bug - #161718

Open
nnethercote wants to merge 4 commits into
rust-lang:mainfrom
nnethercote:parse_cfg-stuff
Open

Fix the wasm32-unknown-unknown target feature/cfg bug#161718
nnethercote wants to merge 4 commits into
rust-lang:mainfrom
nnethercote:parse_cfg-stuff

Conversation

@nnethercote

Copy link
Copy Markdown
Contributor

Due to some bad ordering of session/config initialization code, cfg(target_has_threads) fails to be set for the wasm32-unknown-unknown platform when -Ctarget-feature=+atomics is specified. This PR fixes the problem. Details in individual commits.

r? @Mark-Simulacrum

Due to some bad ordering of session/config initialization code -- more
about that in subsequent commits -- `cfg(target_has_threads)` fails to
be set for the `wasm32-unknown-unknown` platform when
`-Ctarget-feature=+atomics` is specified. This commit modifies a test to
demonstrate the bug; as written the test passes.
- `parse_check_cfg` has a single call site and is followed by
  a call to `fill_well_known`.

- `parse_cfg` has two call sites and in both cases is followed by
  a call to `build_configuration`.

This commit moves the follow-up calls into the functions, simplifying
`run_compiler`.
Currently it modifies the `Session` and the `Cfg` (and the `Cfg`
afterwards is put into the `Session`). It also takes a `CodegenBackend`.
Those are some heavyweight arguments.

This commit moves the `Session` modifications to the caller so the `&mut
Session` isn't necessary, and passes in the `TargetConfig` instead of
the whole `CodegenBackend`, plus some other small arguments.
`add_configuration` ends up more clearly about modifying the `Cfg`. This
is a step towards untangling session/backend initialization.
@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs 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 Aug 25, 2026
@rustbot

This comment has been minimized.

@nnethercote

Copy link
Copy Markdown
Contributor Author

LLM disclosure: an LLM identified this bug and made some suggestions on how to fix it and test the fix. I wrote all the code and text myself.

Comment thread compiler/rustc_interface/src/interface.rs
@RalfJung

Copy link
Copy Markdown
Member

Ah nice, with my recent refactors here we can now funnel everything through sess.internal_target_features. Good catch!

Currently, `parse_cfg` calls `build_configuration`, which calls
`default_configuration`, which calls
`sess.target.singlethread(&sess.internal_target_features)`. But
`sess.internal_target_features` hasn't been set at this point and is
empty!

This commit moves the setting of `sess.internal_target_features` before
the `parse_cfg` call to fix this ordering bug. This results in the
`cfg(target_has_threads)` being correctly set on
`wasm32-unknown-unknown` when `-Ctarget-feature=+atomics` is specified.

Note: I have plans to make this kind of ordering bug
difficult/impossible in a follow-up (e.g. rust-lang#161432).
@rustbot

rustbot commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

@Urgau Urgau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was nerd snipped by the changes to check-cfg.

Looks good to me. r=me with/without the nits or Mark's review

View changes since this review


/// Converts strings provided as `--check-cfg [specs]` into a `CheckCfg`.
pub(crate) fn parse_check_cfg(dcx: DiagCtxtHandle<'_>, specs: Vec<String>) -> CheckCfg {
pub(crate) fn parse_check_cfg(sess: &Session, specs: Vec<String>) -> CheckCfg {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A bit surprising that we take a Session to do some parsing, maybe the functions should be renamed to parse_and_build_...?

@nnethercote nnethercote Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The only things used from the Session are .dcx() and .target. I thought about just passing those in, but #161432 will introduce an EarlySession type that just contains dcx, target, host, and opts and that will probably be what gets passed to parse_check_cfg.

@nnethercote

Copy link
Copy Markdown
Contributor Author

@bors r=Urgau

@rust-bors

rust-bors Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 62578df has been approved by Urgau

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs 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.

5 participants