Skip to main content

Environment

Struct Environment 

Source
pub struct Environment {
Show 21 fields pub next_block_id_counter: u32, pub next_scope_id_counter: u32, pub identifiers: Vec<Identifier>, pub types: Vec<Type>, pub scopes: Vec<ReactiveScope>, pub functions: Vec<HirFunction>, pub errors: CompilerError, pub fn_type: ReactFunctionType, pub output_mode: OutputMode, pub code: Option<String>, pub filename: Option<String>, pub instrument_fn_name: Option<String>, pub instrument_gating_name: Option<String>, pub hook_guard_name: Option<String>, pub renames: Vec<BindingRename>, pub reference_node_ids: HashSet<u32>, pub validate_preserve_existing_memoization_guarantees: bool, pub validate_no_set_state_in_render: bool, pub enable_preserve_existing_memoization_guarantees: bool, pub shapes: ShapeRegistry, pub config: EnvironmentConfig, /* private fields */
}

Fields§

§next_block_id_counter: u32§next_scope_id_counter: u32§identifiers: Vec<Identifier>§types: Vec<Type>§scopes: Vec<ReactiveScope>§functions: Vec<HirFunction>§errors: CompilerError§fn_type: ReactFunctionType§output_mode: OutputMode§code: Option<String>§filename: Option<String>§instrument_fn_name: Option<String>§instrument_gating_name: Option<String>§hook_guard_name: Option<String>§renames: Vec<BindingRename>§reference_node_ids: HashSet<u32>§validate_preserve_existing_memoization_guarantees: bool§validate_no_set_state_in_render: bool§enable_preserve_existing_memoization_guarantees: bool§shapes: ShapeRegistry§config: EnvironmentConfig

Implementations§

Source§

impl Environment

Source

pub fn new() -> Self

Source

pub fn with_config(config: EnvironmentConfig) -> Self

Create a new Environment with the given configuration.

Initializes the shape and global registries, registers custom hooks, and sets up the module type cache.

Source

pub fn for_outlined_fn(&self, fn_type: ReactFunctionType) -> Self

Create a child Environment for compiling an outlined function.

The child shares the same config, globals, and shapes, and receives copies of all arenas (identifiers, types, scopes, functions) so that references from the outlined HIR remain valid. Block/scope counters start past the cloned data to avoid ID conflicts.

Source

pub fn next_block_id(&mut self) -> BlockId

Source

pub fn new_mutable_range( &mut self, start: EvaluationOrder, end: EvaluationOrder, ) -> MutableRange

Create a new MutableRange with a unique ID. Use this when creating a logically new range (not copying an existing one). To copy a range preserving its identity, use .clone() instead.

Source

pub fn next_identifier_id(&mut self) -> IdentifierId

Allocate a new Identifier in the arena with default values, returns its IdentifierId.

Source

pub fn next_scope_id(&mut self) -> ScopeId

Allocate a new ReactiveScope in the arena, returns its ScopeId.

Source

pub fn next_type_id(&mut self) -> TypeId

Allocate a new Type in the arena, returns its TypeId.

Source

pub fn make_type(&mut self) -> TypeId

Allocate a new Type (TypeVar) in the arena, returns its TypeId.

Source

pub fn add_function(&mut self, func: HirFunction) -> FunctionId

Source

pub fn record_error( &mut self, detail: CompilerErrorDetail, ) -> Result<(), CompilerError>

Source

pub fn record_diagnostic(&mut self, diagnostic: CompilerDiagnostic)

Source

pub fn has_errors(&self) -> bool

Source

pub fn error_count(&self) -> usize

Source

pub fn has_invariant_errors(&self) -> bool

Check if any recorded errors have Invariant category. In TS, Invariant errors throw immediately from recordError(), which aborts the current operation.

Source

pub fn errors(&self) -> &CompilerError

Source

pub fn take_errors(&mut self) -> CompilerError

Source

pub fn take_errors_since(&mut self, since_count: usize) -> CompilerError

Take errors added after position since_count, leaving earlier errors in place. Used to detect new errors added by a specific pass.

Source

pub fn take_invariant_errors(&mut self) -> CompilerError

Take only the Invariant errors, leaving non-Invariant errors in place. In TS, Invariant errors throw as a separate CompilerError, so only the Invariant error is surfaced.

Source

pub fn has_todo_errors(&self) -> bool

Check if any recorded errors have Todo category. In TS, Todo errors throw immediately via CompilerError.throwTodo().

Source

pub fn take_thrown_errors(&mut self) -> CompilerError

Take errors that would have been thrown in TS (Invariant and Todo), leaving other accumulated errors in place.

Source

pub fn is_hoisted_identifier(&self, binding_id: u32) -> bool

Check if a binding has been hoisted (via DeclareContext) already.

Source

