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
impl TypeTracker
Sourcepub fn new(schema_registry: TypeSchemaRegistry) -> Self
pub fn new(schema_registry: TypeSchemaRegistry) -> Self
Create a new type tracker with the given schema registry
Sourcepub fn with_stdlib() -> Self
pub fn with_stdlib() -> Self
Create a new type tracker with stdlib types pre-registered
Sourcepub fn schema_registry(&self) -> &TypeSchemaRegistry
pub fn schema_registry(&self) -> &TypeSchemaRegistry
Get the schema registry
Sourcepub fn schema_registry_mut(&mut self) -> &mut TypeSchemaRegistry
pub fn schema_registry_mut(&mut self) -> &mut TypeSchemaRegistry
Get mutable schema registry
Sourcepub fn push_scope(&mut self)
pub fn push_scope(&mut self)
Push a new scope for local types
Sourcepub fn set_local_type(&mut self, slot: u16, type_info: VariableTypeInfo)
pub fn set_local_type(&mut self, slot: u16, type_info: VariableTypeInfo)
Set type info for a local variable
Sourcepub fn set_binding_type(&mut self, slot: u16, type_info: VariableTypeInfo)
pub fn set_binding_type(&mut self, slot: u16, type_info: VariableTypeInfo)
Set type info for a module_binding variable
Sourcepub fn set_local_binding_semantics(
&mut self,
slot: u16,
semantics: BindingSemantics,
)
pub fn set_local_binding_semantics( &mut self, slot: u16, semantics: BindingSemantics, )
Set ownership/storage metadata for a local binding.
Sourcepub fn set_binding_semantics(&mut self, slot: u16, semantics: BindingSemantics)
pub fn set_binding_semantics(&mut self, slot: u16, semantics: BindingSemantics)
Set ownership/storage metadata for a module binding.
Sourcepub fn set_local_binding_storage_class(
&mut self,
slot: u16,
storage_class: BindingStorageClass,
)
pub fn set_local_binding_storage_class( &mut self, slot: u16, storage_class: BindingStorageClass, )
Update only the storage strategy for a local binding.
Sourcepub fn set_binding_storage_class(
&mut self,
slot: u16,
storage_class: BindingStorageClass,
)
pub fn set_binding_storage_class( &mut self, slot: u16, storage_class: BindingStorageClass, )
Update only the storage strategy for a module binding.
Sourcepub fn get_local_type(&self, slot: u16) -> Option<&VariableTypeInfo>
pub fn get_local_type(&self, slot: u16) -> Option<&VariableTypeInfo>
Get type info for a local variable
Sourcepub fn get_binding_type(&self, slot: u16) -> Option<&VariableTypeInfo>
pub fn get_binding_type(&self, slot: u16) -> Option<&VariableTypeInfo>
Get type info for a module_binding variable
Sourcepub fn get_local_binding_semantics(
&self,
slot: u16,
) -> Option<&BindingSemantics>
pub fn get_local_binding_semantics( &self, slot: u16, ) -> Option<&BindingSemantics>
Get ownership/storage metadata for a local binding.
Sourcepub fn get_binding_semantics(&self, slot: u16) -> Option<&BindingSemantics>
pub fn get_binding_semantics(&self, slot: u16) -> Option<&BindingSemantics>
Get ownership/storage metadata for a module binding.
Sourcepub fn register_function_return_type(
&mut self,
func_name: &str,
return_type: &str,
)
pub fn register_function_return_type( &mut self, func_name: &str, return_type: &str, )
Register a function’s return type
Sourcepub fn get_function_return_type(&self, func_name: &str) -> Option<&String>
pub fn get_function_return_type(&self, func_name: &str) -> Option<&String>
Get a function’s return type
Sourcepub fn register_object_field_contracts(
&mut self,
schema_id: SchemaId,
fields: HashMap<String, TypeAnnotation>,
)
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.
Sourcepub fn get_object_field_contract(
&self,
schema_id: SchemaId,
field_name: &str,
) -> Option<&TypeAnnotation>
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.
Sourcepub fn get_typed_field_info(
&self,
type_name: &str,
field_name: &str,
) -> Option<(SchemaId, usize, u16)>
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
Sourcepub fn get_row_view_column_id(
&self,
slot: u16,
is_local: bool,
field_name: &str,
) -> Option<u32>
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.
Sourcepub fn can_use_typed_access(
&self,
slot: u16,
is_local: bool,
field_name: &str,
) -> bool
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
Sourcepub fn get_local_storage_hint(&self, slot: u16) -> Option<StorageHint>
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.
Sourcepub fn get_module_binding_storage_hint(&self, slot: u16) -> Option<StorageHint>
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].
Sourcepub fn local_uses_nan_sentinel(&self, slot: u16) -> bool
pub fn local_uses_nan_sentinel(&self, slot: u16) -> bool
Check if a local variable uses NaN sentinel for nullability
Sourcepub fn module_binding_uses_nan_sentinel(&self, slot: u16) -> bool
pub fn module_binding_uses_nan_sentinel(&self, slot: u16) -> bool
Check if a module_binding variable uses NaN sentinel for nullability
Sourcepub fn clear_locals(&mut self)
pub fn clear_locals(&mut self)
Clear all local type info (for function entry)
Sourcepub fn snapshot_local_binding_semantics(&self) -> HashMap<u16, BindingSemantics>
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).
Sourcepub fn restore_local_binding_semantics(
&mut self,
snapshot: HashMap<u16, BindingSemantics>,
)
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.
Sourcepub fn snapshot_local_types(&self) -> LocalTypesSnapshot
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.
Sourcepub fn restore_local_types(&mut self, snapshot: LocalTypesSnapshot)
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.
Sourcepub 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.
pub fn register_inline_object_schema( &mut self, field_names: &[&str], ) -> SchemaId
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_idSourcepub fn register_inline_object_schema_typed(
&mut self,
fields: &[(&str, FieldType)],
) -> SchemaId
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.
Sourcepub fn register_named_object_schema(
&mut self,
type_name: &str,
fields: &[(&str, FieldType)],
) -> SchemaId
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.
Sourcepub fn register_typed_object_schema(
&mut self,
field_defs: Vec<(String, FieldType)>,
) -> SchemaId
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.
Sourcepub fn register_v2_layout(&mut self, schema_id: SchemaId, layout: StructLayout)
pub fn register_v2_layout(&mut self, schema_id: SchemaId, layout: StructLayout)
Register a v2 StructLayout for the given schema ID.
Sourcepub fn get_v2_layout(&self, schema_id: SchemaId) -> Option<&StructLayout>
pub fn get_v2_layout(&self, schema_id: SchemaId) -> Option<&StructLayout>
Look up a v2 StructLayout by schema ID.
Sourcepub fn is_typed_array(&self, slot: u16) -> Option<FieldKind>
pub fn is_typed_array(&self, slot: u16) -> Option<FieldKind>
Check if a local slot is a typed array and return its element kind.
Sourcepub fn is_typed_struct(&self, slot: u16) -> Option<SchemaId>
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
impl Debug for TypeTracker
Auto Trait Implementations§
impl !Freeze for TypeTracker
impl RefUnwindSafe for TypeTracker
impl Send for TypeTracker
impl Sync for TypeTracker
impl Unpin for TypeTracker
impl UnsafeUnpin for TypeTracker
impl UnwindSafe for TypeTracker
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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