@@ -19,7 +19,7 @@ use lint;
19
19
use middle:: allocator:: AllocatorKind ;
20
20
use middle:: dependency_format;
21
21
use session:: search_paths:: PathKind ;
22
- use session:: config:: { BorrowckMode , DebugInfoLevel , OutputType , Epoch } ;
22
+ use session:: config:: { DebugInfoLevel , OutputType , Epoch } ;
23
23
use ty:: tls;
24
24
use util:: nodemap:: { FxHashMap , FxHashSet } ;
25
25
use util:: common:: { duration_to_secs_str, ErrorReported } ;
@@ -91,7 +91,8 @@ pub struct Session {
91
91
/// multiple crates with the same name to coexist. See the
92
92
/// trans::back::symbol_names module for more information.
93
93
pub crate_disambiguator : RefCell < Option < CrateDisambiguator > > ,
94
- pub features : RefCell < feature_gate:: Features > ,
94
+
95
+ features : RefCell < Option < feature_gate:: Features > > ,
95
96
96
97
/// The maximum recursion limit for potentially infinitely recursive
97
98
/// operations such as auto-dereference and monomorphization.
@@ -192,6 +193,7 @@ impl Session {
192
193
None => bug ! ( "accessing disambiguator before initialization" ) ,
193
194
}
194
195
}
196
+
195
197
pub fn struct_span_warn < ' a , S : Into < MultiSpan > > ( & ' a self ,
196
198
sp : S ,
197
199
msg : & str )
@@ -443,16 +445,22 @@ impl Session {
443
445
self . opts . debugging_opts . print_llvm_passes
444
446
}
445
447
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 ( ) )
450
460
}
451
461
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) ;
456
464
}
457
465
458
466
/// If true, we should gather causal information during NLL
@@ -462,42 +470,6 @@ impl Session {
462
470
self . opts . debugging_opts . nll_dump_cause
463
471
}
464
472
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
-
501
473
/// Calculates the flavor of LTO to use for this compilation.
502
474
pub fn lto ( & self ) -> config:: Lto {
503
475
// If our target has codegen requirements ignore the command line
@@ -1009,7 +981,7 @@ pub fn build_session_(sopts: config::Options,
1009
981
crate_types : RefCell :: new ( Vec :: new ( ) ) ,
1010
982
dependency_formats : RefCell :: new ( FxHashMap ( ) ) ,
1011
983
crate_disambiguator : RefCell :: new ( None ) ,
1012
- features : RefCell :: new ( feature_gate :: Features :: new ( ) ) ,
984
+ features : RefCell :: new ( None ) ,
1013
985
recursion_limit : Cell :: new ( 64 ) ,
1014
986
type_length_limit : Cell :: new ( 1048576 ) ,
1015
987
next_node_id : Cell :: new ( NodeId :: new ( 1 ) ) ,
0 commit comments