Skip to content

Commit 619ced0

Browse files
committed
Auto merge of #47087 - Zoxc:incr_no_in_ignore, r=michaelwoerister
Replace uses of DepGraph.in_ignore with DepGraph.with_ignore I currently plan to track tasks in thread local storage. Ignoring things in a closure ensures that the ignore tasks do not overlap the beginning or end of any other task. The TLS API will also use a closure to change a TLS value, so having the ignore task be a closure also helps there. It also adds `assert_ignored` which is used before a `TyCtxt` is created. Instead of adding a new ignore task this simply ensures that we are in a context where reads are ignored. r? @michaelwoerister
2 parents c9c2980 + 9508922 commit 619ced0

File tree

14 files changed

+273
-261
lines changed

14 files changed

+273
-261
lines changed

src/librustc/dep_graph/graph.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,22 @@ impl DepGraph {
141141
DepGraphQuery::new(&nodes[..], &edges[..])
142142
}
143143

144-
pub fn in_ignore<'graph>(&'graph self) -> Option<raii::IgnoreTask<'graph>> {
145-
self.data.as_ref().map(|data| raii::IgnoreTask::new(&data.current))
144+
pub fn assert_ignored(&self)
145+
{
146+
if let Some(ref data) = self.data {
147+
match data.current.borrow().task_stack.last() {
148+
Some(&OpenTask::Ignore) | None => {
149+
// ignored
150+
}
151+
_ => panic!("expected an ignore context")
152+
}
153+
}
146154
}
147155

148156
pub fn with_ignore<OP,R>(&self, op: OP) -> R
149157
where OP: FnOnce() -> R
150158
{
151-
let _task = self.in_ignore();
159+
let _task = self.data.as_ref().map(|data| raii::IgnoreTask::new(&data.current));
152160
op()
153161
}
154162

src/librustc/hir/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub fn lower_crate(sess: &Session,
180180
// We're constructing the HIR here; we don't care what we will
181181
// read, since we haven't even constructed the *input* to
182182
// incr. comp. yet.
183-
let _ignore = dep_graph.in_ignore();
183+
dep_graph.assert_ignored();
184184

185185
LoweringContext {
186186
crate_root: std_inject::injected_crate_name(),

src/librustc/hir/map/hir_id_validator.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ pub fn check_crate<'hir>(hir_map: &hir::map::Map<'hir>) {
2020
errors: vec![],
2121
};
2222

23-
hir_map.dep_graph.with_ignore(|| {
24-
hir_map.krate().visit_all_item_likes(&mut outer_visitor);
25-
if !outer_visitor.errors.is_empty() {
26-
let message = outer_visitor
27-
.errors
28-
.iter()
29-
.fold(String::new(), |s1, s2| s1 + "\n" + s2);
30-
bug!("{}", message);
31-
}
32-
});
23+
hir_map.dep_graph.assert_ignored();
24+
25+
hir_map.krate().visit_all_item_likes(&mut outer_visitor);
26+
if !outer_visitor.errors.is_empty() {
27+
let message = outer_visitor
28+
.errors
29+
.iter()
30+
.fold(String::new(), |s1, s2| s1 + "\n" + s2);
31+
bug!("{}", message);
32+
}
3333
}
3434

3535
struct HirIdValidator<'a, 'hir: 'a> {

src/librustc/ty/maps/on_disk_cache.rs

