提交 ca88c44a 编写于 作者: J Jeffrey Seyfried

Avoid using the lowering context in `librustc_save_analysis`

上级 02df9f32
......@@ -165,8 +165,7 @@ pub fn compile_input(sess: &Session,
&hir_map,
&expanded_crate,
&hir_map.krate(),
&id[..],
&lcx),
&id[..]),
Ok(()));
}
......@@ -203,7 +202,6 @@ pub fn compile_input(sess: &Session,
&analysis,
mir_map.as_ref(),
tcx,
&lcx,
&id);
(control.after_analysis.callback)(state);
......@@ -345,7 +343,6 @@ pub struct CompileState<'a, 'ast: 'a, 'tcx: 'a> {
pub mir_map: Option<&'a MirMap<'tcx>>,
pub analysis: Option<&'a ty::CrateAnalysis<'a>>,
pub tcx: Option<&'a TyCtxt<'tcx>>,
pub lcx: Option<&'a LoweringContext<'a>>,
pub trans: Option<&'a trans::CrateTranslation>,
}
......@@ -368,7 +365,6 @@ fn empty(input: &'a Input,
analysis: None,
mir_map: None,
tcx: None,
lcx: None,
trans: None,
}
}
......@@ -400,15 +396,13 @@ fn state_after_write_deps(input: &'a Input,
hir_map: &'a hir_map::Map<'ast>,
krate: &'a ast::Crate,
hir_crate: &'a hir::Crate,
crate_name: &'a str,
lcx: &'a LoweringContext<'a>)
crate_name: &'a str)
-> CompileState<'a, 'ast, 'tcx> {
CompileState {
crate_name: Some(crate_name),
ast_map: Some(hir_map),
krate: Some(krate),
hir_crate: Some(hir_crate),
lcx: Some(lcx),
..CompileState::empty(input, session, out_dir)
}
}
......@@ -421,7 +415,6 @@ fn state_after_analysis(input: &'a Input,
analysis: &'a ty::CrateAnalysis,
mir_map: Option<&'a MirMap<'tcx>>,
tcx: &'a TyCtxt<'tcx>,
lcx: &'a LoweringContext<'a>,
crate_name: &'a str)
-> CompileState<'a, 'ast, 'tcx> {
CompileState {
......@@ -430,7 +423,6 @@ fn state_after_analysis(input: &'a Input,
tcx: Some(tcx),
krate: krate,
hir_crate: Some(hir_crate),
lcx: Some(lcx),
crate_name: Some(crate_name),
..CompileState::empty(input, session, out_dir)
}
......
......@@ -499,7 +499,6 @@ fn build_controller(&mut self, sess: &Session) -> CompileController<'a> {
control.after_analysis.callback = box |state| {
time(state.session.time_passes(), "save analysis", || {
save::process_crate(state.tcx.unwrap(),
state.lcx.unwrap(),
state.krate.unwrap(),
state.analysis.unwrap(),
state.crate_name.unwrap(),
......
......@@ -42,8 +42,6 @@
use syntax::print::pprust::{path_to_string, ty_to_string};
use syntax::ptr::P;
use rustc::hir::lowering::lower_expr;
use super::{escape, generated_code, SaveContext, PathCollector};
use super::data::*;
use super::dump::Dump;
......@@ -1222,7 +1220,7 @@ fn visit_expr(&mut self, ex: &ast::Expr) {
visit::walk_expr(self, ex);
}
ast::ExprKind::Struct(ref path, ref fields, ref base) => {
let hir_expr = lower_expr(self.save_ctxt.lcx, ex);
let hir_expr = self.save_ctxt.tcx.map.expect_expr(ex.id);
let adt = self.tcx.expr_ty(&hir_expr).ty_adt_def().unwrap();
let def = self.tcx.resolve_expr(&hir_expr);
self.process_struct_lit(ex, path, fields, adt.variant_of_def(def), base)
......@@ -1241,7 +1239,7 @@ fn visit_expr(&mut self, ex: &ast::Expr) {
ast::ExprKind::TupField(ref sub_ex, idx) => {
self.visit_expr(&sub_ex);
let hir_node = lower_expr(self.save_ctxt.lcx, sub_ex);
let hir_node = self.save_ctxt.tcx.map.expect_expr(sub_ex.id);
let ty = &self.tcx.expr_ty_adjusted(&hir_node).sty;
match *ty {
ty::TyStruct(def, _) => {
......
......@@ -28,7 +28,7 @@
#[macro_use] extern crate syntax;
extern crate serialize as rustc_serialize;
use rustc::hir::{self, lowering};
use rustc::hir;
use rustc::hir::map::NodeItem;
use rustc::hir::def::Def;
use rustc::hir::def_id::DefId;
......@@ -75,7 +75,6 @@ pub enum Row {
pub struct SaveContext<'l, 'tcx: 'l> {
tcx: &'l TyCtxt<'tcx>,
lcx: &'l lowering::LoweringContext<'l>,
span_utils: SpanUtils<'tcx>,
}
......@@ -84,20 +83,16 @@ pub struct SaveContext<'l, 'tcx: 'l> {
);
impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
pub fn new(tcx: &'l TyCtxt<'tcx>,
lcx: &'l lowering::LoweringContext<'l>)
-> SaveContext<'l, 'tcx> {
pub fn new(tcx: &'l TyCtxt<'tcx>) -> SaveContext<'l, 'tcx> {
let span_utils = SpanUtils::new(&tcx.sess);
SaveContext::from_span_utils(tcx, lcx, span_utils)
SaveContext::from_span_utils(tcx, span_utils)
}
pub fn from_span_utils(tcx: &'l TyCtxt<'tcx>,
lcx: &'l lowering::LoweringContext<'l>,
span_utils: SpanUtils<'tcx>)
-> SaveContext<'l, 'tcx> {
SaveContext {
tcx: tcx,
lcx: lcx,
span_utils: span_utils,
}
}
......@@ -378,14 +373,14 @@ pub fn get_trait_ref_data(&self,
}
pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
let hir_node = lowering::lower_expr(self.lcx, expr);
let hir_node = self.tcx.map.expect_expr(expr.id);
let ty = self.tcx.expr_ty_adjusted_opt(&hir_node);
if ty.is_none() || ty.unwrap().sty == ty::TyError {
return None;
}
match expr.node {
ast::ExprKind::Field(ref sub_ex, ident) => {
let hir_node = lowering::lower_expr(self.lcx, sub_ex);
let hir_node = self.tcx.map.expect_expr(sub_ex.id);
match self.tcx.expr_ty_adjusted(&hir_node).sty {
ty::TyStruct(def, _) => {
let f = def.struct_variant().field_named(ident.node.name);
......@@ -405,7 +400,7 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
}
}
ast::ExprKind::Struct(ref path, _, _) => {
let hir_node = lowering::lower_expr(self.lcx, expr);
let hir_node = self.tcx.map.expect_expr(expr.id);
match self.tcx.expr_ty_adjusted(&hir_node).sty {
ty::TyStruct(def, _) => {
let sub_span = self.span_utils.span_for_last_ident(path.span);
......@@ -704,7 +699,6 @@ fn extension(&self) -> &'static str {
}
pub fn process_crate<'l, 'tcx>(tcx: &'l TyCtxt<'tcx>,
lcx: &'l lowering::LoweringContext<'l>,
krate: &ast::Crate,
analysis: &'l ty::CrateAnalysis<'l>,
cratename: &str,
......@@ -755,7 +749,7 @@ pub fn process_crate<'l, 'tcx>(tcx: &'l TyCtxt<'tcx>,
let output = &mut output_file;
let utils: SpanUtils<'tcx> = SpanUtils::new(&tcx.sess);
let save_ctxt = SaveContext::new(tcx, lcx);
let save_ctxt = SaveContext::new(tcx);
macro_rules! dump {
($new_dumper: expr) => {{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册