Skip to content

Commit

Permalink
rustc_interface: Remove ExpansionResult and some Steals
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Oct 24, 2019
1 parent 9f5a530 commit 94216ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
25 changes: 4 additions & 21 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn count_nodes(krate: &ast::Crate) -> usize {
declare_box_region_type!(
pub BoxedResolver,
for(),
(&mut Resolver<'_>) -> (Result<ast::Crate>, ExpansionResult)
(&mut Resolver<'_>) -> (Result<ast::Crate>, ResolverOutputs)
);

/// Runs the "early phases" of the compiler: initial `cfg` processing,
Expand Down Expand Up @@ -149,33 +149,16 @@ pub fn configure_and_expand(
}
};
box_region_allow_access!(for(), (&mut Resolver<'_>), (&mut resolver));
ExpansionResult::from_resolver_outputs(resolver.into_outputs())
resolver.into_outputs()
});
result.map(|k| (k, resolver))
}

pub struct ExpansionResult {
pub resolver_outputs: Steal<ResolverOutputs>,
}

impl ExpansionResult {
fn from_resolver_outputs(resolver_outputs: ResolverOutputs) -> Self {
ExpansionResult { resolver_outputs: Steal::new(resolver_outputs) }
}
}

impl BoxedResolver {
pub fn to_expansion_result(
resolver: Rc<RefCell<BoxedResolver>>,
) -> ExpansionResult {
pub fn to_resolver_outputs(resolver: Rc<RefCell<BoxedResolver>>) -> ResolverOutputs {
match Rc::try_unwrap(resolver) {
Ok(resolver) => resolver.into_inner().complete(),
Err(resolver) => {
let resolver = &*resolver;
resolver.borrow_mut().access(|resolver| {
ExpansionResult::from_resolver_outputs(resolver.clone_outputs())
})
}
Err(resolver) => resolver.borrow_mut().access(|resolver| resolver.clone_outputs()),
}
}
}
Expand Down
17 changes: 10 additions & 7 deletions src/librustc_interface/queries.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::interface::{Compiler, Result};
use crate::passes::{self, BoxedResolver, ExpansionResult, BoxedGlobalCtxt, PluginInfo};
use crate::passes::{self, BoxedResolver, BoxedGlobalCtxt, PluginInfo};

use rustc_incremental::DepGraphFuture;
use rustc_data_structures::sync::Lrc;
Expand All @@ -11,6 +11,7 @@ use rustc::session::Session;
use rustc::lint::LintStore;
use rustc::hir::def_id::LOCAL_CRATE;
use rustc::ty::steal::Steal;
use rustc::ty::ResolverOutputs;
use rustc::dep_graph::DepGraph;
use std::cell::{Ref, RefMut, RefCell};
use std::rc::Rc;
Expand Down Expand Up @@ -81,7 +82,7 @@ pub(crate) struct Queries {
register_plugins: Query<(ast::Crate, PluginInfo, Lrc<LintStore>)>,
expansion: Query<(ast::Crate, Steal<Rc<RefCell<BoxedResolver>>>, Lrc<LintStore>)>,
dep_graph: Query<DepGraph>,
lower_to_hir: Query<(Steal<hir::map::Forest>, ExpansionResult)>,
lower_to_hir: Query<(Steal<hir::map::Forest>, Steal<ResolverOutputs>)>,
prepare_outputs: Query<OutputFilenames>,
global_ctxt: Query<BoxedGlobalCtxt>,
ongoing_codegen: Query<Box<dyn Any>>,
Expand Down Expand Up @@ -191,7 +192,9 @@ impl Compiler {
})
}

pub fn lower_to_hir(&self) -> Result<&Query<(Steal<hir::map::Forest>, ExpansionResult)>> {
pub fn lower_to_hir(
&self,
) -> Result<&Query<(Steal<hir::map::Forest>, Steal<ResolverOutputs>)>> {
self.queries.lower_to_hir.compute(|| {
let expansion_result = self.expansion()?;
let peeked = expansion_result.peek();
Expand All @@ -207,14 +210,14 @@ impl Compiler {
&krate
)
})?);
Ok((hir, BoxedResolver::to_expansion_result(resolver)))
Ok((hir, Steal::new(BoxedResolver::to_resolver_outputs(resolver))))
})
}

pub fn prepare_outputs(&self) -> Result<&Query<OutputFilenames>> {
self.queries.prepare_outputs.compute(|| {
let expansion_result = self.expansion()?;
let (krate, boxed_resolver) = &*expansion_result.peek();
let (krate, boxed_resolver, _) = &*expansion_result.peek();
let crate_name = self.crate_name()?;
let crate_name = crate_name.peek();
passes::prepare_outputs(self.session(), self, &krate, &boxed_resolver, &crate_name)
Expand All @@ -228,12 +231,12 @@ impl Compiler {
let lint_store = self.expansion()?.peek().2.clone();
let hir = self.lower_to_hir()?;
let hir = hir.peek();
let (ref hir_forest, ref expansion) = *hir;
let (hir_forest, resolver_outputs) = &*hir;
Ok(passes::create_global_ctxt(
self,
lint_store,
hir_forest.steal(),
expansion.resolver_outputs.steal(),
resolver_outputs.steal(),
outputs,
&crate_name))
})
Expand Down

0 comments on commit 94216ce

Please sign in to comment.