Skip to content

Conversation

@aDotInTheVoid
Copy link
Member

@aDotInTheVoid aDotInTheVoid commented Oct 29, 2025

These types are Id's to a table stored in TLS, so using them from another tread will either panic, or give wrong results.

Therefor, I've added a ReferencesTlsThreadLocalIndex marker type, which ensures types arn't Send/Sync.

This is a breaking change for users of the rustc_public crate.

It also changes how DefId and similar are Serialized. It would be possible to preserve the old behavior if that's needed, but I couldn't see any tests for these. EDIT: Not anymore: #148261 (comment)

Zulip Discussion: https://rust-lang.zulipchat.com/#narrow/channel/320896-project-stable-mir/topic/WDYM.20.22should.20not.20.20be.20shared.20across.20threads.22/with/547374171

These types are Id's to a table stored in TLS, so using them from another tread will either panic, or give wrong results. Therefor, I've added a `ReferencesTls` marker type, which ensures types arn't `Send`/`Sync`. This is a breaking change for users of the `rustc_public` crate. It also changes how `DefId` and similar are `Serialize`d. Zulip Discussion: https://rust-lang.zulipchat.com/#narrow/channel/320896-project-stable-mir/topic/WDYM.20.22should.20not.20.20be.20shared.20across.20threads.22/with/547374171
@rustbot
Copy link
Collaborator

rustbot commented Oct 29, 2025

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a

@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 Oct 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 29, 2025

r? @celinval

rustbot has assigned @celinval.
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

Copy link
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

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

It's too bad we cannot use negative trait here. KMIR actually uses the serialization. See: https://github.com/runtimeverification/stable-mir-json. They use IDs to map components and correlate then AFAIK.

So can you please make sure you skip the serialization of the new field in the structs you added them?

View changes since this review

}

#[derive(Clone, Copy, Hash, PartialEq, Eq, Default)]
#[derive(serde::Serialize)] // TODO: Don't.
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree... Please don't.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 97e6df4. It's sadly not as simple as using #[serde(skip)], as that still moves serde from serializing just the single field, to a list containing the single field: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=b4aafe4ff5312c4ddedd5e17ee361d5a

Is there somewhere that tests for this could go?

pub type Symbol = String;

/// The number that identifies a crate.
// FIXME: Make this a newtype, so it can have a `ReferencesTls`
Copy link
Contributor

Choose a reason for hiding this comment

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

why not include in this PR?

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 wanted to keep this PR not doing too much at once. But I've added it in 8b3ee9f

Somehow VSCode's format-on-save is formatting differently to ./x. Maybe to do with 2024 edition??
It meant that `DefId(0, ThreadLocalIndex)` would go to json as `[0, null]`, instead of just `0` (like before this PR). Now it's back to going to `0`, so this PR won't effect JSON consumers. This can't be achieved with just `#[serde(skip)]`: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=b4aafe4ff5312c4ddedd5e17ee361d5a
@rust-log-analyzer

This comment has been minimized.

@aDotInTheVoid
Copy link
Member Author

I'd like to squash this after approval but before merging.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer
Copy link
Collaborator

The job pr-check-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
 Checking rustc_lint v0.0.0 (/checkout/compiler/rustc_lint) error: unresolved link to `TLV` --> compiler/rustc_public/src/lib.rs:301:36 | 301 | /// Marker type for indexes into [`TLV`]. | ^^^ no item named `TLV` in scope | = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = note: `-D rustdoc::broken-intra-doc-links` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(rustdoc::broken_intra_doc_links)]` error: could not document `rustc_public` warning: build failed, waiting for other jobs to finish... [RUSTC-TIMING] rustc_lint test:false 3.644 [RUSTC-TIMING] rustc_query_impl test:false 8.850 Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo doc --target x86_64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout --locked --color always --release --features llvm --manifest-path /checkout/compiler/rustc/Cargo.toml -Zskip-rustdoc-fingerprint --no-deps -Zrustdoc-map -p rustc-main -p rustc_abi -p rustc_arena -p rustc_ast -p rustc_ast_ir -p rustc_ast_lowering -p rustc_ast_passes -p rustc_ast_pretty -p rustc_attr_parsing -p rustc_baked_icu_data -p rustc_borrowck -p rustc_builtin_macros -p rustc_codegen_llvm -p rustc_codegen_ssa -p rustc_const_eval -p rustc_data_structures -p rustc_driver -p rustc_driver_impl -p rustc_error_codes -p rustc_error_messages -p rustc_errors -p rustc_expand -p rustc_feature -p rustc_fluent_macro -p rustc_fs_util -p rustc_graphviz -p rustc_hashes -p rustc_hir -p rustc_hir_analysis -p rustc_hir_id -p rustc_hir_pretty -p rustc_hir_typeck -p rustc_incremental -p rustc_index -p rustc_index_macros -p rustc_infer -p rustc_interface -p rustc_lexer -p rustc_lint -p rustc_lint_defs -p rustc_llvm -p rustc_log -p rustc_macros -p rustc_metadata -p rustc_middle -p rustc_mir_build -p rustc_mir_dataflow -p rustc_mir_transform -p rustc_monomorphize -p rustc_next_trait_solver -p rustc_parse -p rustc_parse_format -p rustc_passes -p rustc_pattern_analysis -p rustc_privacy -p rustc_proc_macro -p rustc_public -p rustc_public_bridge -p rustc_query_impl -p rustc_query_system -p rustc_resolve -p rustc_sanitizers -p rustc_serialize -p rustc_session -p rustc_span -p rustc_symbol_mangling -p rustc_target -p rustc_thread_pool -p rustc_trait_selection -p rustc_traits -p rustc_transmute -p rustc_ty_utils -p rustc_type_ir -p rustc_type_ir_macros -p rustc_windows_rc [workdir=/checkout]` failed with exit code 101 Created at: src/bootstrap/src/core/build_steps/doc.rs:902:25 Executed at: src/bootstrap/src/core/build_steps/doc.rs:962:26 Command has failed. Rerun with -v to see more details. Bootstrap failed while executing `doc compiler --stage 1` Build completed unsuccessfully in 0:00:51 local time: Thu Oct 30 02:14:26 UTC 2025 network time: Thu, 30 Oct 2025 02:14:26 GMT ##[error]Process completed with exit code 1. 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants