* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* module/language/cps/dfg.scm ($dfa): Include CFA min-label, k-map, and
k-order inline.
(dfa-k-idx, dfa-k-sym, dfa-k-count): Adapt.
(compute-live-variables): Extract fields of CFA for make-dfa.
(print-dfa): Adapt (and fix positional record matching).
* module/language/cps/dfg.scm (compute-reachable): Reword docstring.
(visit-prompt-control-flow): Likewise.
($dominator-analysis): Change to store min-label instead of CFA.
(compute-idoms, compute-join-edges, mark-loop-body, identify-loops):
Take min-label and label-count, and use the DFG's preds list instead
of requiring a fresh renumbered one.
(analyze-dominators): Adapt to use a DFG with a label range instead of
a CFA.
* module/language/cps/dfg.scm ($cfa): Use a vector to map labels to
indices. Don't export any CFA bindings.
(cfa-k-idx): Adapt.
(compute-reachable, find-prompts, compute-interval):
(find-prompt-bodies, visit-prompt-control-flow): Take a DFG as an
argument instead of a CFA.
(analyze-reverse-control-flow): Refactor from analyze-control-flow, as
it is only used in the reverse case. Simplify accordingly, inlining
the RPO sort.
(compute-live-variables): Adapt to call analyze-reverse-control-flow
instead.
* module/language/cps/dfg.scm (compute-reachable): Fix embarassing bug
where we wouldn't actually iterate to fixpoint. I haven't seen it
yet, but that's just luck...
* module/language/cps/dfg.scm (compute-label-and-var-ranges): Fix to
work with global DFGs -- it wasn't taking $letrec into account for var
ranges.
* module/language/cps/dce.scm (compute-live-code): Use bitvectors to
represent the live var set.
* module/language/cps/renumber.scm (renumber): Refactor to return the
label and var counters as additional values.
* module/language/cps/dce.scm (eliminate-dead-code): Use the renumber
label/var counters to initialize the fresh name state.
* module/language/cps/effects-analysis.scm (compute-effects): Change to
analyze the effects for a subrange of a DFG's continuations.
* module/language/cps/dce.scm (compute-defs, $fun-data, compute-live-code):
(process-eliminations, eliminate-dead-code): Renumber before
eliminating dead code, to avoid computing a CFG and other data.