Auto merge of #33296 - jseyfried:non_idempotent_lowering, r=nrc
Remove the requirement that ast->hir lowering be reproducible This PR changes the ast->hir lowerer to be non-reproducible, and it removes the lowering context's id cache. If the `hir` of an `ast` node needs to be reproduced, we can use the hir map instead of the lowerer -- for example, `tcx.map.expect_expr(expr.id)` instead of `lower_expr(lcx, expr)`. r? @nrc
This commit is contained in:
commit
855fb61922
File diff suppressed because it is too large
Load Diff
@ -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);
|
||||
|
||||
@ -248,9 +246,7 @@ pub fn compile_input(sess: &Session,
|
||||
}
|
||||
|
||||
fn keep_mtwt_tables(sess: &Session) -> bool {
|
||||
sess.opts.debugging_opts.keep_mtwt_tables ||
|
||||
sess.opts.debugging_opts.save_analysis ||
|
||||
sess.opts.debugging_opts.save_analysis_csv
|
||||
sess.opts.debugging_opts.keep_mtwt_tables
|
||||
}
|
||||
|
||||
fn keep_ast(sess: &Session) -> bool {
|
||||
@ -345,7 +341,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 +363,6 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
|
||||
analysis: None,
|
||||
mir_map: None,
|
||||
tcx: None,
|
||||
lcx: None,
|
||||
trans: None,
|
||||
}
|
||||
}
|
||||
@ -400,15 +394,13 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
|
||||
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 +413,6 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
|
||||
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 +421,6 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
|
||||
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 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
||||
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::visit::{self, Visitor};
|
||||
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 @@ impl<'v, 'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'v> for DumpVisitor<'l, 'tcx,
|
||||
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 @@ impl<'v, 'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'v> for DumpVisitor<'l, 'tcx,
|
||||
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 mod recorder {
|
||||
|
||||
pub struct SaveContext<'l, 'tcx: 'l> {
|
||||
tcx: &'l TyCtxt<'tcx>,
|
||||
lcx: &'l lowering::LoweringContext<'l>,
|
||||
span_utils: SpanUtils<'tcx>,
|
||||
}
|
||||
|
||||
@ -84,20 +83,16 @@ macro_rules! option_try(
|
||||
);
|
||||
|
||||
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 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
||||
}
|
||||
|
||||
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 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
||||
}
|
||||
}
|
||||
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 @@ impl Format {
|
||||
}
|
||||
|
||||
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) => {{
|
||||
|
Loading…
Reference in New Issue
Block a user