Closed Sword-Smith closed 5 months ago
After some discussion with @jan-ferdinand and @aszepieniec I am leaning towards 2, re-allocating memory when constructing nested lists. An alternative would be to change BFieldCodec
, option 3 above, such that it contains pointers to appended data, making BFieldCodec
follow layout A. This would probably mean that all non-deterministically initialized objects would have to be placed in memory at address 0 (to make pointers of encoding consistent with pointers to RAM) but since we have dedicated the memory region $[0,2{32})$ to initialized RAM, that should be fine.
For now though, we go with option 2 which is going to make the runtime of building nested vectors and boxing values through Box::new
very expensive. We accept this cost since we do not believe that we need to do any of those things in the recufier.
For now, we accept that this is a known limitation of the compiler. Fixing it according to 2 above (Change memory layout for Vec<Vec<T>>
to match that of Box<Vec<Vec<T>>>
) would incur a runtime punishment of reallocating memory for each element that is pushed to the vector, and a linear running time for index arithmetic for each push
, as the free pointer needs to be found each time push
is called. We don't think we need this, so we're not going to fix it.
With a8d6851b48ad514c53762f84e047aad87095f700 the compiler panics is the developer attempts to build such a vector.
let a: Vec<Vec<u32>> = vec![e0, e1, ...], e0 = vec![e00, e01]
is currently represented like this:Box<Vec<Vec<T>>>
,BFieldCodec
dictates the memory layout, since this is how values are non-deterministically initialized in memory: Layout B Stack: _ *a MemoryThis mismatch in memory layouts is incompatible with the compiler's rule that
Box<Vec<T>>
has the same memory layout asVec<T>
. Currently the code generator for setting and getting values based on indices assumes the memory layout forBox
. So how do we progress here? I see a few options:Box<Vec<T>>
has the same memory layout asVec<T>
in all casesVec<Vec<T>>
BFieldCodec
, though I'm not sure howto use pointersLet me hear your thoughts :)