Andy Wingo [Fri, 28 Mar 2014 16:51:37 +0000 (17:51 +0100)]
Prompt-related refactor in compile-cps
* module/language/tree-il/compile-cps.scm (fix-prompts): New procedure.
Eta-expand prompts before compiling to ensure that they have inline
handlers.
Andy Wingo [Fri, 28 Mar 2014 15:57:40 +0000 (16:57 +0100)]
DCE uses fresh-var instead of gensym
* module/language/cps/dce.scm (eliminate-dead-code): Use fresh-var
instead of gensym.
Andy Wingo [Fri, 28 Mar 2014 15:55:15 +0000 (16:55 +0100)]
Adapt verify-cps to CPS changes
* module/language/cps/verify.scm (verify-cps): Update to expect integer
labels, and to allow integer variables.
Andy Wingo [Fri, 28 Mar 2014 15:29:16 +0000 (16:29 +0100)]
Replace all let-gensyms uses with let-fresh
* .dir-locals.el: Add with-fresh-name-state.
* module/language/cps.scm (fresh-label, fresh-var): Signal an error if
the counters are not initialized.
(with-fresh-name-state): New macro.
(make-cont-folder): New macro, generates an n-ary folder.
(compute-max-label-and-var): New function, uses make-cont-folder.
(fold-conts): Use make-cont-folder.
(let-gensyms): Remove.
* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/constructors.scm:
* module/language/cps/dce.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/specialize-primcalls.scm: Use let-fresh instead of
let-gensyms, and wrap in a with-fresh-name-state as needed.
* module/language/tree-il/compile-cps.scm: Remove hack to avoid
importing let-gensyms from (language tree-il).
Andy Wingo [Fri, 28 Mar 2014 13:23:51 +0000 (14:23 +0100)]
Remove unneeded local exact-integer? definition
* module/system/vm/assembler.scm (link-debug): Remove unneeded
exact-integer? definition.
Andy Wingo [Fri, 28 Mar 2014 13:21:06 +0000 (14:21 +0100)]
Continuation labels and variable identifiers may be integers
* module/language/cps.scm (label-counter, var-counter): New parameters,
for producing fresh label and var names.
(fresh-label, fresh-var): New procedures.
(let-fresh): New macro, will replace let-gensyms.
(build-cps-term): Use let-fresh.
* module/language/tree-il/compile-cps.scm: Use let-fresh to generate
fresh names.
* module/system/vm/assembler.scm (make-meta, begin-kw-arity): Allow
exact integers as labels.
(link-debug): Explicitly mark low-pc as being an "addr" value.
Andy Wingo [Wed, 26 Mar 2014 09:47:40 +0000 (10:47 +0100)]
Sloppier matching in setitimer tests
* test-suite/tests/signals.test: Update setitimer tests to sloppily
match both times -- it seems that the interval can also be sloppy on
some platforms, sadly.
Andy Wingo [Wed, 26 Mar 2014 09:35:53 +0000 (10:35 +0100)]
Adapt test-out-of-memory to work on 32-bit systems
* test-suite/standalone/test-out-of-memory (*limit*): Reduce limit to 50 MB.
Adapt vector test to avoid exceeding maximum vector size on 32-bit
systems.
Andy Wingo [Sat, 22 Mar 2014 15:06:39 +0000 (16:06 +0100)]
Fix compile warnings
* libguile/throw.c (catch): Fix bad declarations.
* libguile/stackchk.c (reset_scm_stack_checking_enabled_p): Remove
unused static function.
Andy Wingo [Sat, 22 Mar 2014 14:49:31 +0000 (15:49 +0100)]
Out-of-memory situations raise exceptions instead of aborting
* libguile/gc.c (scm_oom_fn, scm_init_gc): Install an out-of-memory
handler that raises an unwind-only out-of-memory exception.
(scm_gc_warn_proc, scm_init_gc): Install a warning proc that tries to
print to the current warning port, if the current warning port is a
file port.
(scm_gc_after_nonlocal_exit): New interface. Should be called after a
nonlocal return to potentially collect memory; otherwise allocations
could try to expand again when they should collect.
* libguile/continuations.c (scm_i_make_continuation):
* libguile/eval.c (eval):
* libguile/throw.c (catch):
* libguile/vm.c (scm_call_n): Call scm_gc_after_nonlocal_exit after
nonlocal returns.
* libguile/throw.c (abort_to_prompt, throw_without_pre_unwind): Rework
to avoid allocating memory.
(scm_report_out_of_memory): New interface.
(scm_init_throw): Pre-allocate the arguments for stack-overflow and
out-of-memory errors.
* module/ice-9/boot-9.scm: Add an out-of-memory exception printer.
* module/system/repl/error-handling.scm (call-with-error-handling): Add
out-of-memory to the report-keys set.
* libguile/gc-malloc.c (scm_realloc): Call scm_report_out_of_memory if
realloc fails.
* libguile/error.h:
* libguile/error.c:
* libguile/deprecated.h:
* libguile/deprecated.c (scm_memory_error): Deprecate.
* test-suite/standalone/Makefile.am:
* test-suite/standalone/test-out-of-memory: New test case.
Andy Wingo [Sat, 22 Mar 2014 14:42:15 +0000 (15:42 +0100)]
Define a C fluid for current-warning-port
* libguile/ports.c (scm_current_input_port, scm_current_output_port)
(scm_current_error_port): Fix declarations to C99.
(scm_current_warning_port, scm_set_current_warning_port): Rework to
use a C fluid, like scm_current_error_port.
(scm_init_ports): Initialize and define the warning port fluid.
* libguile/init.c (scm_init_standard_ports): Init the current warning
port.
* module/ice-9/boot-9.scm: Remove definitions for current-warning-port.
Instead, steal it from the boot objtable with port-parameterize!.
Andy Wingo [Mon, 17 Mar 2014 09:10:36 +0000 (10:10 +0100)]
DFG inlines uses of for-each
* module/language/cps/dfg.scm (for-each, for-each/2): Define inline
versions of these. Adapt callers.
Andy Wingo [Sun, 16 Mar 2014 18:58:30 +0000 (19:58 +0100)]
Optimize srfi-1 for-each with two lists.
* module/srfi/srfi-1.scm (for-each): Optimize for the two-list case.
Andy Wingo [Sun, 16 Mar 2014 18:48:48 +0000 (19:48 +0100)]
Simplify boot-9 for-each with two lists
* module/ice-9/boot-9.scm (for-each): Simplify the two-argument case in
the same way as the one-argument case.
Andy Wingo [Sun, 2 Mar 2014 11:38:32 +0000 (12:38 +0100)]
More for-each micro-optimizations
* module/ice-9/boot-9.scm (for-each):
* module/srfi/srfi-1.scm (for-each): Re-implement one-list case using an
explicit check for list? instead of the tortoise-hare thing. Seems to
be faster!
Andy Wingo [Sun, 16 Mar 2014 15:28:28 +0000 (16:28 +0100)]
Doc and NEWS updates
* NEWS: Update section on dynamic stacks. Add link for intptr
interfaces.
* doc/ref/api-data.texi (Integers): Add intptr interfaces.
Andy Wingo [Sun, 16 Mar 2014 14:50:27 +0000 (15:50 +0100)]
Debug options doc fix.
* doc/ref/api-debug.texi (Debug Options): Fix.
Andy Wingo [Sun, 16 Mar 2014 14:46:28 +0000 (15:46 +0100)]
Refine unwind-only exception message.
* libguile/throw.c (throw_without_pre_unwind): Refine warning message.
Andy Wingo [Sun, 16 Mar 2014 14:27:26 +0000 (15:27 +0100)]
Document stack-overflow handlers, limits, and unwind-only exceptions
* module/system/repl/error-handling.scm (call-with-error-handling): Add
#:report-keys kwarg, so that unwind-only exceptions (stack-overflow in
particular) get reported.
* doc/ref/api-debug.texi (Pre-Unwind Debugging): Add documentation for
#:report-keys kwarg of call-with-error-handling.
(Stack Overflow): New subsubsection.
(Debug Options): Remove discussion of stack overflow.
Andy Wingo [Sat, 15 Mar 2014 18:30:26 +0000 (19:30 +0100)]
Add call-with-stack-overflow-handler tests
* test-suite/tests/eval.test ("stack overflow handlers"): Add
call-with-stack-overflow-handler tests, replacing the old stack
overflow test.
Andy Wingo [Sat, 15 Mar 2014 17:56:18 +0000 (18:56 +0100)]
Add stack overflow test
* libguile/throw.c (throw_without_pre_unwind): Newline after the
unwind-only warning.
* test-suite/standalone/Makefile.am:
* test-suite/standalone/test-stack-overflow: New test to handle
mmap/malloc failure.
Andy Wingo [Wed, 12 Mar 2014 16:18:13 +0000 (17:18 +0100)]
Remove default soft stack limit; add call-with-stack-overflow-handler
* libguile/vm.h:
* libguile/vm.c (default_max_stack_size, initialize_default_stack_size):
Remove the default stack limit. In this way, programs run from the
command line or outside of the REPL will have no soft stack limit.
(make_vm): Change `max_stack_size' field to be a stack of limits and
handlers.
(current_overflow_size, should_handle_stack_overflow)
(reset_stack_limit, wind_overflow_handler, unwind_overflow_handler)
(vm_expand_stack): If the stack surpasses a user-set limit, call the
user-specified handler within its outer stack limit.
(call-with-stack-overflow-handler): New interface.
* module/system/vm/vm.scm: Export call-with-stack-overflow-handler.
Andy Wingo [Sun, 2 Mar 2014 11:05:32 +0000 (12:05 +0100)]
Port unrolled one-argument for-each from boot-9 to srfi-1
* module/srfi/srfi-1.scm (for-each): Port unrolled one-argument
implementation here from the boot-9 version.
Andy Wingo [Sun, 2 Mar 2014 11:04:18 +0000 (12:04 +0100)]
Fix for-each bug detecting not-a-list
* module/ice-9/boot-9.scm (for-each): Fix detection of not-a-list in the
unrolled one-argument case.
* test-suite/tests/eval.test ("for-each"): Add a test.
Andy Wingo [Sat, 1 Mar 2014 15:09:30 +0000 (16:09 +0100)]
,profile, statprof, gcprof have an outer stack cut
* module/statprof.scm (<state>): Add outer-cut member.
(fresh-profiler-state): Add outer-cut kwarg.
(sample-stack-procs): Stop when the stack-length is zero, which will
be before the frames run out if there is an outer cut.
(profile-signal-handler): Use the outer cut when capturing the stack.
(call-thunk): New helper, for use as an outer cut.
(statprof, gcprof): Call the thunk within call-thunk, and use
call-thunk as an outer cut.
Andy Wingo [Sat, 1 Mar 2014 14:54:47 +0000 (15:54 +0100)]
Statprof commentings
* module/statprof.scm: Add a big ol' comment.
(sample-stack-procs): If slot 0 isn't a primitive, use the IP to
mark. In the future we will see more non-procedures in slot 0 as we
start to use call-label and tail-call-label.
Andy Wingo [Sat, 1 Mar 2014 11:59:58 +0000 (12:59 +0100)]
statprof-display prints source locations
* module/statprof.scm (call-data): Source is after printable.
(addr->printable): Just produce a name, without source. Anonymous
printables get "anon " prefixed.
(stack-samples->procedure-data): Adapt to call-data change.
(stats): Add "proc-source" element.
(statprof-call-data->stats): Give a source to the call-data.
(statprof-display): Print source also.
Andy Wingo [Fri, 28 Feb 2014 18:42:04 +0000 (19:42 +0100)]
Refactorings: call-data has source, stats is a record
* module/statprof.scm (call-data): Add source member.
(stack-samples->procedure-data): Populate source member
(stats): Convert to record from vector.
(statprof-call-data->stats): Adapt to produce a record.
Andy Wingo [Fri, 28 Feb 2014 18:31:46 +0000 (19:31 +0100)]
Statprof uses stack trace buffer to always provide full stacks
* module/statprof.scm (<state>): Remove record-full-stacks? and stacks
members. The stack trace buffer is sufficient.
(fresh-profiler-state): Adapt.
(sample-stack-procs): Don't save stacks.
(statprof-reset): Deprecate the full-stacks? argument.
(stack-samples->procedure-data): Remove a needless vector-ref.
(stack-samples->callee-lists): New helper.
(statprof-fetch-stacks): Use stack-samples->callee-lists.
(statprof-fetch-call-tree): Use stack-samples->callee-lists, and
implement our own callee->string helper.
(statprof, with-statprof, gcprof): Deprecate full-stacks? argument.
Andy Wingo [Fri, 28 Feb 2014 17:35:25 +0000 (18:35 +0100)]
Statprof always stores full stack traces
* module/statprof.scm (<state>): Instead of a boolean count-calls?,
treat the presence of a call-counts hash table as indicating a need to
count calls. That hash table maps callees to call counts. A "callee"
is either the IP of the entry of a program, the symbolic name of a
primitive, or the identity of a non-program.
New members "buffer" and "buffer-pos" replace "procedure-data".
We try to avoid analyzing things at runtime, instead just recording
the stack traces into a buffer. This will let us do smarter things
when post-processing.
(fresh-buffer, expand-buffer): New helpers.
(fresh-profiler-state): Adapt to <state> changes.
(sample-stack-procs): Instead of updating the procedure-data
table (which no longer exists), instead trace the stack into the
buffer.
(count-call): Update to update the call-counts table instead of the
procedure-data table.
(statprof-start, statprof-start): Adapt to call-counts change.
(call-data): Move lower in the file. Add "name" and "printable"
members, and no longer store a proc.
(source->string, program-debug-info-printable, addr->pdi)
(addr->printable): New helpers.
(stack-samples->procedure-data): New procedure to process stack trace
buffer into a hash table of the same format as the old procedure-data
table.
(statprof-fold-call-data, statprof-proc-call-data): Use
stack-samples->procedure-data instead of procedure-data.
(statprof-call-data->stats): Adapt to count-calls change.
(statprof-display, statprof-display-anomalies): Adapt.
Andy Wingo [Fri, 28 Feb 2014 16:42:45 +0000 (17:42 +0100)]
(system vm program) exports primitive?
* module/system/vm/program.scm: Export primitive?. Primitive
program-code doesn't map uniquely to the primitive, which may be of
interest to various meta-level utilities like statprof.
Andy Wingo [Fri, 28 Feb 2014 16:15:42 +0000 (17:15 +0100)]
Improve statprof test
* test-suite/tests/statprof.test ("statistical sample counts within
expected range"): Increase number of calls, as the computer speed
increases and VM/compiler speed increases have meant that we get fewer
samples than before. Also, compare the maximum deviation to the
square root of the expected value. I don't actually know what the
right statistical check is here, but this is closer to an "all points
fall within a standard deviation" than our previous 30% check. Print
a nicer warning when the check fails.
Andy Wingo [Fri, 28 Feb 2014 10:57:12 +0000 (11:57 +0100)]
Update statprof commentary
* module/statprof.scm: Update commentary.
Andy Wingo [Fri, 28 Feb 2014 10:27:56 +0000 (11:27 +0100)]
More state-related refactors in statprof
* module/statprof.scm (statprof-start, statprof-stop): Take optional
state arg.
(statprof-reset): Return no values.
(statprof): Take port keyword arg. Since statprof-reset is now the
same as parameterizing profiler-state, there's no need to call
statprof-reset. Pass the state argument explicitly to statprof-start,
statprof-stop, and statprof-display.
Andy Wingo [Fri, 28 Feb 2014 10:17:37 +0000 (11:17 +0100)]
Statprof restores previous sigprof handler when stopping
* module/statprof.scm (<state>): Add field for the previous SIGPROF
handler.
(statprof-start, statprof-stop, statprof-reset): Instead of setting
the SIGPROF handler in statprof-reset, set it when the profiler
becomes active, and actually restore it when the profiler becomes
inactive.
Andy Wingo [Fri, 28 Feb 2014 10:06:55 +0000 (11:06 +0100)]
More statprof refactors
* module/statprof.scm (statprof-display, statprof-display-anomalies)
(statprof-accumulated-time, statprof-sample-count)
(statprof-fetch-stacks, statprof-fetch-call-tree): Take optional state
argument.
(statprof-display-anomolies): Deprecate this mis-spelling.
(statprof): Just compute usecs for the period.
Andy Wingo [Fri, 28 Feb 2014 09:48:41 +0000 (10:48 +0100)]
Slight gcprof refactor
* module/statprof.scm (gcprof): Refactor a bit.
Andy Wingo [Fri, 28 Feb 2014 09:36:21 +0000 (10:36 +0100)]
statprof uses new setitimer magical usecs ability
* module/statprof.scm (sample-stack-procs): Take advantage of setitimer
allowing usecs >= 1e6.
Andy Wingo [Fri, 28 Feb 2014 09:31:12 +0000 (10:31 +0100)]
Fix setitimer documentation. Allow microseconds >= 1e6.
* doc/ref/posix.texi (Signals): Fix the documentation for setitimer; it
was wrong.
* libguile/scmsigs.c (pack_tv): New helper. Allow usecs >= 1e6.
(unpack_tv): New helper.
(scm_setitimer): Use the new helpers.
* test-suite/tests/signals.test: Add setitimer tests.
Andy Wingo [Thu, 27 Feb 2014 16:16:29 +0000 (17:16 +0100)]
Fix newline preservation in @example with lines beginning with @
* module/texinfo.scm (read-char-data): Preserve newlines in @example and
similar environments in the case when the next line starts with an @.
* test-suite/tests/texinfo.test ("test-texinfo->stexinfo"): Add a test.
Andy Wingo [Tue, 25 Feb 2014 21:46:32 +0000 (22:46 +0100)]
gcprof tweaks
* module/statprof.scm (gcprof): No need to reset in gcprof; the fresh
profiler state and the parameterize handle that. Fix mistaken
set-vm-trace-level! as well.
Andy Wingo [Tue, 25 Feb 2014 21:40:32 +0000 (22:40 +0100)]
Refactor representation of sampling periods in statprof
* module/statprof.scm (<state>): The sampling frequency is actually a
period; label it as such, and express in microseconds instead of as a
pair. Likewise for remaining-prof-time.
(fresh-profiler-state): Adapt.
(reset-sigprof-timer): New helper.
(profile-signal-handler): Use the new helper.
(statprof-start): Use the new helper.
(statprof-stop): Here too.
(statprof-reset): Adapt to <state> change.
(gcprof): Set remaining prof time to 0.
Andy Wingo [Tue, 25 Feb 2014 21:16:49 +0000 (22:16 +0100)]
statprof and gcprof procedures use a fresh statprof state
* module/statprof.scm (statprof, gcprof): Create a fresh statprof
state.
Andy Wingo [Tue, 25 Feb 2014 20:32:36 +0000 (21:32 +0100)]
Simplification pass prunes all unreachable continuations
* module/language/cps/simplify.scm (prune-continuations): Prune
continuations as a post-pass with a fresh DFG. Using a
pre-eta-conversion DFG as we were doing before missed some cases.
Andy Wingo [Sat, 22 Feb 2014 16:02:53 +0000 (17:02 +0100)]
simplify profile-signal-handler
* module/statprof.scm (profile-signal-handler): Don't bother detecting
if we were in a count-call call or not; it doesn't matter, and we
should accumulate time in any case.
Andy Wingo [Sat, 22 Feb 2014 15:31:31 +0000 (16:31 +0100)]
statprof: accumulated-time is in jiffies
* module/statprof.scm (fresh-profiler-state): accumulated-time and
gc-time-taken are in jiffies, not seconds, so they are exact.
(statprof-accumulated-time): Divide by 1.0 so that we get a flonum.
Also refactor use of assq to get the gc-time-taken.
Andy Wingo [Sat, 22 Feb 2014 14:39:29 +0000 (15:39 +0100)]
Zero-offset branches are backward branches; fix "br" backward branches
* libguile/vm-engine.c (BR_UNARY, BR_BINARY, BR_ARITHMETIC): A jump with
a zero offset is also a backward branch, in the sense that it's not a
forward branch.
("br"): We forgot to VM_HANDLE_INTERRUPTS here on backwards branches.
Oops!
Andy Wingo [Sat, 22 Feb 2014 14:34:46 +0000 (15:34 +0100)]
Avoid attempting to eta-reduce self-loops.
* module/language/cps/simplify.scm (compute-eta-reductions): Avoid
trying to eta-reduce a jump-to-self, as in (let lp () (lp)). This
caused the compiler to hang.
Andy Wingo [Sat, 22 Feb 2014 14:09:54 +0000 (15:09 +0100)]
Pass state around statprof in more places
* module/statprof.scm (get-call-data, sample-stack-procs): Take the
state as an argument.
(profile-signal-handler, count-call, statprof-proc-call-data)
(gcprof): Adapt.
Andy Wingo [Sat, 22 Feb 2014 13:59:21 +0000 (14:59 +0100)]
statprof: call-data is a record type
* module/statprof.scm (call-data): Reimplement as a record type.
Andy Wingo [Sat, 22 Feb 2014 13:54:17 +0000 (14:54 +0100)]
statprof: when/unless instead of if.
* module/statprof.scm: Use when or unless instead of if, where
appropriate.
Andy Wingo [Fri, 21 Feb 2014 21:18:02 +0000 (22:18 +0100)]
add a statprof fixme
* module/statprof.scm: Add a fixme.
Andy Wingo [Fri, 21 Feb 2014 21:12:47 +0000 (22:12 +0100)]
statprof-active? instead of checking profile level
* module/statprof.scm (statprof-reset, statprof-fold-call-data):
(statprof-proc-call-data, statprof-accumulated-time):
(statprof-sample-count): Refactor some things to use statprof-active?
instead of checking the profile level manually.
Andy Wingo [Fri, 21 Feb 2014 20:56:01 +0000 (21:56 +0100)]
statprof-reset creates a new state
* module/statprof.scm (fresh-profiler-state): New helper.
(ensure-profiler-state): Use it.
(accumulate-time): No need to add 0.0 here.
(statprof-reset): Create a new state instead of mutating the existing
one.
Andy Wingo [Fri, 21 Feb 2014 20:43:39 +0000 (21:43 +0100)]
More statprof state refactorings
* module/statprof.scm (existing-profiler-state): New helper, gets the
profiler state or fails if there is no state.
(sample-stack-procs, profile-signal-handler, count-call)
(statprof-fold-call-data, statprof-proc-call-data)
(statprof-call-data->stats, statprof-display)
(statprof-display-anomolies, statprof-accumulated-time)
(statprof-sample-count, statprof-fetch-stacks)
(statprof-fetch-call-tree): Use the new helper.
(statprof-active?): Don't create a state if there isn't one already.
Andy Wingo [Fri, 21 Feb 2014 20:25:50 +0000 (21:25 +0100)]
inside-profiler? to parameter instead of global variable
* module/statprof.scm (<state>): Add inside-profiler? member. Move
mutations of inside-profiler? here.
Andy Wingo [Fri, 21 Feb 2014 20:01:10 +0000 (21:01 +0100)]
Beginnings of statprof threadsafety
* module/statprof.scm (<state>, profiler-state, ensure-profiler-state):
A mostly-mechanical refactor to encapsulate profiler state in a
parameter and a record instead of global variables.
Andy Wingo [Fri, 21 Feb 2014 18:20:16 +0000 (19:20 +0100)]
reform statprof commentary
* module/statprof.scm: Reformat the commentary.
Andy Wingo [Fri, 21 Feb 2014 13:42:24 +0000 (14:42 +0100)]
Fix segfault in thread_mark
* libguile/threads.c (thread_mark): There is a window in which the
thread has a handle but doesn't yet have the set of pointerless
freelists, so don't unconditionally dereference
t->pointerless_freelists.
Andy Wingo [Thu, 20 Feb 2014 20:09:08 +0000 (21:09 +0100)]
Threadsafe stack relocation
* libguile/vm.c (vm_return_to_continuation, vm_expand_stack):
(vm_reinstate_partial_continuation): Hold the GC lock while relocating
the stack.
Andy Wingo [Thu, 20 Feb 2014 18:57:47 +0000 (19:57 +0100)]
assertion refactor in the vm
* libguile/vm.c:
* libguile/vm-engine.c: Change the one use of
VM_ENABLE_PARANOID_ASSERTIONS to ASSERT. That becomes the one use of
VM_ENABLE_ASSERTIONS, so disable that too.
Andy Wingo [Thu, 20 Feb 2014 09:43:40 +0000 (10:43 +0100)]
Fix "VM never extends vp->sp ..." commit
* libguile/vm.c (vm_expand_stack): Make sure the new SP is visible to
vm_error if we throw because of stack overflow.
Andy Wingo [Thu, 20 Feb 2014 09:21:51 +0000 (10:21 +0100)]
Remove the hard stack size limit
* libguile/vm.c (vm_expand_stack): Remove the hard stack size limit.
Andy Wingo [Thu, 20 Feb 2014 09:17:51 +0000 (10:17 +0100)]
VM never extends vp->sp beyond mapped region of stack
* libguile/vm-engine.c (ALLOC_FRAME): Fold CHECK_OVERFLOW into this
routine, and rework to not extend vp->sp until the stack has been
expanded.
* libguile/vm.c (vm_increase_sp): Likewise, don't extend vp->sp until
the stack has expanded.
(vm_expand_stack): Rework to take the new stack pointer as an
argument, and also to update vp->sp_max_since_gc and vp->sp.
Andy Wingo [Thu, 20 Feb 2014 08:45:01 +0000 (09:45 +0100)]
Unwind-only stack overflow exceptions
* module/ice-9/boot-9.scm (catch): Signal an early error if the handler
or pre-unwind handler types aren't right. This is more important than
it was, given that we dispatch on type now when finding matching catch
clauses.
* libguile/vm.c (vm_expand_stack): Use the standard
scm_report_stack_overflow to signal stack overflow. This will avoid
running pre-unwind handlers.
* libguile/throw.h: Move scm_report_stack_overflow here.
* libguile/throw.c (catch): Define a version of catch in C.
(throw_without_pre_unwind): New helper. Besides serving as the
pre-boot "throw" binding, it allows stack overflow to throw without
running pre-unwind handlers.
(scm_catch, scm_catch_with_pre_unwind_handler)
(scm_with_throw_handler): Use the new catch in C.
(scm_report_stack_overflow): Moved from stackchk.c; throws an
unwind-only exception.
* libguile/stackchk.h:
* libguile/stackchk.c: Remove the scm_report_stack_overflow bits.
Andy Wingo [Wed, 19 Feb 2014 20:56:48 +0000 (21:56 +0100)]
%exception-handler fluid refactor
* libguile/throw.c (scm_init_throw): Define %exception-handler here.
* module/ice-9/boot-9.scm (%eh): Use the incoming %exception-handler,
and then delete it. This way we should be able to do unwind-only
exceptions from C.
Andy Wingo [Wed, 19 Feb 2014 18:43:48 +0000 (19:43 +0100)]
Reimplement catch, throw, and with-throw-handler
* module/ice-9/boot-9.scm: Reimplement catch, throw, and
with-throw-handler in such a way that the exception handler is
threaded not through the exception-handling closures, but through a
data structure in the exception-handler fluid. This will allow us to
do unwind-only exception dispatch on stack overflow.
Andy Wingo [Wed, 19 Feb 2014 15:54:40 +0000 (16:54 +0100)]
boot-9 boot order refactor for catch, throw, and such
* module/ice-9/boot-9.scm: Move error-handling initialization after
psyntax initialization. Only "throw" is used before psyntax, and both
throw and catch have pre-boot variants in C.
Andy Wingo [Wed, 19 Feb 2014 10:19:10 +0000 (11:19 +0100)]
Fix scm_i_vm_capture_stack comment.
* libguile/vm.c (scm_i_vm_capture_stack): Fix a comment.
Andy Wingo [Wed, 19 Feb 2014 10:11:46 +0000 (11:11 +0100)]
Default stack size is one page.
* libguile/vm.c (initialize_default_stack_size): Initial stack size is
one page.
Andy Wingo [Wed, 19 Feb 2014 10:01:39 +0000 (11:01 +0100)]
More robust stack expansion and contraction
* libguile/vm.c (allocate_stack, expand_stack): Return NULL on
allocation failure instead of throwing an exception. Throwing an
exception is tricky to get right, and we need more context to do it
correctly.
(return_unused_stack_to_os): Try again if madvise returns -EAGAIN. If
madvise fails, print an error message.
(vm_expand_stack): Abort if stack expansion fails. We'll fix this in
a future patch.
(make_vm): Abort if we can't mmap a single page.
Andy Wingo [Mon, 17 Feb 2014 21:23:40 +0000 (22:23 +0100)]
Don't peval-penalize let-bound lambdas only referenced once
* module/language/tree-il/peval.scm (peval): When going to peval a call
whose operator isn't just a lambda but is a let-bound lambda, as one
bound via define-inlinable, don't create a new counter if the lambda
is only referenced once in the source. Avoids needless failure to
inline once-referenced procedures.
* test-suite/tests/peval.test ("partial evaluation"): Wheeeee
Andy Wingo [Mon, 17 Feb 2014 13:15:30 +0000 (14:15 +0100)]
PT_DYNAMIC inside some other PT_LOAD segment
* libguile/loader.c (load_thunk_from_memory): Only load PT_LOAD
segments, as libc does. The PT_DYNAMIC segment should be inside some
other PT_LOAD segment.
* module/system/vm/linker.scm (segment-kind): Give the .dynamic segment
PT_LOAD kind, so that it is written in a PT_LOAD segment.
(count-segments): Add one if there is a SHT_DYNAMIC segment.
(allocate-segment): Set the paddr to the addr, as binutils do.
(record-special-segments): New routine, to write out special segments
like PT_DYNAMIC.
(allocate-elf): Call record-special-segments.
Andy Wingo [Sun, 16 Feb 2014 14:58:44 +0000 (15:58 +0100)]
Add elf-symbol-value-offset, for properly relocating symtab entries
* module/system/vm/elf.scm (elf-symbol-value-offset): New export.
Andy Wingo [Sun, 16 Feb 2014 11:18:44 +0000 (12:18 +0100)]
ELF linker can produce objects with native ABI
* module/system/vm/elf.scm: Define more ABI types and ELF object types.
Export the ABI, object type, and machine type values.
* module/system/vm/linker.scm (<linker-reloc>, process-reloc): Allow
rel32/1 relocs.
(add-elf-objects, allocate-elf, link-elf): Allow the user to set an
ABI, type, and machine-type.
Andy Wingo [Fri, 14 Feb 2014 09:49:45 +0000 (10:49 +0100)]
bytevector-length reifies to correct module
* module/language/cps/reify-primitives.scm (primitive-module): Whoops,
bytevector-length is needs to map to the (rnrs bytevectors) module.
Andy Wingo [Thu, 13 Feb 2014 16:51:11 +0000 (17:51 +0100)]
bytevector-length is an interesting primitive.
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
(*effect-free-primitives*):
* module/language/cps/effects-analysis.scm: bytevector-length is an
interesting primitive.
Andy Wingo [Thu, 13 Feb 2014 10:04:55 +0000 (11:04 +0100)]
sqrt and abs are interesting primitives
* module/language/cps/effects-analysis.scm:
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
(*effect-free-primitives*): Add sqrt and abs.
Andy Wingo [Thu, 13 Feb 2014 08:30:39 +0000 (09:30 +0100)]
Add prune-top-level-scopes pass
* module/language/cps/prune-top-level-scopes.scm: New pass, to prune
unneeded "cache-current-module!" forms.
* module/language/cps/compile-bytecode.scm:
* module/Makefile.am: Add the new pass to the build and enable by
default.
Andy Wingo [Tue, 11 Feb 2014 20:54:05 +0000 (21:54 +0100)]
Bytevector f32 an f64 ops actually map to VM primitives
* module/language/cps/primitives.scm (*instruction-aliases*): Whoops!
Fix mapping of f32 and f64 instructions to VM primitives.
Andy Wingo [Tue, 11 Feb 2014 19:59:38 +0000 (20:59 +0100)]
guile.m4 tweaks
* meta/guile.m4 (GUILE_PKG): Don't print "checking for guile 2.0" if
we've already found 2.2. Print the correct effective version at the
end.
(GUILE_PROGS): Allow prereleases, whose micro version does not yet
match the effective version. Default to the already-chosen effective
version.
Daniel Llorens [Wed, 8 May 2013 14:06:40 +0000 (16:06 +0200)]
array-contents returns root for empty arrays with empty root
This fixes a compiler issue where (uniform-array->bytevector #2f64())
failed because of the stricter definition of uniform-vector? on this branch.
Perhaps it would be better if uniform-array->bytevector didn't require
a contiguous argument.
* libguile/arrays.c: (scm_array_contents): return the root regardless of
the value of SCM_I_ARRAY_DIMS (ra)->inc.
* test-suite/tests/arrays.test: check.
Daniel Llorens [Thu, 2 May 2013 09:43:31 +0000 (11:43 +0200)]
Add tests for more kinds of typed arrays.
* test-suite/tests/arrays.test: Add more type array tests.
Daniel Llorens [Tue, 30 Apr 2013 14:11:07 +0000 (16:11 +0200)]
Preallocate index list in scm_array_index_map_x
* libguile/array-map.c
- (scm_array_index_map_x): preallocate the index list instead of
constructing it on each rank-1 iteration.
- (ramap, rafe): use SCM_I_ARRAY_V just once.
Daniel Llorens [Mon, 29 Apr 2013 12:19:52 +0000 (14:19 +0200)]
Match types used in arrays.c to struct field types
* libguile/arrays.c
- scm_shared_array_root: check for SCM_I_ARRAYP first.
- scm_i_shap2ra:
* check valid bounds in the '(lbnd ubnd) case. This makes
(make-array 0 '(4 -3)) fail with a 'bad dimension' instead of
with a 'wrong index' error.
* use ssize_t for lbnd/ubnd/inc, not long.
- scm_make_shared_array: use ssize_t for indices, not long.
- scm_transpose_array: use size_t for ndim, not ulong.
- scm_i_print_array: idem.
Daniel Llorens [Fri, 26 Apr 2013 11:02:38 +0000 (13:02 +0200)]
Don't use ASET in scm_array_index_map_x
* libguile/array-map.c: (scm_array_index_map_x): replace ASET by direct
use of handle->impl.
Daniel Llorens [Fri, 26 Apr 2013 00:05:22 +0000 (02:05 +0200)]
In scm_ramapc, only check unrolled axes for emptiness
* libguile/array-map.c: (scm_ramapc)
- Don't check emptiness while preparing ra0, but only after kroll is known,
and only before kroll. len = 0 will be caught by the unrolled loop.
- Use ra0 axis length in unroll check depth for rest args, not ra1's.
- Recover early exit feature when cproc returns 0.
Daniel Llorens [Thu, 25 Apr 2013 13:18:05 +0000 (15:18 +0200)]
Fix corner cases of scm_ramapc
* libguile/array-map.c
- (scm_ramapc): mismatched axes limit unrollk (kroll). Reorganize
the function to do all checking as we go.
- (scm_ra_matchp): unused; remove.
- (find_unrollk): inlined in scm_ramapc; remove.
- (klen): inlined in scm_ramapc; remove.
- (rafill): n is size_t.
- (racp): n is size_t. Use n and not i0end to bound the loop.
- (ramap): Use n and not i0end to bound the loop. This is needed for the rank
0 case to work with the new scm_ramapc, as inc may be set to 0 in that case.
- (rafe): idem.
* test-suite/tests/ramap.test
- check that size mismatch prevents unrolling (matching behavior III) with
both array-copy! and array-map!.
- check that non-contiguous stride in non-ref args prevents unrolling
(rank 2, discontinuous) with both array-copy! and array-map!.
- check rank 0 cases with array-for-each, array-map!.
- Test the 0-inc, non empty case for both array-map! and array-copy!.
Daniel Llorens [Wed, 24 Apr 2013 21:29:48 +0000 (23:29 +0200)]
Rewrite scm_ramapc()
* libguile/array-map.c
- (cind): replace by cindk, that operates only on the unrolled index set.
- (klen): new function.
- (make1array): take extra inc argument.
- (scm_ramapc): rewrite to unroll as many axes as possible instead of just all
or one.
- (AREF): lbnd is known to be 0: remove.
- (ASET): v is known to come from SCM_I_ARRAY_V; assume base, inc, lbnd.
- (racp): use ssize_t instead of long for the indices.
- (scm_array_index_map_x): build the index list at the last-but-one axis, then
set the car of the last element, instead of building the list at the last axis.
* test-suite/tests/ramap.test
- add array-map! test with offset arguments.
Daniel Llorens [Fri, 19 Apr 2013 14:44:48 +0000 (16:44 +0200)]
Factor out make1array() in scm_ramapc()
* libguile/array-map.c: (scm_ramapc): factor out vector->array conversion
to aux function make1array.
Daniel Llorens [Wed, 24 Apr 2013 15:13:56 +0000 (17:13 +0200)]
Check more cases of array-contents
* libguile/arrays.c: (scm_array_contents): fix comment.
* test-suite/tests/arrays.test: add cases that depend on correct
setting of CONTIGUOUS_FLAG.
Daniel Llorens [Fri, 19 Apr 2013 23:27:42 +0000 (01:27 +0200)]
Refactor array-contents
* libguile/arrays.c (scm_array_contents): Branch cases not on
scm_is_generalized_vector but on SCM_I_ARRAYP. Thus lbnd!=0, which
could happen with scm_is_generalized_vector, never appears in the
output.
* test-suite/tests/arrays.test: Test array-contents.
Daniel Llorens [Wed, 24 Apr 2013 14:34:31 +0000 (16:34 +0200)]
Check the documented matching behavior of array-map!/copy!
* test-suite/tests/arrays.test: move array-copy! tests to ramap.test.
* test-suite/tests/ramap.test: check the dissimilar matching behavior of
array-copy! and array-map! with arguments of different size.
Andy Wingo [Sun, 9 Feb 2014 20:11:08 +0000 (21:11 +0100)]
Reindent scm_ramapc
* libguile/array-map.c (scm_ramapc): Reindent.
Daniel Llorens [Fri, 19 Apr 2013 12:53:34 +0000 (14:53 +0200)]
Raw pointer loop in array-copy! for vector/vector case
This special case improves
(define a (make-array 1.
1000000 10))
(define b (make-array *unspecified*
1000000 10))
(define c (transpose-array (make-array *unspecified* 10
1000000) 1 0))
,time (array-copy! a b)
,time (array-copy! a c)
from 0.041598s / 0.072561 to 0.012164s / 0.041886s on a i7-3930K.
* libguile/array-map.c: (racp): if both src and dst are on vectors, use
the element pointers to do the copy.
Andy Wingo [Sun, 9 Feb 2014 19:56:55 +0000 (20:56 +0100)]
Simplify scm_array_get_handle for tc7-arrays
* libguile/array-handle.c (scm_array_get_handle): Simplify for the array
case, as suggested by Daniel Llorens.
Daniel Llorens [Wed, 17 Apr 2013 12:33:40 +0000 (14:33 +0200)]
Test that typed-array? returns #f with non-array argument
* test-suite/tests/arrays.test: ditto.
Daniel Llorens [Wed, 17 Apr 2013 08:19:26 +0000 (10:19 +0200)]
Replace SCM_IMP in array-map.c
* libguile/array-map.c
- scm_ramapc: check scm_array_contents with scm_is_false.
Andy Wingo [Sun, 9 Feb 2014 11:31:59 +0000 (12:31 +0100)]
Remove array impl. registry; instead, hard-code array handle creation
* libguile/array-handle.h (scm_t_vector_ref, scm_t_vector_set): Rename
from scm_t_array_ref, scm_t_array_set. These were named
scm_i_t_array_ref and scm_i_t_array_set in 1.8 and 2.0. Change to
take the vector directly, instead of the array handle. In this way,
generic array handles are layered on top of specific implementations
of backing stores.
Remove scm_t_array_implementation, introduced in 2.0 but never
documented. It was a failed attempt to layer the array implementation
that actually introduced too many layers, as it prevented the "vref"
and "vset" members of scm_t_array_handle (called "ref" and "set" in
1.8, not present in 2.0) from specializing on array backing stores.
(scm_i_register_array_implementation) (scm_i_array_implementation_for_obj):
Remove these internal interfaces.
(scm_t_array_handle): Adapt to scm_t_vector_ref / scm_t_vector_set
change.
(scm_array_handle_ref, scm_array_handle_set): Adapt to change in
vref/vset prototype.
* libguile/array-handle.c (scm_array_get_handle): Inline all the
necessary initializations here for all specific array types.
* libguile/array-map.c (rafill, racp, ramap, rafe, array_index_map_1):
* libguile/arrays.c: Remove array implementation code.
* libguile/bitvectors.h:
* libguile/bitvectors.c: Remove array implementation code.
(scm_i_bitvector_bits): New internal interface.
* libguile/bytevectors.c: Remove array implementation code.
* libguile/srfi-4.h: Remove declarations for internal procedures that
don't exist (!).
* libguile/strings.c: Remove array implementation code.
* libguile/vectors.c: Remove array implementation code.
Daniel Llorens [Fri, 19 Apr 2013 10:57:13 +0000 (12:57 +0200)]
Fix array map functions with empty arguments
* libguile/array-map.c
- scm_ra_matchp: look for empty axes and return new case 5 if so. Use
array handles to remove the SCM_I_ARRAYP / not branch.
- scm_ramapc: Heed case 5.
* test-suite/tests/ramap.test
- test empty arguments for array-copy! and array-for-each. Note those
that failed in 2.0.9.