@@ -20,7 +20,7 @@ use lint::builtin::BuiltinLintDiagnostics;
20
20
use middle:: allocator:: AllocatorKind ;
21
21
use middle:: dependency_format;
22
22
use session:: search_paths:: PathKind ;
23
- use session:: config:: { BorrowckMode , DebugInfoLevel , OutputType , Epoch } ;
23
+ use session:: config:: { DebugInfoLevel , OutputType , Epoch } ;
24
24
use ty:: tls;
25
25
use util:: nodemap:: { FxHashMap , FxHashSet } ;
26
26
use util:: common:: { duration_to_secs_str, ErrorReported } ;
@@ -93,7 +93,8 @@ pub struct Session {
93
93
/// multiple crates with the same name to coexist. See the
94
94
/// trans::back::symbol_names module for more information.
95
95
pub crate_disambiguator : RefCell < Option < CrateDisambiguator > > ,
96
- pub features : RefCell < feature_gate:: Features > ,
96
+
97
+ features : RefCell < Option < feature_gate:: Features > > ,
97
98
98
99
/// The maximum recursion limit for potentially infinitely recursive
99
100
/// operations such as auto-dereference and monomorphization.
@@ -194,6 +195,7 @@ impl Session {
194
195
None => bug ! ( "accessing disambiguator before initialization" ) ,
195
196
}
196
197
}
198
+
197
199
pub fn struct_span_warn < ' a , S : Into < MultiSpan > > ( & ' a self ,
198
200
sp : S ,
199
201
msg : & str )
@@ -456,16 +458,22 @@ impl Session {
456
458
self . opts . debugging_opts . print_llvm_passes
457
459
}
458
460
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.
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 ( ) )
463
473
}
464
474
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) ;
469
477
}
470
478
471
479
/// If true, we should gather causal information during NLL
@@ -475,42 +483,6 @@ impl Session {
475
483
self . opts . debugging_opts . nll_dump_cause
476
484
}
477
485
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
-
514
486
/// Calculates the flavor of LTO to use for this compilation.
515
487
pub fn lto ( & self ) -> config:: Lto {
516
488
// If our target has codegen requirements ignore the command line
@@ -1029,7 +1001,7 @@ pub fn build_session_(sopts: config::Options,
1029
1001
crate_types : RefCell :: new ( Vec :: new ( ) ) ,
1030
1002
dependency_formats : RefCell :: new ( FxHashMap ( ) ) ,
1031
1003
crate_disambiguator : RefCell :: new ( None ) ,
1032
- features : RefCell :: new ( feature_gate :: Features :: new ( ) ) ,
1004
+ features : RefCell :: new ( None ) ,
1033
1005
recursion_limit : Cell :: new ( 64 ) ,
1034
1006
type_length_limit : Cell :: new ( 1048576 ) ,
1035
1007
next_node_id : Cell :: new ( NodeId :: new ( 1 ) ) ,
0 commit comments