Skip to main content

Crate gruel_compiler

Crate gruel_compiler 

Source
Expand description

Gruel compiler driver.

This crate orchestrates the compilation pipeline: Source -> Lexer -> Parser -> AstGen -> Sema -> CodeGen -> ELF

It re-exports types from the component crates for convenience.

§Diagnostic Formatting

The MultiFileFormatter provides a clean API for formatting errors and warnings:

use gruel_compiler::{MultiFileFormatter, SourceInfo, FileId};

let sources = vec![(FileId::new(1), SourceInfo::new(&source, "example.gruel"))];
let formatter = MultiFileFormatter::new(sources);

// Format an error
let error_output = formatter.format_error(&error);
eprintln!("{}", error_output);

§Tracing

This crate is instrumented with tracing spans for performance analysis. Use --log-level info or --time-passes to see timing information.

Structs§

Air
The complete AIR for a function.
AirOutput
Output from semantic analysis (compile_to_air).
AnalyzedFunction
Result of analyzing a function.
Ast
A complete source file (list of items).
AstGen
Generates RIR from an AST.
BackendInputs
Bundle of inputs handed to the backend.
Cfg
The complete CFG for a function.
CfgBuilder
Builder that converts AIR to CFG.
CfgOutput
Output from CFG construction.
CompilationUnit
A unified compilation unit that owns all artifacts from source to machine code.
CompileErrors
A collection of compilation errors.
CompileOptions
Configuration options for compilation.
CompileOutput
Output from successful compilation.
CompileState
Intermediate compilation state after frontend processing.
CompileStateFromRir
Intermediate compilation state after frontend processing from RIR.
Diagnostic
Rich diagnostic information for errors and warnings.
ErrorCode
A unique error code for each error type.
FileId
A file identifier used to track which source file a span belongs to.
Function
A function definition.
FunctionWithCfg
A function with its typed IR (AIR) and control flow graph (CFG).
JsonDiagnostic
A diagnostic formatted for JSON output.
JsonSpan
A span in JSON format with file location and labels.
JsonSuggestion
A suggested fix in JSON format.
Lexer
Logos-based lexer that converts source text into tokens.
LoadedFile
One file loaded by load_import_closure: a path, its text, and an assigned FileId. The caller converts these into [SourceFile]s.
MergedProgram
Result of merging symbols from multiple parsed files.
MultiFileFormatter
A diagnostic formatter that supports diagnostics spanning one or more source files.
MultiFileJsonFormatter
Formats diagnostics as JSON for machine consumption.
ParseCacheStats
Hit/miss counts for one parse-pipeline invocation. Surfaced to --time-passes so users can see whether the cache is doing work.
ParsedFile
Result of parsing a single file.
ParsedProgram
Result of parsing all source files.
Parser
Chumsky-based parser that converts tokens into an AST.
ResolvedPrelude
Result of locating the prelude.
ResolvedPreludeFile
One source file with its path and content.
Rir
The complete RIR for a source file.
RirPrinter
Printer for RIR that resolves symbols to their string values.
Sema
Semantic analyzer that converts RIR to AIR.
SemaOutput
Output from semantic analysis.
SourceFile
A source file with its path and content.
SourceInfo
Source code information for diagnostic rendering.
Span
A span representing a range in the source code.
Spur
The default key for every Rodeo, uses only 32 bits of space
StructDef
Definition of a struct type.
Suggestion
A suggested code fix that can be applied to resolve a diagnostic.
Target
A compilation target, identified by an LLVM-style triple.
ThreadedRodeo
A concurrent string interner that caches strings quickly with a minimal memory footprint, returning a unique key to re-access it with O(1) internment and resolution.
Token
A token with its kind and source span.
Type
A type in the Gruel type system.
TypeInternPool
Thread-safe intern pool for all composite types.
ValidatedProgram
Result of validating and generating RIR from multiple parsed files.

Enums§

