From 904e2b6b3520d39dfc41e1f9c96244239a7e871a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sun, 1 Apr 2018 08:21:21 +0200 Subject: [PATCH] Make Session::features_untracked thread-safe --- src/librustc/session/mod.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 2f036be011be..6784f909ff35 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -101,7 +101,7 @@ pub struct Session { /// trans::back::symbol_names module for more information. pub crate_disambiguator: RefCell>, - features: RefCell>, + features: Once, /// The maximum recursion limit for potentially infinitely recursive /// operations such as auto-dereference and monomorphization. @@ -532,18 +532,12 @@ impl Session { /// DO NOT USE THIS METHOD if there is a TyCtxt available, as it circumvents /// dependency tracking. Use tcx.features() instead. #[inline] - pub fn features_untracked(&self) -> cell::Ref { - let features = self.features.borrow(); - - if features.is_none() { - bug!("Access to Session::features before it is initialized"); - } - - cell::Ref::map(features, |r| r.as_ref().unwrap()) + pub fn features_untracked(&self) -> &feature_gate::Features { + self.features.get() } pub fn init_features(&self, features: feature_gate::Features) { - *(self.features.borrow_mut()) = Some(features); + self.features.set(features); } /// Calculates the flavor of LTO to use for this compilation. @@ -1108,7 +1102,7 @@ pub fn build_session_( crate_types: RefCell::new(Vec::new()), dependency_formats: RefCell::new(FxHashMap()), crate_disambiguator: RefCell::new(None), - features: RefCell::new(None), + features: Once::new(), recursion_limit: Once::new(), type_length_limit: Once::new(), const_eval_stack_frame_limit: 100,