Multi-frontend IR (conceptual)

Multiple source languages can feed the same hybrid pipeline by lowering to textual SIL that hybrid_sil already parses (sil @…, bbN:, function_ref @…, unique SSA ids across the merged module).

Textual SIL merge behavior (hybrid_sil)

parse_textual_sil keeps the legacy top-level function_id as whichever sil @name line appeared last in the input, and still exposes flattened block / instruction vectors for existing callers. It also records explicit per-function entries in SilArtifact::functions, each with its own blocks and instructions. extract_call_graph prefers those per-function records, then falls back to instruction_callers, then to the legacy function_id behavior for old artifacts. Emitters still typically place sil @main last so single-function views line up with main. For full detail see in-language.md.

UnifiedModule (current schema)

Rust type: in_cli::core_ir::UnifiedModule.

FieldMeaning
decls: Vec<Decl>Top-level declarations in source order (before lowering sorts functions for SIL).

.in also has a parser-side surface fact helper for import, capability, and extern declarations. Local relative .in imports merge imported declarations into the current UnifiedModule; std.io / std.fs / std.http / std.json / std.process / std.cli imports synthesize bounded extern-style declarations; imports and capabilities are exposed through in agent JSON, and extern requires contracts produce agent diagnostics when required capabilities are missing. Extern bindings lower into empty Function declarations today so call graph extraction can observe explicit .in calls without expanding the Core IR schema.

Decl variants

VariantFieldsNotes
Structname, fields: Vec<(String, Typ)>.in v0.2 supports multiline field blocks; Tree-sitter and dedicated fronts fill fields where their current extractor supports them.
Functionname, params, ret, body.in, icoreVersion: 2, dedicated Rust/Go/V fronts, and selected Tree-sitter fronts fill bounded statement lists; lowering follows lower_core.

Typ: Int, String, Bool, Void, Named(String).

Boundary IR (icoreVersion: 3)

Rust types: in_cli::boundary_ir::BoundaryModule, CompileArtifact.

FieldMeaning
abi_versionMust match IN_ABI_VERSION in shared/abi/in_abi.h.
moduleStable boundary module id (for example sample.person).
layoutsStruct/enum layouts with C repr, size, align, stride, and per-field transfer mode.
symbolsExported ABI symbols with ownership and calling convention metadata.
allocatorsAllocator ids (host_arena, module heap) used by buffers and borrow tokens.
layout_hashCanonical blake3-… hash over layouts + symbols; empty means compute on ingest.

compiler::icore::parse_icore_artifact verifies boundary modules before lowering. Level-5 language fronts may attach the same BoundaryModule through dedicated extractors (Nim/Odin comment JSON today; Rust/Zig extractors planned) without expanding Core IR statement forms.

ParserId (extensible)

IdSourceEntry
In.in files (and #!in parser=in)in_lang_parseUnifiedModulecompiler::driver / lower_core; parser-side surface facts feed agent effects / capabilities
Icore.icore files (and #!in parser=icore)compiler::icore v1 declarations, v2 bounded body JSON, or v3 Boundary IR (boundary section + optional semantic decls) → CompileArtifact → same lowering
swift, go, ocaml, haskell, c, cpp, java, python, …Known extensions or #!in parser=<slug>Tree-sitter polyglotcompiler::tree_front grammar-backed AST → UnifiedModule. All 37 languages share the same pipeline.

Resolution order for in build

See in-cli/src/parser_registry.rs (resolve_parser_id) and parser-surface.md. In short:

  1. --parser in / --parser icore — force the .in or .icore front.
  2. Magic first line#!in parser=in | auto | <slug>.
  3. IN_PARSER=in / IN_PARSER=icore.
  4. Extension map.in, .icore, .java, .cpp, … → Core IR path (full parsers for .in/.icore; Tree-sitter for other wired extensions).
  5. Unknown extensions: fail closed with an .icore hint.

All 37 languages now route through Core IR. Swift was unified into the Tree-sitter pipeline (the old swift_subset/native_swift_sil/sil_emit modules have been deleted).

Related