You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make compiler tests independent of VM indexes (#2676)
The compiler unit tests do this:
```rust
assert_compiles(Program {
source: r#"
function main() -> int {
let arr = [1, 2, 3];
arr.length()
}
"#,
expected: vec![(
"main",
vec![
Instruction::LoadConst(0), // Index of the constant in the pool
Instruction::LoadConst(1), // Index of the constant in the pool
Instruction::LoadConst(2), // Index of the constant in the pool
Instruction::AllocArray(3),
Instruction::LoadGlobal(GlobalIndex::from_raw(50)), // Index of the function
Instruction::LoadVar(1), // Index of the variable
Instruction::Call(1),
Instruction::Return,
],
)],
})
```
Depending on specific object indexes is bad because if we add new
builtins they change. Also `LoadConst(0)` or `LoadVar(5)` is not very
readable, so instead we want:
```diff
assert_compiles(Program {
source: r#"
function main() -> int {
let arr = [1, 2, 3];
arr.length()
}
"#,
expected: vec![(
"main",
vec![
- Instruction::LoadConst(0), // Index of the constant in the pool
+ Instruction::LoadConst(Value::Int(1)),
- Instruction::LoadConst(1), // Index of the constant in the pool
+ Instruction::LoadConst(Value::Int(2)),
- Instruction::LoadConst(2), // Index of the constant in the pool
+ Instruction::LoadConst(Value::Int(3)),
Instruction::AllocArray(3),
- Instruction::LoadGlobal(GlobalIndex::from_raw(50)), // Index of the function
+ Instruction::LoadGlobal(Value::function("baml.Array.length")),
- Instruction::LoadVar(1), // Index of the variable
+ Instruction::LoadVar("arr".to_string()),
Instruction::Call(1),
Instruction::Return,
],
)],
})
```
0 commit comments