An experiment in static, refcounted, procedural language with ownership
1

Configure Feed

Select the types of activity you want to include in your feed.

print block graph dot

r0nsha (Mar 5, 2024, 6:04 PM +0200) e367fcc0 50dc8317

+33
+1
Cargo.lock
··· 368 368 "compiler_helpers", 369 369 "indexmap", 370 370 "itertools", 371 + "petgraph", 371 372 "pretty", 372 373 "rustc-hash", 373 374 "ustr",
+1
compiler_mir/Cargo.toml
··· 14 14 camino = { workspace = true } 15 15 pretty = { workspace = true } 16 16 itertools = { workspace = true } 17 + petgraph = { workspace = true } 17 18 18 19 [lints] 19 20 workspace = true
+30
compiler_mir/src/lib.rs
··· 6 6 mod pretty; 7 7 pub mod subst; 8 8 9 + use core::fmt; 9 10 use std::{io, iter}; 10 11 11 12 use compiler_data_structures::{ ··· 16 17 use indexmap::{indexset, IndexSet}; 17 18 pub use lower::lower; 18 19 pub use monomorphize::monomorphize; 20 + use petgraph::graph::DiGraph; 21 + use petgraph::graphmap::DiGraphMap; 19 22 use rustc_hash::{FxHashMap, FxHashSet}; 20 23 use ustr::Ustr; 21 24 ··· 344 347 } 345 348 } 346 349 } 350 + 351 + fn block_graph(&self) -> DiGraph<BlockId, ()> { 352 + let mut graph = DiGraphMap::new(); 353 + 354 + for (id, block) in self.blocks().iter_enumerated() { 355 + for &pred in &block.predecessors { 356 + graph.add_edge(pred, id, ()); 357 + } 358 + 359 + for &succ in &block.successors { 360 + graph.add_edge(id, succ, ()); 361 + } 362 + } 363 + 364 + graph.into_graph() 365 + } 366 + 367 + fn print_dot(&self) { 368 + let graph = self.block_graph().map(|_, &id| self.block(id).display_name(), |_, _| ()); 369 + println!("{:?}", petgraph::dot::Dot::new(&graph)); 370 + } 347 371 } 348 372 349 373 fn update_block_ids( ··· 417 441 418 442 pub fn is_connected(&self) -> bool { 419 443 self.id == BlockId::start() || !self.predecessors.is_empty() 444 + } 445 + } 446 + 447 + impl fmt::Display for Block { 448 + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 449 + f.write_str(&self.display_name()) 420 450 } 421 451 } 422 452
+1
compiler_mir/src/ownck.rs
··· 256 256 } 257 257 } 258 258 259 + self.body.print_dot(); 259 260 debug_assert!( 260 261 !is_initial_state, 261 262 "value v{} aka {}(: {}) is missing a state in block b{} aka `{}`.",