@@ -19,7 +19,7 @@ use lint;
1919use middle:: allocator:: AllocatorKind ;
2020use middle:: dependency_format;
2121use session:: search_paths:: PathKind ;
22- use session:: config:: { BorrowckMode , DebugInfoLevel , OutputType , Epoch } ;
22+ use session:: config:: { DebugInfoLevel , OutputType , Epoch } ;
2323use ty:: tls;
2424use util:: nodemap:: { FxHashMap , FxHashSet } ;
2525use util:: common:: { duration_to_secs_str, ErrorReported } ;
@@ -91,7 +91,8 @@ pub struct Session {
9191 /// multiple crates with the same name to coexist. See the
9292 /// trans::back::symbol_names module for more information.
9393 pub crate_disambiguator : RefCell < Option < CrateDisambiguator > > ,
94- pub features : RefCell < feature_gate:: Features > ,
94+
95+ features : RefCell < Option < feature_gate:: Features > > ,
9596
9697 /// The maximum recursion limit for potentially infinitely recursive
9798 /// operations such as auto-dereference and monomorphization.
@@ -192,6 +193,7 @@ impl Session {
192193 None => bug ! ( "accessing disambiguator before initialization" ) ,
193194 }
194195 }
196+
195197 pub fn struct_span_warn < ' a , S : Into < MultiSpan > > ( & ' a self ,
196198 sp : S ,
197199 msg : & str )
@@ -443,16 +445,22 @@ impl Session {
443445 self . opts . debugging_opts . print_llvm_passes
444446 }
445447
446- /// If true, we should use NLL-style region checking instead of
447- /// lexical style.
448- pub fn nll ( & self ) -> bool {
449- self . features . borrow ( ) . nll || self . opts . debugging_opts . nll
448+ /// Get the features enabled for the current compilation session. Do not use
449+ /// DO NOT USE THIS METHOD if there is a TyCtxt available, as it circumvents
450+ /// dependency tracking. Use tcx.features() instead.
451+ #[ inline]
452+ pub fn features_untracked ( & self ) -> cell:: Ref < feature_gate:: Features > {
453+ let features = self . features . borrow ( ) ;
454+
455+ if features. is_none ( ) {
456+ bug ! ( "Access to Session::features before it is initialized" ) ;
457+ }
458+
459+ cell:: Ref :: map ( features, |r| r. as_ref ( ) . unwrap ( ) )
450460 }
451461
452- /// If true, we should use the MIR-based borrowck (we may *also* use
453- /// the AST-based borrowck).
454- pub fn use_mir ( & self ) -> bool {
455- self . borrowck_mode ( ) . use_mir ( )
462+ pub fn init_features ( & self , features : feature_gate:: Features ) {
463+ * ( self . features . borrow_mut ( ) ) = Some ( features) ;
456464 }
457465
458466 /// If true, we should gather causal information during NLL
@@ -462,42 +470,6 @@ impl Session {
462470 self . opts . debugging_opts . nll_dump_cause
463471 }
464472
465- /// If true, we should enable two-phase borrows checks. This is
466- /// done with either `-Ztwo-phase-borrows` or with
467- /// `#![feature(nll)]`.
468- pub fn two_phase_borrows ( & self ) -> bool {
469- self . features . borrow ( ) . nll || self . opts . debugging_opts . two_phase_borrows
470- }
471-
472- /// What mode(s) of borrowck should we run? AST? MIR? both?
473- /// (Also considers the `#![feature(nll)]` setting.)
474- pub fn borrowck_mode ( & self ) -> BorrowckMode {
475- match self . opts . borrowck_mode {
476- mode @ BorrowckMode :: Mir |
477- mode @ BorrowckMode :: Compare => mode,
478-
479- mode @ BorrowckMode :: Ast => {
480- if self . nll ( ) {
481- BorrowckMode :: Mir
482- } else {
483- mode
484- }
485- }
486-
487- }
488- }
489-
490- /// Should we emit EndRegion MIR statements? These are consumed by
491- /// MIR borrowck, but not when NLL is used. They are also consumed
492- /// by the validation stuff.
493- pub fn emit_end_regions ( & self ) -> bool {
494- // FIXME(#46875) -- we should not emit end regions when NLL is enabled,
495- // but for now we can't stop doing so because it causes false positives
496- self . opts . debugging_opts . emit_end_regions ||
497- self . opts . debugging_opts . mir_emit_validate > 0 ||
498- self . use_mir ( )
499- }
500-
501473 /// Calculates the flavor of LTO to use for this compilation.
502474 pub fn lto ( & self ) -> config:: Lto {
503475 // If our target has codegen requirements ignore the command line
@@ -1009,7 +981,7 @@ pub fn build_session_(sopts: config::Options,
1009981 crate_types : RefCell :: new ( Vec :: new ( ) ) ,
1010982 dependency_formats : RefCell :: new ( FxHashMap ( ) ) ,
1011983 crate_disambiguator : RefCell :: new ( None ) ,
1012- features : RefCell :: new ( feature_gate :: Features :: new ( ) ) ,
984+ features : RefCell :: new ( None ) ,
1013985 recursion_limit : Cell :: new ( 64 ) ,
1014986 type_length_limit : Cell :: new ( 1048576 ) ,
1015987 next_node_id : Cell :: new ( NodeId :: new ( 1 ) ) ,
0 commit comments