FunctionAnalyzer

Struct FunctionAnalyzer 

Source
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 SemaContext across 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>

Source

pub fn new(ctx: &'a SemaContext<'ctx>) -> Self

Create a new function analyzer with a reference to the shared context.

Source

pub fn into_output(self) -> FunctionAnalyzerOutput

Consume the analyzer and return its output.

Source

pub fn add_string(&mut self, content: String) -> u32

Add a string to the string table, returning its index. Deduplicates identical strings.

Source

pub fn add_warning(&mut self, warning: CompileWarning)

Add a warning.

Source

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.

Source

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.

Source

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.

Source

pub fn infer_type_to_type(&self, ty: &InferType) -> Type

Convert a fully-resolved InferType to a concrete Type.

Source

pub fn require_preview( &self, feature: PreviewFeature, what: &str, span: Span, ) -> CompileResult<()>

Check that a preview feature is enabled.

Source

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.

Source

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.

Source

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.

Source

pub fn resolve_type( &mut self, type_sym: Spur, span: Span, ) -> CompileResult<Type>

Resolve a type symbol to a Type.

Source

pub fn warnings(&self) -> &[CompileWarning]

Access the warnings collected during analysis.

Source

pub fn strings(&self) -> &[String]

Access the strings collected during analysis.

Trait Implementations§

Source§

impl<'a, 'ctx> Debug for FunctionAnalyzer<'a, 'ctx>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, 'ctx> Freeze for FunctionAnalyzer<'a, 'ctx>

§

impl<'a, 'ctx> !RefUnwindSafe for FunctionAnalyzer<'a, 'ctx>

§

impl<'a, 'ctx> Send for FunctionAnalyzer<'a, 'ctx>

§

impl<'a, 'ctx> Sync for FunctionAnalyzer<'a, 'ctx>

§

impl<'a, 'ctx> Unpin for FunctionAnalyzer<'a, 'ctx>

§

impl<'a, 'ctx> !UnwindSafe for FunctionAnalyzer<'a, 'ctx>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

§

type Proj<U: 'src> = U

§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more