Skip to content

Commit 8cd2a78

Browse files
author
Arnaud Riess
committed
refactor: simplify host parameter handling in function and export generation
1 parent f77f14b commit 8cd2a78

3 files changed

Lines changed: 13 additions & 23 deletions

File tree

crates/herkos/src/codegen/export.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,13 @@ pub fn generate_export_impl<B: Backend>(_backend: &B, info: &ModuleInfo) -> Stri
6262
}
6363

6464
// Add host parameter if function needs it
65-
if ir_func.needs_host {
66-
if let Some(trait_bounds) = &trait_bounds_opt {
67-
if has_multiple_bounds {
68-
// Use generic parameter H
69-
param_parts.push("host: &mut H".to_string());
70-
} else {
71-
// Single trait bound - use impl directly
72-
param_parts.push(format!("host: &mut impl {trait_bounds}"));
73-
}
65+
if let Some(trait_bounds) = &trait_bounds_opt {
66+
if has_multiple_bounds {
67+
// Use generic parameter H
68+
param_parts.push("host: &mut H".to_string());
7469
} else {
75-
// Fallback for backwards compatibility
76-
param_parts.push("host: &mut impl Host".to_string());
70+
// Single trait bound - use impl directly
71+
param_parts.push(format!("host: &mut impl {trait_bounds}"));
7772
}
7873
}
7974

crates/herkos/src/codegen/function.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,13 @@ fn generate_signature_with_info<B: Backend>(
251251
.collect();
252252

253253
// Add host parameter if function needs imports or global imports
254-
if needs_host {
255-
if let Some(trait_bounds) = trait_bounds_opt {
256-
if has_multiple_bounds {
257-
// Use generic parameter H
258-
param_parts.push("host: &mut H".to_string());
259-
} else {
260-
// Single trait bound - use impl directly
261-
param_parts.push(format!("host: &mut impl {trait_bounds}"));
262-
}
254+
if let Some(trait_bounds) = trait_bounds_opt {
255+
if has_multiple_bounds {
256+
// Use generic parameter H
257+
param_parts.push("host: &mut H".to_string());
263258
} else {
264-
// Fallback for backwards compatibility
265-
param_parts.push("host: &mut impl Host".to_string());
259+
// Single trait bound - use impl directly
260+
param_parts.push(format!("host: &mut impl {trait_bounds}"));
266261
}
267262
}
268263

crates/herkos/src/codegen/module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn generate_wrapper_module<B: Backend>(backend: &B, info: &ModuleInfo) -> Result
6464
));
6565
}
6666

67-
// Constructor (standalone for backwards compatibility)
67+
// Constructor (standalone free function)
6868
rust_code.push_str(&generate_constructor(backend, info, has_mut_globals)?);
6969
rust_code.push('\n');
7070

0 commit comments

Comments
 (0)