expanding a def-id is not a read

Across crates only, converting a def-id into its def-key or def-path was
considered a read. This caused spurious reads when computing the symbol
name for some item.
This commit is contained in:
Niko Matsakis 2016-09-02 08:26:36 -04:00
parent 2f91ba05fd
commit fe6557eb62
3 changed files with 56 additions and 2 deletions

View File

@ -425,13 +425,21 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
/// parent `DefId` as well as some idea of what kind of data the
/// `DefId` refers to.
fn def_key(&self, def: DefId) -> hir_map::DefKey {
self.dep_graph.read(DepNode::MetaData(def));
// Note: loading the def-key (or def-path) for a def-id is not
// a *read* of its metadata. This is because the def-id is
// really just an interned shorthand for a def-path, which is the
// canonical name for an item.
//
// self.dep_graph.read(DepNode::MetaData(def));
let cdata = self.get_crate_data(def.krate);
decoder::def_key(&cdata, def.index)
}
fn relative_def_path(&self, def: DefId) -> hir_map::DefPath {
self.dep_graph.read(DepNode::MetaData(def));
// See `Note` above in `def_key()` for why this read is
// commented out:
//
// self.dep_graph.read(DepNode::MetaData(def));
let cdata = self.get_crate_data(def.krate);
decoder::def_path(&cdata, def.index)
}

View File

@ -0,0 +1,18 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(warnings)]
#![crate_name = "a"]
#![crate_type = "rlib"]
pub fn foo(b: u8) -> u32 { b as u32 }
#[cfg(rpass1)]
fn bar() { }

View File

@ -0,0 +1,28 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test that we are able to reuse `main` even though a private
// item was removed from the root module of crate`a`.
// revisions:rpass1 rpass2
// aux-build:a.rs
#![feature(rustc_attrs)]
#![crate_type = "bin"]
#![rustc_partition_reused(module="main", cfg="rpass2")]
extern crate a;
pub fn main() {
let vec: Vec<u8> = vec![0, 1, 2, 3];
for &b in &vec {
println!("{}", a::foo(b));
}
}