* 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/language/cps/compile-bytecode.scm (optimize, compile-bytecode):
Marginally improve bootstrap memory usage by not retaining stale
copies of already-rewritten terms.
* libguile/goops.c (SCM_GOOPS_UNBOUND, SCM_GOOPS_UNBOUNDP): Remove
internal macros.
(scm_make_unbound, scm_unbound_p): Remove internal functions.
(scm_sys_clear_fields_x): Add "unbound" parameter, for the init
value.
* module/oop/goops.scm (*unbound*): Define in Scheme as a simple
heap-allocated value.
(unbound?): New definition.
(%allocate-instance): Pass *unbound* to %clear-fields!.
(make-class, slot-definition-init-value)
(slot-definition-init-form, make-closure-variable): Use *unbound*
instead of (make-unbound), which is now gone.
* module/oop/goops/active-slot.scm (compute-get-n-set): Use *unbound*
instead of make-unbound. This module uses the GOOPS internals module;
perhaps we should export make-unbound or something...
* module/oop/goops/save.scm (make-unbound): Export our own make-unbound
definition, for use by residualized save code.
* module/language/ecmascript/base.scm (<undefined>, *undefined*): Use a
unique object kind and instance for the undefined value.
* libguile/vm.c (scm_i_vm_mark_stack): Fill the stack with
SCM_UNSPECIFIED instead of SCM_UNBOUND.
* libguile/vm-engine.c (allocate-struct, struct-ref, struct-set!): New
instructions, to complement their "immediate" variants.
* module/language/cps/compile-bytecode.scm (compile-fun):
* module/system/vm/assembler.scm (system): Wire up the new instructions.
Fixes <http://bugs.gnu.org/17634>.
Reported by Josep Portella Florit <jpf@primfilat.com>.
* module/language/tree-il/peval.scm (inlined-application): When inlining
an application whose operator is a lambda expression with optional
arguments that rely on default initializers, expand into a series of
nested let expressions, to ensure that previous arguments are in scope
when the default initializers are evaluated.
* test-suite/tests/peval.test ("partial evaluation"): Add tests.
Fixes <http://bugs.gnu.org/18299>.
Reported by Frank Terbeck <ft@bewatermyfriend.org>.
* module/language/tree-il/analyze.scm (format-string-argument-count):
Add case for ~p.
* test-suite/tests/tree-il.test ("warnings")["format"]("~p", "~p, too
few arguments", "~:p", "~:@p, too many arguments", "~:@p, too few
arguments"): New tests.
* module/language/cps/types.scm (&all-types): Represent true and false
as separate bits, so that #f can be removed from types on true
branches. Adapt all users.
* module/language/cps/type-fold.scm (&scalar-types):
(fold-and-reduce): Adapt to boolean type representation change.
* module/language/cps/simplify.scm (redominate): Add micropass to
rewrite the scope tree to reflect the dominator tree. Will enable
better eta reduction.