From 79139549248ec0af95331674927744a25a1e31aa Mon Sep 17 00:00:00 2001 From: dkcumming Date: Tue, 29 Apr 2025 22:15:42 +0900 Subject: [PATCH 1/7] Added parenthesis around Deref --- src/mk_graph.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mk_graph.rs b/src/mk_graph.rs index 90b3d09..d3203a7 100644 --- a/src/mk_graph.rs +++ b/src/mk_graph.rs @@ -395,7 +395,7 @@ fn project(local: String, ps: &[ProjectionElem]) -> String { fn decorate(thing: String, p: &ProjectionElem) -> String { match p { - ProjectionElem::Deref => format!("*{}", thing), + ProjectionElem::Deref => format!("(*{})", thing), ProjectionElem::Field(i, _) => format!("{thing}.{i}"), ProjectionElem::Index(local) => format!("{thing}[_{local}]"), ProjectionElem::ConstantIndex { From f6af8ffa89284089492ece1777f35c2d84915d5c Mon Sep 17 00:00:00 2001 From: dkcumming Date: Tue, 29 Apr 2025 22:16:45 +0900 Subject: [PATCH 2/7] Tweaked formatting of constants --- src/mk_graph.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/mk_graph.rs b/src/mk_graph.rs index d3203a7..61a9360 100644 --- a/src/mk_graph.rs +++ b/src/mk_graph.rs @@ -14,10 +14,10 @@ extern crate stable_mir; use rustc_session::config::{OutFileName, OutputType}; extern crate rustc_session; -use stable_mir::mir::{ +use stable_mir::{mir::{ AggregateKind, BasicBlock, BorrowKind, ConstOperand, Mutability, NonDivergingIntrinsic, NullOp, Operand, Place, ProjectionElem, Rvalue, Statement, StatementKind, TerminatorKind, UnwindAction, -}; +}, ty::RigidTy}; use stable_mir::ty::{IndexedVal, Ty}; use crate::{ @@ -376,7 +376,14 @@ trait GraphLabelString { impl GraphLabelString for Operand { fn label(&self) -> String { match &self { - Operand::Constant(ConstOperand { const_, .. }) => format!("const :: {}", const_.ty()), + Operand::Constant(ConstOperand { const_, .. }) => { + let ty = const_.ty(); + match &ty.kind() { + stable_mir::ty::TyKind::RigidTy(RigidTy::Int(_)) + | stable_mir::ty::TyKind::RigidTy(RigidTy::Uint(_)) => format!("const ?_{}", const_.ty()), + _ => format!("const {}", const_.ty()), + } + } Operand::Copy(place) => format!("cp({})", place.label()), Operand::Move(place) => format!("mv({})", place.label()), } From 66550c2b085c5561350083c9238a0997acdac12c Mon Sep 17 00:00:00 2001 From: dkcumming Date: Tue, 29 Apr 2025 22:18:01 +0900 Subject: [PATCH 3/7] Changed printing of Rvalue::AddressOf --- src/mk_graph.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/mk_graph.rs b/src/mk_graph.rs index 61a9360..9346d69 100644 --- a/src/mk_graph.rs +++ b/src/mk_graph.rs @@ -444,7 +444,12 @@ impl GraphLabelString for Rvalue { fn label(&self) -> String { use Rvalue::*; match &self { - AddressOf(kind, p) => format!("&{:?} {}", kind, p.label()), + AddressOf(mutability, p) => { + match mutability { + Mutability::Not => format!("&raw {}", p.label()), + Mutability::Mut => format!("&raw mut {}", p.label()), + } + }, Aggregate(kind, operands) => { let os: Vec = operands.iter().map(|op| op.label()).collect(); format!("{} ({})", kind.label(), os.join(", ")) From 1f3dba75b914334bad1a86db2ddb90baf9e4e7b0 Mon Sep 17 00:00:00 2001 From: dkcumming Date: Tue, 29 Apr 2025 22:18:48 +0900 Subject: [PATCH 4/7] First attempt at printing locals with types --- src/mk_graph.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/mk_graph.rs b/src/mk_graph.rs index 9346d69..8c41226 100644 --- a/src/mk_graph.rs +++ b/src/mk_graph.rs @@ -87,6 +87,17 @@ impl SmirJson<'_> { c.set_color(Color::LightGrey); } + // Set out the type information of the locals + let mut local_node = c.node_auto(); + let mut vector: Vec = vec![]; + vector.push(String::from("LOCALS")); + for (index, decl) in body.clone().unwrap().local_decls() { + vector.push(format!("{index} = {}", decl.ty)); + } + local_node.set_label(format!("{}", vector.join("\\l")).as_str()); + drop(local_node); + + // Cannot define local functions that capture env. variables. Instead we define _closures_. let process_block = |cluster: &mut Scope<'_, '_>, node_id: usize, b: &BasicBlock| { From c294219edd79977903d0457cbb0517166e4fb5a3 Mon Sep 17 00:00:00 2001 From: dkcumming Date: Tue, 29 Apr 2025 09:45:37 -0400 Subject: [PATCH 5/7] cargo clippy and cargo fmt --- src/mk_graph.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/mk_graph.rs b/src/mk_graph.rs index 8c41226..ac41f13 100644 --- a/src/mk_graph.rs +++ b/src/mk_graph.rs @@ -14,11 +14,15 @@ extern crate stable_mir; use rustc_session::config::{OutFileName, OutputType}; extern crate rustc_session; -use stable_mir::{mir::{ - AggregateKind, BasicBlock, BorrowKind, ConstOperand, Mutability, NonDivergingIntrinsic, NullOp, - Operand, Place, ProjectionElem, Rvalue, Statement, StatementKind, TerminatorKind, UnwindAction, -}, ty::RigidTy}; use stable_mir::ty::{IndexedVal, Ty}; +use stable_mir::{ + mir::{ + AggregateKind, BasicBlock, BorrowKind, ConstOperand, Mutability, NonDivergingIntrinsic, + NullOp, Operand, Place, ProjectionElem, Rvalue, Statement, StatementKind, TerminatorKind, + UnwindAction, + }, + ty::RigidTy, +}; use crate::{ printer::{collect_smir, FnSymType, SmirJson}, @@ -94,10 +98,9 @@ impl SmirJson<'_> { for (index, decl) in body.clone().unwrap().local_decls() { vector.push(format!("{index} = {}", decl.ty)); } - local_node.set_label(format!("{}", vector.join("\\l")).as_str()); + local_node.set_label(vector.join("\\l").to_string().as_str()); drop(local_node); - // Cannot define local functions that capture env. variables. Instead we define _closures_. let process_block = |cluster: &mut Scope<'_, '_>, node_id: usize, b: &BasicBlock| { @@ -391,7 +394,9 @@ impl GraphLabelString for Operand { let ty = const_.ty(); match &ty.kind() { stable_mir::ty::TyKind::RigidTy(RigidTy::Int(_)) - | stable_mir::ty::TyKind::RigidTy(RigidTy::Uint(_)) => format!("const ?_{}", const_.ty()), + | stable_mir::ty::TyKind::RigidTy(RigidTy::Uint(_)) => { + format!("const ?_{}", const_.ty()) + } _ => format!("const {}", const_.ty()), } } @@ -455,11 +460,9 @@ impl GraphLabelString for Rvalue { fn label(&self) -> String { use Rvalue::*; match &self { - AddressOf(mutability, p) => { - match mutability { - Mutability::Not => format!("&raw {}", p.label()), - Mutability::Mut => format!("&raw mut {}", p.label()), - } + AddressOf(mutability, p) => match mutability { + Mutability::Not => format!("&raw {}", p.label()), + Mutability::Mut => format!("&raw mut {}", p.label()), }, Aggregate(kind, operands) => { let os: Vec = operands.iter().map(|op| op.label()).collect(); From a490bf2c4fee7c78f58c8106018af219195fa327 Mon Sep 17 00:00:00 2001 From: Daniel Cumming <124537596+dkcumming@users.noreply.github.com> Date: Thu, 1 May 2025 11:10:39 -0400 Subject: [PATCH 6/7] Update src/mk_graph.rs Co-authored-by: Jost Berthold --- src/mk_graph.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mk_graph.rs b/src/mk_graph.rs index ac41f13..008a6db 100644 --- a/src/mk_graph.rs +++ b/src/mk_graph.rs @@ -98,7 +98,10 @@ impl SmirJson<'_> { for (index, decl) in body.clone().unwrap().local_decls() { vector.push(format!("{index} = {}", decl.ty)); } + vector.push("".to_string()); local_node.set_label(vector.join("\\l").to_string().as_str()); + local_node.set_style(Style::Filled); + local_node.set("color", "palegreen3"); drop(local_node); // Cannot define local functions that capture env. variables. Instead we define _closures_. From 6a1d1f252ac7feeebc2d48fd71b65371f2dbdbcc Mon Sep 17 00:00:00 2001 From: dkcumming Date: Thu, 1 May 2025 11:15:38 -0400 Subject: [PATCH 7/7] fixed missing arg setting the color --- src/mk_graph.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mk_graph.rs b/src/mk_graph.rs index 008a6db..3b18cf5 100644 --- a/src/mk_graph.rs +++ b/src/mk_graph.rs @@ -101,7 +101,7 @@ impl SmirJson<'_> { vector.push("".to_string()); local_node.set_label(vector.join("\\l").to_string().as_str()); local_node.set_style(Style::Filled); - local_node.set("color", "palegreen3"); + local_node.set("color", "palegreen3", false); drop(local_node); // Cannot define local functions that capture env. variables. Instead we define _closures_.