Fix the wasm32-unknown-unknown target feature/cfg bug - #161718
Open
nnethercote wants to merge 4 commits into
Open
Fix the wasm32-unknown-unknown target feature/cfg bug#161718nnethercote wants to merge 4 commits into
nnethercote wants to merge 4 commits into
Conversation
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.
This comment has been minimized.
This comment has been minimized.
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. |
RalfJung
reviewed
Aug 25, 2026
Member
|
Ah nice, with my recent refactors here we can now funnel everything through |
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).
nnethercote
force-pushed
the
parse_cfg-stuff
branch
from
August 25, 2026 10:53
d075ae3 to
62578df
Compare
Collaborator
|
Urgau
approved these changes
Aug 25, 2026
|
|
||
| /// 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 { |
Member
There was a problem hiding this comment.
A bit surprising that we take a Session to do some parsing, maybe the functions should be renamed to parse_and_build_...?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Due to some bad ordering of session/config initialization code,
cfg(target_has_threads)fails to be set for thewasm32-unknown-unknownplatform when-Ctarget-feature=+atomicsis specified. This PR fixes the problem. Details in individual commits.r? @Mark-Simulacrum