Skip to content
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

Handle GlobalCtxt directly from librustc_interface query system #66791

Merged
merged 20 commits into from
Nov 30, 2019

Conversation

cjgillot
Copy link
Contributor

This PR constructs the GlobalCtxt as a member of the Queries in librustc_interface.
This simplifies the code to construct it, at the expense of added complexity in the query control flow.
This allows to handle the arenas directly from librustc_interface.

Based on #66707

r? @Zoxc

The construction of the GlobalCtxt is moved from a generator's stack to
the Queries struct.  Since the GlobalCtxt requires the HIR Forest and the
arenas to live longer, those are moved into Queries the same way.

The resulting handling of objects is more brittle, because consumers of
the Once objects need to be careful of their initialisation.

impl BoxedGlobalCtxt {
impl<'gcx> BoxedGlobalCtxt<'gcx> {
pub fn enter<F, R>(&mut self, f: F) -> R
where
F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> R,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could just be F: FnOnce(TyCtxt<'gcx>) -> R, now.

ty::tls::enter_global(self.0, |tcx| f(tcx))
}

pub fn print_stats(&self) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just remove this function and let its caller call print_stats directly using enter.

src/librustc/ty/context.rs Outdated Show resolved Hide resolved
@@ -74,6 +75,8 @@ pub struct Queries<'comp> {
arenas: Once<AllArenas>,
forest: Once<hir::map::Forest>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add hir::map::Forest to the list of types in arena.rs with a [few] attribute then we can remove this field and allocate it from Arena.

@Zoxc
Copy link
Contributor

Zoxc commented Nov 27, 2019

r? @Mark-Simulacrum

@Zoxc
Copy link
Contributor

Zoxc commented Nov 27, 2019

This looks good to me now.

@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Nov 27, 2019

📌 Commit 1e12f39 has been approved by Mark-Simulacrum

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Nov 27, 2019
@@ -740,93 +741,77 @@ pub fn default_provide_extern(providers: &mut ty::query::Providers<'_>) {
rustc_codegen_ssa::provide_extern(providers);
}

declare_box_region_type!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this macro now be removed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's still used for the resolver.

RalfJung added a commit to RalfJung/rust that referenced this pull request Nov 29, 2019
Handle GlobalCtxt directly from librustc_interface query system

This PR constructs the `GlobalCtxt` as a member of the `Queries` in librustc_interface.
This simplifies the code to construct it, at the expense of added complexity in the query control flow.
This allows to handle the arenas directly from librustc_interface.

Based on rust-lang#66707

r? @Zoxc
RalfJung added a commit to RalfJung/rust that referenced this pull request Nov 29, 2019
Handle GlobalCtxt directly from librustc_interface query system

This PR constructs the `GlobalCtxt` as a member of the `Queries` in librustc_interface.
This simplifies the code to construct it, at the expense of added complexity in the query control flow.
This allows to handle the arenas directly from librustc_interface.

Based on rust-lang#66707

r? @Zoxc
bors added a commit that referenced this pull request Nov 29, 2019
Rollup of 11 pull requests

Successful merges:

 - #66379 (Rephrase docs in for ptr)
 - #66589 (Draw vertical lines correctly in compiler error messages)
 - #66613 (Allow customising ty::TraitRef's printing behavior)
 - #66766 (Panic machinery comments and tweaks)
 - #66791 (Handle GlobalCtxt directly from librustc_interface query system)
 - #66793 (Record temporary static references in generator witnesses)
 - #66808 (Cleanup error code)
 - #66826 (Clarifies how to tag users for assigning PRs)
 - #66837 (Clarify `{f32,f64}::EPSILON` docs)
 - #66844 (Miri: do not consider memory allocated by caller_location leaked)
 - #66872 (Minor documentation fix)

Failed merges:

r? @ghost
@bors bors merged commit 1e12f39 into rust-lang:master Nov 30, 2019
@RalfJung
Copy link
Member

I think I need help to adjust Miri to these changes... we were using compiler.global_ctxt to enter the compiler's typing context. I tried to update that in rust-lang/miri#1086 but now we ICE immediately:

thread 'rustc' panicked at 'assertion failed: self.try_set(value).is_none()', src/librustc_data_structures/sync.rs:492:9
stack backtrace:
  [...]
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:475
  12: std::panicking::begin_panic
  13: rustc::session::Session::init_features
  14: rustc_interface::passes::register_plugins
  15: rustc_interface::queries::Queries::register_plugins
  16: rustc_interface::queries::Queries::expansion
  17: rustc_interface::queries::Queries::prepare_outputs
  18: rustc_interface::queries::Queries::global_ctxt
  19: <miri::MiriCompilerCalls as rustc_driver::Callbacks>::after_analysis::{{closure}}
             at src/bin/miri.rs:37
  20: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
             at /rustc/8f1bbd69e13c9e04a4c2b75612bc0c31af972439/src/librustc_interface/queries.rs:335
  21: <miri::MiriCompilerCalls as rustc_driver::Callbacks>::after_analysis
             at src/bin/miri.rs:36

Comment on lines +386 to +388
if callbacks.after_analysis(compiler) == Compilation::Stop {
return early_exit();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it maybe a problem that now, after_analysis is called inside compiler.enter, so that if the callback needs access to the ctx and calls compiler.enter itself, we end up with nested compiler.enter?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is indeed the problem. The Callbacks are supposed to take &'tcx Queries<'tcx> now to avoid that. So that has to be fixed before Miri can work again. Do you or @cjgillot want to fix that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should probably be an assertion to avoid calling enter twice too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prepared a PR at #66896 (and tested that this indeed is sufficient to fix Miri).

There should probably be an assertion to avoid calling enter twice too.

I didn't do that as I wouldn't know how.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. Do you still need me to do something?

@RalfJung
Copy link
Member

RalfJung commented Nov 30, 2019 via email

@cjgillot cjgillot deleted the arena branch November 30, 2019 23:20
Centril added a commit to Centril/rust that referenced this pull request Dec 1, 2019
pass Queries to compiler callbacks

rust-lang#66791 made it impossible to access the tcx in the callbacks; this should fix that.

r? @Zoxc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants