Skip to content

Split the IR into its own crate, comline-ir #278

Open

Description

@Kinflou

core#144 split core into an IR half and a compiler half with a default compiler feature. Without it, comline-core is the IR alone: frozen units, CBOR, the format stamp, annotations and unverified. That build has no tree-sitter and builds for wasm. This issue proposes making that line a crate boundary, with comline-ir beside comline-core.

Why

  • The compiler enforces the boundary, not cfg. The line is 97 #[cfg(feature = "compiler")] sites in 20 files today (23 in package/build/mod.rs, 14 in diagnostics.rs, 8 in frozen/types.rs). Only the ir_only CI job catches IR code that reaches for the parser. As two crates, that code doesn't compile.
  • Features unify across a workspace. In generation, codegen depends on core with default-features = false, but conformance uses the defaults. A workspace build turns compiler on for codegen too, so codegen is IR-only only when built alone (-p). A separate crate has no such leak.
  • A smaller contract for generators. Third-party generators read only the IR. A crate that changes when the IR format changes is a clearer dependency than all of core, especially once crates are published.

When

Updated 2026-11-16. The plan was to do this together with #268's step 1.2, so core's workspace would be rearranged once. Step 1.2 merged on 2026-11-14 (core#280) without the split: the comline-ir-formats crate is core/formats/ (publish = false, a path dependency of comline-core). So the workspace will be rearranged a second time. One consequence: cargo publish -p comline-core fails until that crate is published or the dependency made optional (noted in #280). The reasons for the split are unchanged; do it before crates.io publishing starts (cli#1, runtime#115), when a third-party generator appears, or when the feature unification above breaks a build, and move or keep comline-ir-formats beside comline-ir in the same change.

Shape

  • comline-ir: the modules the IR-only build has today, with module paths kept where possible.
  • comline-core: the compiler, depending on comline-ir and re-exporting it, so downstream crates (cli, language-server, playground, runtime) keep their imports. Only a crate that wants the IR alone (generation's codegen) switches its dependency.
  • The compiler feature goes away, or stays as a no-op for a release.

Work

  • from_grammar constructors: inherent impls on the frozen types can only live in the crate that defines them. They become free functions, or a trait in comline-core.
  • diagnostics.rs: separate the IR's diagnostic types from parse-error rendering.
  • The official encodings' snapshot (official_units.json, the_snapshot_is_what_freezes) moves with the IR.
  • The ir_only CI job becomes comline-ir's own build and wasm targets.
  • generation's codegen depends on comline-ir.

Not in scope

Splitting the compiler itself into lexer, parser, HIR and driver crates. A 2024 attempt at that (an unpublished compilers/ workspace on ungrammar and verde) never got past scaffolding and has been retired. The parser is the rust-sitter grammars, and no consumer needs stage boundaries.

Activity

  1. Kinflou commented on Nov 15, 2026

    @Kinflou
    MemberAuthor

    Audit 2026-11-16: rewrote the 'When' paragraph (original saved in the audit notes). The plan was to split the IR crate together with #268 step 1.2, but core#280 merged on 2026-11-14 with the comline-ir-formats crate in core/formats and no split, so the workspace will be rearranged twice and comline-core can't be published until that crate is. The case for the split is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1NextchoreMaintenance, cleanup, qualitycompilerParser, IR, CAS

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions