Lines
100 %
Functions
Branches
use std::collections::HashMap;
use super::*;
use crate::ast::{ClosureSigId, StructId};
fn field_id() -> StructId {
StructId(3)
}
#[test]
fn a_field_read_before_any_store_is_provisional_and_the_store_widens_it() {
let mut symbols = SymbolTable::new();
symbols.begin_home_attempt(HashMap::new());
assert_eq!(symbols.field_type(field_id(), 0), WasmType::AnyRef);
symbols.note_field_store(field_id(), 0, Arm::Value(WasmType::I32));
assert_eq!(
symbols.widened_homes(),
Some(HashMap::from([(
HomeKey::Field(field_id(), 0),
WasmType::I32
)]))
);
fn the_first_field_store_types_the_home_and_a_second_kind_widens_it() {
symbols.note_field_store(field_id(), 1, Arm::Value(WasmType::I32));
assert_eq!(symbols.field_type(field_id(), 1), WasmType::I32);
assert_eq!(symbols.widened_homes(), None);
symbols.note_field_store(field_id(), 1, Arm::Value(WasmType::StringRef));
HomeKey::Field(field_id(), 1),
WasmType::AnyRef
fn a_field_hint_types_the_next_attempt_and_a_closure_store_rides_as_any() {
let hint = HomeKey::Field(field_id(), 0);
symbols.begin_home_attempt(HashMap::from([(hint, WasmType::Ratio)]));
assert_eq!(symbols.field_type(field_id(), 0), WasmType::Ratio);
symbols.note_field_store(
field_id(),
0,
Arm::Value(WasmType::Closure(ClosureSigId(0))),
fn field_homes_are_counted_apart_from_globals_and_never_collide_with_them() {
symbols.note_home(
"G",
vec![Arm::Value(WasmType::Ratio)],
None,
WasmType::Ratio,
symbols.note_field_store(StructId(4), 0, Arm::Value(WasmType::I32));
assert_eq!(symbols.site_home_count(), 2);
assert_eq!(symbols.field_type(field_id(), 0), WasmType::I32);
assert_eq!(symbols.hint(&HomeKey::global("G")), None);