Skip to content

Commit ceeb158

Browse files
committed
Address mw nits
1 parent 08a72d2 commit ceeb158

File tree

11 files changed

+54
-57
lines changed

11 files changed

+54
-57
lines changed

src/librustc/dep_graph/graph.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ pub struct DepGraph {
2525
}
2626

2727
struct DepGraphData {
28-
/// we send messages to the thread to let it build up the dep-graph
29-
/// from the current run
28+
/// We send messages to the thread to let it build up the dep-graph
29+
/// from the current run.
3030
thread: DepGraphThreadData,
3131

32-
/// when we load, there may be `.o` files, cached mir, or other such
32+
/// When we load, there may be `.o` files, cached mir, or other such
3333
/// things available to us. If we find that they are not dirty, we
3434
/// load the path to the file storing those work-products here into
3535
/// this map. We can later look for and extract that data.
3636
previous_work_products: RefCell<FnvHashMap<Arc<WorkProductId>, WorkProduct>>,
3737

38-
/// work-products that we generate in this run
38+
/// Work-products that we generate in this run.
3939
work_products: RefCell<FnvHashMap<Arc<WorkProductId>, WorkProduct>>,
4040
}
4141

@@ -132,7 +132,7 @@ impl DepGraph {
132132
/// Each work product is associated with a dep-node, representing the
133133
/// process that produced the work-product. If that dep-node is found
134134
/// to be dirty when we load up, then we will delete the work-product
135-
/// at load time. If the work-product is found to be clean, the we
135+
/// at load time. If the work-product is found to be clean, then we
136136
/// will keep a record in the `previous_work_products` list.
137137
///
138138
/// In addition, work products have an associated hash. This hash is

src/librustc/util/fs.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
use std::path::{self, Path, PathBuf};
1212
use std::ffi::OsString;
13+
use std::fs;
14+
use std::io;
1315

1416
// Unfortunately, on windows, it looks like msvcrt.dll is silently translating
1517
// verbatim paths under the hood to non-verbatim paths! This manifests itself as
@@ -53,3 +55,15 @@ pub fn fix_windows_verbatim_for_gcc(p: &Path) -> PathBuf {
5355
_ => p.to_path_buf(),
5456
}
5557
}
58+
59+
/// Copy `p` into `q`, preferring to use hard-linking if possible. If
60+
/// `q` already exists, it is removed first.
61+
pub fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(p: P, q: Q) -> io::Result<()> {
62+
let p = p.as_ref();
63+
let q = q.as_ref();
64+
if q.exists() {
65+
try!(fs::remove_file(&q));
66+
}
67+
fs::hard_link(p, q)
68+
.or_else(|_| fs::copy(p, q).map(|_| ()))
69+
}

src/librustc_driver/driver.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn compile_input(sess: &Session,
8888
// We need nested scopes here, because the intermediate results can keep
8989
// large chunks of memory alive and we want to free them as soon as
9090
// possible to keep the peak memory usage low
91-
let (outputs, trans, id) = {
91+
let (outputs, trans, crate_name) = {
9292
let krate = match phase_1_parse_input(sess, cfg, input) {
9393
Ok(krate) => krate,
9494
Err(mut parse_error) => {
@@ -113,21 +113,21 @@ pub fn compile_input(sess: &Session,
113113
};
114114

115115
let outputs = build_output_filenames(input, outdir, output, &krate.attrs, sess);
116-
let id = link::find_crate_name(Some(sess), &krate.attrs, input);
116+
let crate_name = link::find_crate_name(Some(sess), &krate.attrs, input);
117117
let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
118118
phase_2_configure_and_expand(
119-
sess, &cstore, krate, &id, addl_plugins, control.make_glob_map,
119+
sess, &cstore, krate, &crate_name, addl_plugins, control.make_glob_map,
120120
|expanded_crate| {
121121
let mut state = CompileState::state_after_expand(
122-
input, sess, outdir, output, &cstore, expanded_crate, &id,
122+
input, sess, outdir, output, &cstore, expanded_crate, &crate_name,
123123
);
124124
controller_entry_point!(after_expand, sess, state, Ok(()));
125125
Ok(())
126126
}
127127
)?
128128
};
129129

130-
write_out_deps(sess, &outputs, &id);
130+
write_out_deps(sess, &outputs, &crate_name);
131131

132132
let arenas = ty::CtxtArenas::new();
133133

@@ -151,7 +151,7 @@ pub fn compile_input(sess: &Session,
151151
&resolutions,
152152
&expanded_crate,
153153
&hir_map.krate(),
154-
&id),
154+
&crate_name),
155155
Ok(()));
156156
}
157157

@@ -171,7 +171,7 @@ pub fn compile_input(sess: &Session,
171171
analysis,
172172
resolutions,
173173
&arenas,
174-
&id,
174+
&crate_name,
175175
|tcx, mir_map, analysis, result| {
176176
{
177177
// Eventually, we will want to track plugins.
@@ -186,7 +186,7 @@ pub fn compile_input(sess: &Session,
186186
&analysis,
187187
mir_map.as_ref(),
188188
tcx,
189-
&id);
189+
&crate_name);
190190
(control.after_analysis.callback)(&mut state);
191191

192192
if control.after_analysis.stop == Compilation::Stop {
@@ -212,11 +212,11 @@ pub fn compile_input(sess: &Session,
212212
// Discard interned strings as they are no longer required.
213213
token::clear_ident_interner();
214214

215-
Ok((outputs, trans, id.clone()))
215+
Ok((outputs, trans, crate_name.clone()))
216216
})??
217217
};
218218

219-
let phase5_result = phase_5_run_llvm_passes(sess, &id, &trans, &outputs);
219+
let phase5_result = phase_5_run_llvm_passes(sess, &crate_name, &trans, &outputs);
220220

221221
controller_entry_point!(after_llvm,
222222
sess,
@@ -1069,14 +1069,14 @@ fn escape_dep_filename(filename: &str) -> String {
10691069
filename.replace(" ", "\\ ")
10701070
}
10711071

1072-
fn write_out_deps(sess: &Session, outputs: &OutputFilenames, id: &str) {
1072+
fn write_out_deps(sess: &Session, outputs: &OutputFilenames, crate_name: &str) {
10731073
let mut out_filenames = Vec::new();
10741074
for output_type in sess.opts.output_types.keys() {
10751075
let file = outputs.path(*output_type);
10761076
match *output_type {
10771077
OutputType::Exe => {
10781078
for output in sess.crate_types.borrow().iter() {
1079-
let p = link::filename_for_input(sess, *output, id, outputs);
1079+
let p = link::filename_for_input(sess, *output, crate_name, outputs);
10801080
out_filenames.push(p);
10811081
}
10821082
}

src/librustc_incremental/persist/load.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ fn load_dep_graph_if_exists<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
6363

6464
match decode_dep_graph(tcx, &dep_graph_data, &work_products_data) {
6565
Ok(()) => return,
66-
Err(err) => bug!("decoding error in dep-graph from `{}` and `{}`: {}",
66+
Err(err) => {
67+
tcx.sess.warn(
68+
&format!("decoding error in dep-graph from `{}` and `{}`: {}",
6769
dep_graph_path.display(),
6870
work_products_path.display(),
69-
err),
71+
err));
72+
}
7073
}
7174
}
7275

@@ -94,9 +97,7 @@ fn load_data(sess: &Session, path: &Path) -> Option<Vec<u8>> {
9497
}
9598

9699
/// Decode the dep graph and load the edges/nodes that are still clean
97-
/// into `tcx.dep_graph`. On success, returns a hashset containing all
98-
/// the paths of work-products from clean nodes (any work-products not
99-
/// in this set can be deleted).
100+
/// into `tcx.dep_graph`.
100101
pub fn decode_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
101102
dep_graph_data: &[u8],
102103
work_products_data: &[u8])

src/librustc_incremental/persist/work_product.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use persist::util::*;
1414
use rustc::dep_graph::{WorkProduct, WorkProductId};
1515
use rustc::session::Session;
16+
use rustc::util::fs::link_or_copy;
1617
use std::fs;
1718
use std::path::Path;
1819
use std::sync::Arc;
@@ -39,10 +40,7 @@ pub fn save_trans_partition(sess: &Session,
3940
let _ = fs::remove_file(&path_in_incr_dir);
4041
}
4142

42-
match
43-
fs::hard_link(path_to_obj_file, &path_in_incr_dir)
44-
.or_else(|_| fs::copy(path_to_obj_file, &path_in_incr_dir).map(|_| ()))
45-
{
43+
match link_or_copy(path_to_obj_file, &path_in_incr_dir) {
4644
Ok(_) => {
4745
let work_product = WorkProduct {
4846
input_hash: partition_hash,

src/librustc_trans/back/write.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ use llvm::SMDiagnosticRef;
2020
use {CrateTranslation, ModuleLlvm, ModuleSource, ModuleTranslation};
2121
use util::common::time;
2222
use util::common::path2cstr;
23+
use util::fs::link_or_copy;
2324
use errors::{self, Handler, Level, DiagnosticBuilder};
2425
use errors::emitter::Emitter;
2526
use syntax_pos::MultiSpan;
2627

2728
use std::collections::HashMap;
2829
use std::ffi::{CStr, CString};
2930
use std::fs;
30-
use std::io;
3131
use std::path::{Path, PathBuf};
3232
use std::str;
3333
use std::sync::{Arc, Mutex};
@@ -929,16 +929,6 @@ fn build_work_item(sess: &Session,
929929
}
930930
}
931931

932-
fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(p: P, q: Q) -> io::Result<()> {
933-
let p = p.as_ref();
934-
let q = q.as_ref();
935-
if q.exists() {
936-
try!(fs::remove_file(&q));
937-
}
938-
fs::hard_link(p, q)
939-
.or_else(|_| fs::copy(p, q).map(|_| ()))
940-
}
941-
942932
fn execute_work_item(cgcx: &CodegenContext,
943933
work_item: WorkItem) {
944934
unsafe {

src/librustc_trans/base.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,12 +2262,20 @@ fn write_metadata(cx: &SharedCrateContext,
22622262

22632263
/// Find any symbols that are defined in one compilation unit, but not declared
22642264
/// in any other compilation unit. Give these symbols internal linkage.
2265-
fn internalize_symbols<'a, 'tcx>(ccxs: &CrateContextList<'a, 'tcx>,
2265+
fn internalize_symbols<'a, 'tcx>(sess: &Session,
2266+
ccxs: &CrateContextList<'a, 'tcx>,
22662267
symbol_map: &SymbolMap<'tcx>,
22672268
reachable: &FnvHashSet<&str>) {
22682269
let scx = ccxs.shared();
22692270
let tcx = scx.tcx();
22702271

2272+
// In incr. comp. mode, we can't necessarily see all refs since we
2273+
// don't generate LLVM IR for reused modules, so skip this
2274+
// step. Later we should get smarter.
2275+
if sess.opts.debugging_opts.incremental.is_some() {
2276+
return;
2277+
}
2278+
22712279
// 'unsafe' because we are holding on to CStr's from the LLVM module within
22722280
// this block.
22732281
unsafe {
@@ -2682,7 +2690,8 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
26822690
}
26832691

26842692
time(shared_ccx.sess().time_passes(), "internalize symbols", || {
2685-
internalize_symbols(&crate_context_list,
2693+
internalize_symbols(sess,
2694+
&crate_context_list,
26862695
&symbol_map,
26872696
&reachable_symbols.iter()
26882697
.map(|s| &s[..])

src/librustc_trans/partitioning.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
362362
if codegen_units.is_empty() {
363363
let codegen_unit_name = InternedString::new(FALLBACK_CODEGEN_UNIT);
364364
codegen_units.entry(codegen_unit_name.clone())
365-
.or_insert_with(|| CodegenUnit::new(codegen_unit_name.clone(),
366-
FnvHashMap()));
365+
.or_insert_with(|| CodegenUnit::empty(codegen_unit_name.clone()));
367366
}
368367

369368
PreInliningPartitioning {

src/librustc_trans/trans_item.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,8 @@ impl<'a, 'tcx> TransItem<'tcx> {
104104
}
105105
}
106106
TransItem::Fn(instance) => {
107-
let _task;
108-
109-
if instance.def.is_local() {
110-
_task = ccx.tcx().dep_graph.in_task(
111-
DepNode::TransCrateItem(instance.def)); // (*)
112-
}
107+
let _task = ccx.tcx().dep_graph.in_task(
108+
DepNode::TransCrateItem(instance.def)); // (*)
113109

114110
base::trans_instance(&ccx, instance);
115111
}

src/test/incremental/spike-neg1.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,10 @@ mod x {
3939
X { x: 11, y: 11 }
4040
}
4141

42-
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
43-
#[rustc_clean(label="ItemSignature", cfg="rpass2")]
4442
pub fn new() -> X {
4543
make()
4644
}
4745

48-
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
49-
#[rustc_clean(label="ItemSignature", cfg="rpass2")]
5046
pub fn sum(x: &X) -> u32 {
5147
x.x + x.y
5248
}
@@ -55,7 +51,6 @@ mod x {
5551
mod y {
5652
use x;
5753

58-
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
5954
pub fn assert_sum() -> bool {
6055
let x = x::new();
6156
x::sum(&x) == 22

src/test/incremental/spike-neg2.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,10 @@ mod x {
3939
X { x: 11, y: 11 }
4040
}
4141

42-
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
43-
#[rustc_clean(label="ItemSignature", cfg="rpass2")]
4442
pub fn new() -> X {
4543
make()
4644
}
4745

48-
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
49-
#[rustc_clean(label="ItemSignature", cfg="rpass2")]
5046
pub fn sum(x: &X) -> u32 {
5147
x.x + x.y
5248
}
@@ -55,7 +51,6 @@ mod x {
5551
mod y {
5652
use x;
5753

58-
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
5954
pub fn assert_sum() -> bool {
6055
let x = x::new();
6156
x::sum(&x) == 22

0 commit comments

Comments
 (0)