diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2023-08-09 20:28:00 +0800 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2023-08-11 16:51:50 +0800 |
| commit | 7353c96be899f02f52455f61bfaf49b80022a182 (patch) | |
| tree | 0f96aa4b5051511d02cb8afad897927d3b8daff4 /compiler/rustc_interface/src | |
| parent | a07bc13e14163102193ac19379235711b1b5e44e (diff) | |
| download | rust-7353c96be899f02f52455f61bfaf49b80022a182.tar.gz rust-7353c96be899f02f52455f61bfaf49b80022a182.zip | |
rustc: Move `features` from `Session` to `GlobalCtxt`
Removes two pieces of mutable state. Follow up to #114622.
Diffstat (limited to 'compiler/rustc_interface/src')
| -rw-r--r-- | compiler/rustc_interface/src/passes.rs | 35 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/queries.rs | 7 |
2 files changed, 30 insertions, 12 deletions
diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index def9fdcd3c7..18a669175b9 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -11,6 +11,7 @@ use rustc_data_structures::steal::Steal; use rustc_data_structures::sync::{Lrc, OnceCell, WorkerLocal}; use rustc_errors::PResult; use rustc_expand::base::{ExtCtxt, LintStoreExpand}; +use rustc_feature::Features; use rustc_fs_util::try_canonicalize; use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE}; use rustc_lint::{unerased_lint_store, BufferedEarlyLint, EarlyCheckNode, LintStore}; @@ -98,6 +99,7 @@ pub(crate) fn create_lint_store( fn pre_expansion_lint<'a>( sess: &Session, + features: &Features, lint_store: &LintStore, registered_tools: &RegisteredTools, check_node: impl EarlyCheckNode<'a>, @@ -107,6 +109,7 @@ fn pre_expansion_lint<'a>( || { rustc_lint::check_ast_node( sess, + features, true, lint_store, registered_tools, @@ -125,13 +128,14 @@ impl LintStoreExpand for LintStoreExpandImpl<'_> { fn pre_expansion_lint( &self, sess: &Session, + features: &Features, registered_tools: &RegisteredTools, node_id: ast::NodeId, attrs: &[ast::Attribute], items: &[rustc_ast::ptr::P<ast::Item>], name: Symbol, ) { - pre_expansion_lint(sess, self.0, registered_tools, (node_id, attrs, items), name); + pre_expansion_lint(sess, features, self.0, registered_tools, (node_id, attrs, items), name); } } @@ -147,10 +151,18 @@ fn configure_and_expand( ) -> ast::Crate { let tcx = resolver.tcx(); let sess = tcx.sess; + let features = tcx.features(); let lint_store = unerased_lint_store(tcx); let crate_name = tcx.crate_name(LOCAL_CRATE); let lint_check_node = (&krate, pre_configured_attrs); - pre_expansion_lint(sess, lint_store, tcx.registered_tools(()), lint_check_node, crate_name); + pre_expansion_lint( + sess, + features, + lint_store, + tcx.registered_tools(()), + lint_check_node, + crate_name, + ); rustc_builtin_macros::register_builtin_macros(resolver); let num_standard_library_imports = sess.time("crate_injection", || { @@ -159,6 +171,7 @@ fn configure_and_expand( pre_configured_attrs, resolver, sess, + features, ) }); @@ -198,16 +211,15 @@ fn configure_and_expand( } // Create the config for macro expansion - let features = sess.features_untracked(); let recursion_limit = get_recursion_limit(pre_configured_attrs, sess); let cfg = rustc_expand::expand::ExpansionConfig { - features: Some(features), + crate_name: crate_name.to_string(), + features, recursion_limit, trace_mac: sess.opts.unstable_opts.trace_macros, should_test: sess.is_test_crate(), span_debug: sess.opts.unstable_opts.span_debug, proc_macro_backtrace: sess.opts.unstable_opts.proc_macro_backtrace, - ..rustc_expand::expand::ExpansionConfig::default(crate_name.to_string()) }; let lint_store = LintStoreExpandImpl(lint_store); @@ -241,11 +253,16 @@ fn configure_and_expand( }); sess.time("maybe_building_test_harness", || { - rustc_builtin_macros::test_harness::inject(&mut krate, sess, resolver) + rustc_builtin_macros::test_harness::inject(&mut krate, sess, features, resolver) }); let has_proc_macro_decls = sess.time("AST_validation", || { - rustc_ast_passes::ast_validation::check_crate(sess, &krate, resolver.lint_buffer()) + rustc_ast_passes::ast_validation::check_crate( + sess, + features, + &krate, + resolver.lint_buffer(), + ) }); let crate_types = tcx.crate_types(); @@ -270,6 +287,7 @@ fn configure_and_expand( rustc_builtin_macros::proc_macro_harness::inject( &mut krate, sess, + features, resolver, is_proc_macro_crate, has_proc_macro_decls, @@ -300,7 +318,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) { // Needs to go *after* expansion to be able to check the results of macro expansion. sess.time("complete_gated_feature_checking", || { - rustc_ast_passes::feature_gate::check_crate(&krate, sess); + rustc_ast_passes::feature_gate::check_crate(&krate, sess, tcx.features()); }); // Add all buffered lints from the `ParseSess` to the `Session`. @@ -329,6 +347,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) { let lint_store = unerased_lint_store(tcx); rustc_lint::check_ast_node( sess, + tcx.features(), false, lint_store, tcx.registered_tools(()), diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 7687e83da76..5d38cf770a2 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -234,9 +234,6 @@ impl<'tcx> Queries<'tcx> { debug_assert_eq!(_id, CRATE_DEF_ID); let untracked = Untracked { cstore, source_span, definitions }; - // FIXME: Move features from session to tcx and make them immutable. - sess.init_features(rustc_expand::config::features(sess, &pre_configured_attrs)); - let qcx = passes::create_global_ctxt( self.compiler, crate_types, @@ -254,11 +251,13 @@ impl<'tcx> Queries<'tcx> { feed.crate_name(crate_name); let feed = tcx.feed_unit_query(); + feed.features_query( + tcx.arena.alloc(rustc_expand::config::features(sess, &pre_configured_attrs)), + ); feed.crate_for_resolver(tcx.arena.alloc(Steal::new((krate, pre_configured_attrs)))); feed.metadata_loader( tcx.arena.alloc(Steal::new(self.codegen_backend().metadata_loader())), ); - feed.features_query(tcx.sess.features_untracked()); }); Ok(qcx) }) |
