@@ -20,7 +20,7 @@ use lint::builtin::BuiltinLintDiagnostics;
2020use middle:: allocator:: AllocatorKind ;
2121use middle:: dependency_format;
2222use session:: search_paths:: PathKind ;
23- use session:: config:: { BorrowckMode , DebugInfoLevel , OutputType , Epoch } ;
23+ use session:: config:: { DebugInfoLevel , OutputType , Epoch } ;
2424use ty:: tls;
2525use util:: nodemap:: { FxHashMap , FxHashSet } ;
2626use util:: common:: { duration_to_secs_str, ErrorReported } ;
@@ -93,7 +93,8 @@ pub struct Session {
9393 /// multiple crates with the same name to coexist. See the
9494 /// trans::back::symbol_names module for more information.
9595 pub crate_disambiguator : RefCell < Option < CrateDisambiguator > > ,
96- pub features : RefCell < feature_gate:: Features > ,
96+
97+ features : RefCell < Option < feature_gate:: Features > > ,
9798
9899 /// The maximum recursion limit for potentially infinitely recursive
99100 /// operations such as auto-dereference and monomorphization.
@@ -194,6 +195,7 @@ impl Session {
194195 None => bug ! ( "accessing disambiguator before initialization" ) ,
195196 }
196197 }
198+
197199 pub fn struct_span_warn < ' a , S : Into < MultiSpan > > ( & ' a self ,
198200 sp : S ,
199201 msg : & str )
@@ -456,16 +458,22 @@ impl Session {
456458 self . opts . debugging_opts . print_llvm_passes
457459 }
458460
459- /// If true, we should use NLL-style region checking instead of
460- /// lexical style.
461- pub fn nll ( & self ) -> bool {
462- self . features . borrow ( ) . nll || self . opts . debugging_opts . nll
461+ /// Get the features enabled for the current compilation session. Do not use
462+ /// DO NOT USE THIS METHOD if there is a TyCtxt available, as it circumvents
463+ /// dependency tracking. Use tcx.features() instead.
464+ #[ inline]
465+ pub fn features_untracked ( & self ) -> cell:: Ref < feature_gate:: Features > {
466+ let features = self . features . borrow ( ) ;
467+
468+ if features. is_none ( ) {
469+ bug ! ( "Access to Session::features before it is initialized" ) ;
470+ }
471+
472+ cell:: Ref :: map ( features, |r| r. as_ref ( ) . unwrap ( ) )
463473 }
464474
465- /// If true, we should use the MIR-based borrowck (we may *also* use
466- /// the AST-based borrowck).
467- pub fn use_mir ( & self ) -> bool {
468- self . borrowck_mode ( ) . use_mir ( )
475+ pub fn init_features ( & self , features : feature_gate:: Features ) {
476+ * ( self . features . borrow_mut ( ) ) = Some ( features) ;
469477 }
470478
471479 /// If true, we should gather causal information during NLL
@@ -475,42 +483,6 @@ impl Session {
475483 self . opts . debugging_opts . nll_dump_cause
476484 }
477485
478- /// If true, we should enable two-phase borrows checks. This is
479- /// done with either `-Ztwo-phase-borrows` or with
480- /// `#![feature(nll)]`.
481- pub fn two_phase_borrows ( & self ) -> bool {
482- self . features . borrow ( ) . nll || self . opts . debugging_opts . two_phase_borrows
483- }
484-
485- /// What mode(s) of borrowck should we run? AST? MIR? both?
486- /// (Also considers the `#![feature(nll)]` setting.)
487- pub fn borrowck_mode ( & self ) -> BorrowckMode {
488- match self . opts . borrowck_mode {
489- mode @ BorrowckMode :: Mir |
490- mode @ BorrowckMode :: Compare => mode,
491-
492- mode @ BorrowckMode :: Ast => {
493- if self . nll ( ) {
494- BorrowckMode :: Mir
495- } else {
496- mode
497- }
498- }
499-
500- }
501- }
502-
503- /// Should we emit EndRegion MIR statements? These are consumed by
504- /// MIR borrowck, but not when NLL is used. They are also consumed
505- /// by the validation stuff.
506- pub fn emit_end_regions ( & self ) -> bool {
507- // FIXME(#46875) -- we should not emit end regions when NLL is enabled,
508- // but for now we can't stop doing so because it causes false positives
509- self . opts . debugging_opts . emit_end_regions ||
510- self . opts . debugging_opts . mir_emit_validate > 0 ||
511- self . use_mir ( )
512- }
513-
514486 /// Calculates the flavor of LTO to use for this compilation.
515487 pub fn lto ( & self ) -> config:: Lto {
516488 // If our target has codegen requirements ignore the command line
@@ -1029,7 +1001,7 @@ pub fn build_session_(sopts: config::Options,
10291001 crate_types : RefCell :: new ( Vec :: new ( ) ) ,
10301002 dependency_formats : RefCell :: new ( FxHashMap ( ) ) ,
10311003 crate_disambiguator : RefCell :: new ( None ) ,
1032- features : RefCell :: new ( feature_gate :: Features :: new ( ) ) ,
1004+ features : RefCell :: new ( None ) ,
10331005 recursion_limit : Cell :: new ( 64 ) ,
10341006 type_length_limit : Cell :: new ( 1048576 ) ,
10351007 next_node_id : Cell :: new ( NodeId :: new ( 1 ) ) ,
0 commit comments