-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Remove queries from the driver interface #134302
Open
bjorn3
wants to merge
6
commits into
rust-lang:master
Choose a base branch
from
bjorn3:remove_driver_queries
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+206
−332
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6ece803
Get rid of of the global_ctxt query
bjorn3 8780253
Remove the parse query
bjorn3 954cd79
Move GlobalCtxt::finish to TyCtxt
bjorn3 6545a2d
Immediately enter in TyCtxt::create_global_ctxt
bjorn3 7738929
Remove two unnecessary references
bjorn3 b0cd37e
Fix tests
bjorn3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ use tracing::{info, instrument}; | |
use crate::interface::Compiler; | ||
use crate::{errors, proc_macro_decls, util}; | ||
|
||
pub(crate) fn parse<'a>(sess: &'a Session) -> ast::Crate { | ||
pub fn parse<'a>(sess: &'a Session) -> ast::Crate { | ||
let krate = sess | ||
.time("parse_crate", || { | ||
let mut parser = unwrap_or_emit_fatal(match &sess.io.input { | ||
|
@@ -709,13 +709,11 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| { | |
*providers | ||
}); | ||
|
||
pub(crate) fn create_global_ctxt<'tcx>( | ||
compiler: &'tcx Compiler, | ||
pub fn create_and_enter_global_ctxt<T, F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> T>( | ||
compiler: &Compiler, | ||
mut krate: rustc_ast::Crate, | ||
gcx_cell: &'tcx OnceLock<GlobalCtxt<'tcx>>, | ||
arena: &'tcx WorkerLocal<Arena<'tcx>>, | ||
hir_arena: &'tcx WorkerLocal<rustc_hir::Arena<'tcx>>, | ||
) -> &'tcx GlobalCtxt<'tcx> { | ||
f: F, | ||
) -> T { | ||
let sess = &compiler.sess; | ||
|
||
rustc_builtin_macros::cmdline_attrs::inject( | ||
|
@@ -763,44 +761,64 @@ pub(crate) fn create_global_ctxt<'tcx>( | |
|
||
let incremental = dep_graph.is_fully_enabled(); | ||
|
||
sess.time("setup_global_ctxt", || { | ||
let qcx = gcx_cell.get_or_init(move || { | ||
TyCtxt::create_global_ctxt( | ||
sess, | ||
crate_types, | ||
stable_crate_id, | ||
arena, | ||
hir_arena, | ||
untracked, | ||
dep_graph, | ||
rustc_query_impl::query_callbacks(arena), | ||
rustc_query_impl::query_system( | ||
providers.queries, | ||
providers.extern_queries, | ||
query_result_on_disk_cache, | ||
incremental, | ||
), | ||
providers.hooks, | ||
compiler.current_gcx.clone(), | ||
) | ||
}); | ||
|
||
qcx.enter(|tcx| { | ||
let feed = tcx.create_crate_num(stable_crate_id).unwrap(); | ||
assert_eq!(feed.key(), LOCAL_CRATE); | ||
feed.crate_name(crate_name); | ||
let gcx_cell = OnceLock::new(); | ||
let arena = WorkerLocal::new(|_| Arena::default()); | ||
let hir_arena = WorkerLocal::new(|_| rustc_hir::Arena::default()); | ||
|
||
// This closure is necessary to force rustc to perform the correct lifetime | ||
// subtyping for GlobalCtxt::enter to be allowed. | ||
let inner: Box< | ||
dyn for<'tcx> FnOnce( | ||
&'tcx Compiler, | ||
&'tcx OnceLock<GlobalCtxt<'tcx>>, | ||
&'tcx WorkerLocal<Arena<'tcx>>, | ||
&'tcx WorkerLocal<rustc_hir::Arena<'tcx>>, | ||
F, | ||
) -> T, | ||
> = Box::new(move |compiler, gcx_cell, arena, hir_arena, f| { | ||
let sess = &compiler.sess; | ||
|
||
TyCtxt::create_global_ctxt( | ||
gcx_cell, | ||
sess, | ||
crate_types, | ||
stable_crate_id, | ||
arena, | ||
hir_arena, | ||
untracked, | ||
dep_graph, | ||
rustc_query_impl::query_callbacks(arena), | ||
rustc_query_impl::query_system( | ||
providers.queries, | ||
providers.extern_queries, | ||
query_result_on_disk_cache, | ||
incremental, | ||
), | ||
providers.hooks, | ||
compiler.current_gcx.clone(), | ||
|tcx| { | ||
let feed = tcx.create_crate_num(stable_crate_id).unwrap(); | ||
assert_eq!(feed.key(), LOCAL_CRATE); | ||
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, | ||
crate_name, | ||
))); | ||
feed.crate_for_resolver(tcx.arena.alloc(Steal::new((krate, pre_configured_attrs)))); | ||
feed.output_filenames(Arc::new(outputs)); | ||
|
||
let res = f(tcx); | ||
// FIXME maybe run finish even when a fatal error occured? or at least tcx.alloc_self_profile_query_strings()? | ||
tcx.finish(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixme is a pre-existing issue. |
||
res | ||
}, | ||
) | ||
}); | ||
|
||
let feed = tcx.feed_unit_query(); | ||
feed.features_query(tcx.arena.alloc(rustc_expand::config::features( | ||
sess, | ||
&pre_configured_attrs, | ||
crate_name, | ||
))); | ||
feed.crate_for_resolver(tcx.arena.alloc(Steal::new((krate, pre_configured_attrs)))); | ||
feed.output_filenames(Arc::new(outputs)); | ||
}); | ||
qcx | ||
}) | ||
inner(compiler, &gcx_cell, &arena, &hir_arena, f) | ||
} | ||
|
||
/// Runs all analyses that we guarantee to run, even if errors were reported in earlier analyses. | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ugly, but the only way I could figure out to get all invariant lifetimes correctly inferred by rustc.