* module/language/cps/contification.scm (compute-first-class-functions):
(compute-functions-called-by-label):
(compute-functions):
(compute-arities):
(compute-contification-candidates):
(compute-call-graph):
(compute-contification):
(apply-contification):
(contify): Given that the frontend will produce $callk now, allow it to
be contified if such callees are all called with the same continuation.
* module/language/cps/closure-conversion.scm: Use standard
compute-reachable-functions and intmap-select from utils to filter
reachable functions, allowing us to pick up callk. Adapt some uses to
expect callk for calls.
* module/language/cps/self-references.scm (resolve-self-references):
Subst the proc, if it's there.
* module/language/cps/split-rec.scm (compute-free-vars): Add a case for
callk.
* module/language/cps.scm:
* module/language/cps/contification.scm:
* module/language/cps/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/types.scm: Allow $kargs to follow $kfun. In that
case, the function must be well-known and callers are responsible for
calling with the appropriate arity.
* module/language/cps/compile-bytecode.scm: Emit "unchecked-arity" for
$kargs following $kfun.
* module/system/vm/assembler.scm: Adapt.
* module/language/cps/devirtualize-integers.scm (peel-trace): Update
comment.
* module/language/cps/contification.scm (apply-contification): Update to
never contify a return of $primcall to $kreceive.
* module/language/cps/verify.scm (check-arities): Require that primcalls
continue to $kargs.
* module/language/cps.scm ($branch): Refactor to be its own CPS term
type, not relying on $continue to specify a continuation (which before
was only for the false case) or a source location. Update allllllll
callers.
* module/language/cps/contification.scm (apply-contification): Inline
returns to the corresponding $kargs.
* module/language/cps/licm.scm (loop-invariant?): Remove handling of
"values" primcall, as this doesn't exist any more.
* module/language/cps.scm ($primcall): Add "param" member, which will be
a constant parameter to the primcall. The idea is that constants used
by primcalls as immediates don't need to participate in optimizations
in any way -- they should not participate in CSE, have the same
lifetime as the primcall so not part of DCE either, and don't need
slot allocation. Indirecting them through a named $const binding is
complication for no benefit. This change should eventually improve
compilation time and memory usage, once we fully take advantage of it,
as the number of labels and variables will go down.
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/constructors.scm:
* module/language/cps/contification.scm:
* module/language/cps/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/handle-interrupts.scm:
* module/language/cps/licm.scm:
* module/language/cps/peel-loops.scm:
* module/language/cps/prune-bailouts.scm:
* module/language/cps/prune-top-level-scopes.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/renumber.scm:
* module/language/cps/rotate-loops.scm:
* module/language/cps/self-references.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/specialize-numbers.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/split-rec.scm:
* module/language/cps/type-checks.scm:
* module/language/cps/type-fold.scm:
* module/language/cps/types.scm:
* module/language/cps/utils.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt all users.
* module/language/cps/compile-bytecode.scm (compile-function): Check for
fallthrough after $kclause too; possible to need to jump if clause
tails are contified.
* module/language/cps/contification.scm (compute-contification-candidates):
Enable inter-clause contification.
* 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.scm ($kclause, $kentry): Instead of having an
entry continuation contain a list of clauses, have the clauses contain
clauses (as in Tree-IL). In some ways it's not as convenient but it
does reflect the continuation tree correctly.
* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/constructors.scm:
* module/language/cps/contification.scm:
* module/language/cps/dce.scm:
* module/language/cps/dfg.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/prune-top-level-scopes.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/renumber.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt aaaaaaall users.
* module/language/cps/dfg.scm (lookup-cont): Change to take a DFG
instead of a cont table.
(build-cont-table): Change to return a vector.
* module/language/cps/arities.scm:
* module/language/cps/contification.scm:
* module/language/cps/dce.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm: Adapt to lookup-cont and
build-cont-table changes.
* module/language/cps/contification.scm (compute-contification):
Converge more quickly by using the information we compute within a
compute-contification pass.
* module/language/cps/contification.scm (compute-contification): If we
decide to contify, don't forget to visit the body. Should make
contification converge faster.
* module/language/cps/contification.scm (compute-contification): Fail as
soon as we see an arity with rest, optional, or keyword arguments.
Fixes ((case-lambda ((a . b) #t) ((a b) #f)) 1 2).
* module/language/cps.scm ($continue, $cont): Put source information on
the $continue, not on the $cont. Otherwise it is difficult for CPS
conversion to preserve source information.
($fun): Add a src member to $fun. Otherwise we might miss the source
info for the start of the function.
* .dir-locals.el:
* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-rtl.scm:
* module/language/cps/constructors.scm:
* module/language/cps/contification.scm:
* module/language/cps/dfg.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Update the whole CPS world
for this change.
* module/language/cps/contification.scm (compute-contification): When
eliding let-bound functions, also record the cont that declares the
function.
(apply-contification): Instead of reifying ($values ()) gotos instead
of the elided function, inline the body that binds the function
directly. This ensures that the function gets contified in its own
scope.
* module/language/cps/contification.scm: Returns from contified
functions should primcall to 'values, as in general the return
continuation is a multiple value context ($ktrunc or $ktail). A later
pass can elide the primcall if appropriate.
* module/language/cps/contification.scm (compute-contification): Rewrite
to avoid mutating the DFG and the function while we are rewriting.
Instead we compute a contification, and if it is not empty, we apply
it and loop.
* module/language/cps/contification.scm (contify): It could be that
visiting pending contifications could enqueue more contifications, so
iterate to a fixed point. Signal an error if there are any pending
contifications at the end of an iteration.
* module/language/cps/dfg.scm: Refactor so that we can think about
building a dominator tree. Split continuations out of use maps and
put them in a separate table, which will have more flow information.
(visit-fun): Mark clauses as using their bodies.
(lookup-predecessors, lookup-successors): New exports.
(find-defining-expression): Add an exception for clauses, now that
clauses are in the flow graph.
(continuation-bound-in?): Rename from variable-bound-in?, as it can
currently only be used for continuations.
* module/language/cps/contification.scm (contify): Adapt to use
lookup-predecessors and continuation-bound-in?.
* module/language/cps/contification.scm (contify): Exhaustively replace
contified tail continuations, to fix a bug in nested tail-recursive
contifications. Likewise, call lookup-return-cont when searching for
common return continuations.
* module/language/cps/dfg.scm (variable-free-in?): Rename from
variable-used-in?, to match CWCC language.
(variable-bound-in?): New interface.
* module/language/cps/contification.scm (contify): Adapt caller. Add
more comments.