pub struct FunctionAnalyzer<'a, 'ctx> {
pub ctx: &'a SemaContext<'ctx>,
/* private fields */
}Expand description
Per-function mutable state during semantic analysis.
This struct contains all mutable state that is modified during function body analysis. For parallel analysis, each function gets its own instance, and results are merged afterward.
§Separation from SemaContext
FunctionAnalyzer holds mutable state while SemaContext holds immutable
type information. This separation enables:
- Sharing
SemaContextacross parallel function analyses - Independent mutable state per function
- Post-analysis merging of results (strings, warnings)
Array types are created via the thread-safe TypeInternPool in SemaContext,
so they don’t require local buffering or post-merge remapping.
Fields§
§ctx: &'a SemaContext<'ctx>Reference to the shared immutable context.
Implementations§
Source§impl<'a, 'ctx> FunctionAnalyzer<'a, 'ctx>
impl<'a, 'ctx> FunctionAnalyzer<'a, 'ctx>
Sourcepub fn new(ctx: &'a SemaContext<'ctx>) -> Self
pub fn new(ctx: &'a SemaContext<'ctx>) -> Self
Create a new function analyzer with a reference to the shared context.
Sourcepub fn into_output(self) -> FunctionAnalyzerOutput
pub fn into_output(self) -> FunctionAnalyzerOutput
Consume the analyzer and return its output.
Sourcepub fn add_string(&mut self, content: String) -> u32
pub fn add_string(&mut self, content: String) -> u32
Add a string to the string table, returning its index. Deduplicates identical strings.
Sourcepub fn add_warning(&mut self, warning: CompileWarning)
pub fn add_warning(&mut self, warning: CompileWarning)
Add a warning.
Sourcepub fn get_or_create_array_type(
&self,
element_type: Type,
length: u64,
) -> ArrayTypeId
pub fn get_or_create_array_type( &self, element_type: Type, length: u64, ) -> ArrayTypeId
Get or create an array type, returning its ID.
Delegates to the thread-safe TypeInternPool in SemaContext.
Sourcepub fn get_array_type_def(&self, id: ArrayTypeId) -> (Type, u64)
pub fn get_array_type_def(&self, id: ArrayTypeId) -> (Type, u64)
Get an array type definition by ID.
Returns (element_type, length) for the array.
Sourcepub fn pre_create_array_types_from_infer_type(&self, ty: &InferType)
pub fn pre_create_array_types_from_infer_type(&self, ty: &InferType)
Pre-create array types from a resolved InferType.
This walks the InferType recursively and ensures all array types that will
be needed during infer_type_to_type conversion are created beforehand.
With the thread-safe TypeInternPool, this is no longer strictly necessary
since infer_type_to_type can create array types on-demand. However, it’s
kept for explicit documentation of intent and potential future optimizations.
Sourcepub fn infer_type_to_type(&self, ty: &InferType) -> Type
pub fn infer_type_to_type(&self, ty: &InferType) -> Type
Convert a fully-resolved InferType to a concrete Type.
Sourcepub fn require_preview(
&self,
feature: PreviewFeature,
what: &str,
span: Span,
) -> CompileResult<()>
pub fn require_preview( &self, feature: PreviewFeature, what: &str, span: Span, ) -> CompileResult<()>
Check that a preview feature is enabled.
Sourcepub fn format_type_name(&self, ty: Type) -> String
pub fn format_type_name(&self, ty: Type) -> String
Get a human-readable name for a type. Delegates to context for most types but handles local array types.
Sourcepub fn is_type_copy(&self, ty: Type) -> bool
pub fn is_type_copy(&self, ty: Type) -> bool
Check if a type is a Copy type. Delegates to context for most types but handles local array types.
Sourcepub fn abi_slot_count(&self, ty: Type) -> u32
pub fn abi_slot_count(&self, ty: Type) -> u32
Get the number of ABI slots required for a type. Delegates to context for most types but handles local array types.
Sourcepub fn resolve_type(
&mut self,
type_sym: Spur,
span: Span,
) -> CompileResult<Type>
pub fn resolve_type( &mut self, type_sym: Spur, span: Span, ) -> CompileResult<Type>
Resolve a type symbol to a Type.
Sourcepub fn warnings(&self) -> &[CompileWarning] ⓘ
pub fn warnings(&self) -> &[CompileWarning] ⓘ
Access the warnings collected during analysis.