1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! Lossless MLIR syntax, semantic processing, editing, and output.
//!
//! The usual flow is to parse an owning [`parser::ParsedFile`], lower it to a
//! [`semantic::Document`], validate or verify it, optionally edit it, and then
//! choose an output mode:
//!
//! - [`parser::ParsedFile::write_original`] reproduces the input bytes exactly.
//! - [`semantic::Document::write_canonical`](crate::semantic::Document::write_canonical)
//! emits deterministic generic MLIR from semantic storage.
//! - [`semantic::Document::write_preserving`](crate::semantic::Document::write_preserving)
//! reuses unchanged source and regenerates edited regions; it requires
//! [`semantic::RetentionProfile::Hybrid`].
//!
//! [`semantic::RetentionProfile`] controls whether lowering retains syntax,
//! semantic storage, or both. [`semantic::LoweringMode::Strict`] returns no
//! document when lowering is incomplete, while `BestEffort` returns a document
//! containing invalid sentinels together with diagnostics. Structural
//! [`semantic::Document::validate_structure`] checks storage invariants;
//! [`semantic::Document::verify_semantics`] additionally runs registered
//! dialect schemas and verifiers.
//!
//! ```
//! use zirium::{
//! dialect::DialectRegistry,
//! parser::ParsedFile,
//! printer::PrintLayout,
//! semantic::{LoweringMode, RetentionProfile, lower_with_dialect_registry_and_retention},
//! };
//!
//! let parsed = ParsedFile::parse(b"\"example\"() : () -> ()".as_slice())?;
//! let lowered = lower_with_dialect_registry_and_retention(
//! &parsed,
//! LoweringMode::Strict,
//! RetentionProfile::SemanticOnly,
//! &DialectRegistry::EMPTY,
//! );
//! let document = lowered.document.expect("strict lowering succeeded");
//! document.validate_structure()?;
//! let bytes = document.canonical_bytes(PrintLayout::Pretty)?;
//! assert!(!bytes.is_empty());
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
pub use ;