Roadmap search

Versions, deliverables, workstreams, tasks, and pages

Beskid

Jump to a Beskid service

Compiler Mods

area

src/content/docs/platform-spec/compiler/compiler-mods/index.mdx

import SpecPageHeader from '@beskid/beskid-ui/platform-spec/SpecPageHeader.astro'; import SpecSection from '@beskid/beskid-ui/platform-spec/SpecSection.astro'; import DomainTiles from '@beskid/beskid-ui/platform-spec/DomainTiles.astro'; import DomainOrAreaHub from '@beskid/beskid-ui/platform-spec/DomainOrAreaHub.astro';

<SpecPageHeader ownerName="Piotr Mikstacki" ownerEmail="pmikstacki@cybernomad.it" submitterName="Piotr Mikstacki" submitterEmail="pmikstacki@cybernomad.it" />

<SpecSection title="Canonical ownership" id="ownership"> This **compiler** area defines the Rust-side behavior for compiler mods. **[Project manifest contract](/platform-spec/tooling/manifests-and-lockfiles/project-manifest-contract/)** defines the **`Mod` project type** and package metadata. **[Compiler Mod SDK](/platform-spec/language-meta/metaprogramming/compiler-mod-sdk/)** defines Beskid-side contracts; this area defines discovery, AOT artifact lifecycle, execution phases, typed merge semantics, diagnostics transport, and incremental invalidation. </SpecSection> <SpecSection title="Scope" id="scope"> Normative pages specify **interfaces, cache boundaries, and host policy**—not product backlogs. They drive `compiler/` and **`corelib`** surfaces exposed at compile time.

Mod projects in this area are strictly for Beskid-authored compile-time work: analysis, code generation (typed AST), and rewrites over host compilations. Compiler-core composition and IoC remain Rust-owned and are specified separately under compiler features. </SpecSection>

<SpecSection title="Compiler mods (concept)" id="compiler-mods"> **Compiler mods** are **`Mod` projects** discovered from the dependency graph. The compiler compiles mods AOT and loads their artifacts during host compilation. Discovery is contract-driven (`Collector`, `Generator`, `Analyzer`, `Rewriter`, `AttributeGenerator`), not grammar-item-driven. </SpecSection> <SpecSection title="Mod API shape (modules)" id="mod-api-shape"> The compile-time package groups the natural compilation shape into modules (exact naming may evolve; boundaries are normative):
ModuleRole
Beskid.SyntaxTyped syntax node mirror with stable identities and structural builders.
Beskid.Compiler.QueryDeclarative query surfaces over syntax and semantic snapshots.
Beskid.Compiler.CollectCollector, Generator, Analyzer, Rewriter, and AttributeGenerator contracts plus target-selection primitives.
Beskid.Compiler.DiagnosticsCompiler-native diagnostics transport for analyzers and rewrite suggestions.
Beskid.Compiler.TypedEmitterTyped AST contributions and typed rewrites; no raw text/formatting contract.

Beskid.Compiler.Compilation remains the handle for the active host compilation instance.

Feature hubs below map onto these boundaries with traceability into beskid_analysis, beskid_lsp, beskid_codegen, beskid_engine, and beskid_runtime. </SpecSection>

<SpecSection title="Mod projects and pipeline phase ids" id="mod-projects">
flowchart LR
  parse[parse]
  modload[mod.load]
  collect[mod.collect]
  generate[mod.generate]
  reparse[reparse if needed]
  semantic[semantic.snapshot]
  analyze[mod.analyze]
  rewrite[mod.rewrite]
  lowerready[lower.ready]
  parse --> modload --> collect --> generate --> reparse --> semantic --> analyze --> rewrite --> lowerready

For project.type = Mod, the host registers mod contracts and emits beskid_pipeline phase events for collection, generation, analyzer, and rewrite boundaries. Strings below are normative literals that must be defined in compiler/crates/beskid_pipeline/src/phases.rs and asserted by conformance tests.

Phase id (literal)Rust constant (recommended)When emittedTypical invalidation
mod.loadMOD_LOADAfter dependency graph resolves and mod AOT artifacts are availableFull mod schedule rebuild
syntax.generationSYNTAX_GENERATIONAfter parse produces a new immutable Program snapshot for a compilation unitQuery/collect keys tied to syntax ids
mod.collectMOD_COLLECTCollector contracts declare target sets for active modsCollector cache boundaries
mod.generateMOD_GENERATEGenerators emit typed AST contributions (incremental by default)Generation replay boundaries
semantic.snapshotSEMANTIC_SNAPSHOTAfter semantic rules complete for merged host+generated programAnalyzer read boundary
mod.analyzeMOD_ANALYZEAnalyzer contracts emit diagnostics and fixesAnalyzer cache boundaries
mod.rewriteMOD_REWRITERewriter contracts apply typed node replacementsRewrite replay boundaries
lower.readyLOWER_READYImmediately before HIR lowering on a consistent merged programLowering safety boundary

Insertion order (host compilation with mods) — After parse, run mod.load (if needed), mod.collect, mod.generate, then re-parse when generation changed syntax, followed by semantic/semantic.snapshot, mod.analyze, optional mod.rewrite, and then lower/backend phases. Exact ordering is pinned in Stage ordering and lowering / design model.

Budgets (maxGeneratorRounds, step caps) and capability checks are specified in Mod host bridge; cache keys in Incremental scheduling and determinism. </SpecSection>

<DomainOrAreaHub pathPrefix="platform-spec/compiler/compiler-mods" summaryTitle="Subtree summary" /> <SpecSection title="Relationship diagram" id="architecture"> The embedded architecture graph summarizes how `Mod` manifests, Beskid SDK contracts, the Rust host bridge, and downstream pipelines connect. </SpecSection> <SpecSection title="Feature index" id="feature-index"> Use the tiles for normative **feature** contracts (`status` + owner metadata on each hub). </SpecSection> <DomainTiles pathPrefix="platform-spec/compiler/compiler-mods" heading="Features" />