Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This fixes a bug where mutations to stack frames weren't being captured correctly. When pushing a frame to the stack, a reference is taken to the frame slice's backing array. If frames are added and a new backing array is allocated, the references are invalidated and any further mutations are lost. The three alternatives for fixing the issue were: 1. avoid a dynamic array and instead use a linked list for the frames, so that adding new frames doesn't invalidate previous references 2. update the stack's `Push()` method to return a different reference to a frame (e.g. `FrameRef{stack, index}`), and intercept mutating calls so that they're routed to the correct place 3. update the stack's `Push()` method to instead return a `Frame` by value, and require that callers store the frame after mutations have been made when unwinding the stack I went with option 3 given that: * there a lot of mutations (we need to update the IP often) * we don't always need to persist the frame; only when unwinding; so no need to pay the cost of indirection at all times * there are potentially many frames so we want to avoid many small allocations/fragmentation
- Loading branch information