Store crate_disambiguator as an InternedString

We used to use `Name`, but the session outlives the tokenizer, which
means that attempts to read this field after trans has complete
otherwise panic. All reads want an `InternedString` anyhow.
This commit is contained in:
Niko Matsakis 2016-07-21 12:41:29 -04:00
parent 2b38c4bdea
commit ffc13b2f80
6 changed files with 14 additions and 10 deletions

View File

@ -80,7 +80,7 @@ pub struct Session {
// forms a unique global identifier for the crate. It is used to allow
// multiple crates with the same name to coexist. See the
// trans::back::symbol_names module for more information.
pub crate_disambiguator: Cell<ast::Name>,
pub crate_disambiguator: RefCell<token::InternedString>,
pub features: RefCell<feature_gate::Features>,
/// The maximum recursion limit for potentially infinitely recursive
@ -106,6 +106,9 @@ pub struct Session {
}
impl Session {
pub fn local_crate_disambiguator(&self) -> token::InternedString {
self.crate_disambiguator.borrow().clone()
}
pub fn struct_span_warn<'a, S: Into<MultiSpan>>(&'a self,
sp: S,
msg: &str)
@ -438,7 +441,7 @@ pub fn build_session_(sopts: config::Options,
plugin_attributes: RefCell::new(Vec::new()),
crate_types: RefCell::new(Vec::new()),
dependency_formats: RefCell::new(FnvHashMap()),
crate_disambiguator: Cell::new(token::intern("")),
crate_disambiguator: RefCell::new(token::intern("").as_str()),
features: RefCell::new(feature_gate::Features::new()),
recursion_limit: Cell::new(64),
next_node_id: Cell::new(1),

View File

@ -504,7 +504,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn crate_disambiguator(self, cnum: ast::CrateNum) -> token::InternedString {
if cnum == LOCAL_CRATE {
self.sess.crate_disambiguator.get().as_str()
self.sess.local_crate_disambiguator()
} else {
self.sess.cstore.crate_disambiguator(cnum)
}

View File

@ -566,7 +566,8 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
});
*sess.crate_types.borrow_mut() = collect_crate_types(sess, &krate.attrs);
sess.crate_disambiguator.set(token::intern(&compute_crate_disambiguator(sess)));
*sess.crate_disambiguator.borrow_mut() =
token::intern(&compute_crate_disambiguator(sess)).as_str();
time(time_passes, "recursion limit", || {
middle::recursion_limit::update_recursion_limit(sess, &krate);

View File

@ -36,7 +36,7 @@ impl<'a, 'tcx> SvhCalculate for TyCtxt<'a, 'tcx, 'tcx> {
// to ensure it is not incorporating implementation artifacts into
// the hash that are not otherwise visible.)
let crate_disambiguator = self.sess.crate_disambiguator.get();
let crate_disambiguator = self.sess.local_crate_disambiguator();
let krate = self.map.krate();
// FIXME: this should use SHA1, not SipHash. SipHash is not built to
@ -47,10 +47,10 @@ impl<'a, 'tcx> SvhCalculate for TyCtxt<'a, 'tcx, 'tcx> {
// FIXME(#32753) -- at (*) we `to_le` for endianness, but is
// this enough, and does it matter anyway?
"crate_disambiguator".hash(&mut state);
crate_disambiguator.as_str().len().to_le().hash(&mut state); // (*)
crate_disambiguator.as_str().hash(&mut state);
crate_disambiguator.len().to_le().hash(&mut state); // (*)
crate_disambiguator.hash(&mut state);
debug!("crate_disambiguator: {:?}", crate_disambiguator.as_str());
debug!("crate_disambiguator: {:?}", crate_disambiguator);
debug!("state: {:?}", state);
{

View File

@ -243,7 +243,7 @@ impl<'a> CrateReader<'a> {
// Check for (potential) conflicts with the local crate
if self.local_crate_name == crate_name &&
self.sess.crate_disambiguator.get().as_str() == disambiguator {
self.sess.local_crate_disambiguator() == disambiguator {
span_fatal!(self.sess, span, E0519,
"the current crate is indistinguishable from one of its \
dependencies: it has the same crate-name `{}` and was \

View File

@ -1893,7 +1893,7 @@ fn encode_metadata_inner(rbml_w: &mut Encoder,
encode_crate_name(rbml_w, &ecx.link_meta.crate_name);
encode_crate_triple(rbml_w, &ecx.tcx.sess.opts.target_triple);
encode_hash(rbml_w, &ecx.link_meta.crate_hash);
encode_crate_disambiguator(rbml_w, &ecx.tcx.sess.crate_disambiguator.get().as_str());
encode_crate_disambiguator(rbml_w, &ecx.tcx.sess.local_crate_disambiguator());
encode_dylib_dependency_formats(rbml_w, &ecx);
encode_panic_strategy(rbml_w, &ecx);