Skip to content

Commit 65a3c1a

Browse files
committed
Auto merge of #149124 - Zalathar:rollup-objfz6n, r=Zalathar
Rollup of 10 pull requests Successful merges: - #146925 (Add doc for va_list APIs) - #147035 (alloc: fix `Debug` implementation of `ExtractIf`) - #147173 (Add support for hexagon-unknown-qurt target) - #148261 (rustc_public: Make Id types !Send / !Sync) - #148831 (Bump compiler dependencies) - #149041 (ignore unsized types in mips64 and sparc64 callconvs) - #149056 (fix the fragment_in_dst_padding_gets_overwritten test on s390x) - #149071 (Add test scaffolding for the `remote-test-client`) - #149095 (rustc-dev-guide subtree update) - #149108 ([AIX][ppc64le-linux-gnu] Add Amy Kwan to target maintainers) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 683dd08 + d72760b commit 65a3c1a

File tree

61 files changed

+1472
-842
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1472
-842
lines changed

Cargo.lock

Lines changed: 571 additions & 560 deletions
Large diffs are not rendered by default.

compiler/rustc/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ rustc_public = { path = "../rustc_public" }
2020
rustc_public_bridge = { path = "../rustc_public_bridge" }
2121
# tidy-alphabetical-end
2222

23+
# Pin these to avoid pulling in a package with a binary blob
24+
# <https://github.com/rust-lang/rust/pull/136395#issuecomment-2692769062>
25+
[target.'cfg(target_os = "wasi")'.dependencies]
26+
getrandom = "=0.3.3"
27+
wasi = "=0.14.2"
28+
29+
2330
[dependencies.tikv-jemalloc-sys]
2431
version = "0.6.0"
2532
optional = true

compiler/rustc_public/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ rustc_session = { path = "../rustc_session" }
1313
rustc_span = { path = "../rustc_span" }
1414
rustc_target = { path = "../rustc_target" }
1515
scoped-tls = "1.0"
16-
serde = { version = "1.0.125", features = [ "derive" ] }
16+
serde = { version = "1.0.125", features = ["derive"] }
1717
tracing = "0.1"
1818
# tidy-alphabetical-end
1919

20+
[dev-dependencies]
21+
# tidy-alphabetical-start
22+
serde_json = "1.0.142"
23+
# tidy-alphabetical-end
24+
2025
[features]
2126
# tidy-alphabetical-start
2227
# Provides access to APIs that expose internals of the rust compiler.

compiler/rustc_public/src/abi.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use serde::Serialize;
77
use crate::compiler_interface::with;
88
use crate::mir::FieldIdx;
99
use crate::target::{MachineInfo, MachineSize as Size};
10-
use crate::ty::{Align, Ty, VariantIdx};
11-
use crate::{Error, Opaque, error};
10+
use crate::ty::{Align, Ty, VariantIdx, index_impl};
11+
use crate::{Error, Opaque, ThreadLocalIndex, error};
1212

1313
/// A function ABI definition.
1414
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
@@ -109,24 +109,16 @@ impl LayoutShape {
109109
}
110110
}
111111

112-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize)]
113-
pub struct Layout(usize);
112+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
113+
pub struct Layout(usize, ThreadLocalIndex);
114+
index_impl!(Layout);
114115

115116
impl Layout {
116117
pub fn shape(self) -> LayoutShape {
117118
with(|cx| cx.layout_shape(self))
118119
}
119120
}
120121

