Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit f450458

Browse files
committed
lints + format
1 parent fc5ed39 commit f450458

File tree

6 files changed

+43
-25
lines changed

6 files changed

+43
-25
lines changed

src/cli.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
use std::rc::Rc;
33

44
use clap::Parser;
5-
use hugr::{HugrView, Hugr};
6-
use inkwell::module::Module;
7-
use thiserror::Error;
85
use hugr::std_extensions::arithmetic::{
96
conversions::EXTENSION as CONVERSIONS_EXTENSION, float_ops::EXTENSION as FLOAT_OPS_EXTENSION,
107
float_types::EXTENSION as FLOAT_TYPES_EXTENSION, int_ops::EXTENSION as INT_OPS_EXTENSION,
118
int_types::EXTENSION as INT_TYPES_EXTENSION,
129
};
1310
use hugr::std_extensions::logic::EXTENSION as LOGICS_EXTENSION;
11+
use hugr::Hugr;
12+
use inkwell::module::Module;
13+
use thiserror::Error;
1414

15+
use anyhow::Result;
1516
use hugr::extension::{ExtensionRegistry, PRELUDE};
16-
use anyhow::{anyhow,Result};
1717
use lazy_static::lazy_static;
1818

1919
use crate::custom::CodegenExtsMap;
@@ -54,7 +54,13 @@ pub enum CliError {
5454
Other(#[from] anyhow::Error),
5555
}
5656

57-
pub fn emit_module<'c>(context: &'c inkwell::context::Context, hugr: &'c Hugr, module_name: impl AsRef<str>, namer: Rc<Namer>, exts: Rc<CodegenExtsMap<'c, Hugr>>) -> Result<Module<'c>> {
57+
pub fn emit_module<'c>(
58+
context: &'c inkwell::context::Context,
59+
hugr: &'c Hugr,
60+
module_name: impl AsRef<str>,
61+
namer: Rc<Namer>,
62+
exts: Rc<CodegenExtsMap<'c, Hugr>>,
63+
) -> Result<Module<'c>> {
5864
let module = context.create_module(module_name.as_ref());
5965
let emit = EmitHugr::new(context, module, namer, exts);
6066
Ok(emit.emit_module(hugr.fat_root().unwrap())?.finish())
@@ -67,8 +73,16 @@ impl CmdLineArgs {
6773
let hugr = self.base.run(registry)?;
6874

6975
let context = inkwell::context::Context::create();
70-
let module = emit_module(&context, &hugr, &self.module_name, self.namer(), self.codegenexts())?;
71-
module.verify().map_err(|e| anyhow::anyhow!(e.to_string()))?;
76+
let module = emit_module(
77+
&context,
78+
&hugr,
79+
&self.module_name,
80+
self.namer(),
81+
self.codegenexts(),
82+
)?;
83+
module
84+
.verify()
85+
.map_err(|e| anyhow::anyhow!(e.to_string()))?;
7286
println!("{}", module.print_to_string());
7387
Ok(())
7488
}
@@ -82,7 +96,7 @@ impl CmdLineArgs {
8296
Namer::new(self.mangle_prefix.clone(), self.mangle_node_suffix).into()
8397
}
8498

85-
fn codegenexts<'c>(&self) -> Rc<CodegenExtsMap<'c,Hugr>> {
99+
fn codegenexts<'c>(&self) -> Rc<CodegenExtsMap<'c, Hugr>> {
86100
CodegenExtsMap::new().add_int_extensions().into()
87101
}
88102
}

src/emit.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<OT, H: HugrView> EmitOp<'_, OT, H> for NullEmitLlvm {
117117
#[derive(Clone)]
118118
pub struct Namer {
119119
prefix: String,
120-
node_suffix: bool
120+
node_suffix: bool,
121121
}
122122

