Skip to content

Commit 390a637

Browse files
committed
move things from rustc_target::abi to rustc_abi
1 parent 27fb904 commit 390a637

File tree

21 files changed

+1700
-1673
lines changed

21 files changed

+1700
-1673
lines changed

Cargo.lock

+15-4
Original file line numberDiff line numberDiff line change
@@ -3202,6 +3202,20 @@ dependencies = [
32023202
"winapi",
32033203
]
32043204

3205+
[[package]]
3206+
name = "rustc_abi"
3207+
version = "0.0.0"
3208+
dependencies = [
3209+
"bitflags",
3210+
"rand 0.8.5",
3211+
"rand_xoshiro",
3212+
"rustc_data_structures",
3213+
"rustc_index",
3214+
"rustc_macros",
3215+
"rustc_serialize",
3216+
"tracing",
3217+
]
3218+
32053219
[[package]]
32063220
name = "rustc_apfloat"
32073221
version = "0.0.0"
@@ -4281,8 +4295,7 @@ name = "rustc_target"
42814295
version = "0.0.0"
42824296
dependencies = [
42834297
"bitflags",
4284-
"rand 0.8.5",
4285-
"rand_xoshiro",
4298+
"rustc_abi",
42864299
"rustc_data_structures",
42874300
"rustc_feature",
42884301
"rustc_index",
@@ -4363,8 +4376,6 @@ dependencies = [
43634376
name = "rustc_ty_utils"
43644377
version = "0.0.0"
43654378
dependencies = [
4366-
"rand 0.8.5",
4367-
"rand_xoshiro",
43684379
"rustc_data_structures",
43694380
"rustc_errors",
43704381
"rustc_hir",

compiler/rustc_abi/Cargo.toml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "rustc_abi"
3+
version = "0.0.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
bitflags = "1.2.1"
8+
tracing = "0.1"
9+
rand = { version = "0.8.4", default-features = false, optional = true }
10+
rand_xoshiro = { version = "0.6.0", optional = true }
11+
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
12+
rustc_index = { path = "../rustc_index", default-features = false }
13+
rustc_macros = { path = "../rustc_macros", optional = true }
14+
rustc_serialize = { path = "../rustc_serialize", optional = true }
15+
16+
[features]
17+
default = ["nightly", "randomize"]
18+
randomize = ["rand", "rand_xoshiro"]
19+
nightly = [
20+
"rustc_data_structures",
21+
"rustc_index/nightly",
22+
"rustc_macros",
23+
"rustc_serialize",
24+
]

compiler/rustc_target/src/abi/layout.rs renamed to compiler/rustc_abi/src/layout.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use std::{
77
ops::{Bound, Deref},
88
};
99

10+
#[cfg(feature = "randomize")]
1011
use rand::{seq::SliceRandom, SeedableRng};
12+
#[cfg(feature = "randomize")]
1113
use rand_xoshiro::Xoshiro128StarStar;
1214

1315
use tracing::debug;
@@ -91,14 +93,16 @@ pub trait LayoutCalculator {
9193
// If `-Z randomize-layout` was enabled for the type definition we can shuffle
9294
// the field ordering to try and catch some code making assumptions about layouts
9395
// we don't guarantee
94-
if repr.can_randomize_type_layout() {
95-
// `ReprOptions.layout_seed` is a deterministic seed that we can use to
96-
// randomize field ordering with
97-
let mut rng = Xoshiro128StarStar::seed_from_u64(repr.field_shuffle_seed);
98-
99-
// Shuffle the ordering of the fields
100-
optimizing.shuffle(&mut rng);
96+
if repr.can_randomize_type_layout() && cfg!(feature = "randomize") {
97+
#[cfg(feature = "randomize")]
98+
{
99+
// `ReprOptions.layout_seed` is a deterministic seed that we can use to
100+
// randomize field ordering with
101+
let mut rng = Xoshiro128StarStar::seed_from_u64(repr.field_shuffle_seed);
101102

103+
// Shuffle the ordering of the fields
104+
optimizing.shuffle(&mut rng);
105+
}
102106
// Otherwise we just leave things alone and actually optimize the type's fields
103107
} else {
104108
match kind {
@@ -900,7 +904,7 @@ pub trait LayoutCalculator {
900904
let mut abi = Abi::Aggregate { sized: true };
901905
let index = V::new(0);
902906
for field in &variants[index] {
903-
assert!(!field.is_unsized());
907+
assert!(field.is_sized());
904908
align = align.max(field.align);
905909

906910
// If all non-ZST fields have the same ABI, forward this ABI

0 commit comments

Comments
 (0)