Skip to content

Commit c168a1d

Browse files
committed
fix(mlir): remove text round-trip from finalize_module
The round-trip serialized the MLIR module to text and re-parsed it to promote dictionary attributes to inherent properties. The patched melior-macro now sets ODS attributes as inherent from the start, making the round-trip unnecessary.
1 parent b737f59 commit c168a1d

1 file changed

Lines changed: 6 additions & 17 deletions

File tree

solx-mlir/src/context/mod.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -296,43 +296,32 @@ impl<'context> Context<'context> {
296296
///
297297
/// # Errors
298298
///
299-
/// Returns an error if re-parsing fails, the pass pipeline fails, or
300-
/// the deployed module is not found.
299+
/// Returns an error if the pass pipeline fails or the deployed module
300+
/// is not found.
301301
pub fn finalize_module(
302302
self,
303303
runtime_code_identifier: &str,
304304
emit_mlir: bool,
305305
) -> anyhow::Result<HashMap<String, String>> {
306-
// Re-parse the generated MLIR text to promote OperationBuilder
307-
// dictionary attributes to MLIR operation properties. Without this
308-
// round-trip, the Sol conversion pass fails because it expects
309-
// properties (not dict attrs) on operations like sol.func. This is
310-
// a melior limitation: OperationBuilder puts all attributes in the
311-
// dictionary, but the Sol C++ dialect defines them as properties.
312-
// The text format parser correctly separates them.
313-
let sol_text = self.module.as_operation().to_string();
314-
let mut parsed_module =
315-
Module::parse(self.builder.context, &sol_text).ok_or_else(|| {
316-
anyhow::anyhow!("failed to re-parse generated Sol dialect MLIR:\n{sol_text}")
317-
})?;
306+
let mut module = self.module;
318307

319308
let mut stages = HashMap::new();
320309

321310
// Capture the Sol dialect MLIR before lowering (only when requested).
322311
if emit_mlir {
323312
stages.insert(
324313
Self::DIALECT_SOL.to_owned(),
325-
parsed_module.as_operation().to_string(),
314+
module.as_operation().to_string(),
326315
);
327316
}
328317

329318
// Lower Sol → LLVM dialect.
330-
Self::run_sol_passes(self.builder.context, &mut parsed_module)?;
319+
Self::run_sol_passes(self.builder.context, &mut module)?;
331320

332321
// Walk the outer module's body to find the inner module whose
333322
// `sym_name` matches `runtime_code_identifier` and extract it as
334323
// the runtime code.
335-
let body = parsed_module.body();
324+
let body = module.body();
336325
let mut deployed_operation = None;
337326
let mut operation = body.first_operation();
338327
while let Some(current) = operation {

0 commit comments

Comments
 (0)