When a value is captured into the environment in Lower.rewriteExpression we
don't update the locals count. This means we will still allocate a local slot for
the captured value even though we have re-written any references to it to now
point to the environment slot instead.
This is a bit of an in-depth change however as if we remove shaddow locals
then local indicies would no longer match up with the indices in EmitCtx.Locals.
The solution to this might be to have Lambda values own the entire list of locals
and filter that down as we move storage into the environment. Another option
might be to re-write local indices when we have moved some items into the
environment to get rid of any 'holes'.
When a value is captured into the environment in
Lower.rewriteExpression
we don't update thelocals
count. This means we will still allocate a local slot for the captured value even though we have re-written any references to it to now point to the environment slot instead.This is a bit of an in-depth change however as if we remove shaddow locals then local indicies would no longer match up with the indices in
EmitCtx.Locals
.The solution to this might be to have
Lambda
values own the entire list of locals and filter that down as we move storage into the environment. Another option might be to re-write local indices when we have moved some items into the environment to get rid of any 'holes'.In the above example the local for
bar
captures itself, but we would still allocate local 0 for it.