8000 Remove queries from rustc_interface by Zoxc · Pull Request #59904 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Remove queries from rustc_interface #59904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Turn parsing into a query
  • Loading branch information
Zoxc committed Jul 8, 2019
commit 391fc0570d80daa585ea1c0c399b24bb24b358c0
23 changes: 23 additions & 0 deletions src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@ use syntax_pos::symbol::InternedString;
// as they will raise an fatal error on query cycles instead.
rustc_queries! {
Other {
query parse(_: ()) -> Result<Lrc<Steal<ast::Crate>>, ErrorReported> {
no_hash
eval_always
desc { "parsing crate" }
}

query register_plugins(
_: ()
) -> Result<Lrc<Steal<(ast::Crate, ty::PluginInfo)>>, ErrorReported> {
no_hash
eval_always
desc { "registering plugins" }
}

/// The definite name of the current crate after taking into account
/// attributes, commandline parameters, etc.
query early_crate_name(_: ()) -> Result<Symbol, ErrorReported> {
no_hash
eval_always
desc { "finding the crate name" }
}

query expand_macros(_: ()) -> Result<Lrc<ty::ExpansionResult>, ErrorReported> {
no_hash
eval_always
Expand Down Expand Up @@ -771,6 +793,7 @@ rustc_queries! {
eval_always
desc { "looking up the hash a crate" }
}
// FIXME: Remove this as it's the same as `crate_name`
query original_crate_name(_: CrateNum) -> Symbol {
eval_always
desc { "looking up the original name a crate" }
Expand Down
5 changes: 5 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ top_level_options!(
// try to not rely on this too much.
actually_rustdoc: bool [TRACKED],

// Replaces bodies with loops
everybody_loops: bool [TRACKED],

// Specifications of codegen units / ThinLTO which are forced as a
// result of parsing command line options. These are not necessarily
// what rustc was invoked with, but massaged a bit to agree with
Expand Down Expand Up @@ -630,6 +633,7 @@ impl Default for Options {
unstable_features: UnstableFeatures::Disallow,
debug_assertions: true,
actually_rustdoc: false,
everybody_loops: false,
cli_forced_codegen_units: None,
cli_forced_thinlto_off: false,
remap_path_prefix: Vec::new(),
Expand Down Expand Up @@ -2449,6 +2453,7 @@ pub fn build_session_options_and_crate_config(
unstable_features: UnstableFeatures::from_environment(),
debug_assertions,
actually_rustdoc: false,
everybody_loops: false,
cli_forced_codegen_units: codegen_units,
cli_forced_thinlto_off: disable_thinlto,
remap_path_prefix,
Expand Down
26 changes: 9 additions & 17 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
StableVec};
use arena::SyncDroplessArena;
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
use rustc_data_structures::sync::{Lrc, Lock, WorkerLocal, AtomicOnce, Once, OneThread};
use rustc_data_structures::sync::{self, Lrc, Lock, WorkerLocal, AtomicOnce, Once};
use std::any::Any;
use std::borrow::Borrow;
use std::cmp::Ordering;
Expand Down Expand Up @@ -1011,13 +1011,10 @@ pub struct GlobalCtxt<'tcx> {

/// This stores a `Lrc<CStore>`, but that type depends on
/// rustc_metadata, so it cannot be used here.
pub cstore_rc: OneThread<Steal<Box<dyn Any>>>,
pub cstore_rc: &'tcx (dyn Any + sync::Sync),

pub sess_rc: Lrc<Session>,

/// The AST after registering plugins.
pub ast_crate: Steal<(ast::Crate, ty::PluginInfo)>,

lowered_hir: AtomicOnce<&'tcx hir::LoweredHir>,
hir_map: AtomicOnce<&'tcx hir_map::Map<'tcx>>,

Expand All @@ -1037,9 +1034,7 @@ pub struct GlobalCtxt<'tcx> {
/// Merge this with `selection_cache`?
pub evaluation_cache: traits::EvaluationCache<'tcx>,

/// The definite name of the current crate after taking into account
/// attributes, commandline parameters, etc.
pub crate_name: Symbol,
pub crate_name_override: Option<String>,

/// Data layout specification for the current target.
pub data_layout: TargetDataLayout,
Expand Down Expand Up @@ -1179,15 +1174,13 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn create_global_ctxt(
s: &'tcx Lrc<Session>,
cstore: &'tcx CrateStoreDyn,
cstore_rc: Box<dyn Any>,
cstore_rc: &'tcx (dyn Any + sync::Sync),
local_providers: ty::query::Providers<'tcx>,
extern_providers: ty::query::Providers<'tcx>,
arenas: &'tcx AllArenas,
dep_graph: DepGraph,
ast_crate: ast::Crate,
plugin_info: ty::PluginInfo,
on_disk_query_result_cache: query::OnDiskCache<'tcx>,
crate_name: &str,
crate_name: Option<String>,
tx: mpsc::Sender<Box<dyn Any + Send>>,
io: InputsAndOutputs,
) -> GlobalCtxt<'tcx> {
Expand All @@ -1212,15 +1205,14 @@ impl<'tcx> TyCtxt<'tcx> {
sess: &**s,
arena: WorkerLocal::new(|_| Arena::default()),
cstore,
cstore_rc: OneThread::new(Steal::new(cstore_rc)),
cstore_rc,
sess_rc: s.clone(),
interners,
dep_graph,
common,
types: common_types,
lifetimes: common_lifetimes,
consts: common_consts,
ast_crate: Steal::new((ast_crate, plugin_info)),
lowered_hir: AtomicOnce::new(),
hir_map: AtomicOnce::new(),
metadata_dep_nodes: Once::new(),
Expand All @@ -1232,7 +1224,7 @@ impl<'tcx> TyCtxt<'tcx> {
rcache: Default::default(),
selection_cache: Default::default(),
evaluation_cache: Default::default(),
crate_name: Symbol::intern(crate_name),
crate_name_override: crate_name,
data_layout,
layout_interner: Default::default(),
stability_interner: Default::default(),
Expand Down Expand Up @@ -1351,7 +1343,7 @@ impl<'tcx> TyCtxt<'tcx> {
// statements within the query system and we'd run into endless
// recursion otherwise.
let (crate_name, crate_disambiguator) = if def_id.is_local() {
(self.crate_name.clone(),
(self.crate_name(LOCAL_CRATE),
self.sess.local_crate_disambiguator())
} else {
(self.cstore.crate_name_untracked(def_id.krate),
Expand Down Expand Up @@ -2874,7 +2866,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
};
providers.crate_name = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
tcx.crate_name
tcx.early_crate_name(()).unwrap()
};
providers.get_lib_features = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3279,8 +3279,7 @@ fn crate_disambiguator(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CrateDisambiguat
}

fn original_crate_name(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Symbol {
assert_eq!(crate_num, LOCAL_CRATE);
tcx.crate_name.clone()
tcx.crate_name(crate_num)
}

fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl CodegenBackend for LlvmCodegenBackend {
target_features(sess)
}

fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync> {
fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync + Send> {
box metadata::LlvmMetadataLoader
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_utils/codegen_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub trait CodegenBackend {
fn print_version(&self) {}
fn diagnostics(&self) -> &[(&'static str, &'static str)] { &[] }

fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync>;
fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync + Send>;
fn provide(&self, _providers: &mut Providers<'_>);
fn provide_extern(&self, _providers: &mut Providers<'_>);
fn codegen_crate<'tcx>(
Expand Down
58 changes: 30 additions & 28 deletions src/librustc_driver/lib.rs
10000
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ pub fn run_compiler(

callbacks.config(&mut config);

let pretty_info = parse_pretty(&mut config.opts, &matches);

interface::run_compiler(config, |compiler| {
let sess = compiler.session();
let should_stop = RustcDefaultCalls::print_crate_info(
Expand All @@ -260,14 +262,9 @@ pub fn run_compiler(
return sess.compile_status();
}

let pretty_info = parse_pretty(sess, &matches);

compiler.parse()?;

if let Some((ppm, opt_uii)) = pretty_info {
if ppm.needs_ast_map(&opt_uii) {
pretty::visit_crate(sess, &mut compiler.parse()?.peek_mut(), ppm);
compiler.global_ctxt()?.peek_mut().enter(|tcx| {
compiler.enter(|tcx| {
let expansion_result = tcx.expand_macros(())?;
pretty::print_after_hir_lowering(
tcx,
Expand All @@ -281,19 +278,24 @@ pub fn run_compiler(
})?;
return sess.compile_status();
} else {
let mut krate = compiler.parse()?.take();
pretty::visit_crate(sess, &mut krate, ppm);
pretty::print_after_parsing(
sess,
&compiler.input(),
&krate,
ppm,
compiler.output_file().as_ref().map(|p| &**p),
);
compiler.enter(|tcx| {
let krate = tcx.parse(())?;
let krate = krate.borrow();
pretty::print_after_parsing(
sess,
&compiler.input(),
&krate,
ppm,
compiler.output_file().as_ref().map(|p| &**p),
);
Ok(())
})?;
return sess.compile_status();
}
}

compiler.enter(|tcx| tcx.parse(()))?;

if !callbacks.after_parsing(compiler) {
return sess.compile_status();
}
Expand All @@ -304,15 +306,15 @@ pub fn run_compiler(
return sess.compile_status();
}

compiler.register_plugins()?;
compiler.enter(|tcx| tcx.register_plugins(()))?;

// Lint plugins are registered; now we can process command line flags.
if sess.opts.describe_lints {
describe_lints(&sess, &sess.lint_store.borrow(), true);
return sess.compile_status();
}

compiler.global_ctxt()?.peek_mut().enter(|tcx| {
compiler.enter(|tcx| {
tcx.prepare_outputs(())?;
Ok(())
})?;
Expand All @@ -323,7 +325,7 @@ pub fn run_compiler(
return sess.compile_status();
}

compiler.global_ctxt()?.peek_mut().enter(|tcx| {
compiler.enter(|tcx| {
tcx.lower_ast_to_hir(())?;
Ok(())
})?;
Expand All @@ -334,10 +336,10 @@ pub fn run_compiler(
}

if sess.opts.debugging_opts.save_analysis {
compiler.global_ctxt()?.peek_mut().enter(|tcx| {
compiler.enter(|tcx| {
let expansion_result = tcx.expand_macros(())?;
let result = tcx.analysis(LOCAL_CRATE);
let crate_name = &tcx.crate_name.as_str();
let crate_name = &tcx.crate_name(LOCAL_CRATE).as_str();

time(sess, "save analysis", || {
save::process_crate(
Expand All @@ -355,20 +357,20 @@ pub fn run_compiler(
// (needed by the RLS)
})?;
} else {
compiler.global_ctxt()?.peek_mut().enter(|tcx| {
compiler.enter(|tcx| {
// Drop AST after lowering HIR to free memory
mem::drop(tcx.expand_macros(()).unwrap().ast_crate.steal());
});
}

compiler.global_ctxt()?.peek_mut().enter(|tcx| tcx.analysis(LOCAL_CRATE))?;
compiler.enter(|tcx| tcx.analysis(LOCAL_CRATE))?;

if !callbacks.after_analysis(compiler) {
return sess.compile_status();
}

if sess.opts.debugging_opts.save_analysis {
compiler.global_ctxt()?.peek_mut().enter(|tcx| {
compiler.enter(|tcx| {
// Drop AST after lowering HIR to free memory
mem::drop(tcx.expand_macros(()).unwrap().ast_crate.steal());
});
Expand Down Expand Up @@ -441,22 +443,22 @@ fn make_input(free_matches: &[String]) -> Option<(Input, Option<PathBuf>, Option
}
}

fn parse_pretty(sess: &Session,
fn parse_pretty(opts: &mut config::Options,
matches: &getopts::Matches)
-> Option<(PpMode, Option<UserIdentifiedItem>)> {
let pretty = if sess.opts.debugging_opts.unstable_options {
let pretty = if opts.debugging_opts.unstable_options {
matches.opt_default("pretty", "normal").map(|a| {
// stable pretty-print variants only
pretty::parse_pretty(sess, &a, false)
pretty::parse_pretty(opts, &a, false)
})
} else {
None
};

if pretty.is_none() {
sess.opts.debugging_opts.unpretty.as_ref().map(|a| {
opts.debugging_opts.unpretty.clone().map(|a| {
// extended with unstable pretty-print variants
pretty::parse_pretty(sess, &a, true)
pretty::parse_pretty(opts, &a, true)
})
} else {
pretty
Expand Down
Loading
0