Store dumper directly in Visitor
This commit is contained in:
parent
a6d6eea4c8
commit
5b822891be
@ -75,10 +75,10 @@ macro_rules! access_from_vis {
|
||||
};
|
||||
}
|
||||
|
||||
pub struct DumpVisitor<'l, 'tcx, 'll> {
|
||||
pub struct DumpVisitor<'l, 'tcx> {
|
||||
save_ctxt: SaveContext<'l, 'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
dumper: &'ll mut Dumper,
|
||||
dumper: Dumper,
|
||||
|
||||
span: SpanUtils<'l>,
|
||||
|
||||
@ -90,12 +90,12 @@ pub struct DumpVisitor<'l, 'tcx, 'll> {
|
||||
// macro_calls: FxHashSet<Span>,
|
||||
}
|
||||
|
||||
impl<'l, 'tcx, 'll> DumpVisitor<'l, 'tcx, 'll> {
|
||||
impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
|
||||
pub fn new(
|
||||
save_ctxt: SaveContext<'l, 'tcx>,
|
||||
dumper: &'ll mut Dumper,
|
||||
) -> DumpVisitor<'l, 'tcx, 'll> {
|
||||
) -> DumpVisitor<'l, 'tcx> {
|
||||
let span_utils = SpanUtils::new(&save_ctxt.tcx.sess);
|
||||
let dumper = Dumper::new(save_ctxt.config.clone());
|
||||
DumpVisitor {
|
||||
tcx: save_ctxt.tcx,
|
||||
save_ctxt,
|
||||
@ -106,9 +106,13 @@ impl<'l, 'tcx, 'll> DumpVisitor<'l, 'tcx, 'll> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_analysis(self) -> rls_data::Analysis {
|
||||
self.dumper.into_analysis()
|
||||
}
|
||||
|
||||
fn nest_tables<F>(&mut self, item_id: NodeId, f: F)
|
||||
where
|
||||
F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll>),
|
||||
F: FnOnce(&mut Self),
|
||||
{
|
||||
let item_def_id = self.tcx.hir().local_def_id_from_node_id(item_id);
|
||||
if self.tcx.has_typeck_tables(item_def_id) {
|
||||
@ -1298,7 +1302,7 @@ impl<'l, 'tcx, 'll> DumpVisitor<'l, 'tcx, 'll> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'l, 'tcx, 'll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll> {
|
||||
impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
|
||||
fn visit_mod(&mut self, m: &'l ast::Mod, span: Span, attrs: &[ast::Attribute], id: NodeId) {
|
||||
// Since we handle explicit modules ourselves in visit_item, this should
|
||||
// only get called for the root module of a crate.
|
||||
|
@ -22,8 +22,8 @@ impl Dumper {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_output(self, f: impl FnOnce(&Analysis)) {
|
||||
f(&self.result)
|
||||
pub fn into_analysis(self) -> Analysis {
|
||||
self.result
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,6 @@ use syntax::visit::{self, Visitor};
|
||||
use syntax::print::pprust::{arg_to_string, ty_to_string};
|
||||
use syntax_pos::*;
|
||||
|
||||
use dumper::Dumper;
|
||||
use dump_visitor::DumpVisitor;
|
||||
use span_utils::SpanUtils;
|
||||
|
||||
@ -1076,18 +1075,15 @@ impl<'a> SaveHandler for DumpHandler<'a> {
|
||||
) {
|
||||
let sess = &save_ctxt.tcx.sess;
|
||||
let (output, file_name) = self.output_file(&save_ctxt);
|
||||
let mut dumper = Dumper::new(save_ctxt.config.clone());
|
||||
let mut visitor = DumpVisitor::new(save_ctxt, &mut dumper);
|
||||
let mut visitor = DumpVisitor::new(save_ctxt);
|
||||
|
||||
visitor.dump_crate_info(cratename, krate);
|
||||
visitor.dump_compilation_options(input, cratename);
|
||||
visit::walk_crate(&mut visitor, krate);
|
||||
|
||||
dumper.to_output(|analysis| {
|
||||
if let Err(e) = serde_json::to_writer(output, analysis) {
|
||||
error!("Can't serialize save-analysis: {:?}", e);
|
||||
}
|
||||
});
|
||||
if let Err(e) = serde_json::to_writer(output, &visitor.into_analysis()) {
|
||||
error!("Can't serialize save-analysis: {:?}", e);
|
||||
}
|
||||
|
||||
if sess.opts.debugging_opts.emit_artifact_notifications {
|
||||
sess.parse_sess.span_diagnostic
|
||||
@ -1109,19 +1105,13 @@ impl<'b> SaveHandler for CallbackHandler<'b> {
|
||||
cratename: &str,
|
||||
input: &'l Input,
|
||||
) {
|
||||
// We're using the Dumper here because it has the format of the
|
||||
// save-analysis results that we will pass to the callback. IOW, we are
|
||||
// using the Dumper to collect the save-analysis results, but not
|
||||
// actually to dump them to a file. This is all a bit convoluted and
|
||||
// there is certainly a simpler design here trying to get out (FIXME).
|
||||
let mut dumper = Dumper::new(save_ctxt.config.clone());
|
||||
let mut visitor = DumpVisitor::new(save_ctxt, &mut dumper);
|
||||
let mut visitor = DumpVisitor::new(save_ctxt);
|
||||
|
||||
visitor.dump_crate_info(cratename, krate);
|
||||
visitor.dump_compilation_options(input, cratename);
|
||||
visit::walk_crate(&mut visitor, krate);
|
||||
|
||||
dumper.to_output(|a| (self.callback)(a))
|
||||
(self.callback)(&visitor.into_analysis())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user