Skip to content

Commit 499484f

Browse files
authored
Auto merge of #35684 - nikomatsakis:incr-comp-metadata-audit-35111, r=mw
Restructure metadata encoder to track deps precisely This issue restructures meta-data encoding to track dependencies very precisely. It uses a cute technique I hope to spread elsewhere, where we can guard the data flowing into a new dep-graph task and ensure that it is not "leaking" information from the outside, which would result in missing edges. There are no tests because we don't know of any bugs in the old system, but it's clear that there was leaked data. The commit series is standalone, but the refactorings are kind of "windy". It's a good idea to read the comment in `src/librustc_metadata/index_builder.rs` to get a feeling for the overall strategy I was aiming at. In several cases, I wound up adding some extra hashtable lookups, I think primarily for looking up `AdtDef` instances. We could remove these by implementing `DepGraphRead` for an `AdtDef` and then having it register a read to the adt-defs table, I guess, but I doubt it is really noticeable. Eventually I think I'd like to extend this pattern to the dep-graph more generally, since it effectively guarantees that data cannot leak. Fixes #35111. r? @michaelwoerister
2 parents 43c090e + 37d974f commit 499484f

File tree

4 files changed

+1217
-959
lines changed

4 files changed

+1217
-959
lines changed

src/librustc_metadata/decoder.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,10 @@ fn reexports<'a>(d: rbml::Doc<'a>) -> reader::TaggedDocsIterator<'a> {
240240
reader::tagged_docs(d, tag_items_data_item_reexport)
241241
}
242242

243-
fn variant_disr_val(d: rbml::Doc) -> Option<u64> {
244-
reader::maybe_get_doc(d, tag_disr_val).and_then(|val_doc| {
245-
reader::with_doc_data(val_doc, |data| {
246-
str::from_utf8(data).ok().and_then(|s| s.parse().ok())
247-
})
243+
fn variant_disr_val(d: rbml::Doc) -> u64 {
244+
let val_doc = reader::get_doc(d, tag_disr_val);
245+
reader::with_doc_data(val_doc, |data| {
246+
str::from_utf8(data).unwrap().parse().unwrap()
248247
})
249248
}
250249

@@ -402,17 +401,10 @@ pub fn get_adt_def<'a, 'tcx>(cdata: Cmd,
402401
}
403402
}
404403
fn get_enum_variants<'tcx>(cdata: Cmd, doc: rbml::Doc) -> Vec<ty::VariantDefData<'tcx, 'tcx>> {
405-
let mut disr_val = 0;
406404
reader::tagged_docs(doc, tag_items_data_item_variant).map(|p| {
407405
let did = translated_def_id(cdata, p);
408406
let item = cdata.lookup_item(did.index);
409-
410-
if let Some(disr) = variant_disr_val(item) {
411-
disr_val = disr;
412-
}
413-
let disr = disr_val;
414-
disr_val = disr_val.wrapping_add(1);
415-
407+
let disr = variant_disr_val(item);
416408
ty::VariantDefData {
417409
did: did,
418410
name: item_name(item),

0 commit comments

Comments
 (0)