Andy Wingo [Tue, 1 Apr 2014 09:59:03 +0000 (11:59 +0200)]
Add visit-cont-successors helper
* module/language/cps/dfg.scm (lookup-successors, control-point?): Use
the new helper.
* module/language/cps.scm (visit-cont-successors): New helper.
Andy Wingo [Mon, 31 Mar 2014 16:08:11 +0000 (18:08 +0200)]
Fix analyze-control-flow to preserve order among unordered labels
* module/language/cps/dfg.scm (analyze-control-flow): Sort blocks to
preserve order among unordered successors.
(lookup-successors): Choose a more natural order, now that it doesn't
matter.
Andy Wingo [Mon, 31 Mar 2014 14:38:53 +0000 (16:38 +0200)]
Use Tree-IL-like case-lambda clause chaining in CPS
* module/language/cps.scm ($kclause, $kentry): Instead of having an
entry continuation contain a list of clauses, have the clauses contain
clauses (as in Tree-IL). In some ways it's not as convenient but it
does reflect the continuation tree correctly.
* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/constructors.scm:
* module/language/cps/contification.scm:
* module/language/cps/dce.scm:
* module/language/cps/dfg.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/prune-top-level-scopes.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/renumber.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt aaaaaaall users.
Andy Wingo [Mon, 31 Mar 2014 10:10:08 +0000 (12:10 +0200)]
Rewrite control-point? to avoid consing
* module/language/cps/dfg.scm (control-point?): Rewrite to avoid consing
a successors list.
Andy Wingo [Mon, 31 Mar 2014 10:09:46 +0000 (12:09 +0200)]
Remove succs from DFG
* module/language/cps/dfg.scm ($dfg): Remove "succs" from DFG. Instead
we can compute the successors set on-demand.
(lookup-successors): Adapt.
Andy Wingo [Sun, 30 Mar 2014 20:28:07 +0000 (22:28 +0200)]
Simplify boot-9 and srfi-1 map
* module/ice-9/boot-9.scm (map):
* module/srfi/srfi-1.scm (map): Simplify the implementations to check
for list? beforehand. It's faster, and it will be needed if we decide
to go recursive.
Andy Wingo [Sun, 30 Mar 2014 19:28:10 +0000 (21:28 +0200)]
Avoid consing in compute-label-and-var-ranges.
* module/language/cps/dfg.scm (compute-label-and-var-ranges): Avoid
consing.
Andy Wingo [Sun, 30 Mar 2014 19:14:31 +0000 (21:14 +0200)]
Scope and scope-level in DFG vector
* module/language/cps/dfg.scm ($dfg): Hoist scopes and scope levels out
of $block and into $dfg. Adapt all callers.
Andy Wingo [Sun, 30 Mar 2014 18:55:57 +0000 (20:55 +0200)]
Predecessors and successors in DFG vectors
* module/language/cps/dfg.scm ($dfg, $block): Record predecessors and
successors in vectors instead of in $block data structures. Adapt
users.
Andy Wingo [Sun, 30 Mar 2014 18:27:31 +0000 (20:27 +0200)]
DFG refactor
* module/language/cps/dfg.scm (lookup-cont, lookup-block):
(lookup-def, constant-needs-allocation?): Rework these accessors to
avoid completely destructuring the $dfg.
Andy Wingo [Sun, 30 Mar 2014 17:31:07 +0000 (19:31 +0200)]
Renumber functions before emitting code
* module/language/cps/compile-bytecode.scm (compile-bytecode): Renumber
a function before going to compile it, so that the vars and labels are
contiguous within each function.
Andy Wingo [Sun, 30 Mar 2014 17:09:40 +0000 (19:09 +0200)]
Add renumber module
* module/language/cps/renumber.scm: New module.
* module/Makefile.am: Add to build.
fix renumber
Andy Wingo [Sun, 30 Mar 2014 09:48:47 +0000 (11:48 +0200)]
Replace use-map in DFG with separate def / use vectors
* module/language/cps/dfg.scm ($dfg, $use-map): Replace use-map vector
with "defs" and "uses" vectors. Adapt callers.
Andy Wingo [Sun, 30 Mar 2014 09:36:59 +0000 (11:36 +0200)]
Remove "sym" from $use-map
* module/language/cps/dfg.scm ($use-map): Remove "sym" from use-map;
it's redundant. Adapt callers.
Andy Wingo [Sun, 30 Mar 2014 09:25:23 +0000 (11:25 +0200)]
$use-map no longer has name member
* module/language/cps/dfg.scm ($use-map): Remove name member. Adapt
users.
Andy Wingo [Sun, 30 Mar 2014 09:23:51 +0000 (11:23 +0200)]
$dfa no longer includes name vector (can get that from dfg)
* module/language/cps/dfg.scm ($dfa, dfa-var-name):
(compute-live-variables, print-dfa): Remove "names" from DFAs.
Andy Wingo [Sun, 30 Mar 2014 09:14:45 +0000 (11:14 +0200)]
DFG stores conts, blocks, and use-maps in vectors
* module/language/cps/dfg.scm ($dfg): Change to store conts, blocks, and
use-maps as vectors. A DFG also records the minimum label, minimum
variable, and the number of labels and variables. The first entry in
one of these vectors corresponds to the minimum. This can be
optimum in the local case if the conts and variables have been renamed
appropriately.
Adapt callers.
(compute-live-variables): Adapt. This is currently suboptimal but it
works, so it's a useful base for optimization.
Andy Wingo [Sun, 30 Mar 2014 08:41:31 +0000 (10:41 +0200)]
lookup-cont takes a DFG as its argument
* module/language/cps/dfg.scm (lookup-cont): Change to take a DFG
instead of a cont table.
(build-cont-table): Change to return a vector.
* module/language/cps/arities.scm:
* module/language/cps/contification.scm:
* module/language/cps/dce.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm: Adapt to lookup-cont and
build-cont-table changes.
Andy Wingo [Sat, 29 Mar 2014 06:56:08 +0000 (07:56 +0100)]
Public make-cont-folder
* module/language/cps.scm (make-cont-folder): Add global? parameter, and
make public.
(fold-conts): Adapt.
(fold-local-conts): Use make-cont-folder, and take a function instead
of a continuation.
* module/language/cps/arities.scm (fix-clause-arities, fix-arities*):
* module/language/cps/compile-bytecode.scm (collect-conts):
* module/language/cps/elide-values.scm (elide-values*): Adapt to
fold-local-conts change.
Andy Wingo [Fri, 28 Mar 2014 21:27:48 +0000 (22:27 +0100)]
Vars and labels are separate namespaces
* module/language/cps.scm (fresh-var, with-fresh-name-state): Vars have
their own namespace.
Andy Wingo [Fri, 28 Mar 2014 20:55:46 +0000 (21:55 +0100)]
Prepare for decoupling of var/label name uniqueness
* module/language/cps/simplify.scm (compute-beta-reductions):
(beta-reduce): Separate state into two tables, so we can relax current
guarantee that vars and labels are mutually unique.
Andy Wingo [Fri, 28 Mar 2014 20:32:26 +0000 (21:32 +0100)]
Update verify-cps
* module/language/cps/verify.scm (verify-cps): Vars should only be exact
integers now.
Andy Wingo [Fri, 28 Mar 2014 20:30:55 +0000 (21:30 +0100)]
CPS conversion renames incoming gensyms to small integers
* module/language/tree-il/compile-cps.scm (fold-formals)
(unbound?, init-default-value, convert): Arrange to rename incoming
gensyms as small integers.
(canonicalize): Convert vector and abort here too.
Andy Wingo [Fri, 28 Mar 2014 18:17:22 +0000 (19:17 +0100)]
Less copying in tree-il pre-order / post-order.
* module/language/tree-il.scm (pre-post-order): If the pre handler
doesn't modify the components of a tree-il expression, avoid copying a
new one.
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.