pub struct Sema<'a> { /* private fields */ }Expand description
Semantic analyzer that converts RIR to AIR.
Implementations§
Source§impl<'a> Sema<'a>
impl<'a> Sema<'a>
Sourcepub fn analyze_specialized_function(
&mut self,
infer_ctx: &InferenceContext,
return_type: Type,
params: &[(Spur, Type, RirParamMode)],
body: InstRef,
type_subst: &HashMap<Spur, Type>,
) -> Result<(Air, u32, u32, Vec<bool>, Vec<Type>, Vec<DiagnosticWrapper<WarningKind>>, Vec<String>, HashSet<Spur>, HashSet<(StructId, Spur)>), DiagnosticWrapper<ErrorKind>>
pub fn analyze_specialized_function( &mut self, infer_ctx: &InferenceContext, return_type: Type, params: &[(Spur, Type, RirParamMode)], body: InstRef, type_subst: &HashMap<Spur, Type>, ) -> Result<(Air, u32, u32, Vec<bool>, Vec<Type>, Vec<DiagnosticWrapper<WarningKind>>, Vec<String>, HashSet<Spur>, HashSet<(StructId, Spur)>), DiagnosticWrapper<ErrorKind>>
Analyze a specialized function body.
This is similar to analyze_function but for generic function specialization.
The type_subst map provides substitutions for type parameters to their
concrete types.
For example, when specializing fn identity<T>(x: T) -> T { x } with T = i32,
the params will be [(x, i32, Normal)] and return_type will be i32.
Source§impl<'a> Sema<'a>
impl<'a> Sema<'a>
Sourcepub fn build_inference_context(&self) -> InferenceContext
pub fn build_inference_context(&self) -> InferenceContext
Build an InferenceContext from the collected type information.
This should be called after the collection phase and builds the pre-computed maps needed for Hindley-Milner type inference. Building this once and reusing for all function analyses avoids the O(n²) cost of rebuilding these maps per function.
§Performance
This converts all function/method signatures to use InferType
(which handles arrays structurally rather than by ID). This conversion
is done once instead of per-function.
Source§impl<'a> Sema<'a>
impl<'a> Sema<'a>
Sourcepub fn set_file_paths(&mut self, file_paths: HashMap<FileId, String>)
pub fn set_file_paths(&mut self, file_paths: HashMap<FileId, String>)
Set file paths for module resolution in multi-file compilation.
This maps FileIds to their corresponding source file paths, enabling relative import resolution during @import.
Source§impl Sema<'_>
impl Sema<'_>
Sourcepub fn evaluate_const_initializers(
&mut self,
) -> Result<(), DiagnosticWrapper<ErrorKind>>
pub fn evaluate_const_initializers( &mut self, ) -> Result<(), DiagnosticWrapper<ErrorKind>>
Evaluate const initializers to determine their types.
This is Phase 2.5 of semantic analysis, called after declaration gathering but before function body analysis. It handles:
const x = @import("module")- evaluates to Type::Module- Other const initializers are left with placeholder types for now
This enables module re-exports where a const holds an imported module that can be accessed via dot notation.
Source§impl<'a> Sema<'a>
impl<'a> Sema<'a>
Sourcepub fn build_sema_context<'s>(&'s self) -> SemaContext<'s>where
'a: 's,
pub fn build_sema_context<'s>(&'s self) -> SemaContext<'s>where
'a: 's,
Build a SemaContext from the current Sema state.
This creates an immutable context that can be shared across threads for parallel function body analysis. The SemaContext contains all type definitions, function signatures, and method signatures.
The returned SemaContext borrows functions and methods from Sema,
so Sema must outlive the SemaContext. This is reflected in the
lifetime relationship: the returned context lives for 's (the
borrow of self), not 'a (the lifetime of the RIR/interner).
§Usage
let mut sema = Sema::new(rir, interner, preview);
sema.inject_builtin_types();
sema.register_type_names()?;
sema.resolve_declarations()?;
let ctx = sema.build_sema_context();
// Now ctx can be shared across threads for parallel analysis
// (while sema is borrowed)Source§impl Sema<'_>
impl Sema<'_>
Sourcepub fn resolve_enum_through_module(
&self,
_module_ref: InstRef,
type_name: Spur,
span: Span,
) -> Result<EnumId, DiagnosticWrapper<ErrorKind>>
pub fn resolve_enum_through_module( &self, _module_ref: InstRef, type_name: Spur, span: Span, ) -> Result<EnumId, DiagnosticWrapper<ErrorKind>>
Resolve an enum type through a module reference.
Used for qualified enum paths like module.EnumName::Variant in match patterns.
Checks visibility: private enums are only accessible from the same directory.
Source§impl<'a> Sema<'a>
impl<'a> Sema<'a>
Sourcepub fn new(
rir: &'a Rir,
interner: &'a ThreadedRodeo,
preview_features: HashSet<PreviewFeature>,
) -> Sema<'a>
pub fn new( rir: &'a Rir, interner: &'a ThreadedRodeo, preview_features: HashSet<PreviewFeature>, ) -> Sema<'a>
Create a new semantic analyzer.
Sourcepub fn set_suppress_comptime_dbg_print(&mut self, suppress: bool)
pub fn set_suppress_comptime_dbg_print(&mut self, suppress: bool)
Configure whether comptime @dbg prints to stderr on-the-fly.
When suppressed, output is still buffered into comptime_dbg_output
and warnings are still emitted.
Sourcepub fn analyze_all(self) -> Result<SemaOutput, CompileErrors>
pub fn analyze_all(self) -> Result<SemaOutput, CompileErrors>
Perform semantic analysis on the RIR.
This is the main entry point for semantic analysis. It returns analyzed functions, struct definitions, enum definitions, and any warnings.
Sourcepub fn analyze_all_bodies(self) -> Result<SemaOutput, CompileErrors>
pub fn analyze_all_bodies(self) -> Result<SemaOutput, CompileErrors>
Analyze all function bodies, assuming declarations are already collected.
Auto Trait Implementations§
impl<'a> !Freeze for Sema<'a>
impl<'a> !RefUnwindSafe for Sema<'a>
impl<'a> Send for Sema<'a>
impl<'a> Sync for Sema<'a>
impl<'a> Unpin for Sema<'a>
impl<'a> !UnwindSafe for Sema<'a>
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