Just like with other stacks we call ecl_dealloc on the old stack. Previously
we had stack frames that could have referenced it, but we can treat it like
other stacks, because there are not lingering references.
Previously we've cached the stack base and dereferenced from there, but when the
stack is resized, this reference is invalidated and there is no good fix it in
all frames (we don't store back references).
This commit replaces pointers with indexes, so the stack frame is always
displaced onto the current lisp stack.
ad6f1f7f10 (2008-05-12) allowed for displacing
stack frames onto the values vector. This commit seems to be before we've stored
them on lisp stack.
As for the rationale why we revert that change:
1. There may be a slight performance improvement because the standard gf
dispatch won't be forced to copy the stack frame
2. Stack frame operators assume that they are displaced onto env->stack*, for
example ecl_stack_frame_push increments env->stack_top
3. If we fully buy into assumption that the stack frame is displaced onto
env->stack* then we may replace pointers with indexes and protect the user from
accessing invalidated memory when the stack grows
The last point will be implemented in the next commit. It is worth noting, that
frames auto-heal themselves if their own operation is the cause of the stack
growth, but all other stack frames are left invalid after the operation.
OP_FLET previously had to first create functions referencing the env "before"
and then add these functions to the env "after". This is because we were
addressing from the stack top:
env: bottom[0:var]top
fn1: ref(top-1)
fn2: ref(top-1)
env: bottom[0:var, 1:fn1, 2:f2n]top
Otherwise fn2 referencing top-1 would point to fn1 instead of var.
Now that locals are addressed from the stack bottom we can add functions eagerly
to locals without consing intermediate sequence of functions:
env: bottom[0:var]top
fn1: ref(bottom+0)
env: bottom[0:var, 1:fn1]top
fn2: ref(bottom+0)
env: bottom[0:var, 1:fn1, 2:f2n]top
That saves us one loop (nfun iterations).
A similar observation applies to LABELS, although we still need the closure
fixup because earlier function may reference a function defined later, so we
still need a second loop. That said we don't have to cons a separate sequence of
functions, because we may iterate over locals vector instead.
Both changes save us from an operator that adds a collection to the lcl_env, so
we remove tack_lcl macro and its expansion function foot_lcl.
Previously when unbinding we've skipped blocks and tags and let the frame exit
to collect the frame variable. This commit simplifies managing the environment
in the compiler.
Previously our calculations were off because:
- we've counted special variables
- we didn't decrement the env size when unbound
One could argue that we need only to increment it, but then we'd end up with the
size too big. Consider:
(progn
(let ((a 1)) (foobar))
(let ((b 1)) (foobar)))
In this snippet we have two local variables, but we never look at locals beyond
the first element.
env_size is not computed correctly (neither max size nor current size), these
assertions are meant to help with mending the issue in order to correctly
determine the size of the locals environment.
c_lcl_idx computes the location of the entry in the locals env. It does traverse
the list again, so it adds a little overhead, but this will allow us to
customize it later to compute a location from the bottom.
We are going to change the representation of the local environment, but first we
make identify accessors and put them behind macros.
While doing so the OP_LABELS has been changed to look similar to OP_FLET. Among
other things we cons separately functions into fun_env, but this inefficiency
will be removed later when we address local entries from the frame.base.
As noted in the comment, GCC 12.0 onwards generates an invalid warning about
array bounds when we cast a stack allocated object to cl_object and use it
warning: array subscript ‘union cl_lispunion[0]’ is partly outside array
bounds of ‘struct ecl_stack_frame[1]’ [-Warray-bounds=]
The code is conforming, but apparently GCC IR has generated a dead branch that
accesses the array out of bounds. For time being we disable this warning.
See also:
https://gitlab.com/libeigen/eigen/-/issues/2506https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106274https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
and generally explroe gcc bugzilla for this kind of false positive.
Currently it returns NIL because runtime_stack is not a vector nor a list (or
other lisp structure). Technically we could return a foreign data pointer.
There are two things to fix:
- `bool` is a keyword in C23, so `typedef int bool` is invalid. We
already require C99, so just include stdbool.h instead. This also
means that `bool` and `int` are no longer synonymous, so we have to
be more careful in defining return types for some functions.
- Function definitions and function pointers with unspecified
arguments are no longer valid. Fix the definitions to include
arguments and add casts for the function pointers.
The deftype expansion functions now take two parameters, the type
argument and an environment. More precisely, for an atomic type 'x the
type argument for the expansion function is given by '(x) while for a
non-atomic type '(x y z) it is given by '(x y z). This also fixes the
value of &whole parameters in deftype lambda lists. The new behaviour
is consistent with SBCL and CCL.
Fixes#750
When we don't use mprotect (nor guard page), we allocate the memory manually.
This simplifies some code and makes the booting process less intervened with GC.
We will use this operators to allocate the first environment and stacks so that
there is no circularity between ecl_boot and starting the garbage collector.
The stack is represented as an actually adjustable vector with a fill
pointer. The main difference from other vector constructors is that it does not
modify the process env -- most notably VALUES vector -- and can be safely used
in the interpreter.
In case that someone wants to store the definition when compiling the file, we
need to make sure that the compiler does not error if it has unreadable objects.