pub fn add_hoisted_identifier(&mut self, binding_id: u32)

Mark a binding as hoisted.

Source

pub fn get_global_declaration( &mut self, binding: &NonLocalBinding, loc: Option<SourceLocation>, ) -> Result<Option<Global>, CompilerError>

Resolve a non-local binding to its type. Ported from TS getGlobalDeclaration.

The loc parameter is used for error diagnostics when validating module type configurations. Pass None if no source location is available.

Source

pub fn get_property_type( &mut self, receiver: &Type, property: &str, ) -> Result<Option<Type>, CompilerDiagnostic>

Get the type of a named property on a receiver type. Ported from TS getPropertyType.

Source

pub fn get_property_type_numeric( &self, receiver: &Type, ) -> Result<Option<Type>, CompilerDiagnostic>

Get the type of a numeric property on a receiver type. Ported from the numeric branch of TS getPropertyType.

Source

pub fn get_fallthrough_property_type( &self, receiver: &Type, ) -> Result<Option<Type>, CompilerDiagnostic>

Get the fallthrough (wildcard *) property type for computed property access. Ported from TS getFallthroughPropertyType.

Source

pub fn get_function_signature( &self, ty: &Type, ) -> Result<Option<&FunctionSignature>, CompilerDiagnostic>

Get the function signature for a function type. Ported from TS getFunctionSignature.

Source

pub fn get_hook_kind_for_type( &self, ty: &Type, ) -> Result<Option<&HookKind>, CompilerDiagnostic>

Get the hook kind for a type, if it represents a hook. Ported from TS getHookKindForType in HIR.ts.

Source

pub fn get_custom_hook_type_opt(&mut self) -> Option<Global>

Public accessor for the custom hook type, used by InferTypes for property resolution fallback when a property name looks like a hook.

Source

pub fn shapes(&self) -> &ShapeRegistry

Get a reference to the shapes registry.

Source

pub fn globals(&self) -> &GlobalRegistry

Get a reference to the globals registry.

Source

pub fn generate_globally_unique_identifier_name( &mut self, name: Option<&str>, ) -> String

Generate a globally unique identifier name, analogous to TS generateGloballyUniqueIdentifierName which delegates to Babel’s scope.generateUidIdentifier. Matches Babel’s naming convention: first name is _<name>, subsequent are _<name>2, _<name>3, etc. Also applies Babel’s toIdentifier sanitization on the input name.

Like Babel’s generateUid, checks for collisions against existing bindings (source-level identifier names) and previously generated UIDs, rather than using a blind counter.

Source

pub fn seed_uid_known_names(&mut self, names: &HashSet<String>)

Seed the UID known names set with external names (e.g. from ProgramContext). This ensures UID generation avoids names generated by previous function compilations, matching Babel’s behavior where the program scope accumulates all generated UIDs.

Source

pub fn take_uid_known_names(&mut self) -> Option<HashSet<String>>

Return the UID known names accumulated during this compilation.

Source

pub fn outline_function( &mut self, func: HirFunction, fn_type: Option<ReactFunctionType>, )

Record an outlined function (extracted during outlineFunctions or outlineJSX). Corresponds to TS env.outlineFunction(fn, type).

Source

pub fn get_outlined_functions(&self) -> &[OutlinedFunctionEntry]

Get the outlined functions accumulated during compilation.

Source

pub fn take_outlined_functions(&mut self) -> Vec<OutlinedFunctionEntry>

Take the outlined functions, leaving the vec empty.

Source

pub fn enable_memoization(&self) -> bool

Whether memoization is enabled for this compilation. Ported from TS get enableMemoization() in Environment.ts. Returns true for client/lint modes, false for SSR.

Source

pub fn enable_validations(&self) -> bool

Whether validations are enabled for this compilation. Ported from TS get enableValidations() in Environment.ts.

Source

pub fn identifier_name_for_id(&self, id: IdentifierId) -> Option<String>

Get the user-visible name for an identifier.

First checks the identifier’s own name. If None, looks for another identifier with the same declaration_id that has a name. This handles SSA identifiers that don’t carry names but share a declaration_id with the original named identifier from lowering.

This is analogous to identifierName on Babel’s SourceLocation, which the parser sets on every identifier node.

Source

pub fn has_no_alias_signature(&self, identifier_id: IdentifierId) -> bool

Check whether the function type for an identifier has a noAlias signature. Looks up the identifier’s type and checks its function signature.

Source

pub fn get_hook_kind_for_id( &self, identifier_id: IdentifierId, ) -> Result<Option<&HookKind>, CompilerDiagnostic>

Get the hook kind for an identifier, if its type represents a hook. Looks up the identifier’s type and delegates to get_hook_kind_for_type.

Trait Implementations§

Source§

impl Default for Environment

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.

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.

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.