+126-126
Original file line numberDiff line numberDiff line change
@@ -165,113 +165,113 @@ impl<'sess> OnDiskCache<'sess> {
165165
where E: ty_codec::TyEncoder
166166
{
167167
// Serializing the DepGraph should not modify it:
168-
let _in_ignore = tcx.dep_graph.in_ignore();
169-
170-
// Allocate FileMapIndices
171-
let (file_to_file_index, file_index_to_stable_id) = {
172-
let mut file_to_file_index = FxHashMap();
173-
let mut file_index_to_stable_id = FxHashMap();
174-
175-
for (index, file) in tcx.sess.codemap().files().iter().enumerate() {
176-
let index = FileMapIndex(index as u32);
177-
let file_ptr: *const FileMap = &**file as *const _;
178-
file_to_file_index.insert(file_ptr, index);
179-
file_index_to_stable_id.insert(index, StableFilemapId::new(&file));
180-
}
181-
182-
(file_to_file_index, file_index_to_stable_id)
183-
};
184-
185-
let mut encoder = CacheEncoder {
186-
tcx,
187-
encoder,
188-
type_shorthands: FxHashMap(),
189-
predicate_shorthands: FxHashMap(),
190-
expn_info_shorthands: FxHashMap(),
191-
codemap: CachingCodemapView::new(tcx.sess.codemap()),
192-
file_to_file_index,
193-
};
194-
195-
// Load everything into memory so we can write it out to the on-disk
196-
// cache. The vast majority of cacheable query results should already
197-
// be in memory, so this should be a cheap operation.
198-
tcx.dep_graph.exec_cache_promotions(tcx);
199-
200-
// Encode query results
201-
let mut query_result_index = EncodedQueryResultIndex::new();
202-
203-
{
204-
use ty::maps::queries::*;
205-
let enc = &mut encoder;
206-
let qri = &mut query_result_index;
207-
208-
// Encode TypeckTables
209-
encode_query_results::<typeck_tables_of, _>(tcx, enc, qri)?;
210-
encode_query_results::<optimized_mir, _>(tcx, enc, qri)?;
211-
encode_query_results::<unsafety_check_result, _>(tcx, enc, qri)?;
212-
encode_query_results::<borrowck, _>(tcx, enc, qri)?;
213-
encode_query_results::<mir_borrowck, _>(tcx, enc, qri)?;
214-
encode_query_results::<mir_const_qualif, _>(tcx, enc, qri)?;
215-
encode_query_results::<def_symbol_name, _>(tcx, enc, qri)?;
216-
encode_query_results::<const_is_rvalue_promotable_to_static, _>(tcx, enc, qri)?;
217-
encode_query_results::<contains_extern_indicator, _>(tcx, enc, qri)?;
218-
encode_query_results::<symbol_name, _>(tcx, enc, qri)?;
219-
encode_query_results::<trans_fulfill_obligation, _>(tcx, enc, qri)?;
220-
encode_query_results::<check_match, _>(tcx, enc, qri)?;
221-
}
168+
tcx.dep_graph.with_ignore(|| {
169+
// Allocate FileMapIndices
170+
let (file_to_file_index, file_index_to_stable_id) = {
171+
let mut file_to_file_index = FxHashMap();
172+
let mut file_index_to_stable_id = FxHashMap();
173+
174+
for (index, file) in tcx.sess.codemap().files().iter().enumerate() {
175+
let index = FileMapIndex(index as u32);
176+
let file_ptr: *const FileMap = &**file as *const _;
177+
file_to_file_index.insert(file_ptr, index);
178+
file_index_to_stable_id.insert(index, StableFilemapId::new(&file));
179+
}
222180

223-
// Encode diagnostics
224-
let diagnostics_index = {
225-
let mut diagnostics_index = EncodedDiagnosticsIndex::new();
226-
227-
for (dep_node_index, diagnostics) in self.current_diagnostics
228-
.borrow()
229-
.iter() {
230-
let pos = AbsoluteBytePos::new(encoder.position());
231-
// Let's make sure we get the expected type here:
232-
let diagnostics: &EncodedDiagnostics = diagnostics;
233-
let dep_node_index =
234-
SerializedDepNodeIndex::new(dep_node_index.index());
235-
encoder.encode_tagged(dep_node_index, diagnostics)?;
236-
diagnostics_index.push((dep_node_index, pos));
181+
(file_to_file_index, file_index_to_stable_id)
182+
};
183+
184+
let mut encoder = CacheEncoder {
185+
tcx,
186+
encoder,
187+
type_shorthands: FxHashMap(),
188+
predicate_shorthands: FxHashMap(),
189+
expn_info_shorthands: FxHashMap(),
190+
codemap: CachingCodemapView::new(tcx.sess.codemap()),
191+
file_to_file_index,
192+
};
193+
194+
// Load everything into memory so we can write it out to the on-disk
195+
// cache. The vast majority of cacheable query results should already
196+
// be in memory, so this should be a cheap operation.
197+
tcx.dep_graph.exec_cache_promotions(tcx);
198+
199+
// Encode query results
200+
let mut query_result_index = EncodedQueryResultIndex::new();
201+
202+
{
203+
use ty::maps::queries::*;
204+
let enc = &mut encoder;
205+
let qri = &mut query_result_index;
206+
207+
// Encode TypeckTables
208+
encode_query_results::<typeck_tables_of, _>(tcx, enc, qri)?;
209+
encode_query_results::<optimized_mir, _>(tcx, enc, qri)?;
210+
encode_query_results::<unsafety_check_result, _>(tcx, enc, qri)?;
211+
encode_query_results::<borrowck, _>(tcx, enc, qri)?;
212+
encode_query_results::<mir_borrowck, _>(tcx, enc, qri)?;
213+
encode_query_results::<mir_const_qualif, _>(tcx, enc, qri)?;
214+
encode_query_results::<def_symbol_name, _>(tcx, enc, qri)?;
215+
encode_query_results::<const_is_rvalue_promotable_to_static, _>(tcx, enc, qri)?;
216+
encode_query_results::<contains_extern_indicator, _>(tcx, enc, qri)?;
217+
encode_query_results::<symbol_name, _>(tcx, enc, qri)?;
218+
encode_query_results::<trans_fulfill_obligation, _>(tcx, enc, qri)?;
219+
encode_query_results::<check_match, _>(tcx, enc, qri)?;
237220
}
238221

239-
diagnostics_index
240-
};
222+
// Encode diagnostics
223+
let diagnostics_index = {
224+
let mut diagnostics_index = EncodedDiagnosticsIndex::new();
225+
226+
for (dep_node_index, diagnostics) in self.current_diagnostics
227+
.borrow()
228+
.iter() {
229+
let pos = AbsoluteBytePos::new(encoder.position());
230+
// Let's make sure we get the expected type here:
231+
let diagnostics: &EncodedDiagnostics = diagnostics;
232+
let dep_node_index =
233+
SerializedDepNodeIndex::new(dep_node_index.index());
234+
encoder.encode_tagged(dep_node_index, diagnostics)?;
235+
diagnostics_index.push((dep_node_index, pos));
236+
}
241237

242-
let sorted_cnums = sorted_cnums_including_local_crate(tcx);
243-
let prev_cnums: Vec<_> = sorted_cnums.iter().map(|&cnum| {
244-
let crate_name = tcx.original_crate_name(cnum).as_str().to_string();
245-
let crate_disambiguator = tcx.crate_disambiguator(cnum);
246-
(cnum.as_u32(), crate_name, crate_disambiguator)
247-
}).collect();
248-
249-
// Encode the file footer
250-
let footer_pos = encoder.position() as u64;
251-
encoder.encode_tagged(TAG_FILE_FOOTER, &Footer {
252-
file_index_to_stable_id,
253-
prev_cnums,
254-
query_result_index,
255-
diagnostics_index,
256-
})?;
257-
258-
// Encode the position of the footer as the last 8 bytes of the
259-
// file so we know where to look for it.
260-
IntEncodedWithFixedSize(footer_pos).encode(encoder.encoder)?;
261-
262-
// DO NOT WRITE ANYTHING TO THE ENCODER AFTER THIS POINT! The address
263-
// of the footer must be the last thing in the data stream.
264-
265-
return Ok(());
266-
267-
fn sorted_cnums_including_local_crate(tcx: TyCtxt) -> Vec<CrateNum> {
268-
let mut cnums = vec![LOCAL_CRATE];
269-
cnums.extend_from_slice(&tcx.crates()[..]);
270-
cnums.sort_unstable();
271-
// Just to be sure...
272-
cnums.dedup();
273-
cnums
274-
}
238+
diagnostics_index
239+
};
240+
241+
let sorted_cnums = sorted_cnums_including_local_crate(tcx);
242+
let prev_cnums: Vec<_> = sorted_cnums.iter().map(|&cnum| {
243+
let crate_name = tcx.original_crate_name(cnum).as_str().to_string();
244+
let crate_disambiguator = tcx.crate_disambiguator(cnum);
245+
(cnum.as_u32(), crate_name, crate_disambiguator)
246+
}).collect();
247+
248+
// Encode the file footer
249+
let footer_pos = encoder.position() as u64;
250+
encoder.encode_tagged(TAG_FILE_FOOTER, &Footer {
251+
file_index_to_stable_id,
252+
prev_cnums,
253+
query_result_index,
254+
diagnostics_index,
255+
})?;
256+
257+
// Encode the position of the footer as the last 8 bytes of the
258+
// file so we know where to look for it.
259+
IntEncodedWithFixedSize(footer_pos).encode(encoder.encoder)?;
260+
261+
// DO NOT WRITE ANYTHING TO THE ENCODER AFTER THIS POINT! The address
262+
// of the footer must be the last thing in the data stream.
263+
264+
return Ok(());
265+
266+
fn sorted_cnums_including_local_crate(tcx: TyCtxt) -> Vec<CrateNum> {
267+
let mut cnums = vec![LOCAL_CRATE];
268+
cnums.extend_from_slice(&tcx.crates()[..]);
269+
cnums.sort_unstable();
270+
// Just to be sure...
271+
cnums.dedup();
272+
cnums
273+
}
274+
})
275275
}
276276

277277
/// Load a diagnostic emitted during the previous compilation session.
@@ -380,30 +380,30 @@ impl<'sess> OnDiskCache<'sess> {
380380
prev_cnums: &[(u32, String, CrateDisambiguator)])
381381
-> IndexVec<CrateNum, Option<CrateNum>>
382382
{
383-
let _in_ignore = tcx.dep_graph.in_ignore();
384-
385-
let current_cnums = tcx.all_crate_nums(LOCAL_CRATE).iter().map(|&cnum| {
386-
let crate_name = tcx.original_crate_name(cnum)
387-
.as_str()
388-
.to_string();
389-
let crate_disambiguator = tcx.crate_disambiguator(cnum);
390-
((crate_name, crate_disambiguator), cnum)
391-
}).collect::<FxHashMap<_,_>>();
392-
393-
let map_size = prev_cnums.iter()
394-
.map(|&(cnum, ..)| cnum)
395-
.max()
396-
.unwrap_or(0) + 1;
397-
let mut map = IndexVec::new();
398-
map.resize(map_size as usize, None);
399-
400-
for &(prev_cnum, ref crate_name, crate_disambiguator) in prev_cnums {
401-
let key = (crate_name.clone(), crate_disambiguator);
402-
map[CrateNum::from_u32(prev_cnum)] = current_cnums.get(&key).cloned();
403-
}
383+
tcx.dep_graph.with_ignore(|| {
384+
let current_cnums = tcx.all_crate_nums(LOCAL_CRATE).iter().map(|&cnum| {
385+
let crate_name = tcx.original_crate_name(cnum)
386+
.as_str()
387+
.to_string();
388+
let crate_disambiguator = tcx.crate_disambiguator(cnum);
389+
((crate_name, crate_disambiguator), cnum)
390+
}).collect::<FxHashMap<_,_>>();
391+
392+
let map_size = prev_cnums.iter()
393+
.map(|&(cnum, ..)| cnum)
394+
.max()
395+
.unwrap_or(0) + 1;
396+
let mut map = IndexVec::new();
397+
map.resize(map_size as usize, None);
398+
399+
for &(prev_cnum, ref crate_name, crate_disambiguator) in prev_cnums {
400+
let key = (crate_name.clone(), crate_disambiguator);
401+
map[CrateNum::from_u32(prev_cnum)] = current_cnums.get(&key).cloned();
402+
}
404403

405-
map[LOCAL_CRATE] = Some(LOCAL_CRATE);
406-
map
404+
map[LOCAL_CRATE] = Some(LOCAL_CRATE);
405+
map
406+
})
407407
}
408408
}
409409

src/librustc_driver/driver.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub fn compile_input(sess: &Session,
191191
|| hir_map::map_crate(sess, cstore, &mut hir_forest, &defs));
192192

193193
{
194-
let _ignore = hir_map.dep_graph.in_ignore();
194+
hir_map.dep_graph.assert_ignored();
195195
controller_entry_point!(after_hir_lowering,
196196
sess,
197197
CompileState::state_after_hir_lowering(input,
@@ -233,18 +233,18 @@ pub fn compile_input(sess: &Session,
233233
|tcx, analysis, rx, result| {
234234
{
235235
// Eventually, we will want to track plugins.
236-
let _ignore = tcx.dep_graph.in_ignore();
237-
238-
let mut state = CompileState::state_after_analysis(input,
239-
sess,
240-
outdir,
241-
output,
242-
opt_crate,
243-
tcx.hir.krate(),
244-
&analysis,
245-
tcx,
246-
&crate_name);
247-
(control.after_analysis.callback)(&mut state);
236+
tcx.dep_graph.with_ignore(|| {
237+
let mut state = CompileState::state_after_analysis(input,
238+
sess,
239+
outdir,
240+
output,
241+
opt_crate,
242+
tcx.hir.krate(),
243+
&analysis,
244+
tcx,
245+
&crate_name);
246+
(control.after_analysis.callback)(&mut state);
247+
});
248248

249249
if control.after_analysis.stop == Compilation::Stop {
250250
return result.and_then(|_| Err(CompileIncomplete::Stopped));

src/librustc_driver/pretty.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ impl PpSourceMode {
243243
tcx,
244244
tables: Cell::new(&empty_tables)
245245
};
246-
let _ignore = tcx.dep_graph.in_ignore();
247-
f(&annotation, hir_map.forest.krate())
246+
tcx.dep_graph.with_ignore(|| {
247+
f(&annotation, hir_map.forest.krate())
248+
})
248249
}),
249250
sess)
250251
}

0 commit comments

Comments
 (0)