Skip to main content

TypeTracker

Struct TypeTracker 

Source
pub struct TypeTracker {
    pub v2_layouts: HashMap<SchemaId, StructLayout>,
    /* private fields */
}
Expand description

Tracks type information for variables during compilation

Fields§

§v2_layouts: HashMap<SchemaId, StructLayout>

v2: Computed C-compatible struct layouts indexed by SchemaId. Enables the compiler to look up field offsets at compile time for typed codegen.

Implementations§

Source§

impl TypeTracker

Source

pub fn new(schema_registry: TypeSchemaRegistry) -> Self

Create a new type tracker with the given schema registry

Source

pub fn empty() -> Self

Create a new type tracker with an empty registry

Source

pub fn with_stdlib() -> Self

Create a new type tracker with stdlib types pre-registered

Source

pub fn schema_registry(&self) -> &TypeSchemaRegistry

Get the schema registry

Source

pub fn schema_registry_mut(&mut self) -> &mut TypeSchemaRegistry

Get mutable schema registry

Source

pub fn push_scope(&mut self)

Push a new scope for local types

Source

pub fn pop_scope(&mut self)

Pop a scope, removing local type info for that scope

Source

pub fn set_local_type(&mut self, slot: u16, type_info: VariableTypeInfo)

Set type info for a local variable

Source

pub fn set_binding_type(&mut self, slot: u16, type_info: VariableTypeInfo)

Set type info for a module_binding variable

Source

pub fn set_local_binding_semantics( &mut self, slot: u16, semantics: BindingSemantics, )

Set ownership/storage metadata for a local binding.

Source

pub fn set_binding_semantics(&mut self, slot: u16, semantics: BindingSemantics)

Set ownership/storage metadata for a module binding.

Source

pub fn set_local_binding_storage_class( &mut self, slot: u16, storage_class: BindingStorageClass, )

Update only the storage strategy for a local binding.

Source

pub fn set_binding_storage_class( &mut self, slot: u16, storage_class: BindingStorageClass, )

Update only the storage strategy for a module binding.

Source

pub fn get_local_type(&self, slot: u16) -> Option<&VariableTypeInfo>

Get type info for a local variable

Source

pub fn get_binding_type(&self, slot: u16) -> Option<&VariableTypeInfo>

Get type info for a module_binding variable

Source

pub fn get_local_binding_semantics( &self, slot: u16, ) -> Option<&BindingSemantics>

Get ownership/storage metadata for a local binding.

Source

pub fn get_binding_semantics(&self, slot: u16) -> Option<&BindingSemantics>

Get ownership/storage metadata for a module binding.

Source

pub fn register_function_return_type( &mut self, func_name: &str, return_type: &str, )

Register a function’s return type

Source

pub fn get_function_return_type(&self, func_name: &str) -> Option<&String>

Get a function’s return type

Source

pub fn register_object_field_contracts( &mut self, schema_id: SchemaId, fields: HashMap<String, TypeAnnotation>, )

Register compile-time field type contracts for an object schema id.

Source

pub fn get_object_field_contract( &self, schema_id: SchemaId, field_name: &str, ) -> Option<&TypeAnnotation>

Lookup a compile-time field type contract for a schema field.

Source

pub fn get_typed_field_info( &self, type_name: &str, field_name: &str, ) -> Option<(SchemaId, usize, u16)>

Get field offset for typed field access

Returns (schema_id, field_offset, field_index) if type and field are known

Source

pub fn get_row_view_column_id( &self, slot: u16, is_local: bool, field_name: &str, ) -> Option<u32>

Get column index for a RowView field access.

Returns the field index (used as col_id for ColumnAccess operand) if the variable is a RowView and the field exists in its schema.

Source

pub fn can_use_typed_access( &self, slot: u16, is_local: bool, field_name: &str, ) -> bool

Check if we can use typed field access for a variable and field

Source

pub fn get_local_storage_hint(&self, slot: u16) -> Option<StorageHint>

Get storage hint for a local variable. Returns None for unknown slots or when the slot’s kind has not yet been proven — per ADR-006 §2.7.5.1, callers handle the “not proven” arm explicitly rather than dispatching on a placeholder sentinel.

Source

pub fn get_module_binding_storage_hint(&self, slot: u16) -> Option<StorageHint>

Get storage hint for a module_binding variable. Returns None for unknown slots or unproven kinds — see [get_local_storage_hint].

Source

pub fn local_uses_nan_sentinel(&self, slot: u16) -> bool

Check if a local variable uses NaN sentinel for nullability

Source

pub fn module_binding_uses_nan_sentinel(&self, slot: u16) -> bool

Check if a module_binding variable uses NaN sentinel for nullability

Source

pub fn clear_locals(&mut self)

Clear all local type info (for function entry)

Source

