Mark H Weaver [Fri, 25 Apr 2014 05:39:59 +0000 (01:39 -0400)]
print: Fix printing of weak vectors.
* libguile/print.c (print_vector_or_weak_vector): New static function.
(iprin1): Use 'print_vector_or_weak_vector' in the vector and weak
vector cases.
Ludovic Courtès [Thu, 24 Apr 2014 21:46:20 +0000 (23:46 +0200)]
build: Clean up rules for meta/{guild,guile-config}.
* meta/Makefile.am (guile-config, guild): Avoid useless 'cat'
invocation'. Quote all occurrences of '@'.
Suggested by Eric Blake <eblake@redhat.com>.
Ludovic Courtès [Thu, 24 Apr 2014 09:16:21 +0000 (11:16 +0200)]
build: Honor program name transformation in 'guild'.
* configure.ac: Remove erroneous 'guile_program_name' substitute; see
<https://lists.gnu.org/archive/html/autoconf/2014-04/msg00010.html>
for details. Remove 'meta/guild' config file.
* meta/Makefile.am (guild): New target.
(CLEANFILES): Add 'guild'.
* meta/guild.in: Remove 'prefix' and 'exec_prefix' definitions; use
@installed_guile@.
Ludovic Courtès [Wed, 23 Apr 2014 16:12:26 +0000 (18:12 +0200)]
Set $GC_MARKERS to 1 when libgc 7.4.0 is used.
* libguile/gc.c (scm_storage_prehistory) [GC_VERSION == 7.4.0]: Add
'setenv' call.
Andy Wingo [Mon, 21 Apr 2014 19:48:39 +0000 (21:48 +0200)]
Add make-vector opcode
* libguile/vm-engine.c (make-vector): New opcode.
* module/language/cps/compile-bytecode.scm (compile-fun):
* module/system/vm/assembler.scm (system): Support the new opcode.
(*bytecode-minor-version*): Bump.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* test-suite/tests/compiler.test ("limits"): Add vector test.
Andy Wingo [Mon, 21 Apr 2014 17:28:06 +0000 (19:28 +0200)]
Operations on 8-bit and 12-bit operands shuffle args into range
* module/language/cps/slot-allocation.scm (allocate-slots): Avoid
allocating locals in the range [253,255].
* module/system/vm/assembler.scm: List exports explicitly. For
operations with limited-range operands, export wrapper assemblers that
handle shuffling their operands into and out of their range.
(define-assembler): Get rid of enclosing begin.
(shuffling-assembler, define-shuffling-assembler): New helpers to
define shuffling wrapper assemblers.
(emit-mov*, emit-receive*): New functions.
(shuffle-up-args): New helper.
(standard-prelude, opt-prelude, kw-prelude): Call shuffle-up-args
after finishing.
* test-suite/tests/compiler.test ("limits"): Add test cases.
Andy Wingo [Mon, 21 Apr 2014 10:13:54 +0000 (12:13 +0200)]
More expansion-time-only definitions in assembler.scm
* module/system/vm/assembler.scm (define-inline): Change so that the
defined macro is only defined at expansion-time.
(u32-ref, u32-set!, s32-ref, s32-set!, pack-arity-flags): Use
define-inline.
(pack-flags, assert-match, *block-size*, id-append, assembler)
(define-assembler, visit-opcodes, define-macro-assembler): Wrap in
eval-when expand.
Andy Wingo [Mon, 21 Apr 2014 10:01:46 +0000 (12:01 +0200)]
define-inline in assembler.scm
* module/system/vm/assembler.scm (define-inline): New local helper.
Update local users of define-inlinable to use it.
Andy Wingo [Sun, 20 Apr 2014 09:52:14 +0000 (11:52 +0200)]
VM opcodes only have <24-bit slot operands in the first word
* libguile/vm-engine.c (make-array): Change to only have
restricted-width operands in the first word. This instruction is
currently unused, however.
* module/system/vm/assembler.scm (assembler):
* module/system/vm/disassembler.scm (disassembler): Disallow
restricted-width operands in tail words.
Andy Wingo [Thu, 17 Apr 2014 13:29:13 +0000 (15:29 +0200)]
Add interface to disable automatic finalization
* libguile/finalizers.h:
* libguile/finalizers.c (run_finalizers_async_thunk)
(finalization_thread_proc): Call the new scm_run_finalizers helper.
(scm_i_finalizer_pre_fork): Only spawn the thread if automatic
finalization is enabled.
(scm_set_automatic_finalization_enabled, scm_run_finalizers): New
functions.
(scm_init_finalizers, scm_init_finalizer_thread): Only set a finalizer
notifier if automatic finalization is enabled.
* doc/ref/libguile-smobs.texi (Garbage Collecting Smobs): Add discussion
of concurrency.
* doc/ref/api-smobs.texi (Smobs): Document new functions.
Andy Wingo [Wed, 16 Apr 2014 17:21:50 +0000 (19:21 +0200)]
Slot allocation can re-use closure and argument slots
* module/language/cps/slot-allocation.scm (allocate-slots): Allow slot
allocation to re-use the closure and argument slots.
Andy Wingo [Wed, 16 Apr 2014 17:20:42 +0000 (19:20 +0200)]
Remove SCM_FRAME_PROGRAM
* libguile/frames.h: Remove SCM_FRAME_PROGRAM, now unused.
Andy Wingo [Wed, 16 Apr 2014 17:20:23 +0000 (19:20 +0200)]
VM robustness for optimized closures
* libguile/vm.c (vm_error_unbound, vm_error_unbound_fluid): Remove proc
argument. The value in slot 0 is not necessarily the procedure being
applied, after the prelude is done.
* libguile/vm-engine.c (vm_engine): Use LOCAL_REF (0) instead of
SCM_FRAME_PROGRAM, and adapt to above changes.
Andy Wingo [Wed, 16 Apr 2014 17:18:29 +0000 (19:18 +0200)]
Fix rewinding continuations when outermost frame has zero locals
* libguile/vm.c (vm_reinstate_partial_continuation_inner): Fix boundary
condition when the outermost frame has zero locals.
Andy Wingo [Wed, 16 Apr 2014 17:17:38 +0000 (19:17 +0200)]
frame-previous, frame-procedure robustness
* libguile/frames.c (scm_c_frame_closure): Don't use SCM_FRAME_PROGRAM,
as we don't know if the frame actually has any locals.
(scm_c_frame_previous): More robustly detect end-of-stack. Allows
scm_c_frame_previous to work on partial continuations.
Andy Wingo [Wed, 16 Apr 2014 17:16:10 +0000 (19:16 +0200)]
make-stack works on delimited continuations
* libguile/stacks.c (scm_make_stack, scm_stack_id):
* libguile/vm.c (scm_i_vm_cont_to_frame): Allow delimited continuations
as the argument to make-stack.
Andy Wingo [Wed, 16 Apr 2014 17:13:49 +0000 (19:13 +0200)]
More robust coverage tests
* test-suite/tests/coverage.test ("line-execution-counts"): Allow zero
or one count on the loop head.
Andy Wingo [Wed, 16 Apr 2014 17:13:09 +0000 (19:13 +0200)]
Change some make-stack tests to use frame-call-representation
* test-suite/tests/eval.test ("stacks"): Use frame-call-representation.
Andy Wingo [Wed, 16 Apr 2014 17:12:43 +0000 (19:12 +0200)]
Fix statprof for optimizations
* module/statprof.scm (profile-signal-handler): Bind in a letrec.
Otherwise the compiler may see the closure slot as dead, and the inner
stack cut won't work.
Andy Wingo [Wed, 16 Apr 2014 12:54:46 +0000 (14:54 +0200)]
Fix a frame-call-representation bug
* module/system/vm/frame.scm (frame-call-representation): Fix logic for
displaying names of non-procedures and procedures out of arities.
Andy Wingo [Wed, 16 Apr 2014 12:33:20 +0000 (14:33 +0200)]
Better backtraces from C, especially for optimized closures
* libguile/frames.h:
* libguile/frames.c (scm_frame_call_representation): New interface;
dispatches to Scheme.
* libguile/backtrace.c (display_application): Use
scm_frame_call_representation. This should be monotonically better,
given that scm_frame_arguments (which was previously called) also
dispatched to Scheme and actually ended up calling
frame-call-representation.
Andy Wingo [Wed, 16 Apr 2014 12:19:18 +0000 (14:19 +0200)]
frame-call-representation checks available-bindings, as appropriate
* module/system/vm/frame.scm (available-bindings): Map indexes in such a
way that the first argument is index 1.
(frame-call-representation): Update to search the bindings for live
bindings.
Andy Wingo [Wed, 16 Apr 2014 11:58:17 +0000 (13:58 +0200)]
Update frame-bindings interface
* module/system/repl/debug.scm (print-locals): Update to work with new
interface.
(frame->module): Update. Still doesn't work due to lack of
`program-module', though.
* module/system/vm/program.scm (make-binding, binding:name)
(binding:definition-offset, program-arity-bindings-for-ip): Remove
these.
* module/system/vm/frame.scm (<binding>): New type.
(available-bindings): Return a list of <binding> instances.
(frame-lookup-binding, frame-binding-set!, frame-binding-ref):
(frame-environment, frame-object-name): Adapt.
Andy Wingo [Wed, 16 Apr 2014 10:59:45 +0000 (12:59 +0200)]
Implement frame-bindings
* module/system/vm/frame.scm (parse-code, compute-predecessors):
(compute-genv, compute-defs-by-slot, compute-killv, available-bindings):
(frame-bindings): Add a bunch of hairy code to compute the set of
bindings that are live in a frame.
Andy Wingo [Wed, 16 Apr 2014 10:58:35 +0000 (12:58 +0200)]
Add arity-code
* module/system/vm/debug.scm (arity-code): New interface.
Andy Wingo [Wed, 16 Apr 2014 10:58:20 +0000 (12:58 +0200)]
Add parsing interfaces to the disassembler
* module/system/vm/disassembler.scm (instruction-length):
(instruction-has-fallthrough?, instruction-relative-jump-targets):
(instruction-slot-clobbers): New interfaces; to be used when
determining the bindings available at a given point of a procedure.
Andy Wingo [Wed, 16 Apr 2014 10:51:34 +0000 (12:51 +0200)]
Fix up some opcode metadata
* libguile/vm-engine.c (make-long-immediate, static-ref): Mark as "dst"
instructions.
Andy Wingo [Tue, 15 Apr 2014 20:24:48 +0000 (22:24 +0200)]
Add ability to query local definitions for a procedure
* module/system/vm/debug.scm (arity-definitions): New interface.
* module/system/vm/program.scm (make-binding, binding:boxed?)
(binding:index, binding:start, binding:end): Remove.
(binding:definition-offset, binding:slot): Add.
(program-arity-bindings-for-ip): Rename from program-bindings-for-ip,
as it gives all definitions in an arity. The user will have to do
data-flow analysis to recover the set of variables that are actually
available at any given point.
(arity->arguments-alist): Remove crufty code.
Andy Wingo [Tue, 15 Apr 2014 20:00:30 +0000 (22:00 +0200)]
Fix rtl tests
* module/system/vm/assembler.scm (write-arities): Add a diagnostic.
* test-suite/tests/rtl.test: Fix tests to emit "definition"
instructions.
Andy Wingo [Tue, 15 Apr 2014 19:47:46 +0000 (21:47 +0200)]
Fix frame-call-representation for primitive applications
* module/system/vm/frame.scm (frame-call-representation): Fix to work
for primitives.
* test-suite/tests/eval.test ("stacks"): Update expected result for
substring.
Andy Wingo [Tue, 15 Apr 2014 18:25:16 +0000 (20:25 +0200)]
Assembler residualizes local variable definition locations
* module/system/vm/assembler.scm (write-arities): Serialize definition
locations after names.
(definition): Store definition as a byte offset.
Andy Wingo [Tue, 15 Apr 2014 18:20:01 +0000 (20:20 +0200)]
Bump minor objcode version for recent changes
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION):
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.
Andy Wingo [Tue, 15 Apr 2014 15:52:41 +0000 (17:52 +0200)]
Write all local variable names into the arities section
* module/system/vm/assembler.scm (put-uleb128, put-sleb128)
(port-position): Lift out these helpers.
(arity-header-len, write-arities, link-arities): Add "nlocals" to the
arity headers. Write names of all locals into the arities section,
not just the arguments. Write them as uleb128's instead of uint32's,
to save space.
* module/system/vm/debug.scm (arity-header-len, arity-nlocals*)
(arity-nlocals, arity-locals, arity-arguments-alist): Adapt to new
encoding for arities.
Andy Wingo [Tue, 15 Apr 2014 13:27:19 +0000 (15:27 +0200)]
Tweak arities debugging representation
* module/system/vm/assembler.scm (meta-arities-size, write-arity-links):
* module/system/vm/debug.scm (arity-keyword-args)
(arity-arguments-alist): Rewrite to put they keyword literals link
first. Unfortunately requires a recompile :/
Andy Wingo [Tue, 15 Apr 2014 12:02:25 +0000 (14:02 +0200)]
Beginnings of local variable information
* module/system/vm/assembler.scm (<arity>, begin-kw-arity, end-arity):
(definition): Add definition macro-instruction. Arrange to record
variable definitions.
* module/language/cps/compile-bytecode.scm (compile-fun): Emit
definition macro-instructions as appropriate.
Andy Wingo [Tue, 15 Apr 2014 10:25:26 +0000 (12:25 +0200)]
Remove needless label remapping in slot-allocation
* module/language/cps/slot-allocation.scm (dead-after-def?):
(dead-after-use?, allocate-slots): Remove some needless remapping
between label indexes in the CFA, the DFA, and their names.
Andy Wingo [Tue, 15 Apr 2014 10:16:41 +0000 (12:16 +0200)]
DFA datums don't rename their labels
* module/language/cps/dfg.scm (analyze-reverse-control-flow): Don't
compute and return an order vector; it's not needed.
($dfa): Remove label renaming. We can just rename labels before
returning the DFA.
(dfa-k-idx, dfa-k-sym, dfa-k-count): Adapt.
(compute-live-variables): Adapt, and rename labels before returning.
Andy Wingo [Tue, 15 Apr 2014 09:18:50 +0000 (11:18 +0200)]
Better backtraces for optimized closures
* module/system/vm/debug.scm (arity-keyword-args, find-program-arity):
New exports.
* module/system/vm/frame.scm (frame-call-representation): Prefer to use
the frame IP to get the procedure.
Andy Wingo [Mon, 14 Apr 2014 15:06:05 +0000 (17:06 +0200)]
statprof avoids mucking with VM trace levels when not counting calls
* module/statprof.scm (statprof-start, statprof-stop): Don't futz the vm
trace level when we aren't counting calls. With this change, statprof
now imposes no overhead on the measured program.
Andy Wingo [Mon, 14 Apr 2014 14:54:51 +0000 (16:54 +0200)]
Better state handling in statprof
* module/statprof.scm (statprof-fold-call-data)
(statprof-proc-call-data): Add optional state arg.
(gcprof): Add optional port arg, and pass state arg explicitly.
(statprof-display-anomalies, statprof-display)
(statprof-call-data->stats): Pass state explicitly.
Andy Wingo [Mon, 14 Apr 2014 14:31:02 +0000 (16:31 +0200)]
Optimize make-stack
* libguile/continuations.h:
* libguile/continuations.c (scm_i_continuation_to_frame): Operate on
low-level C structures instead of heap objects.
* libguile/frames.h:
* libguile/frames.c (frame_offset, frame_stack_base): Const args.
(scm_c_frame_closure): New helper.
(scm_frame_procedure): Use the new helper.
* libguile/stacks.c (stack_depth, narrow_stack, scm_make_stack): Rework
to avoid allocating frames as we traverse the stack, and to avoid an
n**2 case where there are outer cuts.
Andy Wingo [Mon, 14 Apr 2014 13:14:26 +0000 (15:14 +0200)]
scm_c_make_frame takes struct scm_frame as arg
* libguile/frames.h:
* libguile/frames.c (scm_c_make_frame): Adapt to take a const struct
scm_frame as the argument. Adapt callers.
* libguile/continuations.c:
* libguile/stacks.c: Adapt callers.
Andy Wingo [Mon, 14 Apr 2014 12:54:14 +0000 (14:54 +0200)]
Refactor to frames code
* libguile/frames.h:
* libguile/frames.c (scm_c_frame_previous): New internal helper.
(scm_frame_previous): Use the helper.
(RELOC): Take kind and low-level frame args separately. Adapt
callers.
(frame_stack_base, frame_offset): New helpers.
(scm_i_frame_offset, scm_i_frame_stack_base): Use low-level helpers.
Andy Wingo [Mon, 14 Apr 2014 11:53:35 +0000 (13:53 +0200)]
Optimize make-global-cont-folder
* module/language/cps.scm (make-global-cont-folder): Inline the
fold-values, as peval doesn't do so. Allows closure conversion to
avoid any closure creation.
Andy Wingo [Sun, 13 Apr 2014 12:40:22 +0000 (14:40 +0200)]
Improve disassembly for optimized closures
* module/system/vm/disassembler.scm (code-annotation): Add call-label
and tail-call-label cases.
(disassemble-addr): With call-label we can see sets of mutually
recursive functions, so keep a global "visited?" set.
Andy Wingo [Sun, 13 Apr 2014 12:26:03 +0000 (14:26 +0200)]
Remove debugging code in closure-conversion
* module/language/cps/closure-conversion.scm (prune-free-vars): Remove
pk.
Andy Wingo [Sun, 13 Apr 2014 12:22:22 +0000 (14:22 +0200)]
Eval has no more free variables
* module/ice-9/eval.scm (primitive-eval): Expand out the call to
make-general-closure, so that make-general-closure becomes
well-known. Now eval has no more free variables!
Andy Wingo [Sun, 13 Apr 2014 12:21:25 +0000 (14:21 +0200)]
Closure conversion eliminates self-references introduced by fixpoint
* module/language/cps/closure-conversion.scm (analyze-closures): Build a
bound-vars set as well, to resolve introduced self-references.
(prune-free-vars, convert-one): Arrange to eliminate self-references.
Andy Wingo [Sun, 13 Apr 2014 11:52:56 +0000 (13:52 +0200)]
Refactor to closure-conversion
* module/language/cps/closure-conversion.scm (convert-one): Refactor to
pull in helpers locally, as they will need more state.
Andy Wingo [Sun, 13 Apr 2014 10:21:36 +0000 (12:21 +0200)]
Avoid consing an unbound-arg marker in the evaluator
* module/ice-9/eval.scm (primitive-eval): Turns out we don't need to
cons to make the unbound-arg marker.
Andy Wingo [Sun, 13 Apr 2014 09:47:17 +0000 (11:47 +0200)]
Optimize closures with one free variable
* module/language/cps/closure-conversion.scm (convert-free-var)
(allocate-closure, init-closure, prune-free-vars, convert-one)
(convert-closures): Optimize closures with one free variable.
Andy Wingo [Sat, 12 Apr 2014 21:31:08 +0000 (23:31 +0200)]
Well-known closures represented using pairs or vectors
* module/language/cps/closure-conversion.scm (convert-free-var):
(convert-free-vars): Take self-known? param, to do the right thing for
well-known closures.
(allocate-closure): New helper. Well-known closures are represented
using pairs or vectors.
(init-closure): Adapt tpo DTRT for well-known closures.
(prune-free-vars): Move up.
(convert-one): Adapt to new well-known closure representation.
Andy Wingo [Sat, 12 Apr 2014 20:42:23 +0000 (22:42 +0200)]
Update verify-cps
* module/language/cps/verify.scm (verify-cps): Update for recent CPS
changes.
Andy Wingo [Sat, 12 Apr 2014 17:46:23 +0000 (19:46 +0200)]
Avoid creating closures with no free variables
* module/language/cps/closure-conversion.scm (init-closure): Return just
one value.
(analyze-closures): Rewrite the well-known set to key off the label
instead of the closure identifiers before returning.
(convert-one): Avoid creating closure objects at runtime or load-time
when "instantiating" or calling well-known closures with no free
variables.
(prune-free-vars): New pass.
(convert-closures): Adapt.
Andy Wingo [Sat, 12 Apr 2014 14:12:33 +0000 (16:12 +0200)]
Hard-wire calls to known procedures
* module/language/cps/closure-conversion.scm (analyze-closures):
(convert-one, convert-closures): Hard-wire calls to known procedures
by transforming $call to $callk.
Andy Wingo [Sat, 12 Apr 2014 13:53:58 +0000 (15:53 +0200)]
closure conversion computes well-known functions
* module/language/cps/closure-conversion.scm (analyze-closures)
(convert-closures, convert-one): Adapt to compute well-known
functions. We don't yet produce $callk though.
Andy Wingo [Sat, 12 Apr 2014 09:52:38 +0000 (11:52 +0200)]
First-order CPS has $program and $closure forms
* module/language/cps.scm ($closure, $program): New CPS types, part of
low-level (first-order) CPS.
(build-cps-exp, build-cps-term, parse-cps, unparse-cps)
(compute-max-label-and-var): Update for new CPS types.
* module/language/cps/closure-conversion.scm: Rewrite to produce a
$program with $closures, and no $funs.
* module/language/cps/reify-primitives.scm:
* module/language/cps/compile-bytecode.scm (compile-fun):
(compile-bytecode): Adapt to new first-order format.
* module/language/cps/dfg.scm (compute-dfg): Add $closure case.
* module/language/cps/renumber.scm (renumber): Allow this pass to work
on either format.
* module/language/cps/slot-allocation.scm (allocate-slots): Add $closure
case.
Andy Wingo [Fri, 11 Apr 2014 16:01:23 +0000 (18:01 +0200)]
Separate make-cont-folder into global and local variants
* module/language/cps.scm (make-global-cont-folder)
(make-local-cont-folder): Separate this macro in two. It's hot and
the difference can be important for perf.
* module/language/cps/dfg.scm (compute-label-and-var-ranges):
* module/language/cps/cse.scm (compute-label-and-var-ranges):
* module/language/cps/dce.scm (compute-live-code): Adapt.
Andy Wingo [Fri, 11 Apr 2014 12:01:27 +0000 (14:01 +0200)]
Root higher-order CPS term is always $kfun $cont
* 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/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/prune-bailouts.scm:
* module/language/cps/prune-top-level-scopes.scm:
* module/language/cps/renumber.scm:
* module/language/cps/self-references.scm:
* module/language/cps/simplify.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/tree-il/compile-cps.scm: Adapt to produce and consume
raw $kfun $cont instances.
* .dir-locals.el: Update $letrec indentation.
Andy Wingo [Fri, 11 Apr 2014 09:51:34 +0000 (11:51 +0200)]
Closure conversion, reify-primitives use $kfun $cont
* module/language/cps/closure-conversion.scm: Produce a $kfun $cont.
* module/language/cps/reify-primitives.scm: Produce and consume $kfun
$cont.
* module/language/cps/compile-bytecode.scm: Adapt.
Andy Wingo [Fri, 11 Apr 2014 09:34:50 +0000 (11:34 +0200)]
Preparation for compile-bytecode to work on $kfun $conts
* module/language/cps/compile-bytecode.scm (compile-fun): Change to take
a $kfun $cont instead of a $fun.
(visit-funs): Change likewise, and call the proc on $kfun $cont's, not
$fun's.
(compile-bytecode): Adapt.
* module/language/cps/dfg.scm (analyze-reverse-control-flow): Adapt to
expect a $kfun $cont.
Andy Wingo [Fri, 11 Apr 2014 09:22:06 +0000 (11:22 +0200)]
compute-dfg takes a $kfun $cont, not a $fun
* module/language/cps/dfg.scm (compute-dfg): Take a $kfun $cont instead
of a $fun.
* module/language/cps/arities.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/contification.scm:
* module/language/cps/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/simplify.scm:
* module/language/cps/specialize-primcalls.scm: Adapt callers.
Andy Wingo [Fri, 11 Apr 2014 08:21:04 +0000 (10:21 +0200)]
with-fresh-name-state takes a cont, not a $fun
* module/language/cps.scm (with-fresh-name-state): Take a cont instead
of a fun.
* module/language/cps/closure-conversion.scm:
* module/language/cps/constructors.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/prune-bailouts.scm:
* module/language/cps/reify-primitives.scm: Adapt.
Andy Wingo [Fri, 11 Apr 2014 08:12:37 +0000 (10:12 +0200)]
Function defined by make-cont-folder takes a cont, not a $fun
* module/language/cps.scm (make-cont-folder): Take a cont instead of a
$fun.
(with-fresh-name-state): Adapt.
* module/language/cps/cse.scm (compute-label-and-var-ranges):
* module/language/cps/dce.scm (compute-live-code):
* module/language/cps/dfg.scm (compute-dfg):
* module/language/cps/elide-values.scm (elide-values):
* module/language/cps/reify-primitives.scm (reify-primitives):
* module/language/cps/renumber.scm (compute-new-labels-and-vars):
(renumber): Adapt.
Andy Wingo [Thu, 10 Apr 2014 10:11:35 +0000 (12:11 +0200)]
Rename $kentry to $kfun
* module/language/cps.scm ($kfun): Rename from $kentry.
* 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/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/dfg.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/prune-bailouts.scm:
* module/language/cps/prune-top-level-scopes.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/renumber.scm:
* module/language/cps/self-references.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 users.
Andy Wingo [Thu, 10 Apr 2014 08:50:17 +0000 (10:50 +0200)]
src and meta are fields of $kentry, not $fun
* module/language/cps.scm ($kentry, $fun): Attach "src" and "meta" on
the $kentry, not the $fun. This prepares us for $callk to $kentry
continuations that have no corresponding $fun.
* 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/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/dfg.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/prune-bailouts.scm:
* module/language/cps/prune-top-level-scopes.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/renumber.scm:
* module/language/cps/self-references.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.
Andy Wingo [Thu, 10 Apr 2014 07:25:38 +0000 (09:25 +0200)]
Remove tests for old Tree-IL CSE module
* test-suite/tests/cse.test: Remove.
* test-suite/Makefile.am:
Andy Wingo [Tue, 8 Apr 2014 12:10:36 +0000 (14:10 +0200)]
Remove obsolete comment in compile-bytecode.scm
* module/language/cps/compile-bytecode.scm (optimize): Remove an
obsolete comment.
Andy Wingo [Tue, 8 Apr 2014 19:41:42 +0000 (21:41 +0200)]
New pass to avoid free variable creation for self-recursion
* module/language/cps/self-references.scm: New pass, avoids the need for
self-recursion to allocate free variables.
* module/Makefile.am:
* module/language/cps/compile-bytecode.scm: Wire up the new pass.
Andy Wingo [Tue, 8 Apr 2014 08:06:40 +0000 (10:06 +0200)]
Compile some standalone tests to bytecode
* test-suite/standalone/test-out-of-memory:
* test-suite/standalone/test-stack-overflow: Compile these files before
running them. That way, recursion can check the stack-overflow
mechanism instead of the memory allocation mechanism. We compile
beforehand as a prepass so as not to impose an rlimit on a Guile that
previously ran auto-compilation.
Andy Wingo [Sun, 6 Apr 2014 09:08:05 +0000 (11:08 +0200)]
Remove old Tree-IL CSE pass
* module/language/tree-il/cse.scm: Delete.
* module/language/tree-il/optimize.scm: Remove use of Tree-IL CSE.
* module/Makefile.am: Remove language/tree-il/cse.scm.
* module/language/cps/compile-bytecode.scm: Rename CSE keyword to
#:cse?.
Andy Wingo [Sat, 5 Apr 2014 19:08:09 +0000 (21:08 +0200)]
Flow-sensitive analysis of truth values
* module/language/cps/cse.scm (compute-truthy-expressions):
(compute-equivalent-subexpressions, apply-cse): Arrange to infer
truthiness of expressions, and use that information to elide redundant
tests.
Andy Wingo [Sat, 5 Apr 2014 19:06:35 +0000 (21:06 +0200)]
Add effects for specialized primitives
* module/language/cps/effects-analysis.scm (make-vector)
(make-vector/immediate, vector-ref/immediate, vector-set!/immediate)
(struct-ref/immediate, struct-set!/immediate): Add effects.
Andy Wingo [Sat, 5 Apr 2014 12:38:37 +0000 (14:38 +0200)]
Minor cleanup/optimization in CSE
* module/language/cps/cse.scm (compute-available-expressions): Remove
needless for-each definition.
(compute-equivalent-subexpressions): Optimize for-each/2.
Andy Wingo [Sat, 5 Apr 2014 10:16:34 +0000 (12:16 +0200)]
Prune bailouts after contification
* module/language/cps/compile-bytecode.scm (optimize): Prune bailouts
after contifying, so that we return to the tail of the contified
function.
Andy Wingo [Sat, 5 Apr 2014 09:56:44 +0000 (11:56 +0200)]
Match and srfi-9 expose their bailouts to the CSE pass
* module/ice-9/match.upstream.scm (match-next): Inline a call to
"error", so the new CSE pass will see this case as a bailout.
* module/srfi/srfi-9.scm (throw-bad-struct): Reimplement as a syntax
rule, so that the CSE pass sees the "throw" call.
Andy Wingo [Sat, 5 Apr 2014 09:21:33 +0000 (11:21 +0200)]
Remove &bailout; replace uses of &unknown-effects with &all-effects
* module/language/cps/effects-analysis.scm (&bailout): Remove effect.
(&unknown-effects): Remove. Replace uses with &all-effects.
* module/language/cps/cse.scm:
Andy Wingo [Sat, 5 Apr 2014 09:18:20 +0000 (11:18 +0200)]
Remove parts of CSE that deal with bailout
* module/language/cps/cse.scm (compute-available-expressions, cse):
(compute-idoms, compute-equivalent-subexpressions, apply-cse): Remove
attempts to deal with bailout, as the bailout pass handles that
already.
Andy Wingo [Sat, 5 Apr 2014 09:08:47 +0000 (11:08 +0200)]
Add prune-bailouts pass
* module/language/cps/prune-bailouts.scm: New pass.
* module/language/cps/compile-bytecode.scm: Wire it up.
* module/Makefile.am: Add new file.
Andy Wingo [Sat, 5 Apr 2014 08:27:26 +0000 (10:27 +0200)]
Disable Tree-IL CSE
* module/language/tree-il/optimize.scm (optimize): Disable Tree-IL CSE
by default.
Andy Wingo [Sat, 5 Apr 2014 09:32:06 +0000 (11:32 +0200)]
Fix effects analysis for cached-module-box
* module/language/cps/effects-analysis.scm (cached-module-box): Fix
expected arity.
Andy Wingo [Fri, 4 Apr 2014 14:49:59 +0000 (16:49 +0200)]
Fix coverage expectations
* test-suite/tests/coverage.test ("line-execution-counts"): Update
expectations. Since there's nothing to do at the loop header and the
renaming of X happens at the end of the loops, the compiled code only
sees the loop header once.
Andy Wingo [Fri, 4 Apr 2014 12:29:11 +0000 (14:29 +0200)]
More bailout preparation work
* module/language/cps/cse.scm (compute-available-expressions): Compute a
bailout set -- or at least, set things up so that we can do so.
(compute-idoms): Don't add predecessors that bail out.
(apply-cse, cse, compute-equivalent-subexpressions): Thread the
bailout set through the computations.
Andy Wingo [Fri, 4 Apr 2014 11:42:54 +0000 (13:42 +0200)]
Prepare for CSE bailout propagation
* module/language/cps/cse.scm (compute-available-expressions): Prepare
for being able to prune joins from bailouts. Always loop after the
first iteration.
* module/language/cps/effects-analysis.scm: Remove &possible-bailout.
Rename &definite-bailout to &bailout, and rename
&all-effects-but-bailout to &unknown-effects.
Andy Wingo [Fri, 4 Apr 2014 10:15:10 +0000 (12:15 +0200)]
Add common subexpression elimination pass on CPS
* module/language/cps/cse.scm: New file.
* module/language/cps/compile-bytecode.scm: Wire up CSE, on by default.
Currently using the #:cps-cse? keyword.
* module/Makefile.am: Add new file.
Andy Wingo [Fri, 4 Apr 2014 10:08:52 +0000 (12:08 +0200)]
Effects analysis tweaks
* module/language/cps/effects-analysis.scm: Add &fluid-environment
effect, a dependency of fluid-ref and fluid-set!, and an effect of
push-fluid/pop-fluid.
(list): Depend on &cdr.
(resolve, cached-toplevel-box, cached-module-box): Don't depend on
&box.
Andy Wingo [Fri, 4 Apr 2014 10:07:24 +0000 (12:07 +0200)]
Fix verify-cps to work
* module/language/cps/verify.scm (verify-cps): Relax requirements for
variable names to be symbols.
Andy Wingo [Fri, 4 Apr 2014 10:06:59 +0000 (12:06 +0200)]
constant-needs-allocation? fix
* module/language/cps/dfg.scm (constant-needs-allocation?): Constants
need allocation when they are used as a slot-needing operand, not when
they are not used as an immediate operand. Fixes the case where one
var is used in both ways after CSE, in struct-set!/immediate.
Andy Wingo [Fri, 4 Apr 2014 08:39:42 +0000 (10:39 +0200)]
Remove variable-set! clause from compile-fun
* module/language/cps/compile-bytecode.scm (compile-fun): Remove
vestigial `variable-set!' clause.
Andy Wingo [Thu, 3 Apr 2014 14:37:07 +0000 (16:37 +0200)]
Effects analysis: define causes-all-effects?
* module/language/cps/effects-analysis.scm (causes-all-effects?): New
export.
Andy Wingo [Thu, 3 Apr 2014 14:36:23 +0000 (16:36 +0200)]
build-cps niceties
* module/language/cps.scm (build-cps-exp, build-cont-body): Respect
unquote in list builders (kargs, call, callk, primcall, and values).
Andy Wingo [Thu, 3 Apr 2014 07:40:18 +0000 (09:40 +0200)]
Minor CSE optimization
* module/language/tree-il/cse.scm (cse): Use hashq instead of modulo to
convert a full-width hash value to a vector index.
Andy Wingo [Wed, 2 Apr 2014 14:25:07 +0000 (16:25 +0200)]
Add with-fresh-name-state-from-dfg
* module/language/cps/dfg.scm (with-fresh-name-state-from-dfg): New
helper.
($dfg, compute-dfg): Store max-var and max-label in the dfg.
* module/language/cps.scm (with-fresh-name-state): Don't raise an error
on recursive invocation; that was mostly useful when finding a bug.
* module/language/cps/arities.scm (fix-arities):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
Use the new helper.
* .dir-locals.el: Update.
Andy Wingo [Wed, 2 Apr 2014 20:00:14 +0000 (22:00 +0200)]
(test-suite lib) uses plain old catch, not stack-catch
* test-suite/test-suite/lib.scm (run-test-exception): Refactor to just
use "catch" instead of stack-catch.
Andy Wingo [Wed, 2 Apr 2014 13:58:06 +0000 (15:58 +0200)]
Refactor toplevel scope name generation in compile-cps
* module/language/tree-il/compile-cps.scm (scope-counter, fresh-scope-id):
(toplevel-box, capture-toplevel-scope, convert, cps-convert/thunk):
Refactor to avoid abusing the var counter to generate scope
identifiers.
Andy Wingo [Wed, 2 Apr 2014 13:48:13 +0000 (15:48 +0200)]
compute-max-label-and-var takes letrec vars into account.
* module/language/cps.scm (compute-max-label-and-var): Fix to take
letrec vars into account.
Andy Wingo [Wed, 2 Apr 2014 13:41:14 +0000 (15:41 +0200)]
Fix DCE for refactor-introduced borkage
* module/language/cps/dce.scm ($fun-data, compute-live-code)
(process-eliminations): Fix clownshoes regarding fun-data field names
and order.
Andy Wingo [Wed, 2 Apr 2014 13:40:03 +0000 (15:40 +0200)]
Fix prune-top-level-scopes to allow collisions between var, scope, cont names
* module/language/cps/prune-top-level-scopes.scm (compute-referenced-scopes):
Fix to not assume that scope names, continuation names, and var names
are mutually unique.
(prune-top-level-scopes): Better variable names.
Andy Wingo [Wed, 2 Apr 2014 10:08:48 +0000 (12:08 +0200)]
Update old-style REPL code for deprecation
* module/ice-9/scm-style-repl.scm:
* module/ice-9/save-stack.scm: As the deprecated bindings have been
removed from the default environment, use #:export instead of
#:replace.
Andy Wingo [Wed, 2 Apr 2014 10:00:09 +0000 (12:00 +0200)]
Remove CFA data type
* module/language/cps/dfg.scm: Remove CFA data type.
(analyze-reverse-control-flow): Take min-label and label-count as
args, and return multiple values instead of returning a CFA object.
(compute-live-variables): Rework to accept multiple values from
analyze-reverse-control-flow.
($dfa): Update comments.