* module/language/cps2/verify.scm: New diagnostic pass.
* module/Makefile.am: Add verify.scm.
* module/language/cps2/optimize.scm: Wire up verification pass.
Always run the pass at the end, and if a variable is set run it
between passes too.
* module/language/cps2/self-references.scm: New pass, ported from CPS.
* module/language/cps2/optimize.scm: Wire up the self references pass.
* module/Makefile.am: Add new file.
* module/language/cps2/simplify.scm (compute-singly-referenced-vars):
New helper.
(compute-eta-reductions): Turns out, eta conversion on a graph
doesn't work the same way that it works on nested terms -- since
uses and defs are computed using the flow graph and not nested
terms, we need to check additionally that the vars are singly-used.
* module/language/cps/slot-allocation.scm (allocate-slots): Even if an
expression does not define a live value, it might need a place to
put its value. In that case we should stop scanning for hints,
otherwise e.g. an (current-module) primcall whose value isn't used
could clobber a hinted variable.
* module/language/cps2/cse.scm: New file, ported from CPS.
* module/language/cps2/optimize.scm: Wire up CSE.
* module/Makefile.am: Add language/cps2/cse.scm.
* module/language/cps/compile-bytecode.scm (optimize): Disable
prune-top-level-scopes on old CPS. It seems to not work if CSE has
run beforehand.
* module/language/cps2/utils.scm (compute-function-body): $callk does
not add to a local function graph.
(compute-successors): Fix extraction of "handler" continuation for
$prompt.
* module/language/cps2/utils.scm (compute-successors): New helper.
(compute-reverse-post-order): Move here from contification.scm and
rename from "sort-nodes".
(invert-graph): New helper.
(compute-strongly-connected-components): Move here from
contification.scm and rename from "compute-sccs".
* module/language/cps2/contification.scm (sort-nodes, compute-sccs): Remove.
* module/language/cps2/elide-values.scm: New file.
* module/language/cps2/optimize.scm (optimize): Wire up elide-values.
* module/Makefile.am: Add new file.
* module/language/cps2/prune-top-level-scopes.scm
(prune-top-level-scopes): Given that cache-current-module! is an
instruction, it will always continue to a nullary $kargs, so $values
is actually the correct replacement and not a values primcall.
* module/language/cps2/specialize-primcalls.scm: New file.
* module/language/cps2/optimize.scm: Wire up specialize-primcalls.
* module/Makefile.am: Add new file.
* module/Makefile.am:
* module/language/cps2/types.scm: Port to CPS2. Relative to the CPS1
module, this one uses worklists, which should result in fewer
visits, though it does use a different strategy for deciding when to
saturate. We'll see!
* module/Makefile.am (CPS2_LANG_SOURCES): Add effects-analysis.scm.
* module/language/cps2/effects-analysis.scm: New file, based on
cps/effects-analysis.scm.
* module/language/cps2/utils.scm (intmap-map):
(compute-defining-expressions, compute-constant-values): New helpers.
* module/language/cps/intmap.scm: Intmaps can now contain any value;
#f does not indicate the absence of a value. Instead we use a unique
private sentinel to mark absent values or branches.
(*absent*, absent?, present?): New helpers.
(new-branch): Initialize empty elements to *absent*.
(clone-branch-with-edit): New helper.
(clone-branch-and-set): Use clone-branch-with-edit.
(writable-branch): Use clone-branch-with-edit
(empty-intmap): Initialize value to *absent*.
(add-level): clone-branch-and-set doesn't take #f as a branch any
more; use new-branch.
(branch-empty?, make-intmap/prune, intmap-add!):
(intmap-add, intmap-remove, intmap-next, intmap-prev):
(intmap-fold, intmap-union, intmap-intersect): Use absent? to detect
absent branches / values.
(intmap-ref): Likewise. Instead of returning #f if the value is not
found, call the optional not-found procedure. By default this will
signal an error.
* module/language/cps/types.scm:
* module/language/cps2/renumber.scm:
* module/language/cps2/simplify.scm: Adapt to intmap-ref signalling an
error by default if the value is not found.
* module/language/tree-il/compile-cps2.scm: Adapt to intmap-add
signalling an error if #f was in the intmap as a value.
* module/language/tree-il/peval.scm (<operand>): Rename "alias-value"
field to "alias", which is now an operand and not an expression.
This allows the operand to capture its environment; before, the
alias was being visited in its use environment instead of its
definition environment.
(peval): Adapt to operand change. Fix construction of rest bindings
as well.
* test-suite/tests/peval.test ("partial evaluation"): New test.
* module/language/cps2/utils.scm (fixpoint): Fix embarrassing bug
where it wouldn't actually fixpoint! Didn't show up in practice
because CPS2 hasn't run after contification yet.
* module/language/tree-il/compile-cps2.scm (convert): Fix bug
in (apply - ...), because the instruction for "-" is "sub", and
"sub" lookup was failing. Caught by numbers.test. Really I would
like to get rid of $prim, somehow.
* module/language/cps2/optimize.scm: New file.
* module/language/cps2/simplify.scm: New file, factored out of
simplify2.scm.
* module/language/cps/simplify2.scm: Remove, as it's obsolete.
* module/language/cps2/compile-cps.scm: Optimize the CPS.
* module/Makefile.am: Adapt for added and deleted files.
This is an intermediate step. We'll replace CPS bit by bit. If it
turns out to be a terrible idea we can just revert.
* module/Makefile.am (TREE_IL_LANG_SOURCES): Remove compile-cps.scm.
(CPS_LANG_SOURCES): Remove arities.scm.
* module/language/cps/arities.scm: Remove.
* module/language/tree-il/compile-cps.scm: Remove.
* module/language/tree-il/spec.scm: Remove use of compile-cps.scm.
* module/language/cps/compile-bytecode.scm: Remove use of arities.scm.
Instead, incoming terms are expected to call their continuations
with the correct number of arguments.
* module/language/tree-il/compile-cps2.scm (adapt-arity): New
procedure. This is equivalent to (language cps arities), but as it
is a necessary pass and not an optimization it's more proper to put
it in the converter itself. Unlike with the nested CPS
representation, it's possible to look up continuations without
making a DFG.
(convert): Adapt arities as necessary.
* module/language/cps/intset.scm (intset-add!): If the root is a
branch but isn't editable, be sure to actually update the transient
intset's root to store the writable root.