Skip to content

Commit

Permalink
Cargo clippy and undo exposing the GraphNodeID in GraphNodeRef
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez committed Jun 18, 2024
1 parent b839835 commit 6fff22f
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions crates/codegen/runtime/cargo/src/runtime/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ impl Bindings {
}

pub fn cursor_to_handle(&self, cursor: &Cursor) -> Option<Handle<'_>> {
for (handle, handle_cursor) in self.cursors.iter() {
for (handle, handle_cursor) in &self.cursors {
if handle_cursor == cursor {
return Some(Handle {
owner: self,
handle: *handle,
});
}
}
return None;
None
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/metaslang/graph_builder/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions crates/solidity/outputs/cargo/slang_solidity/src/assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn check_assertions(bindings: &Bindings, assertions: &Assertions) -> Result<(),
success += 1;
}

for assertion in assertions.references.iter() {
for assertion in &assertions.references {
count += 1;

let Assertion::Reference { id, cursor } = assertion else {
Expand Down Expand Up @@ -195,18 +195,18 @@ impl fmt::Display for Assertion {
write!(f, "Assert ")?;
let cursor = match self {
Self::Definition { id, cursor } => {
write!(f, "Definition {}", id,)?;
write!(f, "Definition {id}")?;
cursor
}
Self::Reference { id: None, cursor } => {
write!(f, "Unresolved Reference",)?;
write!(f, "Unresolved Reference")?;
cursor
}
Self::Reference {
id: Some(id),
cursor,
} => {
write!(f, "Reference {}", id,)?;
write!(f, "Reference {id}")?;
cursor
}
};
Expand Down Expand Up @@ -295,7 +295,7 @@ fn search_asserted_node_backwards(mut cursor: Cursor, anchor_column: usize) -> O
match cursor_column.cmp(&anchor_column) {
Ordering::Equal => return Some(cursor),
Ordering::Greater => continue,
_ => (),
Ordering::Less => (),
}

// Node is not found, and probably the anchor is invalid
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions crates/solidity/outputs/cargo/slang_solidity/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ impl FromArgMatches for CliCommand {
impl Subcommand for CliCommand {
fn augment_subcommands(cmd: Command) -> Command {
let cmd = cli::Commands::augment_subcommands(cmd);
let cmd = CustomCommands::augment_subcommands(cmd);
cmd
CustomCommands::augment_subcommands(cmd)
}
fn augment_subcommands_for_update(cmd: Command) -> Command {
let cmd = cli::Commands::augment_subcommands(cmd);
let cmd = CustomCommands::augment_subcommands(cmd);
cmd
CustomCommands::augment_subcommands(cmd)
}
fn has_subcommand(name: &str) -> bool {
cli::Commands::has_subcommand(name) || CustomCommands::has_subcommand(name)
Expand Down
19 changes: 10 additions & 9 deletions crates/solidity/outputs/cargo/tests/src/graph_output/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -7,8 +10,6 @@ use slang_solidity::bindings::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<()> {
Expand Down Expand Up @@ -52,28 +53,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(())
Expand Down
2 changes: 1 addition & 1 deletion crates/solidity/outputs/cargo/tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(test)]

mod cst_output;
mod graph_output;
mod doc_examples;
mod graph_output;
mod trivia;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6fff22f

Please sign in to comment.