From 9a2689d4030a0359cfbd5d40133bb0503c84c717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Fri, 14 Jun 2024 00:06:21 -0400 Subject: [PATCH] Cargo clippy and undo exposing the GraphNodeID in GraphNodeRef --- .../runtime/cargo/src/runtime/bindings/mod.rs | 2 +- crates/metaslang/graph_builder/src/graph.rs | 2 +- .../solidity/outputs/cargo/tests/Cargo.toml | 2 +- .../cargo/tests/src/graph_output/mod.rs | 19 ++++++++++--------- .../solidity/outputs/cargo/tests/src/lib.rs | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/crates/codegen/runtime/cargo/src/runtime/bindings/mod.rs b/crates/codegen/runtime/cargo/src/runtime/bindings/mod.rs index e6a1ceb5e..0459f0540 100644 --- a/crates/codegen/runtime/cargo/src/runtime/bindings/mod.rs +++ b/crates/codegen/runtime/cargo/src/runtime/bindings/mod.rs @@ -1,8 +1,8 @@ #[path = "generated/binding_rules.rs"] mod binding_rules; -use metaslang_graph_builder::{ast, ParseError}; pub use metaslang_graph_builder::functions::Functions; +use metaslang_graph_builder::{ast, ParseError}; pub use metaslang_graph_builder::{ExecutionConfig, ExecutionError, NoCancellation, Variables}; use crate::cst::KindTypes; diff --git a/crates/metaslang/graph_builder/src/graph.rs b/crates/metaslang/graph_builder/src/graph.rs index 4bc51cfc5..233e5b97e 100644 --- a/crates/metaslang/graph_builder/src/graph.rs +++ b/crates/metaslang/graph_builder/src/graph.rs @@ -689,7 +689,7 @@ impl std::fmt::Debug for SyntaxNodeRef { /// A reference to a graph node #[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct GraphNodeRef(pub GraphNodeID); +pub struct GraphNodeRef(GraphNodeID); impl GraphNodeRef { /// Returns the index of the graph node that this reference refers to. diff --git a/crates/solidity/outputs/cargo/tests/Cargo.toml b/crates/solidity/outputs/cargo/tests/Cargo.toml index d411646ff..a00b4faa1 100644 --- a/crates/solidity/outputs/cargo/tests/Cargo.toml +++ b/crates/solidity/outputs/cargo/tests/Cargo.toml @@ -19,7 +19,7 @@ infra_utils = { workspace = true } once_cell = { workspace = true } regex = { workspace = true } semver = { workspace = true } -slang_solidity = { workspace = true, features = ["__private_ariadne"] } +slang_solidity = { workspace = true, features = ["__private_ariadne", "__experimental_bindings_api"] } solidity_language = { workspace = true } strum_macros = { workspace = true } diff --git a/crates/solidity/outputs/cargo/tests/src/graph_output/mod.rs b/crates/solidity/outputs/cargo/tests/src/graph_output/mod.rs index 6b971a520..5ed945a9a 100644 --- a/crates/solidity/outputs/cargo/tests/src/graph_output/mod.rs +++ b/crates/solidity/outputs/cargo/tests/src/graph_output/mod.rs @@ -1,3 +1,6 @@ +use std::fmt; +use std::fs::{self, create_dir_all}; + use anyhow::Result; use infra_utils::cargo::CargoWorkspace; use infra_utils::paths::FileWalker; @@ -6,8 +9,6 @@ use slang_solidity::bindings::{ get_stack_graph_builder, ExecutionConfig, Functions, Graph, NoCancellation, Variables, }; use slang_solidity::language::Language; -use std::fmt; -use std::fs::{self, create_dir_all}; #[test] pub fn run_all() -> Result<()> { @@ -51,28 +52,28 @@ fn run(file_name: &str) -> Result<()> { Ok(()) } -fn print_graph_as_mermaid<'a>(graph: &'a Graph) -> impl fmt::Display + 'a { +fn print_graph_as_mermaid(graph: &Graph) -> impl fmt::Display + '_ { struct DisplayGraph<'a>(&'a Graph); impl<'a> fmt::Display for DisplayGraph<'a> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let graph = self.0; - write!(f, "graph TD\n")?; + writeln!(f, "graph TD")?; for node in graph.iter_nodes() { let gn = &graph[node]; let node_label = if let Some(symbol) = gn.attributes.get("symbol") { symbol.to_string() } else { - format!("{}", node.0) + format!("{}", node.index()) }; let node_type = gn.attributes.get("type").and_then(|x| x.as_str().ok()); match node_type { - Some("push_symbol") => write!(f, "\tN{}[/{}\\]\n", node.0, node_label)?, - Some("pop_symbol") => write!(f, "\tN{}[\\{}/]\n", node.0, node_label)?, - _ => write!(f, "\tN{}[{}]\n", node.0, node_label)?, + Some("push_symbol") => writeln!(f, "\tN{}[/{}\\]", node.index(), node_label)?, + Some("pop_symbol") => writeln!(f, "\tN{}[\\{}/]", node.index(), node_label)?, + _ => writeln!(f, "\tN{}[{}]", node.index(), node_label)?, } for (sink, _edge) in gn.iter_edges() { - write!(f, "\tN{} --> N{}\n", node.0, sink.0)?; + writeln!(f, "\tN{} --> N{}", node.index(), sink.index())?; } } Ok(()) diff --git a/crates/solidity/outputs/cargo/tests/src/lib.rs b/crates/solidity/outputs/cargo/tests/src/lib.rs index ef40326fa..c3ce8042c 100644 --- a/crates/solidity/outputs/cargo/tests/src/lib.rs +++ b/crates/solidity/outputs/cargo/tests/src/lib.rs @@ -1,6 +1,6 @@ #![cfg(test)] mod cst_output; -mod graph_output; mod doc_examples; +mod graph_output; mod trivia;