Skip to content
Beskid Platform specification

Beskid

Jump to a Beskid service

Beskid

Jump to a Beskid service

Compiler Mods

Platform spec area

Compiler Mods

Owner
Piotr Mikstacki
Submitter
Piotr Mikstacki

Canonical ownership

This compiler area defines the Rust-side behavior for compiler mods. Project manifest contract defines the Mod project type and package metadata. Compiler Mod SDK defines Beskid-side contracts; this area defines discovery, AOT artifact lifecycle, execution phases, typed merge semantics, diagnostics transport, and incremental invalidation.

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.

Compiler mods (concept)

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.

Mod API shape (modules)

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.

Mod projects and pipeline phase ids

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.

Relationship diagram

The embedded architecture graph summarizes how Mod manifests, Beskid SDK contracts, the Rust host bridge, and downstream pipelines connect.

Feature index

Use the tiles for normative feature contracts (status + owner metadata on each hub).

Features