Applicability
How confident we are that a suggested fix is correct.
Arch
The CPU architecture of a target.
ColorChoice
Color choice for diagnostic output.
ErrorKind
The kind of compilation error.
Expr
An expression.
ImportLoadError
A non-fatal load failure for one file (the entry, or a transitively imported file). The walker logs these up to the caller; sema will surface the eventual ModuleNotFound diagnostic for unresolved @imports.
Item
A top-level item in a source file.
LinkerMode
Which linker to use for the final linking phase.
OptLevel
Optimization level, following standard compiler conventions.
PreviewFeature
A preview feature that can be enabled with --preview.
TokenKind
Token kinds in the Gruel language.
WarningKind
The kind of compilation warning.

Functions§

compile
Compile source code to an ELF binary.
compile_backend
Compile analyzed functions to a binary.
compile_frontend
Compile source code through all frontend phases (up to but not including codegen).
compile_frontend_from_ast
Compile from an already-parsed AST through all remaining frontend phases.
compile_frontend_from_ast_with_file_paths
Full-control variant: like compile_frontend_from_ast_with_options_full_target but additionally threads a file_id → path map into sema so @import("...") resolution can find sibling modules. The LSP needs this on the per-root compile path — parse_all_files_with_preview doesn’t populate sema’s file_paths map on its own.
compile_frontend_from_ast_with_options
Compile from an already-parsed AST through all remaining frontend phases.
compile_frontend_from_ast_with_options_full
Like compile_frontend_from_ast_with_options, but additionally lets the caller suppress the on-the-fly stderr print of comptime @dbg output.
compile_frontend_from_ast_with_options_full_target
Like compile_frontend_from_ast_with_options_full, but additionally accepts the compile target so @target_arch() / @target_os() reflect it (ADR-0077). Use this from --emit paths that already have a target in hand. The non-_target variants default to the host.
compile_frontend_from_rir_with_file_paths
Compile frontend from RIR with file paths for module resolution.
compile_frontend_from_rir_with_options
Compile from already-generated RIR through remaining frontend phases.
compile_frontend_with_options
Compile source code through all frontend phases.
compile_frontend_with_options_full
Like compile_frontend_with_options, but additionally lets the caller suppress the on-the-fly stderr print of comptime @dbg output. When suppress_comptime_dbg_print is true, output is only collected in the SemaOutput.comptime_dbg_output buffer. Used by fuzz harnesses that consume the buffer directly and don’t want noise on stderr.
compile_multi_file_with_options
Compile multiple source files to an ELF binary.
compile_to_air
Compile source code up to AIR (typed IR) without building CFG.
compile_to_cfg
Compile source code up to CFG (control flow graph).
compile_with_options
Compile source code to an ELF binary with the given options.
embedded_prelude
Embedded prelude (the include_dir! fallback).
generate_llvm_ir
Generate LLVM textual IR from analyzed functions.
load_import_closure
Load the entry file plus every file it transitively @imports.
loaded_files_as_view
View the closure as (path, text, FileId) triples so the caller can construct SourceFile<'_> borrows.
merge_symbols
Merge symbols from all parsed files into a unified program.
parse_all_files
Parse multiple source files with a shared interner.
parse_all_files_cached
Run the parse pipeline with cache lookup/store enabled.
parse_all_files_with_preview
Parse all files with an explicit set of preview features for the parser (ADR-0049).
parse_key
Compute the parse-cache key for one source file.
prepend_prelude
ADR-0078 Phase 1: lex+parse the embedded prelude using interner and prepend its top-level items to ast. Useful for callers that bypass CompilationUnit::parse (lib tests, --emit-only flows that already have a parsed AST in hand) but still want the prelude-resident declarations (Option, Result, Arch, Os, Drop/Copy/Clone, etc.) to be visible during sema.
resolved_prelude
Resolve the prelude.
validate_and_generate_rir_parallel
Validate symbols and generate RIR in parallel for multi-file compilation.

Type Aliases§

CompileError
A compilation error with optional source location information.
CompileResult
Result type for compilation operations.
CompileWarning
A compilation warning with optional source location information.
ImportOverlay
Hook that, given an absolute (or workspace-relative) file path, may return overriding source text for that file.
MultiErrorResult
Result type for operations that can produce multiple errors.
PreviewFeatures
A set of enabled preview features.