hana
hana copied to clipboard
rewrite vm in rust
The VM should be rewritten in Rust for:
- Better link-time optimization
- Safer abstraction over GC objects (the current C implementation does not increase GC object's reference count which may lead to use-after-free if a GC cycle occurs while the vm is executing an instruction).
- 🦀
Cons:
- The current Rust reimplementation is 2x slower than the C implementation (this may be due to LLVM adding an additional bound-check branch on instruction dispatching)
- LLVM does optimize dispatching by providing a table for us, however it doesn't store the first branch in the match arm inside the table, it inlines the branch then does dispatching
- Might be solved when rust-lang/rust#26179 gets closed
- Rust does not currently allow packed enums, so values will take 16 bytes (8 data bytes+8 tag bytes) which is less efficient than the current 9 bytes (8 data bytes+1 tag bytes)
Checklist:
- [ ] Port all opcodes from C vm to Rust
- [ ] Values on the VM's stack or global values will be reference counted; This will mean we will have to do extra work whenever we insert or remove a value from the stack or global.
- Maybe remove VM's tracing function and just consider nodes with non-zero refcount as roots.
- [ ] Standard library functions must be rewritten.
A rewrite will be in order on the riir branch.