diff options
| author | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2020-10-04 15:22:23 -0700 |
|---|---|---|
| committer | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2020-10-04 16:07:03 -0700 |
| commit | e72e43c730a205237cacb8e9a7928ca0a0746252 (patch) | |
| tree | df36d4b62347a189456b033bf008960ee76dcd9a /compiler/rustc_mir/src/dataflow/framework | |
| parent | 4ccf5f731bb71db3470002d6baf5ab4792b821d9 (diff) | |
| download | rust-e72e43c730a205237cacb8e9a7928ca0a0746252.tar.gz rust-e72e43c730a205237cacb8e9a7928ca0a0746252.zip | |
Replace `(Body, DefId)` with `Body` where possible
A `Body` now contains its `MirSource`, which in turn contains the `DefId` of the item associated with the `Body`.
Diffstat (limited to 'compiler/rustc_mir/src/dataflow/framework')
| -rw-r--r-- | compiler/rustc_mir/src/dataflow/framework/engine.rs | 30 | ||||
| -rw-r--r-- | compiler/rustc_mir/src/dataflow/framework/graphviz.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_mir/src/dataflow/framework/mod.rs | 23 |
3 files changed, 17 insertions, 49 deletions
diff --git a/compiler/rustc_mir/src/dataflow/framework/engine.rs b/compiler/rustc_mir/src/dataflow/framework/engine.rs index f39c78f503d..b836e85c3a7 100644 --- a/compiler/rustc_mir/src/dataflow/framework/engine.rs +++ b/compiler/rustc_mir/src/dataflow/framework/engine.rs @@ -81,7 +81,6 @@ where { tcx: TyCtxt<'tcx>, body: &'a mir::Body<'tcx>, - def_id: DefId, dead_unwinds: Option<&'a BitSet<BasicBlock>>, entry_sets: IndexVec<BasicBlock, A::Domain>, pass_name: Option<&'static str>, @@ -103,18 +102,13 @@ where T: Idx, { /// Creates a new `Engine` to solve a gen-kill dataflow problem. - pub fn new_gen_kill( - tcx: TyCtxt<'tcx>, - body: &'a mir::Body<'tcx>, - def_id: DefId, - analysis: A, - ) -> Self { + pub fn new_gen_kill(tcx: TyCtxt<'tcx>, body: &'a mir::Body<'tcx>, analysis: A) -> Self { // If there are no back-edges in the control-flow graph, we only ever need to apply the // transfer function for each block exactly once (assuming that we process blocks in RPO). // // In this case, there's no need to compute the block transfer functions ahead of time. if !body.is_cfg_cyclic() { - return Self::new(tcx, body, def_id, analysis, None); + return Self::new(tcx, body, analysis, None); } // Otherwise, compute and store the cumulative transfer function for each block. @@ -131,7 +125,7 @@ where trans_for_block[bb].apply(state.borrow_mut()); }); - Self::new(tcx, body, def_id, analysis, Some(apply_trans as Box<_>)) + Self::new(tcx, body, analysis, Some(apply_trans as Box<_>)) } } @@ -145,19 +139,13 @@ where /// /// Gen-kill problems should use `new_gen_kill`, which will coalesce transfer functions for /// better performance. - pub fn new_generic( - tcx: TyCtxt<'tcx>, - body: &'a mir::Body<'tcx>, - def_id: DefId, - analysis: A, - ) -> Self { - Self::new(tcx, body, def_id, analysis, None) + pub fn new_generic(tcx: TyCtxt<'tcx>, body: &'a mir::Body<'tcx>, analysis: A) -> Self { + Self::new(tcx, body, analysis, None) } fn new( tcx: TyCtxt<'tcx>, body: &'a mir::Body<'tcx>, - def_id: DefId, analysis: A, apply_trans_for_block: Option<Box<dyn Fn(BasicBlock, &mut A::Domain)>>, ) -> Self { @@ -173,7 +161,6 @@ where analysis, tcx, body, - def_id, dead_unwinds: None, pass_name: None, entry_sets, @@ -209,7 +196,6 @@ where analysis, body, dead_unwinds, - def_id, mut entry_sets, tcx, apply_trans_for_block, @@ -261,7 +247,7 @@ where let results = Results { analysis, entry_sets }; - let res = write_graphviz_results(tcx, def_id, &body, &results, pass_name); + let res = write_graphviz_results(tcx, &body, &results, pass_name); if let Err(e) = res { warn!("Failed to write graphviz dataflow results: {}", e); } @@ -276,7 +262,6 @@ where /// `rustc_mir` attributes. fn write_graphviz_results<A>( tcx: TyCtxt<'tcx>, - def_id: DefId, body: &mir::Body<'tcx>, results: &Results<'tcx, A>, pass_name: Option<&'static str>, @@ -285,6 +270,7 @@ where A: Analysis<'tcx>, A::Domain: DebugWithContext<A>, { + let def_id = body.source.def_id(); let attrs = match RustcMirAttrs::parse(tcx, def_id) { Ok(attrs) => attrs, @@ -323,7 +309,7 @@ where debug!("printing dataflow results for {:?} to {}", def_id, path.display()); let mut buf = Vec::new(); - let graphviz = graphviz::Formatter::new(body, def_id, results, style); + let graphviz = graphviz::Formatter::new(body, results, style); let mut render_opts = vec![dot::RenderOption::Fontname(tcx.sess.opts.debugging_opts.graphviz_font.clone())]; if tcx.sess.opts.debugging_opts.graphviz_dark_mode { diff --git a/compiler/rustc_mir/src/dataflow/framework/graphviz.rs b/compiler/rustc_mir/src/dataflow/framework/graphviz.rs index 5d4c4251961..4e54257a1cb 100644 --- a/compiler/rustc_mir/src/dataflow/framework/graphviz.rs +++ b/compiler/rustc_mir/src/dataflow/framework/graphviz.rs @@ -6,7 +6,6 @@ use std::{io, ops, str}; use regex::Regex; use rustc_graphviz as dot; -use rustc_hir::def_id::DefId; use rustc_middle::mir::{self, BasicBlock, Body, Location}; use super::fmt::{DebugDiffWithAdapter, DebugWithAdapter, DebugWithContext}; @@ -33,7 +32,6 @@ where A: Analysis<'tcx>, { body: &'a Body<'tcx>, - def_id: DefId, results: &'a Results<'tcx, A>, style: OutputStyle, } @@ -42,13 +40,8 @@ impl<A> Formatter<'a, 'tcx, A> where A: Analysis<'tcx>, { - pub fn new( - body: &'a Body<'tcx>, - def_id: DefId, - results: &'a Results<'tcx, A>, - style: OutputStyle, - ) -> Self { - Formatter { body, def_id, results, style } + pub fn new(body: &'a Body<'tcx>, results: &'a Results<'tcx, A>, style: OutputStyle) -> Self { + Formatter { body, results, style } } } @@ -77,7 +70,7 @@ where type Edge = CfgEdge; fn graph_id(&self) -> dot::Id<'_> { - let name = graphviz_safe_def_name(self.def_id); + let name = graphviz_safe_def_name(self.body.source.def_id()); dot::Id::new(format!("graph_for_def_id_{}", name)).unwrap() } diff --git a/compiler/rustc_mir/src/dataflow/framework/mod.rs b/compiler/rustc_mir/src/dataflow/framework/mod.rs index 65c159e6a72..524ad0af1a7 100644 --- a/compiler/rustc_mir/src/dataflow/framework/mod.rs +++ b/compiler/rustc_mir/src/dataflow/framework/mod.rs @@ -13,9 +13,9 @@ //! ```ignore(cross-crate-imports) //! use rustc_mir::dataflow::Analysis; // Makes `into_engine` available. //! -//! fn do_my_analysis(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>, did: DefId) { +//! fn do_my_analysis(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>) { //! let analysis = MyAnalysis::new() -//! .into_engine(tcx, body, did) +//! .into_engine(tcx, body) //! .iterate_to_fixpoint() //! .into_results_cursor(body); //! @@ -33,7 +33,6 @@ use std::borrow::BorrowMut; use std::cmp::Ordering; -use rustc_hir::def_id::DefId; use rustc_index::bit_set::{BitSet, HybridBitSet}; use rustc_index::vec::Idx; use rustc_middle::mir::{self, BasicBlock, Location}; @@ -218,16 +217,11 @@ pub trait Analysis<'tcx>: AnalysisDomain<'tcx> { /// .iterate_to_fixpoint() /// .into_results_cursor(body); /// ``` - fn into_engine( - self, - tcx: TyCtxt<'tcx>, - body: &'mir mir::Body<'tcx>, - def_id: DefId, - ) -> Engine<'mir, 'tcx, Self> + fn into_engine(self, tcx: TyCtxt<'tcx>, body: &'mir mir::Body<'tcx>) -> Engine<'mir, 'tcx, Self> where Self: Sized, { - Engine::new_generic(tcx, body, def_id, self) + Engine::new_generic(tcx, body, self) } } @@ -381,16 +375,11 @@ where /* Extension methods */ - fn into_engine( - self, - tcx: TyCtxt<'tcx>, - body: &'mir mir::Body<'tcx>, - def_id: DefId, - ) -> Engine<'mir, 'tcx, Self> + fn into_engine(self, tcx: TyCtxt<'tcx>, body: &'mir mir::Body<'tcx>) -> Engine<'mir, 'tcx, Self> where Self: Sized, { - Engine::new_gen_kill(tcx, body, def_id, self) + Engine::new_gen_kill(tcx, body, self) } } |
