Skip to content

Commit db1acaa

Browse files
committed
Auto merge of #53073 - Mark-Simulacrum:data-structures, r=pnkfelix
Cleanup to librustc::session and related code No functional changes, just some cleanup. This also creates the `rustc_fs_util` crate, but I can remove that change if desired. It felt a little odd to force crates to depend on librustc for some fs utilities; and also seemed good to generally keep the size of librustc lower (for compile times); fs_util will compile in parallel with essentially the first crate since it has no dependencies beyond std.
2 parents fb65d75 + a8e19be commit db1acaa

File tree

42 files changed

+185
-169
lines changed

Some content is hidden

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

42 files changed

+185
-169
lines changed

src/Cargo.lock

+6
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,7 @@ dependencies = [
18871887
"rustc_apfloat 0.0.0",
18881888
"rustc_data_structures 0.0.0",
18891889
"rustc_errors 0.0.0",
1890+
"rustc_fs_util 0.0.0",
18901891
"rustc_target 0.0.0",
18911892
"scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
18921893
"serialize 0.0.0",
@@ -2185,6 +2186,10 @@ dependencies = [
21852186
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
21862187
]
21872188

2189+
[[package]]
2190+
name = "rustc_fs_util"
2191+
version = "0.0.0"
2192+
21882193
[[package]]
21892194
name = "rustc_incremental"
21902195
version = "0.0.0"
@@ -2194,6 +2199,7 @@ dependencies = [
21942199
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
21952200
"rustc 0.0.0",
21962201
"rustc_data_structures 0.0.0",
2202+
"rustc_fs_util 0.0.0",
21972203
"serialize 0.0.0",
21982204
"syntax 0.0.0",
21992205
"syntax_pos 0.0.0",

src/librustc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ backtrace = "0.3.3"
3232
parking_lot = "0.5.5"
3333
byteorder = { version = "1.1", features = ["i128"]}
3434
chalk-engine = { version = "0.6.0", default-features=false }
35+
rustc_fs_util = { path = "../librustc_fs_util" }
3536

3637
# Note that these dependencies are a lie, they're just here to get linkage to
3738
# work.

src/librustc/hir/map/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::*;
1212
use dep_graph::{DepGraph, DepKind, DepNodeIndex};
1313
use hir::def_id::{LOCAL_CRATE, CrateNum};
1414
use hir::intravisit::{Visitor, NestedVisitorMap};
15-
use hir::svh::Svh;
15+
use rustc_data_structures::svh::Svh;
1616
use ich::Fingerprint;
1717
use middle::cstore::CrateStore;
1818
use session::CrateDisambiguator;

src/librustc/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ use hir::def_id::{CRATE_DEF_INDEX, DefId, LocalDefId, DefIndexAddressSpace};
2222
use middle::cstore::CrateStore;
2323

2424
use rustc_target::spec::abi::Abi;
25+
use rustc_data_structures::svh::Svh;
2526
use syntax::ast::{self, Name, NodeId, CRATE_NODE_ID};
2627
use syntax::codemap::Spanned;
2728
use syntax::ext::base::MacroKind;
2829
use syntax_pos::{Span, DUMMY_SP};
2930

3031
use hir::*;
3132
use hir::print::Nested;
32-
use hir::svh::Svh;
3333
use util::nodemap::FxHashMap;
3434

3535
use std::io;

src/librustc/hir/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ pub mod lowering;
7070
pub mod map;
7171
pub mod pat_util;
7272
pub mod print;
73-
pub mod svh;
7473

7574
/// A HirId uniquely identifies a node in the HIR of the current crate. It is
7675
/// composed of the `owner`, which is the DefIndex of the directly enclosing

src/librustc/ich/hcx.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use rustc_data_structures::stable_hasher::{HashStable,
3737
use rustc_data_structures::accumulate_vec::AccumulateVec;
3838
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
3939

40-
pub fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
40+
fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
4141
debug_assert!(ich::IGNORED_ATTRIBUTES.len() > 0);
4242
ich::IGNORED_ATTRIBUTES.iter().map(|&s| Symbol::intern(s)).collect()
4343
}
@@ -183,7 +183,10 @@ impl<'a> StableHashingContext<'a> {
183183

184184
#[inline]
185185
pub fn is_ignored_attr(&self, name: Symbol) -> bool {
186-
self.sess.ignored_attr_names.contains(&name)
186+
thread_local! {
187+
static IGNORED_ATTRIBUTES: FxHashSet<Symbol> = compute_ignored_attr_names();
188+
}
189+
IGNORED_ATTRIBUTES.with(|attrs| attrs.contains(&name))
187190
}
188191

189192
pub fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self, f: F) {

src/librustc/ich/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010

1111
//! ICH - Incremental Compilation Hash
1212
13-
pub use self::fingerprint::Fingerprint;
13+
crate use rustc_data_structures::fingerprint::Fingerprint;
1414
pub use self::caching_codemap_view::CachingCodemapView;
1515
pub use self::hcx::{StableHashingContextProvider, StableHashingContext, NodeIdHashingMode,
16-
hash_stable_trait_impls, compute_ignored_attr_names};
17-
mod fingerprint;
16+
hash_stable_trait_impls};
1817
mod caching_codemap_view;
1918
mod hcx;
2019

src/librustc/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#![feature(in_band_lifetimes)]
7373
#![feature(macro_at_most_once_rep)]
7474
#![feature(crate_in_paths)]
75+
#![feature(crate_visibility_modifier)]
7576

7677
#![recursion_limit="512"]
7778

@@ -99,6 +100,7 @@ extern crate syntax_pos;
99100
extern crate jobserver;
100101
extern crate proc_macro;
101102
extern crate chalk_engine;
103+
extern crate rustc_fs_util;
102104

103105
extern crate serialize as rustc_serialize; // used by deriving
104106

@@ -162,9 +164,9 @@ pub mod util {
162164
pub mod common;
163165
pub mod ppaux;
164166
pub mod nodemap;
165-
pub mod fs;
166167
pub mod time_graph;
167168
pub mod profiling;
169+
pub mod bug;
168170
}
169171

170172
// A private module so that macro-expanded idents like

src/librustc/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ macro_rules! enum_from_u32 {
5151
macro_rules! bug {
5252
() => ( bug!("impossible case reached") );
5353
($($message:tt)*) => ({
54-
$crate::session::bug_fmt(file!(), line!(), format_args!($($message)*))
54+
$crate::util::bug::bug_fmt(file!(), line!(), format_args!($($message)*))
5555
})
5656
}
5757

5858
#[macro_export]
5959
macro_rules! span_bug {
6060
($span:expr, $($message:tt)*) => ({
61-
$crate::session::span_bug_fmt(file!(), line!(), $span, format_args!($($message)*))
61+
$crate::util::bug::span_bug_fmt(file!(), line!(), $span, format_args!($($message)*))
6262
})
6363
}
6464

src/librustc/middle/cstore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
2626
use hir::map as hir_map;
2727
use hir::map::definitions::{DefKey, DefPathTable};
28-
use hir::svh::Svh;
28+
use rustc_data_structures::svh::Svh;
2929
use ty::{self, TyCtxt};
3030
use session::{Session, CrateDisambiguator};
3131
use session::search_paths::PathKind;

src/librustc/session/code_stats.rs

+1-14
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use ty::AdtKind;
12-
use ty::layout::{Align, Size};
13-
11+
use rustc_target::abi::{Align, Size};
1412
use rustc_data_structures::fx::{FxHashSet};
15-
1613
use std::cmp::{self, Ordering};
1714

1815
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
@@ -38,16 +35,6 @@ pub struct FieldInfo {
3835
pub align: u64,
3936
}
4037

41-
impl From<AdtKind> for DataTypeKind {
42-
fn from(kind: AdtKind) -> Self {
43-
match kind {
44-
AdtKind::Struct => DataTypeKind::Struct,
45-
AdtKind::Enum => DataTypeKind::Enum,
46-
AdtKind::Union => DataTypeKind::Union,
47-
}
48-
}
49-
}
50-
5138
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
5239
pub enum DataTypeKind {
5340
Struct,

src/librustc/session/config.rs

+4-32
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ use std::str::FromStr;
1616
use session::{early_error, early_warn, Session};
1717
use session::search_paths::SearchPaths;
1818

19-
use ich::StableHashingContext;
2019
use rustc_target::spec::{LinkerFlavor, PanicStrategy, RelroLevel};
2120
use rustc_target::spec::{Target, TargetTriple};
22-
use rustc_data_structures::stable_hasher::ToStableHashKey;
2321
use lint;
2422
use middle::cstore;
2523

@@ -126,25 +124,7 @@ pub enum OutputType {
126124
DepInfo,
127125
}
128126

129-
130-
impl_stable_hash_for!(enum self::OutputType {
131-
Bitcode,
132-
Assembly,
133-
LlvmAssembly,
134-
Mir,
135-
Metadata,
136-
Object,
137-
Exe,
138-
DepInfo
139-
});
140-
141-
impl<'a, 'tcx> ToStableHashKey<StableHashingContext<'a>> for OutputType {
142-
type KeyType = OutputType;
143-
#[inline]
144-
fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> Self::KeyType {
145-
*self
146-
}
147-
}
127+
impl_stable_hash_via_hash!(OutputType);
148128

149129
impl OutputType {
150130
fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
@@ -233,9 +213,7 @@ impl Default for ErrorOutputType {
233213
#[derive(Clone, Hash)]
234214
pub struct OutputTypes(BTreeMap<OutputType, Option<PathBuf>>);
235215

236-
impl_stable_hash_for!(tuple_struct self::OutputTypes {
237-
map
238-
});
216+
impl_stable_hash_via_hash!(OutputTypes);
239217

240218
impl OutputTypes {
241219
pub fn new(entries: &[(OutputType, Option<PathBuf>)]) -> OutputTypes {
@@ -512,7 +490,7 @@ impl Input {
512490
}
513491
}
514492

515-
#[derive(Clone)]
493+
#[derive(Clone, Hash)]
516494
pub struct OutputFilenames {
517495
pub out_directory: PathBuf,
518496
pub out_filestem: String,
@@ -521,13 +499,7 @@ pub struct OutputFilenames {
521499
pub outputs: OutputTypes,
522500
}
523501

524-
impl_stable_hash_for!(struct self::OutputFilenames {
525-
out_directory,
526-
out_filestem,
527-
single_output_file,
528-
extra,
529-
outputs
530-
});
502+
impl_stable_hash_via_hash!(OutputFilenames);
531503

532504
pub const RUST_CGU_EXT: &str = "rcgu";
533505

src/librustc/session/filesearch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::fs;
1919
use std::path::{Path, PathBuf};
2020

2121
use session::search_paths::{SearchPaths, PathKind};
22-
use util::fs as rustcfs;
22+
use rustc_fs_util::fix_windows_verbatim_for_gcc;
2323

2424
#[derive(Copy, Clone)]
2525
pub enum FileMatch {
@@ -151,7 +151,7 @@ pub fn get_or_default_sysroot() -> PathBuf {
151151
// See comments on this target function, but the gist is that
152152
// gcc chokes on verbatim paths which fs::canonicalize generates
153153
// so we try to avoid those kinds of paths.
154-
Ok(canon) => Some(rustcfs::fix_windows_verbatim_for_gcc(&canon)),
154+
Ok(canon) => Some(fix_windows_verbatim_for_gcc(&canon)),
155155
Err(e) => bug!("failed to get realpath: {}", e),
156156
}
157157
})

src/librustc/session/mod.rs

+2-46
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ pub use self::code_stats::{DataTypeKind, SizeKind, FieldInfo, VariantInfo};
1212
use self::code_stats::CodeStats;
1313

1414
use hir::def_id::CrateNum;
15-
use ich::Fingerprint;
15+
use rustc_data_structures::fingerprint::Fingerprint;
1616

17-
use ich;
1817
use lint;
1918
use lint::builtin::BuiltinLintDiagnostics;
2019
use middle::allocator::AllocatorKind;
2120
use middle::dependency_format;
2221
use session::search_paths::PathKind;
2322
use session::config::{OutputType, Lto};
24-
use ty::tls;
2523
use util::nodemap::{FxHashMap, FxHashSet};
2624
use util::common::{duration_to_secs_str, ErrorReported};
2725
use util::common::ProfileQueriesMsg;
@@ -34,7 +32,6 @@ use errors::emitter::{Emitter, EmitterWriter};
3432
use syntax::edition::Edition;
3533
use syntax::json::JsonEmitter;
3634
use syntax::feature_gate;
37-
use syntax::symbol::Symbol;
3835
use syntax::parse;
3936
use syntax::parse::ParseSess;
4037
use syntax::{ast, codemap};
@@ -51,7 +48,6 @@ use std;
5148
use std::cell::{self, Cell, RefCell};
5249
use std::collections::HashMap;
5350
use std::env;
54-
use std::fmt;
5551
use std::io::Write;
5652
use std::path::{Path, PathBuf};
5753
use std::time::Duration;
@@ -128,9 +124,6 @@ pub struct Session {
128124

129125
incr_comp_session: OneThread<RefCell<IncrCompSession>>,
130126

131-
/// A cache of attributes ignored by StableHashingContext
132-
pub ignored_attr_names: FxHashSet<Symbol>,
133-
134127
/// Used by -Z profile-queries in util::common
135128
pub profile_channel: Lock<Option<mpsc::Sender<ProfileQueriesMsg>>>,
136129

@@ -1143,7 +1136,6 @@ pub fn build_session_(
11431136
injected_panic_runtime: Once::new(),
11441137
imported_macro_spans: OneThread::new(RefCell::new(HashMap::new())),
11451138
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
1146-
ignored_attr_names: ich::compute_ignored_attr_names(),
11471139
self_profiling: Lock::new(SelfProfiler::new()),
11481140
profile_channel: Lock::new(None),
11491141
perf_stats: PerfStats {
@@ -1235,7 +1227,7 @@ impl From<Fingerprint> for CrateDisambiguator {
12351227
}
12361228
}
12371229

1238-
impl_stable_hash_for!(tuple_struct CrateDisambiguator { fingerprint });
1230+
impl_stable_hash_via_hash!(CrateDisambiguator);
12391231

12401232
/// Holds data on the current incremental compilation session, if there is one.
12411233
#[derive(Debug)]
@@ -1307,39 +1299,3 @@ pub fn compile_result_from_err_count(err_count: usize) -> CompileResult {
13071299
Err(CompileIncomplete::Errored(ErrorReported))
13081300
}
13091301
}
1310-
1311-
#[cold]
1312-
#[inline(never)]
1313-
pub fn bug_fmt(file: &'static str, line: u32, args: fmt::Arguments) -> ! {
1314-
// this wrapper mostly exists so I don't have to write a fully
1315-
// qualified path of None::<Span> inside the bug!() macro definition
1316-
opt_span_bug_fmt(file, line, None::<Span>, args);
1317-
}
1318-
1319-
#[cold]
1320-
#[inline(never)]
1321-
pub fn span_bug_fmt<S: Into<MultiSpan>>(
1322-
file: &'static str,
1323-
line: u32,
1324-
span: S,
1325-
args: fmt::Arguments,
1326-
) -> ! {
1327-
opt_span_bug_fmt(file, line, Some(span), args);
1328-
}
1329-
1330-
fn opt_span_bug_fmt<S: Into<MultiSpan>>(
1331-
file: &'static str,
1332-
line: u32,
1333-
span: Option<S>,
1334-
args: fmt::Arguments,
1335-
) -> ! {
1336-
tls::with_opt(move |tcx| {
1337-
let msg = format!("{}:{}: {}", file, line, args);
1338-
match (tcx, span) {
1339-
(Some(tcx), Some(span)) => tcx.sess.diagnostic().span_bug(span, &msg),
1340-
(Some(tcx), None) => tcx.sess.diagnostic().bug(&msg),
1341-
(None, _) => panic!(msg),
1342-
}
1343-
});
1344-
unreachable!();
1345-
}

0 commit comments

Comments
 (0)