pub fn snapshot_local_binding_semantics(&self) -> HashMap<u16, BindingSemantics>

Track A.1C.2: snapshot the outer function’s local binding semantics before entering a nested function compilation. Pairs with [restore_local_binding_semantics] to preserve ownership / storage classification across compile_function’s clear_locals call so subsequent closures in the outer scope still observe the binding’s classification (e.g. var → Flexible, let mut → OwnedMutable).

Source

pub fn restore_local_binding_semantics( &mut self, snapshot: HashMap<u16, BindingSemantics>, )

Track A.1C.2: restore a previously-snapshotted local binding semantics map. Used by compile_function after a nested closure body compilation wipes the outer function’s semantics.

Source

pub fn snapshot_local_types(&self) -> LocalTypesSnapshot

Sweep phase 3c.1: snapshot the outer function’s local type information before entering a nested function compilation. Pairs with [restore_local_types] to preserve typed-tracker state (e.g. let base = 100 → int) across compile_function’s clear_locals call so post-closure strict-typing-sweep code paths can still resolve outer-scope identifier types — e.g. inferring f’s return type for let f = |x: int| x + base.

The snapshot covers both the flattened local_types map AND the per-scope local_type_scopes stack — pop_scope (called during closure compile teardown) reads from the scope stack to know which local_types entries to evict, so a restore that only re-installs local_types would have its outer-scope entries silently re-evicted by the next pop_scope whose scope stack still contains the inner-closure slot indices.

Source

pub fn restore_local_types(&mut self, snapshot: LocalTypesSnapshot)

Sweep phase 3c.1: restore a previously-snapshotted local types map and scope stack. Used by compile_function after a nested closure body compilation wipes the outer function’s type information.

Source

pub fn register_inline_object_schema( &mut self, field_names: &[&str], ) -> SchemaId

👎Deprecated since 0.3.0:

Prefer register_inline_object_schema_typed per audit §4.D.5 W17.2-C (PROPAGATE per-field types at call site). The untyped variant routes through the typed variant with FieldType::Any per field; the post_inference_verify pass absorbs via the _inline_obj* transitional row.

Register an inline object schema from field names.

Creates a TypeSchema for an object literal with the given fields. All fields are typed FieldType::Any at the schema layer since the caller does not provide per-field type info — the post_inference_verify pass at crates/shape-vm/src/compiler/post_inference_verify.rs absorbs the resulting __inline_obj_N schemas via the W17.2-C narrowed transitional whitelist row pre-W17.3 (per audit §4.D.5 + §9.B.3 supervisor ratify 2026-05-19).

Deprecation (W17.2-C): prefer Self::register_inline_object_schema_typed when per-field types are known at the call site. The untyped variant routes internally through register_inline_object_schema_typed with each field stamped FieldType::Any — same __inline_obj_N name format + same verification-pass absorber. Per audit §4.D.5 PROPAGATE disposition: callers SHOULD migrate to the typed variant; the verification-pass safety net catches any residual Any leakage at user-facing schemas. ADR-006 §2.7.5 producer-side stamp.

Returns the SchemaId for use with NewTypedObject opcode.

§Example
ⓘ
// For: let x = { a: 1, b: "hello" }
let schema_id = tracker.register_inline_object_schema(&["a", "b"]);
// Now emit NewTypedObject with schema_id
Source

pub fn register_inline_object_schema_typed( &mut self, fields: &[(&str, FieldType)], ) -> SchemaId

Register an inline object schema with typed fields

Like register_inline_object_schema but allows specifying field types for better JIT optimization. Deduplicates by matching both field names and types.

Source

pub fn register_named_object_schema( &mut self, type_name: &str, fields: &[(&str, FieldType)], ) -> SchemaId

Register a named struct schema (e.g. Point { x, y })

Unlike register_inline_object_schema which auto-generates names, this uses the actual struct type name so .type() can resolve it.

Source

pub fn register_typed_object_schema( &mut self, field_defs: Vec<(String, FieldType)>, ) -> SchemaId

Register an inline object schema with typed fields

Like register_inline_object_schema but allows specifying field types for better JIT optimization.

Source

pub fn register_v2_layout(&mut self, schema_id: SchemaId, layout: StructLayout)

Register a v2 StructLayout for the given schema ID.

Source

pub fn get_v2_layout(&self, schema_id: SchemaId) -> Option<&StructLayout>

Look up a v2 StructLayout by schema ID.

Source

pub fn is_typed_array(&self, slot: u16) -> Option<FieldKind>

Check if a local slot is a typed array and return its element kind.

Source

pub fn is_typed_struct(&self, slot: u16) -> Option<SchemaId>

Check if a local slot has a v2 struct layout and return its schema ID.

Trait Implementations§

Source§

impl Debug for TypeTracker

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for TypeTracker

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> Instrument for T

Source§

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

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,