Skip to content

Commit ffc13b2

Browse files
committed
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.
1 parent 2b38c4b commit ffc13b2

File tree

6 files changed

+14
-10
lines changed

6 files changed

+14
-10
lines changed

src/librustc/session/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub struct Session {
8080
// forms a unique global identifier for the crate. It is used to allow
8181
// multiple crates with the same name to coexist. See the
8282
// trans::back::symbol_names module for more information.
83-
pub crate_disambiguator: Cell<ast::Name>,
83+
pub crate_disambiguator: RefCell<token::InternedString>,
8484
pub features: RefCell<feature_gate::Features>,
8585

8686
/// The maximum recursion limit for potentially infinitely recursive
@@ -106,6 +106,9 @@ pub struct Session {
106106
}
107107

108108
impl Session {
109+
pub fn local_crate_disambiguator(&self) -> token::InternedString {
110+
self.crate_disambiguator.borrow().clone()
111+
}
109112
pub fn struct_span_warn<'a, S: Into<MultiSpan>>(&'a self,
110113
sp: S,
111114
msg: &str)
@@ -438,7 +441,7 @@ pub fn build_session_(sopts: config::Options,
438441
plugin_attributes: RefCell::new(Vec::new()),
439442
crate_types: RefCell::new(Vec::new()),
440443
dependency_formats: RefCell::new(FnvHashMap()),
441-
crate_disambiguator: Cell::new(token::intern("")),
444+
crate_disambiguator: RefCell::new(token::intern("").as_str()),
442445
features: RefCell::new(feature_gate::Features::new()),
443446
recursion_limit: Cell::new(64),
444447
next_node_id: Cell::new(1),

src/librustc/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
504504

505505
pub fn crate_disambiguator(self, cnum: ast::CrateNum) -> token::InternedString {
506506
if cnum == LOCAL_CRATE {
507-
self.sess.crate_disambiguator.get().as_str()
507+
self.sess.local_crate_disambiguator()
508508
} else {
509509
self.sess.cstore.crate_disambiguator(cnum)
510510
}

src/librustc_driver/driver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
566566
});
567567

568568
*sess.crate_types.borrow_mut() = collect_crate_types(sess, &krate.attrs);
569-
sess.crate_disambiguator.set(token::intern(&compute_crate_disambiguator(sess)));
569+
*sess.crate_disambiguator.borrow_mut() =
570+
token::intern(&compute_crate_disambiguator(sess)).as_str();
570571

571572
time(time_passes, "recursion limit", || {
572573
middle::recursion_limit::update_recursion_limit(sess, &krate);

src/librustc_incremental/calculate_svh.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'a, 'tcx> SvhCalculate for TyCtxt<'a, 'tcx, 'tcx> {
3636
// to ensure it is not incorporating implementation artifacts into
3737
// the hash that are not otherwise visible.)
3838

39-
let crate_disambiguator = self.sess.crate_disambiguator.get();
39+
let crate_disambiguator = self.sess.local_crate_disambiguator();
4040
let krate = self.map.krate();
4141

4242
// 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> {
4747
// FIXME(#32753) -- at (*) we `to_le` for endianness, but is
4848
// this enough, and does it matter anyway?
4949
"crate_disambiguator".hash(&mut state);
50-
crate_disambiguator.as_str().len().to_le().hash(&mut state); // (*)
51-
crate_disambiguator.as_str().hash(&mut state);
50+
crate_disambiguator.len().to_le().hash(&mut state); // (*)
51+
crate_disambiguator.hash(&mut state);
5252

53-
debug!("crate_disambiguator: {:?}", crate_disambiguator.as_str());
53+
debug!("crate_disambiguator: {:?}", crate_disambiguator);
5454
debug!("state: {:?}", state);
5555

5656
{

src/librustc_metadata/creader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<'a> CrateReader<'a> {
243243

244244
// Check for (potential) conflicts with the local crate
245245
if self.local_crate_name == crate_name &&
246-
self.sess.crate_disambiguator.get().as_str() == disambiguator {
246+
self.sess.local_crate_disambiguator() == disambiguator {
247247
span_fatal!(self.sess, span, E0519,
248248
"the current crate is indistinguishable from one of its \
249249
dependencies: it has the same crate-name `{}` and was \

src/librustc_metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,7 @@ fn encode_metadata_inner(rbml_w: &mut Encoder,
18931893
encode_crate_name(rbml_w, &ecx.link_meta.crate_name);
18941894
encode_crate_triple(rbml_w, &ecx.tcx.sess.opts.target_triple);
18951895
encode_hash(rbml_w, &ecx.link_meta.crate_hash);
1896-
encode_crate_disambiguator(rbml_w, &ecx.tcx.sess.crate_disambiguator.get().as_str());
1896+
encode_crate_disambiguator(rbml_w, &ecx.tcx.sess.local_crate_disambiguator());
18971897
encode_dylib_dependency_formats(rbml_w, &ecx);
18981898
encode_panic_strategy(rbml_w, &ecx);
18991899

0 commit comments

Comments
 (0)