pub struct CompilationUnit<'src> { /* private fields */ }Expand description
A unified compilation unit that owns all artifacts from source to machine code.
The compilation unit progresses through phases:
- New: Just source files
- Parsed: ASTs and interner from parsing
- Lowered: RIR (untyped intermediate representation)
- Analyzed: AIR (typed IR) and CFGs for all functions
Each phase builds on the previous one. The unit validates that phases are run in order - you can’t analyze before parsing.
§Thread Safety
The compilation unit uses ThreadedRodeo for string interning, which is
thread-safe. Parallel operations (like per-function CFG construction) can
safely share the interner.
Implementations§
Source§impl<'src> CompilationUnit<'src>
impl<'src> CompilationUnit<'src>
Sourcepub fn new(sources: Vec<SourceFile<'src>>, options: CompileOptions) -> Self
pub fn new(sources: Vec<SourceFile<'src>>, options: CompileOptions) -> Self
Create a new compilation unit from source files.
This initializes the unit with source files but does not run any
compilation phases. Call parse(), lower(),
and analyze() to progress through compilation.
§Arguments
sources- Source files to compileoptions- Compilation options (target, optimization, etc.)
Sourcepub fn parse(&mut self) -> MultiErrorResult<()>
pub fn parse(&mut self) -> MultiErrorResult<()>
Parse all source files.
This runs lexing and parsing on each source file, producing ASTs. The ASTs are then merged into a single program, detecting any duplicate symbol definitions.
§Errors
Returns errors if:
- Any file fails to lex or parse
- Duplicate function, struct, or enum definitions are found
Sourcepub fn lower(&mut self) -> MultiErrorResult<()>
pub fn lower(&mut self) -> MultiErrorResult<()>
Sourcepub fn analyze(&mut self) -> MultiErrorResult<()>
pub fn analyze(&mut self) -> MultiErrorResult<()>
Sourcepub fn compile(&self) -> MultiErrorResult<CompileOutput>
pub fn compile(&self) -> MultiErrorResult<CompileOutput>
Sourcepub fn run_frontend(&mut self) -> MultiErrorResult<()>
pub fn run_frontend(&mut self) -> MultiErrorResult<()>
Run all frontend phases (parse, lower, analyze).
This is a convenience method that runs the complete frontend pipeline.
Equivalent to calling parse(), lower(), and analyze() in sequence.
Sourcepub fn run_all(&mut self) -> MultiErrorResult<CompileOutput>
pub fn run_all(&mut self) -> MultiErrorResult<CompileOutput>
Run all phases and produce a compiled binary.
This is a convenience method that runs the complete compilation pipeline.
Equivalent to calling run_frontend() followed by compile().
Sourcepub fn is_lowered(&self) -> bool
pub fn is_lowered(&self) -> bool
Check if RIR generation has been completed.
Sourcepub fn is_analyzed(&self) -> bool
pub fn is_analyzed(&self) -> bool
Check if semantic analysis has been completed.
Sourcepub fn options(&self) -> &CompileOptions
pub fn options(&self) -> &CompileOptions
Get the compilation options.
Sourcepub fn interner(&self) -> &ThreadedRodeo
pub fn interner(&self) -> &ThreadedRodeo
Sourcepub fn functions(&self) -> &[FunctionWithCfg]
pub fn functions(&self) -> &[FunctionWithCfg]
Sourcepub fn type_pool(&self) -> &TypeInternPool
pub fn type_pool(&self) -> &TypeInternPool
Sourcepub fn warnings(&self) -> &[CompileWarning] ⓘ
pub fn warnings(&self) -> &[CompileWarning] ⓘ
Get all warnings collected during compilation.
Sourcepub fn file_paths(&self) -> &HashMap<FileId, String>
pub fn file_paths(&self) -> &HashMap<FileId, String>
Get the file paths map.
Sourcepub fn take_interner(&mut self) -> ThreadedRodeo
pub fn take_interner(&mut self) -> ThreadedRodeo
Sourcepub fn take_functions(&mut self) -> Vec<FunctionWithCfg>
pub fn take_functions(&mut self) -> Vec<FunctionWithCfg>
Sourcepub fn take_type_pool(&mut self) -> TypeInternPool
pub fn take_type_pool(&mut self) -> TypeInternPool
Sourcepub fn take_strings(&mut self) -> Vec<String>
pub fn take_strings(&mut self) -> Vec<String>
Sourcepub fn take_warnings(&mut self) -> Vec<CompileWarning> ⓘ
pub fn take_warnings(&mut self) -> Vec<CompileWarning> ⓘ
Take the warnings out of the compilation unit.
Trait Implementations§
Auto Trait Implementations§
impl<'src> !Freeze for CompilationUnit<'src>
impl<'src> !RefUnwindSafe for CompilationUnit<'src>
impl<'src> Send for CompilationUnit<'src>
impl<'src> Sync for CompilationUnit<'src>
impl<'src> Unpin for CompilationUnit<'src>
impl<'src> UnwindSafe for CompilationUnit<'src>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more