* 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.
* module/ice-9/eval.scm (primitive-eval): Lazily compile lambda bodies.
Special-case calls to top-level or module variables, and recognize
some of those calls as primcalls. In that case, emit closures with
the primcalls.
* module/language/cps/compile-bytecode.scm (optimize, compile-bytecode):
Marginally improve bootstrap memory usage by not retaining stale
copies of already-rewritten terms.
* module/ice-9/psyntax.scm (resolve-identifier): There is a case where a
syntax object can resolve to itself. Prevent an infinite loop in that
case by continuing to resolve by name.
* module/ice-9/psyntax-pp.scm: Regenerate.
* test-suite/tests/syncase.test ("infinite loop bug"): Add a test.
* libguile/goops.h (SCM_VTABLE_FLAG_GOOPS_STATIC): Reserve the fourth
GOOPS flag to indicate that a class has static slot allocation.
* libguile/goops.c (scm_init_goops_builtins): Define
vtable-flag-goops-static for goops.scm.
* module/oop/goops.scm (class-has-statically-allocated-slots?): New
helper.
(build-slots-list): Instead of the ad-hoc checks for <class> or
<slot>, use the new helper.
(initialize): Accept #:static-slot-allocation? keyword.
* module/system/foreign-object.scm (make-foreign-object-type): Declare
foreign object classes as having static slot allocation.
* test-suite/tests/goops.test ("static slot allocation"): Add tests.
* libguile/goops.c (is_accessor_method, scm_compute_applicable_methods):
Fix regression from 51f66c9120 (2009).
Accessor methods are added on each subclass on which the slot is
present; therefore if a subclass doesn't have a method, then the
methods doesn't apply. Truly fixes#17355, unlike
583a23bf10.
* module/oop/goops.scm (compute-cmethod, compute-getter-method)
(compute-setter-method): Revert earlier changes.
* test-suite/tests/goops.test ("accessor slots"): Update for new
expectations, in agreement with Guile 1.8.
* module/oop/goops/compile.scm: Inline into goops.scm, leaving a
compatible interface stub behind.
* module/oop/goops/dispatch.scm: Don't import (oop goops compile), to
break circularities.
* module/oop/goops.scm: Move (oop goops util) include up to the top, and
import (ice-9 match).
(compute-cmethod): Move here from compile.scm. Add a special case for
accessor methods, so as to fix bug #17355.
(compute-getter-method, compute-setter-method): #:procedure slot is
now generic.
* test-suite/tests/goops.test ("accessor slots"): New test.
Fixes bug #17355.
* module/oop/goops.scm (memoize-effective-method!): Adapt to
compute-effective-method change.
(compute-effective-method, %compute-effective-method): Renamed from
compute-cmethod; now a generic protocol.
(compute-specialized-effective-method)
(%compute-specialized-effective-method): New sub-protocol.
(memoize-generic-function-application!): Adapt to call the hard-wired
compute-applicable-methods based on the concrete arguments types --
the semantics is that %compute-applicable-methods is the
implementation for <generic> functions. Perhaps we should do the same
for sort-applicable-methods and method-more-specific?.
(compute-getter-method, compute-setter-method): The standard
#:procedure is now a generic slot-ref. It wasn't valid to inline
field access here, because subtypes could have different field
layouts.
(compute-applicable-methods): Refactor generic definition to use
lexical scoping.
(compute-specialized-effective-method): New method for
<accessor-method>, which does field access inlining based on the
concrete types being applied.
* test-suite/tests/goops.test ("accessor slots"): New test.
* module/oop/goops.scm (fold-slot-slots): Add `slot-ref/raw' slot, which
is what the slot-ref slot was. Now the slot-ref slot checks that the
slot is bound, if needed.
(slot-definition-slot-ref/raw): Define.
(make-slot): Adapt. Also, effective slot definition slots have no
initargs.
(define-standard-accessor-method, bound-check-get, standard-get)
(standard-set): Move definitions up.
(allocate-slots): Adapt. If the slot has an init thunk, we don't need
to check that it's bound.
(slot-ref, slot-set!, slot-bound?): Simplify.
(class-slot-ref): Use the raw getter so that we can call
`slot-unbound' with just the class.
(compute-getter-method, compute-setter-method): Simplify to just use
the slot-ref / slot-set! functions from the slot.
(%initialize-object): Simplify.