Skip to content

Commit 87d6fdc

Browse files
committed
revert: drop rustfmt-only refactor from this PR
1 parent 9aa6171 commit 87d6fdc

File tree

11 files changed

+125
-167
lines changed

11 files changed

+125
-167
lines changed

src/bin/cargo_stable_mir_json.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
use {
2-
anyhow::{bail, Result},
3-
std::{
4-
env,
5-
io::Write,
6-
os::unix::fs::PermissionsExt,
7-
path::{Path, PathBuf},
8-
},
9-
};
1+
use std::env;
2+
3+
use std::io::Write;
4+
use std::os::unix::fs::PermissionsExt;
5+
use std::path::{Path, PathBuf};
6+
7+
use anyhow::{bail, Result};
108

119
fn main() -> Result<()> {
1210
let args: Vec<_> = env::args().collect();

src/driver.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This module provides a compiler driver such that:
22
//!
3-
//! 1. the rustc compiler context is available
4-
//! 2. the rustc `stable_mir` APIs are available
3+
//! 1. the rustc compiler context is available
4+
//! 2. the rustc `stable_mir` APIs are available
55
//!
66
//! It exports a single function:
77
//!
@@ -22,10 +22,10 @@ extern crate rustc_interface;
2222
extern crate rustc_middle;
2323
extern crate rustc_session;
2424
extern crate rustc_smir;
25-
use {
26-
rustc_driver::Compilation, rustc_interface::interface::Compiler, rustc_middle::ty::TyCtxt,
27-
rustc_smir::rustc_internal,
28-
};
25+
use rustc_driver::Compilation;
26+
use rustc_interface::interface::Compiler;
27+
use rustc_middle::ty::TyCtxt;
28+
use rustc_smir::rustc_internal;
2929

3030
struct StableMirCallbacks {
3131
callback_fn: fn(TyCtxt) -> (),

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
pub mod driver;
33
pub mod mk_graph;
44
pub mod printer;
5-
pub use {driver::stable_mir_driver, printer::*};
5+
pub use driver::stable_mir_driver;
6+
pub use printer::*;

src/main.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
use std::env;
33
pub mod driver;
44
pub mod printer;
5-
use {
6-
driver::stable_mir_driver,
7-
printer::emit_smir,
8-
stable_mir_json::mk_graph::{emit_d2file, emit_dotfile},
9-
};
5+
use driver::stable_mir_driver;
6+
use printer::emit_smir;
7+
use stable_mir_json::mk_graph::{emit_d2file, emit_dotfile};
108

119
fn main() {
1210
let mut args: Vec<String> = env::args().collect();

src/mk_graph/context.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@
33
use std::collections::HashMap;
44

55
extern crate stable_mir;
6-
use {
7-
super::{
8-
index::{AllocIndex, LayoutInfo, TypeEntry, TypeIndex, TypeKind},
9-
util::{function_string, short_fn_name, GraphLabelString},
10-
},
11-
crate::printer::SmirJson,
12-
stable_mir::{
13-
mir::{
14-
BorrowKind, ConstOperand, Mutability, NonDivergingIntrinsic, Operand, Rvalue,
15-
Statement, StatementKind, Terminator, TerminatorKind,
16-
},
17-
ty::{ConstantKind, IndexedVal, MirConst, Ty},
18-
},
6+
use stable_mir::mir::{
7+
BorrowKind, ConstOperand, Mutability, NonDivergingIntrinsic, Operand, Rvalue, Statement,
8+
StatementKind, Terminator, TerminatorKind,
199
};
10+
use stable_mir::ty::{ConstantKind, IndexedVal, MirConst, Ty};
11+
12+
use crate::printer::SmirJson;
13+
14+
use super::index::{AllocIndex, LayoutInfo, TypeEntry, TypeIndex, TypeKind};
15+
use super::util::{function_string, short_fn_name, GraphLabelString};
2016

2117
// =============================================================================
2218
// GraphContext
@@ -116,8 +112,7 @@ impl GraphContext {
116112
lines
117113
}
118114

119-
/// Resolve a call target to a function name if it's a constant function
120-
/// pointer
115+
/// Resolve a call target to a function name if it's a constant function pointer
121116
pub fn resolve_call_target(&self, func: &Operand) -> Option<String> {
122117
match func {
123118
Operand::Constant(ConstOperand { const_, .. }) => {

src/mk_graph/index.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
use std::collections::HashMap;
44

55
extern crate stable_mir;
6-
use {
7-
crate::printer::{AllocInfo, TypeMetadata},
8-
stable_mir::{
9-
abi::{FieldsShape, LayoutShape},
10-
mir::alloc::GlobalAlloc,
11-
ty::{IndexedVal, Ty},
12-
CrateDef,
13-
},
14-
};
6+
use stable_mir::abi::{FieldsShape, LayoutShape};
7+
use stable_mir::mir::alloc::GlobalAlloc;
8+
use stable_mir::ty::{IndexedVal, Ty};
9+
use stable_mir::CrateDef;
10+
11+
use crate::printer::{AllocInfo, TypeMetadata};
1512

1613
// =============================================================================
1714
// Index Structures
@@ -326,8 +323,7 @@ impl TypeEntry {
326323
.iter()
327324
.map(|&t| FieldInfo {
328325
ty: t,
329-
offset: None, /* Enum variant offsets require variant-specific
330-
* layout */
326+
offset: None, // Enum variant offsets require variant-specific layout
331327
})
332328
.collect(),
333329
})

src/mk_graph/mod.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@
33
//! This module provides functionality to generate graph visualizations
44
//! of Rust's MIR in various formats (DOT, D2).
55
6-
use std::{
7-
fs::File,
8-
io::{self, Write},
9-
};
6+
use std::fs::File;
7+
use std::io::{self, Write};
108

119
extern crate rustc_middle;
1210
use rustc_middle::ty::TyCtxt;
1311

1412
extern crate rustc_session;
15-
use {
16-
crate::printer::collect_smir,
17-
rustc_session::config::{OutFileName, OutputType},
18-
};
13+
use rustc_session::config::{OutFileName, OutputType};
14+
15+
use crate::printer::collect_smir;
1916

2017
// Sub-modules
2118
pub mod context;
@@ -24,11 +21,9 @@ pub mod output;
2421
pub mod util;
2522

2623
// Re-exports for convenience
27-
pub use {
28-
context::GraphContext,
29-
index::{AllocEntry, AllocIndex, AllocKind, TypeIndex},
30-
util::GraphLabelString,
31-
};
24+
pub use context::GraphContext;
25+
pub use index::{AllocEntry, AllocIndex, AllocKind, TypeIndex};
26+
pub use util::GraphLabelString;
3227

3328
// =============================================================================
3429
// Entry Points

src/mk_graph/output/d2.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
//! D2 diagram format output for MIR graphs.
22
33
extern crate stable_mir;
4-
use {
5-
crate::{
6-
mk_graph::{
7-
context::GraphContext,
8-
util::{escape_d2, is_unqualified, name_lines, short_name, terminator_targets},
9-
},
10-
printer::SmirJson,
11-
MonoItemKind,
12-
},
13-
stable_mir::mir::TerminatorKind,
4+
use stable_mir::mir::TerminatorKind;
5+
6+
use crate::printer::SmirJson;
7+
use crate::MonoItemKind;
8+
9+
use crate::mk_graph::context::GraphContext;
10+
use crate::mk_graph::util::{
11+
escape_d2, is_unqualified, name_lines, short_name, terminator_targets,
1412
};
1513

1614
impl SmirJson<'_> {

src/mk_graph/output/dot.rs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
//! DOT (Graphviz) format output for MIR graphs.
22
3-
use {
4-
dot_writer::{Attributes, Color, DotWriter, Scope, Shape, Style},
5-
std::collections::HashSet,
6-
};
3+
use std::collections::HashSet;
4+
5+
use dot_writer::{Attributes, Color, DotWriter, Scope, Shape, Style};
76

87
extern crate stable_mir;
9-
use {
10-
crate::{
11-
mk_graph::{
12-
context::GraphContext,
13-
util::{block_name, is_unqualified, name_lines, short_name, GraphLabelString},
14-
},
15-
printer::SmirJson,
16-
MonoItemKind,
17-
},
18-
stable_mir::mir::{BasicBlock, ConstOperand, Operand, TerminatorKind, UnwindAction},
19-
};
8+
use stable_mir::mir::{BasicBlock, ConstOperand, Operand, TerminatorKind, UnwindAction};
9+
10+
use crate::printer::SmirJson;
11+
use crate::MonoItemKind;
12+
13+
use crate::mk_graph::context::GraphContext;
14+
use crate::mk_graph::util::{block_name, is_unqualified, name_lines, short_name, GraphLabelString};
2015

2116
impl SmirJson<'_> {
2217
/// Convert the MIR to DOT (Graphviz) format
@@ -96,8 +91,7 @@ impl SmirJson<'_> {
9691
local_node.set("color", "palegreen3", false);
9792
drop(local_node);
9893

99-
// Cannot define local functions that capture env. variables. Instead we
100-
// define _closures_.
94+
// Cannot define local functions that capture env. variables. Instead we define _closures_.
10195
let process_block =
10296
|cluster: &mut Scope<'_, '_>, node_id: usize, b: &BasicBlock| {
10397
let name = &item.symbol_name;
@@ -179,11 +173,8 @@ impl SmirJson<'_> {
179173
.set_label(&dest);
180174
}
181175

182-
// The call edge has to be drawn outside
183-
// the cluster, outside this function
184-
// (cluster borrows &mut graph)!
185-
// Code for that is therefore separated
186-
// into its own second function below.
176+
// The call edge has to be drawn outside the cluster, outside this function (cluster borrows &mut graph)!
177+
// Code for that is therefore separated into its own second function below.
187178
}
188179
Assert {
189180
cond,
@@ -244,10 +235,9 @@ impl SmirJson<'_> {
244235

245236
drop(c); // so we can borrow graph again
246237

247-
// call edges have to be added _outside_ the cluster of blocks for one
248-
// function because they go between different
249-
// clusters. Due to a scope/borrow issue, we have to
250-
// make a 2nd pass over the bodies of the item.
238+
// call edges have to be added _outside_ the cluster of blocks for one function
239+
// because they go between different clusters. Due to a scope/borrow issue, we have
240+
// to make a 2nd pass over the bodies of the item.
251241
let add_call_edges =
252242
|graph: &mut Scope<'_, '_>, offset: usize, bs: &Vec<BasicBlock>| {
253243
for (i, b) in bs.iter().enumerate() {
@@ -262,17 +252,15 @@ impl SmirJson<'_> {
262252
if let Some(callee) =
263253
ctx.functions.get(&const_.ty())
264254
{
265-
// callee node/body will be added when its
266-
// body is added, missing ones added before
255+
// callee node/body will be added when its body is added, missing ones added before
267256
graph.edge(
268257
&this_block,
269258
block_name(callee, 0),
270259
)
271260
} else {
272261
let unknown = format!("{}", const_.ty());
273262
// pathological case, could panic! instead.
274-
// all unknown callees will be collapsed
275-
// into one `unknown` node
263+
// all unknown callees will be collapsed into one `unknown` node
276264
graph.edge(&this_block, unknown)
277265
}
278266
}

src/mk_graph/util.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
use std::hash::{DefaultHasher, Hash, Hasher};
44

55
extern crate stable_mir;
6-
use {
7-
crate::printer::FnSymType,
8-
stable_mir::{
9-
mir::{
10-
AggregateKind, BorrowKind, ConstOperand, Mutability, NonDivergingIntrinsic, NullOp,
11-
Operand, Place, ProjectionElem, Rvalue, Terminator, TerminatorKind, UnwindAction,
12-
},
13-
ty::{IndexedVal, RigidTy},
14-
},
6+
use stable_mir::mir::{
7+
AggregateKind, BorrowKind, ConstOperand, Mutability, NonDivergingIntrinsic, NullOp, Operand,
8+
Place, ProjectionElem, Rvalue, Terminator, TerminatorKind, UnwindAction,
159
};
10+
use stable_mir::ty::{IndexedVal, RigidTy};
11+
12+
use crate::printer::FnSymType;
1613

1714
// =============================================================================
1815
// GraphLabelString Trait

0 commit comments

Comments
 (0)