Skip to main content

Crate zirium

Crate zirium 

Source
Expand description

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:

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.

This example edits a hybrid document, commits the transaction, writes source-preserving output, and then shows what happens to an erased handle:

use zirium::{
    dialect::DialectRegistry,
    parser::ParsedFile,
    printer::PrintLayout,
    semantic::{
        AttributeSpec, EditError, LoweringMode, RetentionProfile,
        lower_with_dialect_registry_and_retention,
    },
};

let source = b"\"keep\"() : () -> ()\n\"edit\"() : () -> ()\n";
let parsed = ParsedFile::parse(source.as_slice())?;
let registry = DialectRegistry::EMPTY;
let lowered = lower_with_dialect_registry_and_retention(
    &parsed,
    LoweringMode::Strict,
    RetentionProfile::Hybrid,
    &registry,
);
let mut document = lowered.document.expect("strict lowering succeeds");
document.verify_semantics(&registry)?;
let edited = document.root_operations()[1];

let mut transaction = document.edit(&registry)?;
transaction.set_attribute(
    edited,
    AttributeSpec::string("tag", "checked"),
)?;
transaction.commit()?;
let output = document.preserving_bytes(PrintLayout::Pretty)?;
assert!(String::from_utf8(output)?.contains("tag = \"checked\""));

let mut transaction = document.edit(&registry)?;
transaction.erase(edited)?;
transaction.commit()?;
assert!(matches!(
    document.check_operation(edited),
    Err(EditError::StaleOperation(_))
));

Modules§

dialect
Explicit, static dialect registration descriptors.
diff
Structural and dataflow comparison for two semantic MLIR documents.
formatter
Source-aware layout formatting for textual MLIR.
lexer
Lossless tokenization for textual MLIR.
parser
Owning parse results, resource limits, text edits, and typed CST views.
printer
Deterministic generic MLIR output from semantic documents.
query
Composable operation-selection queries, editing, and output.
semantic
Mutable semantic IR, lowering, verification, analyses, and transactions.
source
Owned source bytes and checked byte ranges.

Structs§

CompletedMarker
EventBuilder
Marker
NodeId
SyntaxTree

Enums§

CompactError
Event
SyntaxElement
SyntaxKind