Skip to content

Commit d0b70ca

Browse files
committed
clippy and tests
1 parent f4a1701 commit d0b70ca

File tree

5 files changed

+23
-25
lines changed

5 files changed

+23
-25
lines changed

engine/baml-lib/baml/tests/bytecode_files/loops/c_for.baml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ function Nothing() -> int {
5959
// 4 8 LOAD_VAR 2 (i)
6060
// 9 BIN_OP +
6161
// 10 STORE_VAR 1 (s)
62-
// 11 LOAD_VAR 2 (i)
6362
//
64-
// 3 12 LOAD_CONST 3 (1)
63+
// 3 11 LOAD_VAR 2 (i)
64+
// 12 LOAD_CONST 3 (1)
6565
// 13 BIN_OP +
6666
// 14 STORE_VAR 2 (i)
6767
// 15 JUMP -13 (to 2)
@@ -98,9 +98,9 @@ function Nothing() -> int {
9898
// 19 JUMP +3 (to 22)
9999
// 20 JUMP +2 (to 22)
100100
// 21 POP 1
101-
// 22 LOAD_VAR 1 (s)
102101
//
103-
// 13 23 LOAD_VAR 2 (i)
102+
// 13 22 LOAD_VAR 1 (s)
103+
// 23 LOAD_VAR 2 (i)
104104
// 24 BIN_OP +
105105
// 25 STORE_VAR 1 (s)
106106
// 26 JUMP -24 (to 2)

engine/baml-lib/baml/tests/hir_files/loops/c_for.baml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ function Nothing() -> int {
5050
// let s = 0;
5151
// {
5252
// let i = 1;
53-
// for (;i <= 10;i += 1;) { s += i;}
53+
// for (;i <= 10;{
54+
// i += 1;
55+
// }) { s += i;}
5456
// }
5557
//
5658
// s
@@ -60,7 +62,9 @@ function Nothing() -> int {
6062
// let s = 0;
6163
// {
6264
// let i = 0;
63-
// for (;;s += i;) { }
65+
// for (;;{
66+
// s += i;
67+
// }) { }
6468
// }
6569
//
6670
// s

engine/baml-runtime/src/control_flow.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl ControlFlowVizBuilder {
136136
}
137137

138138
fn add_node(&mut self, node: Node) {
139-
self.nodes.insert(node.id.clone(), node);
139+
self.nodes.insert(node.id, node);
140140
}
141141

142142
fn add_edge(&mut self, src: NodeId, dst: NodeId) {
@@ -146,7 +146,7 @@ impl ControlFlowVizBuilder {
146146
fn finish(self) -> ControlFlowVisualization {
147147
let mut edges_by_src: IndexMap<NodeId, Vec<Edge>> = IndexMap::new();
148148
for edge in self.edges {
149-
edges_by_src.entry(edge.src.clone()).or_default().push(edge);
149+
edges_by_src.entry(edge.src).or_default().push(edge);
150150
}
151151

152152
ControlFlowVisualization {
@@ -463,7 +463,7 @@ impl HirTraversalContext {
463463
let lexical_id = self.build_lexical_id(&segment);
464464
let node_id = self.graph.allocate_id();
465465
let parent_id = self.current_parent_id();
466-
let node_label = label.unwrap_or_else(|| "".to_string());
466+
let node_label = label.unwrap_or_default();
467467
let node = Node::new(
468468
node_id,
469469
parent_id,
@@ -769,10 +769,10 @@ impl HirTraversalContext {
769769
if !parent_entry {
770770
return;
771771
}
772-
if let Some(prev) = self.frames[parent_index].last_linear_child.clone() {
773-
self.graph.add_edge(prev, node_id.clone());
772+
if let Some(prev) = self.frames[parent_index].last_linear_child {
773+
self.graph.add_edge(prev, *node_id);
774774
}
775-
self.frames[parent_index].last_linear_child = Some(node_id.clone());
775+
self.frames[parent_index].last_linear_child = Some(*node_id);
776776
}
777777

778778
fn pop_headers_to_level(&mut self, desired_level: u8) {

engine/baml-runtime/src/control_flow/mermaid.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,34 @@ impl<'a> MermaidRenderer<'a> {
2020
fn new(viz: &'a ControlFlowVisualization) -> Self {
2121
let mut aliases = HashMap::new();
2222
for (idx, node) in viz.nodes.values().enumerate() {
23-
aliases.insert(node.id.clone(), format!("n{idx}"));
23+
aliases.insert(node.id, format!("n{idx}"));
2424
}
2525

2626
let mut roots = Vec::new();
2727
let mut children: HashMap<NodeId, Vec<NodeId>> = HashMap::new();
2828
for node in viz.nodes.values() {
2929
if let Some(parent) = &node.parent_node_id {
30-
children
31-
.entry(parent.clone())
32-
.or_default()
33-
.push(node.id.clone());
30+
children.entry(*parent).or_default().push(node.id);
3431
} else {
35-
roots.push(node.id.clone());
32+
roots.push(node.id);
3633
}
3734
}
3835

3936
let mut edges_by_parent: HashMap<NodeId, Vec<(NodeId, NodeId)>> = HashMap::new();
4037
let mut root_edges = Vec::new();
4138
for (src_id, list) in &viz.edges_by_src {
42-
let parent = viz
43-
.nodes
44-
.get(src_id)
45-
.and_then(|node| node.parent_node_id.clone());
39+
let parent = viz.nodes.get(src_id).and_then(|node| node.parent_node_id);
4640

4741
match parent {
4842
Some(parent_id) => {
4943
let entry = edges_by_parent.entry(parent_id).or_default();
5044
for edge in list {
51-
entry.push((src_id.clone(), edge.dst.clone()));
45+
entry.push((*src_id, edge.dst));
5246
}
5347
}
5448
None => {
5549
for edge in list {
56-
root_edges.push((src_id.clone(), edge.dst.clone()));
50+
root_edges.push((*src_id, edge.dst));
5751
}
5852
}
5953
}

engine/baml-runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2047,7 +2047,7 @@ impl InternalRuntimeInterface for BamlRuntime {
20472047
_ctx: &RuntimeContext,
20482048
) -> Result<ControlFlowVisualization> {
20492049
let ast = self.db.ast();
2050-
let hir = hir::Hir::from_ast(&ast);
2050+
let hir = hir::Hir::from_ast(ast);
20512051
let viz = build_from_hir(&hir, function_name)?;
20522052
Ok(flatten_control_flow(&viz).into())
20532053
}

0 commit comments

Comments
 (0)