Skip to content

Commit 09a3846

Browse files
committed
make rustc_target usable outside of rustc
1 parent 1dda298 commit 09a3846

File tree

11 files changed

+163
-77
lines changed

11 files changed

+163
-77
lines changed

compiler/rustc_index/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ edition = "2021"
77

88
[dependencies]
99
arrayvec = { version = "0.7", default-features = false }
10-
rustc_serialize = { path = "../rustc_serialize" }
11-
rustc_macros = { path = "../rustc_macros" }
10+
rustc_serialize = { path = "../rustc_serialize", optional = true }
11+
rustc_macros = { path = "../rustc_macros", optional = true }
1212
smallvec = "1.8.1"
13+
14+
[features]
15+
default = ["nightly"]
16+
nightly = ["rustc_serialize", "rustc_macros"]

compiler/rustc_index/src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
#![deny(rustc::untranslatable_diagnostic)]
22
#![deny(rustc::diagnostic_outside_of_impl)]
3-
#![feature(allow_internal_unstable)]
4-
#![feature(extend_one)]
5-
#![feature(min_specialization)]
6-
#![feature(new_uninit)]
7-
#![feature(step_trait)]
8-
#![feature(stmt_expr_attributes)]
9-
#![feature(test)]
3+
#![cfg_attr(feature = "nightly", feature(allow_internal_unstable))]
4+
#![cfg_attr(feature = "nightly", feature(extend_one))]
5+
#![cfg_attr(feature = "nightly", feature(min_specialization))]
6+
#![cfg_attr(feature = "nightly", feature(new_uninit))]
7+
#![cfg_attr(feature = "nightly", feature(step_trait))]
8+
#![cfg_attr(feature = "nightly", feature(stmt_expr_attributes))]
9+
#![cfg_attr(feature = "nightly", feature(test))]
1010

11+
#[cfg(feature = "nightly")]
1112
pub mod bit_set;
13+
#[cfg(feature = "nightly")]
1214
pub mod interval;
1315
pub mod vec;
1416

17+
#[cfg(feature = "rustc_macros")]
1518
pub use rustc_macros::newtype_index;
1619

1720
/// Type size assertion. The first argument is a type and the second argument is its expected size.

compiler/rustc_index/src/vec.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(feature = "rustc_serialize")]
12
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
23

34
use std::fmt;
@@ -61,12 +62,14 @@ pub struct IndexVec<I: Idx, T> {
6162
// not the phantom data.
6263
unsafe impl<I: Idx, T> Send for IndexVec<I, T> where T: Send {}
6364

65+
#[cfg(feature = "rustc_serialize")]
6466
impl<S: Encoder, I: Idx, T: Encodable<S>> Encodable<S> for IndexVec<I, T> {
6567
fn encode(&self, s: &mut S) {
6668
Encodable::encode(&self.raw, s);
6769
}
6870
}
6971

72+
#[cfg(feature = "rustc_serialize")]
7073
impl<D: Decoder, I: Idx, T: Decodable<D>> Decodable<D> for IndexVec<I, T> {
7174
fn decode(d: &mut D) -> Self {
7275
IndexVec { raw: Decodable::decode(d), _marker: PhantomData }
@@ -359,11 +362,13 @@ impl<I: Idx, T> Extend<T> for IndexVec<I, T> {
359362
}
360363

361364
#[inline]
365+
#[cfg(feature = "nightly")]
362366
fn extend_one(&mut self, item: T) {
363367
self.raw.push(item);
364368
}
365369

366370
#[inline]
371+
#[cfg(feature = "nightly")]
367372
fn extend_reserve(&mut self, additional: usize) {
368373
self.raw.reserve(additional);
369374
}

compiler/rustc_middle/src/arena.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
macro_rules! arena_types {
77
($macro:path) => (
88
$macro!([
9-
[] layout: rustc_target::abi::LayoutS<'tcx>,
9+
[] layout: rustc_target::abi::LayoutS<rustc_target::abi::VariantIdx>,
1010
[] fn_abi: rustc_target::abi::call::FnAbi<'tcx, rustc_middle::ty::Ty<'tcx>>,
1111
// AdtDef are interned and compared by address
1212
[decode] adt_def: rustc_middle::ty::AdtDefData,

compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub struct CtxtInterners<'tcx> {
148148
const_: InternedSet<'tcx, ConstS<'tcx>>,
149149
const_allocation: InternedSet<'tcx, Allocation>,
150150
bound_variable_kinds: InternedSet<'tcx, List<ty::BoundVariableKind>>,
151-
layout: InternedSet<'tcx, LayoutS<'tcx>>,
151+
layout: InternedSet<'tcx, LayoutS<VariantIdx>>,
152152
adt_def: InternedSet<'tcx, AdtDefData>,
153153
}
154154

@@ -2244,7 +2244,7 @@ direct_interners! {
22442244
region: mk_region(RegionKind<'tcx>): Region -> Region<'tcx>,
22452245
const_: mk_const_internal(ConstS<'tcx>): Const -> Const<'tcx>,
22462246
const_allocation: intern_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>,
2247-
layout: intern_layout(LayoutS<'tcx>): Layout -> Layout<'tcx>,
2247+
layout: intern_layout(LayoutS<VariantIdx>): Layout -> Layout<'tcx>,
22482248
adt_def: intern_adt_def(AdtDefData): AdtDef -> AdtDef<'tcx>,
22492249
}
22502250

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ where
610610
})
611611
}
612612

613-
Variants::Multiple { ref variants, .. } => variants[variant_index],
613+
Variants::Multiple { ref variants, .. } => cx.tcx().intern_layout(variants[variant_index].clone()),
614614
};
615615

616616
assert_eq!(*layout.variants(), Variants::Single { index: variant_index });

compiler/rustc_target/Cargo.toml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,20 @@ edition = "2021"
77
bitflags = "1.2.1"
88
tracing = "0.1"
99
serde_json = "1.0.59"
10-
rustc_data_structures = { path = "../rustc_data_structures" }
11-
rustc_feature = { path = "../rustc_feature" }
12-
rustc_index = { path = "../rustc_index" }
13-
rustc_macros = { path = "../rustc_macros" }
14-
rustc_serialize = { path = "../rustc_serialize" }
15-
rustc_span = { path = "../rustc_span" }
10+
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
11+
rustc_feature = { path = "../rustc_feature", 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+
rustc_span = { path = "../rustc_span", optional = true }
16+
17+
[features]
18+
default = ["nightly"]
19+
nightly = [
20+
"rustc_data_structures",
21+
"rustc_feature",
22+
"rustc_index/nightly",
23+
"rustc_macros",
24+
"rustc_serialize",
25+
"rustc_span",
26+
]

0 commit comments

Comments
 (0)