121-
impl crate::IndexedVal for Layout {
122-
fn to_val(index: usize) -> Self {
123-
Layout(index)
124-
}
125-
fn to_index(&self) -> usize {
126-
self.0
127-
}
128-
}
129-
130122
/// Describes how the fields of a type are shaped in memory.
131123
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
132124
pub enum FieldsShape {

compiler/rustc_public/src/compiler_interface.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::ty::{
2525
use crate::unstable::{RustcInternal, Stable, new_item_kind};
2626
use crate::{
2727
AssocItems, Crate, CrateDef, CrateItem, CrateItems, CrateNum, DefId, Error, Filename,
28-
ImplTraitDecls, ItemKind, Symbol, TraitDecls, alloc, mir,
28+
ImplTraitDecls, ItemKind, Symbol, ThreadLocalIndex, TraitDecls, alloc, mir,
2929
};
3030

3131
pub struct BridgeTys;
@@ -866,7 +866,7 @@ fn smir_crate<'tcx>(
866866
) -> Crate {
867867
let name = cx.crate_name(crate_num);
868868
let is_local = cx.crate_is_local(crate_num);
869-
let id = cx.crate_num_id(crate_num);
869+
let id = CrateNum(cx.crate_num_id(crate_num), ThreadLocalIndex);
870870
debug!(?name, ?crate_num, "smir_crate");
871871
Crate { id, name, is_local }
872872
}

compiler/rustc_public/src/crate_def.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
//! Module that define a common trait for things that represent a crate definition,
22
//! such as, a function, a trait, an enum, and any other definitions.
33
4-
use serde::Serialize;
5-
6-
use crate::ty::{GenericArgs, Span, Ty};
7-
use crate::{AssocItems, Crate, Symbol, with};
4+
use crate::ty::{GenericArgs, Span, Ty, index_impl};
5+
use crate::{AssocItems, Crate, Symbol, ThreadLocalIndex, with};
86

97
/// A unique identification number for each item accessible for the current compilation unit.
10-
#[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize)]
11-
pub struct DefId(pub(crate) usize);
8+
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
9+
pub struct DefId(pub(crate) usize, ThreadLocalIndex);
10+
index_impl!(DefId);
1211

1312
impl DefId {
1413
/// Return fully qualified name of this definition

compiler/rustc_public/src/lib.rs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
//! [crates.io](https://crates.io).
1818
1919
use std::fmt::Debug;
20+
use std::marker::PhantomData;
2021
use std::{fmt, io};
2122

2223
pub(crate) use rustc_public_bridge::IndexedVal;
@@ -33,7 +34,10 @@ pub use crate::crate_def::{CrateDef, CrateDefItems, CrateDefType, DefId};
3334
pub use crate::error::*;
3435
use crate::mir::mono::StaticDef;
3536
use crate::mir::{Body, Mutability};
36-
use crate::ty::{AssocItem, FnDef, ForeignModuleDef, ImplDef, ProvenanceMap, Span, TraitDef, Ty};
37+
use crate::ty::{
38+
AssocItem, FnDef, ForeignModuleDef, ImplDef, ProvenanceMap, Span, TraitDef, Ty,
39+
serialize_index_impl,
40+
};
3741
use crate::unstable::Stable;
3842

3943
pub mod abi;
@@ -46,31 +50,25 @@ pub mod compiler_interface;
4650
pub mod error;
4751
pub mod mir;
4852
pub mod target;
53+
#[cfg(test)]
54+
mod tests;
4955
pub mod ty;
5056
pub mod visitor;
5157

5258
/// Use String for now but we should replace it.
5359
pub type Symbol = String;
5460

5561
/// The number that identifies a crate.
56-
pub type CrateNum = usize;
62+
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
63+
pub struct CrateNum(pub(crate) usize, ThreadLocalIndex);
64+
serialize_index_impl!(CrateNum);
5765

5866
impl Debug for DefId {
5967
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6068
f.debug_struct("DefId").field("id", &self.0).field("name", &self.name()).finish()
6169
}
6270
}
6371

64-
impl IndexedVal for DefId {
65-
fn to_val(index: usize) -> Self {
66-
DefId(index)
67-
}
68-
69-
fn to_index(&self) -> usize {
70-
self.0
71-
}
72-
}
73-
7472
/// A list of crate items.
7573
pub type CrateItems = Vec<CrateItem>;
7674

@@ -297,3 +295,25 @@ impl rustc_public_bridge::bridge::Allocation<compiler_interface::BridgeTys>
297295
}
298296
}
299297
}
298+
299+
#[derive(Clone, Copy, Hash, PartialEq, Eq, Default)]
300+
/// Marker type for indexes into thread local structures.
301+
///
302+
/// Makes things `!Send`/`!Sync`, so users don't move `rustc_public` types to
303+
/// thread with no (or worse, different) `rustc_public` pointer.
304+
///
305+
/// Note. This doesn't make it impossible to confuse TLS. You could return a
306+
/// `DefId` from one `run!` invocation, and then use it inside a different
307+
/// `run!` invocation with different tables.
308+
pub(crate) struct ThreadLocalIndex {
309+
_phantom: PhantomData<*const ()>,
310+
}
311+
#[expect(non_upper_case_globals)]
312+
/// Emulating unit struct `struct ThreadLocalIndex`;
313+
pub(crate) const ThreadLocalIndex: ThreadLocalIndex = ThreadLocalIndex { _phantom: PhantomData };
314+
315+
impl fmt::Debug for ThreadLocalIndex {
316+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
317+
f.debug_tuple("ThreadLocalIndex").finish()
318+
}
319+
}