123123
impl Namer {
@@ -127,13 +127,17 @@ impl Namer {
127127
pub fn new(prefix: impl Into<String>, node_suffix: bool) -> Self {
128128
Self {
129129
prefix: prefix.into(),
130-
node_suffix
130+
node_suffix,
131131
}
132132
}
133133

134134
/// Mangle the the name of a [FuncDefn] or [FuncDecl].
135135
pub fn name_func(&self, name: impl AsRef<str>, node: Node) -> String {
136-
let suffix = if self.node_suffix { format!(".{}", node.index()) } else { "".to_string() };
136+
let suffix = if self.node_suffix {
137+
format!(".{}", node.index())
138+
} else {
139+
"".to_string()
140+
};
137141
format!("{}{}{}", &self.prefix, name.as_ref(), suffix)
138142
}
139143
}
@@ -144,7 +148,7 @@ impl Default for Namer {
144148
fn default() -> Self {
145149
Self {
146150
prefix: NAMER_DEFAULT_PREFIX.into(),
147-
node_suffix: true
151+
node_suffix: true,
148152
}
149153
}
150154
}

src/emit/func.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use std::{
55

66
use anyhow::{anyhow, Result};
77
use hugr::{
8-
ops::{FuncDecl, FuncDefn}, types::Type, HugrView, NodeIndex, OutgoingPort, PortIndex, Wire
8+
ops::{FuncDecl, FuncDefn},
9+
types::Type,
10+
HugrView, NodeIndex, OutgoingPort, PortIndex, Wire,
911
};
1012
use inkwell::{
1113
basic_block::BasicBlock,

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@
6161
//! [BasicValueEnum]: [inkwell::values::BasicValueEnum]
6262
//! [BasicValue]: [inkwell::values::BasicValue]
6363
//!
64+
pub mod cli;
6465
pub mod custom;
6566
pub mod emit;
6667
pub mod fat;
6768
pub mod types;
68-
pub mod cli;
6969

7070
#[allow(unreachable_code)]
7171
pub fn llvm_version() -> &'static str {
@@ -74,6 +74,5 @@ pub fn llvm_version() -> &'static str {
7474
panic!("No recognised llvm feature")
7575
}
7676

77-
7877
#[cfg(test)]
7978
pub mod test;

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use hugr::std_extensions::logic::EXTENSION as LOGICS_EXTENSION;
77

88
use hugr::extension::{ExtensionRegistry, PRELUDE};
99

10-
use hugr_cli::{Parser, Level, CmdLineArgs};
10+
use hugr_cli::{CmdLineArgs, Level, Parser};
1111

1212
fn main() {
1313
let opts = CmdLineArgs::parse();

tests/guppy.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{env, path::{Path, PathBuf}};
1+
use std::{env, path::PathBuf};
22

33
use rstest::{fixture, rstest};
44

@@ -9,14 +9,15 @@ struct TestConfig {
99

1010
impl TestConfig {
1111
pub fn new() -> TestConfig {
12-
let python_bin = env::var("HUGR_LLVM_PYTHON_BIN").map(Into::into).ok().or_else( ||
13-
pathsearch::find_executable_in_path("python")
14-
).unwrap_or_else(|| panic!("Could not find python in PATH or HUGR_LLVM_PYTHON_BIN")
15-
);
12+
let python_bin = env::var("HUGR_LLVM_PYTHON_BIN")
13+
.map(Into::into)
14+
.ok()
15+
.or_else(|| pathsearch::find_executable_in_path("python"))
16+
.unwrap_or_else(|| panic!("Could not find python in PATH or HUGR_LLVM_PYTHON_BIN"));
1617
let hugr_llvm_bin = env!("CARGO_BIN_EXE_hugr-llvm").into();
1718
TestConfig {
1819
python_bin,
19-
hugr_llvm_bin
20+
hugr_llvm_bin,
2021
}
2122
}
2223
}
@@ -27,6 +28,4 @@ fn test_config() -> TestConfig {
2728
}
2829

2930
#[rstest]
30-
fn test_even_odd(test_config: TestConfig) {
31-
32-
}
31+
fn test_even_odd(test_config: TestConfig) {}

0 commit comments

Comments
 (0)