Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract rustc_mir_pretty crate from rustc_middle #89636

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3670,6 +3670,7 @@ dependencies = [
"rustc_lexer",
"rustc_middle",
"rustc_mir_dataflow",
"rustc_mir_pretty",
"rustc_serialize",
"rustc_session",
"rustc_span",
Expand Down Expand Up @@ -3782,6 +3783,7 @@ dependencies = [
"rustc_macros",
"rustc_middle",
"rustc_mir_dataflow",
"rustc_mir_pretty",
"rustc_query_system",
"rustc_session",
"rustc_span",
Expand Down Expand Up @@ -3839,6 +3841,7 @@ dependencies = [
"rustc_lint",
"rustc_metadata",
"rustc_middle",
"rustc_mir_pretty",
"rustc_parse",
"rustc_plugin_impl",
"rustc_save_analysis",
Expand Down Expand Up @@ -4132,8 +4135,6 @@ version = "0.0.0"
dependencies = [
"bitflags",
"chalk-ir",
"either",
"gsgdt",
"polonius-engine",
"rand 0.8.4",
"rand_xoshiro 0.6.0",
Expand All @@ -4146,7 +4147,6 @@ dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
"rustc_graphviz",
"rustc_hir",
"rustc_index",
"rustc_macros",
Expand Down Expand Up @@ -4195,6 +4195,7 @@ dependencies = [
"rustc_hir",
"rustc_index",
"rustc_middle",
"rustc_mir_pretty",
"rustc_serialize",
"rustc_session",
"rustc_span",
Expand All @@ -4203,6 +4204,23 @@ dependencies = [
"tracing",
]

[[package]]
name = "rustc_mir_pretty"
version = "0.0.0"
dependencies = [
"either",
"gsgdt",
"rustc_data_structures",
"rustc_graphviz",
"rustc_hir",
"rustc_index",
"rustc_middle",
"rustc_session",
"rustc_span",
"rustc_target",
"tracing",
]

[[package]]
name = "rustc_mir_transform"
version = "0.0.0"
Expand All @@ -4218,6 +4236,7 @@ dependencies = [
"rustc_index",
"rustc_middle",
"rustc_mir_dataflow",
"rustc_mir_pretty",
"rustc_query_system",
"rustc_serialize",
"rustc_session",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_borrowck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rustc_lexer = { path = "../rustc_lexer" }
rustc_middle = { path = "../rustc_middle" }
rustc_const_eval = { path = "../rustc_const_eval" }
rustc_mir_dataflow = { path = "../rustc_mir_dataflow" }
rustc_mir_pretty = { path = "../rustc_mir_pretty" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_session = { path = "../rustc_session" }
rustc_target = { path = "../rustc_target" }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use rustc_data_structures::vec_map::VecMap;
use rustc_errors::Diagnostic;
use rustc_index::vec::IndexVec;
use rustc_infer::infer::InferCtxt;
use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere};
use rustc_middle::mir::{
BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location,
Promoted,
};
use rustc_middle::ty::{self, OpaqueTypeKey, RegionKind, RegionVid, Ty};
use rustc_mir_pretty::{create_dump_file, dump_enabled, dump_mir, PassWhere};
use rustc_span::symbol::sym;
use std::env;
use std::fmt::Debug;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) fn codegen_fn<'tcx>(
let mir = tcx.instance_mir(instance.def);
let _mir_guard = crate::PrintOnPanic(|| {
let mut buf = Vec::new();
rustc_middle::mir::write_mir_pretty(tcx, Some(instance.def_id()), &mut buf).unwrap();
rustc_mir_pretty::write_mir_pretty(tcx, Some(instance.def_id()), &mut buf).unwrap();
String::from_utf8_lossy(&buf).into_owned()
});

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern crate rustc_incremental;
extern crate rustc_index;
extern crate rustc_interface;
extern crate rustc_metadata;
extern crate rustc_mir_pretty;
extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_target;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_const_eval/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ rustc_infer = { path = "../rustc_infer" }
rustc_macros = { path = "../rustc_macros" }
rustc_middle = { path = "../rustc_middle" }
rustc_mir_dataflow = { path = "../rustc_mir_dataflow" }
rustc_mir_pretty = { path = "../rustc_mir_pretty" }
rustc_query_system = { path = "../rustc_query_system" }
rustc_session = { path = "../rustc_session" }
rustc_target = { path = "../rustc_target" }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use rustc_errors::ErrorReported;
use rustc_hir::def::DefKind;
use rustc_middle::mir;
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::mir::pretty::display_allocation;
use rustc_middle::traits::Reveal;
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, subst::Subst, TyCtxt};
use rustc_mir_pretty::display_allocation;
use rustc_span::source_map::Span;
use rustc_target::abi::Abi;
use std::borrow::Cow;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use std::ptr;

use rustc_ast::Mutability;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_middle::mir::display_allocation;
use rustc_middle::ty::{Instance, ParamEnv, TyCtxt};
use rustc_mir_pretty::display_allocation;
use rustc_target::abi::{Align, HasDataLayout, Size, TargetDataLayout};

use super::{
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rustc_feature = { path = "../rustc_feature" }
rustc_hir = { path = "../rustc_hir" }
rustc_hir_pretty = { path = "../rustc_hir_pretty" }
rustc_metadata = { path = "../rustc_metadata" }
rustc_mir_pretty = { path = "../rustc_mir_pretty" }
rustc_const_eval = { path = "../rustc_const_eval" }
rustc_parse = { path = "../rustc_parse" }
rustc_plugin_impl = { path = "../rustc_plugin_impl" }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_driver/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use rustc_errors::ErrorReported;
use rustc_hir as hir;
use rustc_hir_pretty as pprust_hir;
use rustc_middle::hir::map as hir_map;
use rustc_middle::mir::{write_mir_graphviz, write_mir_pretty};
use rustc_middle::ty::{self, TyCtxt};
use rustc_mir_pretty::{write_mir_graphviz, write_mir_pretty};
use rustc_session::config::{Input, PpAstTreeMode, PpHirMode, PpMode, PpSourceMode};
use rustc_session::Session;
use rustc_span::symbol::Ident;
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_middle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ doctest = false
[dependencies]
rustc_arena = { path = "../rustc_arena" }
bitflags = "1.2.1"
either = "1.5.0"
gsgdt = "0.1.2"
tracing = "0.1"
rustc-rayon = "0.3.1"
rustc-rayon-core = "0.3.1"
Expand All @@ -24,7 +22,6 @@ rustc_macros = { path = "../rustc_macros" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_query_system = { path = "../rustc_query_system" }
rustc_errors = { path = "../rustc_errors" }
rustc_graphviz = { path = "../rustc_graphviz" }
rustc_index = { path = "../rustc_index" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_ast = { path = "../rustc_ast" }
Expand Down
11 changes: 0 additions & 11 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,19 @@ use self::predecessors::{PredecessorCache, Predecessors};
pub use self::query::*;

pub mod coverage;
mod generic_graph;
pub mod generic_graphviz;
mod graph_cyclic_cache;
pub mod graphviz;
pub mod interpret;
pub mod mono;
pub mod patch;
mod predecessors;
pub mod pretty;
mod query;
pub mod spanview;
pub mod tcx;
pub mod terminator;
pub use terminator::*;
pub mod traversal;
mod type_foldable;
pub mod visit;

pub use self::generic_graph::graphviz_safe_def_name;
pub use self::graphviz::write_mir_graphviz;
pub use self::pretty::{
create_dump_file, display_allocation, dump_enabled, dump_mir, write_mir_pretty, PassWhere,
};

/// Types for locals
pub type LocalDecls<'tcx> = IndexVec<Local, LocalDecl<'tcx>>;

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_mir_dataflow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rustc_graphviz = { path = "../rustc_graphviz" }
rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
rustc_middle = { path = "../rustc_middle" }
rustc_mir_pretty = { path = "../rustc_mir_pretty" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_session = { path = "../rustc_session" }
rustc_target = { path = "../rustc_target" }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_dataflow/src/framework/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use rustc_hir::def_id::DefId;
use rustc_index::bit_set::BitSet;
use rustc_index::vec::{Idx, IndexVec};
use rustc_middle::mir::{self, traversal, BasicBlock};
use rustc_middle::mir::{create_dump_file, dump_enabled};
use rustc_middle::ty::TyCtxt;
use rustc_mir_pretty::{create_dump_file, dump_enabled};
use rustc_span::symbol::{sym, Symbol};

use super::fmt::DebugWithContext;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_dataflow/src/framework/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::{io, ops, str};

use regex::Regex;
use rustc_graphviz as dot;
use rustc_middle::mir::graphviz_safe_def_name;
use rustc_middle::mir::{self, BasicBlock, Body, Location};
use rustc_mir_pretty::graphviz_safe_def_name;

use super::fmt::{DebugDiffWithAdapter, DebugWithAdapter, DebugWithContext};
use super::{Analysis, Direction, Results, ResultsRefCursor, ResultsVisitor};
Expand Down
20 changes: 20 additions & 0 deletions compiler/rustc_mir_pretty/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "rustc_mir_pretty"
version = "0.0.0"
edition = "2021"

[lib]
doctest = false

[dependencies]
either = "1.5.0"
gsgdt = "0.1.2"
tracing = "0.1"
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_graphviz = { path = "../rustc_graphviz" }
rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
rustc_middle = { path = "../rustc_middle" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
19 changes: 19 additions & 0 deletions compiler/rustc_mir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![feature(in_band_lifetimes)]
#![feature(try_blocks)]

#[macro_use]
extern crate rustc_middle;
#[macro_use]
extern crate tracing;

mod generic_graph;
pub mod generic_graphviz;
mod graphviz;
mod pretty;
pub mod spanview;

pub use self::generic_graph::graphviz_safe_def_name;
pub use self::graphviz::write_mir_graphviz;
pub use self::pretty::{
create_dump_file, display_allocation, dump_enabled, dump_mir, write_mir_pretty, PassWhere,
};
1 change: 1 addition & 0 deletions compiler/rustc_mir_transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ rustc_index = { path = "../rustc_index" }
rustc_middle = { path = "../rustc_middle" }
rustc_const_eval = { path = "../rustc_const_eval" }
rustc_mir_dataflow = { path = "../rustc_mir_dataflow" }
rustc_mir_pretty = { path = "../rustc_mir_pretty" }
rustc_query_system = { path = "../rustc_query_system" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_session = { path = "../rustc_session" }
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_mir_transform/src/coverage/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,13 @@
use super::graph::{BasicCoverageBlock, BasicCoverageBlockData, CoverageGraph};
use super::spans::CoverageSpan;

use rustc_middle::mir::create_dump_file;
use rustc_middle::mir::generic_graphviz::GraphvizWriter;
use rustc_middle::mir::spanview::{self, SpanViewable};

use rustc_data_structures::fx::FxHashMap;
use rustc_middle::mir::coverage::*;
use rustc_middle::mir::{self, BasicBlock, TerminatorKind};
use rustc_middle::ty::TyCtxt;
use rustc_mir_pretty::create_dump_file;
use rustc_mir_pretty::generic_graphviz::GraphvizWriter;
use rustc_mir_pretty::spanview::{self, SpanViewable};
use rustc_span::Span;

use std::iter;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ use rustc_index::vec::IndexVec;
use rustc_middle::hir;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::coverage::*;
use rustc_middle::mir::dump_enabled;
use rustc_middle::mir::{
self, BasicBlock, BasicBlockData, Coverage, SourceInfo, Statement, StatementKind, Terminator,
TerminatorKind,
};
use rustc_middle::ty::TyCtxt;
use rustc_mir_pretty::dump_enabled;
use rustc_span::def_id::DefId;
use rustc_span::source_map::SourceMap;
use rustc_span::{CharPos, ExpnKind, Pos, SourceFile, Span, Symbol};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/coverage/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use super::debug::term_type;
use super::graph::{BasicCoverageBlock, BasicCoverageBlockData, CoverageGraph, START_BCB};

use rustc_data_structures::graph::WithNumNodes;
use rustc_middle::mir::spanview::source_range_no_file;
use rustc_middle::mir::{
self, AggregateKind, BasicBlock, FakeReadCause, Rvalue, Statement, StatementKind, Terminator,
TerminatorKind,
};
use rustc_middle::ty::TyCtxt;
use rustc_mir_pretty::spanview::source_range_no_file;
use rustc_span::source_map::original_sp;
use rustc_span::{BytePos, ExpnKind, MacroKind, Span, Symbol};

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/dest_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ use rustc_index::{
};
use rustc_middle::mir::tcx::PlaceTy;
use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor};
use rustc_middle::mir::{dump_mir, PassWhere};
use rustc_middle::mir::{
traversal, Body, InlineAsmOperand, Local, LocalKind, Location, Operand, Place, PlaceElem,
Rvalue, Statement, StatementKind, Terminator, TerminatorKind,
};
use rustc_middle::ty::TyCtxt;
use rustc_mir_dataflow::impls::{MaybeInitializedLocals, MaybeLiveLocals};
use rustc_mir_dataflow::Analysis;
use rustc_mir_pretty::{dump_mir, PassWhere};

// Empirical measurements have resulted in some observations:
// - Running on a body with a single block and 500 locals takes barely any time
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/dump_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::fs::File;
use std::io;

use crate::MirPass;
use rustc_middle::mir::write_mir_pretty;
use rustc_middle::mir::Body;
use rustc_middle::ty::TyCtxt;
use rustc_mir_pretty::write_mir_pretty;
use rustc_session::config::{OutputFilenames, OutputType};

pub struct Marker(pub &'static str);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ use rustc_hir as hir;
use rustc_hir::lang_items::LangItem;
use rustc_index::bit_set::{BitMatrix, BitSet};
use rustc_index::vec::{Idx, IndexVec};
use rustc_middle::mir::dump_mir;
use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor};
use rustc_middle::mir::*;
use rustc_middle::ty::subst::{Subst, SubstsRef};
Expand All @@ -68,6 +67,7 @@ use rustc_mir_dataflow::impls::{
};
use rustc_mir_dataflow::storage;
use rustc_mir_dataflow::{self, Analysis};
use rustc_mir_pretty::dump_mir;
use rustc_target::abi::VariantIdx;
use rustc_target::spec::PanicStrategy;
use std::{iter, ops};
Expand Down
Loading