compiler/rustc_public/src/mir/alloc.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use serde::Serialize;
66

77
use crate::mir::mono::{Instance, StaticDef};
88
use crate::target::{Endian, MachineInfo};
9-
use crate::ty::{Allocation, Binder, ExistentialTraitRef, Ty};
10-
use crate::{Error, IndexedVal, with};
9+
use crate::ty::{Allocation, Binder, ExistentialTraitRef, Ty, index_impl};
10+
use crate::{Error, ThreadLocalIndex, with};
1111

1212
/// An allocation in the rustc_public's IR global memory can be either a function pointer,
1313
/// a static, or a "real" allocation with some data in it.
@@ -47,17 +47,9 @@ impl GlobalAlloc {
4747
}
4848

4949
/// A unique identification number for each provenance
50-
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Serialize)]
51-
pub struct AllocId(usize);
52-
53-
impl IndexedVal for AllocId {
54-
fn to_val(index: usize) -> Self {
55-
AllocId(index)
56-
}
57-
fn to_index(&self) -> usize {
58-
self.0
59-
}
60-
}
50+
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
51+
pub struct AllocId(usize, ThreadLocalIndex);
52+
index_impl!(AllocId);
6153

6254
/// Utility function used to read an allocation data into a unassigned integer.
6355
pub(crate) fn read_target_uint(mut bytes: &[u8]) -> Result<u128, Error> {

compiler/rustc_public/src/mir/mono.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use serde::Serialize;
77
use crate::abi::FnAbi;
88
use crate::crate_def::CrateDef;
99
use crate::mir::Body;
10-
use crate::ty::{Allocation, ClosureDef, ClosureKind, FnDef, GenericArgs, Ty};
11-
use crate::{CrateItem, DefId, Error, IndexedVal, ItemKind, Opaque, Symbol, with};
10+
use crate::ty::{Allocation, ClosureDef, ClosureKind, FnDef, GenericArgs, Ty, index_impl};
11+
use crate::{CrateItem, DefId, Error, ItemKind, Opaque, Symbol, ThreadLocalIndex, with};
1212

1313
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
1414
pub enum MonoItem {
@@ -241,8 +241,9 @@ impl From<StaticDef> for CrateItem {
241241
}
242242
}
243243

244-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize)]
245-
pub struct InstanceDef(usize);
244+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
245+
pub struct InstanceDef(usize, ThreadLocalIndex);
246+
index_impl!(InstanceDef);
246247

247248
impl CrateDef for InstanceDef {
248249
fn def_id(&self) -> DefId {
@@ -294,12 +295,3 @@ impl StaticDef {
294295
with(|cx| cx.eval_static_initializer(*self))
295296
}
296297
}
297-
298-
impl IndexedVal for InstanceDef {
299-
fn to_val(index: usize) -> Self {
300-
InstanceDef(index)
301-
}
302-
fn to_index(&self) -> usize {
303-
self.0
304-
}
305-
}

compiler/rustc_public/src/rustc_internal/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ where
5353
}
5454

5555
pub fn crate_num(item: &crate::Crate) -> CrateNum {
56-
item.id.into()
56+
item.id.0.into()
5757
}
5858

5959
/// Loads the current context and calls a function with it.

0 commit comments

Comments
 (0)