Skip to content

Commit 6a3973b

Browse files
hyperpolymathclaude
andcommitted
chore: fix, Rust, lint/fmt, issues
Batch Justfile audit: standardised naming (lowercase→Justfile), fixed parse errors, removed useless build-riscv from non-Rust repos, added missing assail recipe, and fixed code quality issues. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9a37500 commit 6a3973b

7 files changed

Lines changed: 51 additions & 45 deletions

File tree

src/abi/mod.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,17 @@ use std::fmt;
1414
/// Nim can compile to C, C++, or JavaScript.
1515
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1616
#[serde(rename_all = "lowercase")]
17+
#[derive(Default)]
1718
pub enum CompilationTarget {
1819
/// Compile to C (default, best for system libraries).
20+
#[default]
1921
C,
2022
/// Compile to C++ (for C++ interop).
2123
Cpp,
2224
/// Compile to JavaScript (for browser/Deno targets).
2325
Js,
2426
}
2527

26-
impl Default for CompilationTarget {
27-
fn default() -> Self {
28-
CompilationTarget::C
29-
}
30-
}
31-
3228
impl fmt::Display for CompilationTarget {
3329
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3430
match self {
@@ -43,21 +39,17 @@ impl fmt::Display for CompilationTarget {
4339
/// ARC and ORC are the modern, deterministic options; None disables GC entirely.
4440
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4541
#[serde(rename_all = "lowercase")]
42+
#[derive(Default)]
4643
pub enum GcStrategy {
4744
/// ARC — deterministic reference counting with move semantics.
45+
#[default]
4846
Arc,
4947
/// ORC — ARC + cycle collector for cyclic data structures.
5048
Orc,
5149
/// No GC — fully manual memory management.
5250
None,
5351
}
5452

55-
impl Default for GcStrategy {
56-
fn default() -> Self {
57-
GcStrategy::Arc
58-
}
59-
}
60-
6153
impl fmt::Display for GcStrategy {
6254
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6355
match self {
@@ -124,10 +116,7 @@ pub enum NimType {
124116
/// ref T — traced (GC-managed) reference.
125117
Ref(Box<NimType>),
126118
/// array[N, T] — fixed-size array.
127-
Array {
128-
size: usize,
129-
element: Box<NimType>,
130-
},
119+
Array { size: usize, element: Box<NimType> },
131120
/// seq[T] — dynamic sequence.
132121
Seq(Box<NimType>),
133122
/// object type with named fields.

src/codegen/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ pub fn run(manifest: &Manifest, args: &[String]) -> Result<()> {
118118
);
119119
}
120120

121-
println!("Running {} workload: {}", "nimiser", manifest.project.name);
122-
let status = std::process::Command::new(&format!("./{}", binary))
121+
println!("Running nimiser workload: {}", manifest.project.name);
122+
let status = std::process::Command::new(format!("./{}", binary))
123123
.args(args)
124124
.status()
125125
.with_context(|| format!("Failed to run {}", binary))?;

src/codegen/nim_gen.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ pub fn generate_nim_source(manifest: &Manifest, procs: &[NimProc]) -> String {
2323
"# Generated by nimiser for library '{}'",
2424
manifest.project.name
2525
));
26-
lines.push(format!(
27-
"# Version: {}",
28-
manifest.project.version
29-
));
26+
lines.push(format!("# Version: {}", manifest.project.version));
3027
if !manifest.project.description.is_empty() {
3128
lines.push(format!("# {}", manifest.project.description));
3229
}

src/codegen/parser.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ use crate::manifest::{FunctionConfig, Manifest};
1212

1313
/// Parse all function declarations from a manifest into NimProc ABI types.
1414
pub fn parse_functions(manifest: &Manifest) -> Result<Vec<NimProc>> {
15-
manifest
16-
.functions
17-
.iter()
18-
.map(|f| parse_function(f))
19-
.collect()
15+
manifest.functions.iter().map(parse_function).collect()
2016
}
2117

2218
/// Parse a single FunctionConfig into a NimProc.

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub mod abi;
99
pub mod codegen;
1010
pub mod manifest;
1111

12-
pub use manifest::{load_manifest, validate, Manifest};
12+
pub use manifest::{Manifest, load_manifest, validate};
1313

1414
/// Convenience: load, validate, and generate all artifacts in one call.
1515
pub fn generate(manifest_path: &str, output_dir: &str) -> anyhow::Result<()> {

src/manifest/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ pub struct LegacyOptions {
167167
pub fn load_manifest(path: &str) -> Result<Manifest> {
168168
let content = std::fs::read_to_string(path)
169169
.with_context(|| format!("Failed to read manifest: {}", path))?;
170-
toml::from_str(&content)
171-
.with_context(|| format!("Failed to parse manifest: {}", path))
170+
toml::from_str(&content).with_context(|| format!("Failed to parse manifest: {}", path))
172171
}
173172

174173
/// Validate the manifest for required fields and logical consistency.
@@ -300,7 +299,10 @@ opt-level = "speed"
300299

301300
/// Print summary information about a loaded manifest.
302301
pub fn print_info(manifest: &Manifest) {
303-
println!("=== {} v{} ===", manifest.project.name, manifest.project.version);
302+
println!(
303+
"=== {} v{} ===",
304+
manifest.project.name, manifest.project.version
305+
);
304306
if !manifest.project.description.is_empty() {
305307
println!("Description: {}", manifest.project.description);
306308
}

tests/integration_tests.rs

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ fn test_parse_fast_lib_functions() {
5151
assert_eq!(add.params.len(), 2);
5252
assert_eq!(add.params[0].name, "a");
5353
assert_eq!(add.params[0].nim_type, NimType::Primitive("cint".into()));
54-
assert_eq!(
55-
add.return_type,
56-
Some(NimType::Primitive("cint".into()))
57-
);
54+
assert_eq!(add.return_type, Some(NimType::Primitive("cint".into())));
5855
assert!(add.pragmas.contains(&NimPragma::Exportc));
5956
assert!(add.pragmas.contains(&NimPragma::Cdecl));
6057

@@ -91,8 +88,9 @@ fn test_generate_nim_source_content() {
9188
"Missing fast_add proc declaration"
9289
);
9390
assert!(
94-
nim_source
95-
.contains("proc fast_multiply(x: cdouble, y: cdouble): cdouble {.exportc, cdecl, noSideEffect.} ="),
91+
nim_source.contains(
92+
"proc fast_multiply(x: cdouble, y: cdouble): cdouble {.exportc, cdecl, noSideEffect.} ="
93+
),
9694
"Missing fast_multiply proc declaration"
9795
);
9896
assert!(
@@ -265,10 +263,19 @@ opt-level = "speed"
265263
let m = manifest::load_manifest(&path).unwrap();
266264
let cmd = build_gen::build_command_from_manifest(&m, "c_lib.nim", true);
267265
let rendered = cmd.render();
268-
assert!(rendered.starts_with("nim c"), "C backend should use 'nim c'");
266+
assert!(
267+
rendered.starts_with("nim c"),
268+
"C backend should use 'nim c'"
269+
);
269270
assert!(rendered.contains("--gc:arc"), "Should use ARC GC");
270-
assert!(rendered.contains("--app:lib"), "C target should compile as library");
271-
assert!(rendered.contains("-d:release"), "Release build should have -d:release");
271+
assert!(
272+
rendered.contains("--app:lib"),
273+
"C target should compile as library"
274+
);
275+
assert!(
276+
rendered.contains("-d:release"),
277+
"Release build should have -d:release"
278+
);
272279

273280
// Test JS + ORC
274281
let dir2 = TempDir::new().unwrap();
@@ -286,9 +293,15 @@ opt-level = "none"
286293
let m_js = manifest::load_manifest(&path_js).unwrap();
287294
let cmd_js = build_gen::build_command_from_manifest(&m_js, "js_lib.nim", false);
288295
let rendered_js = cmd_js.render();
289-
assert!(rendered_js.starts_with("nim js"), "JS backend should use 'nim js'");
296+
assert!(
297+
rendered_js.starts_with("nim js"),
298+
"JS backend should use 'nim js'"
299+
);
290300
assert!(rendered_js.contains("--gc:orc"), "Should use ORC GC");
291-
assert!(!rendered_js.contains("--app:lib"), "JS target should not use --app:lib");
301+
assert!(
302+
!rendered_js.contains("--app:lib"),
303+
"JS target should not use --app:lib"
304+
);
292305

293306
// Test CPP + None GC
294307
let dir3 = TempDir::new().unwrap();
@@ -306,9 +319,15 @@ opt-level = "size"
306319
let m_cpp = manifest::load_manifest(&path_cpp).unwrap();
307320
let cmd_cpp = build_gen::build_command_from_manifest(&m_cpp, "cpp_lib.nim", true);
308321
let rendered_cpp = cmd_cpp.render();
309-
assert!(rendered_cpp.starts_with("nim cpp"), "CPP backend should use 'nim cpp'");
322+
assert!(
323+
rendered_cpp.starts_with("nim cpp"),
324+
"CPP backend should use 'nim cpp'"
325+
);
310326
assert!(rendered_cpp.contains("--gc:none"), "Should use no GC");
311-
assert!(rendered_cpp.contains("--opt:size"), "Should optimise for size");
327+
assert!(
328+
rendered_cpp.contains("--opt:size"),
329+
"Should optimise for size"
330+
);
312331
}
313332

314333
// ---------------------------------------------------------------------------
@@ -330,7 +349,10 @@ fn test_init_creates_valid_manifest() {
330349
manifest::validate(&m).expect("Generated manifest should be valid");
331350

332351
assert!(!m.project.name.is_empty());
333-
assert!(m.functions.len() >= 2, "Template should have example functions");
352+
assert!(
353+
m.functions.len() >= 2,
354+
"Template should have example functions"
355+
);
334356
}
335357

336358
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)