* 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.
The tentative plan is to replace CPS with CPS2, and to rename CPS2 to
CPS. We will add a pass to compile tree-il to CPS2, then work from
the top down to replace the CPS compiler passes.
* module/language/cps2.scm:
* module/language/cps2/compile-cps.scm:
* module/language/cps2/renumber.scm:
* module/language/cps2/utils.scm: New files.
* module/Makefile.am: Add new files to build.
* module/language/cps/intmap.scm (intmap->alist, print-intmap)
(print-transient-intmap): New functions.
Install the new functions as printers for <intmap> and <transient-intmap>.
* module/language/cps/intset.scm (make-atomic-reference)
(get-atomic-reference, set-atomic-reference!): New functions.
(*branch-size-with-edit*, *edit-index*): New constants.
(<transient-intset>): New data type.
(new-branch, clone-branch-and-set): Adapt to set edit field.
(transient-intset, persistent-intset): New exports.
(intset-add!): New interface, supporting "transient" intsets.
(intset-ref, intset-next, intset-prev, intset-fold, intset-fold2):
Work with transients.
* module/language/cps/intmap.scm (make-atomic-reference):
(get-atomic-reference, set-atomic-reference!): New helpers.
(*branch-size-with-edit*, *edit-index*): Branches now have a trailing
field, an atomic reference to their owner.
(<transient-intmap>): New record type. A mutable intmap.
(new-branch): Set the "edit" field on the branch.
(clone-branch-and-set): No editor for this field.
(assert-readable!, writable-branch): New helpers.
(transient-intmap, persistent-intmap): New exported functions.
(intmap-add!): New function.
(intmap-next, intmap-prev, intmap-ref): Work on transient intmaps.
(intmap-fold): Persist the intmap before folding over it.
* module/language/cps/intmap.scm (*branch-bits*): Switch to 32-way
branching. Marginally faster on lookup, and creation costs can be
amortized via using the transient interface. Marginal speedup for
assembler.scm compilation.
* module/language/cps/intmap.scm (meet-error): New helper.
(intmap-add, intmap-union, intmap-intersect): The "meet" argument is
optional and defaults to meet-error.
* module/language/cps.scm ($rec): Replace $letrec with $rec, which is an
expression, not a term. This means that the names bound by the letrec
appear twice: once in the $rec term, and once in the continuation.
This is not very elegant, but the situation is better than it was
before. Adapt all callers.
* doc/ref/compiler.texi (CPS in Guile): Incomplete documentation
updates. I'll update these later when the IL settles down.
* module/ice-9/eval.scm (primitive-eval): Factor out primitive=?
helper. Simplify compile-top-call. Add compile-top-branch for
primcall branches, so the compiler can see the specialized branch
operator.