These numeric predicates now have CPS branching primcalls, which allows
type inference and folding to reduce them to less-strong instructions.
* module/language/cps/effects-analysis.scm (heap-numbers-equal?): Put
all the number predicates together. None have type checks.
* module/language/cps/guile-vm/lower-primcalls.scm
(define-branching-primcall-alias): New helper.
(complex?): Same as number?.
* module/language/cps/guile-vm/lower-primcalls.scm (real?)
(rational?, integer?, exact-integer?, exact?, inexact?): Define
lowerers.
* module/language/cps/type-fold.scm (number?, complex?, real?)
(rational?, integer?, exact-integer?, exact?, inexact?): Add folders and
reducers for all of these.
* module/language/cps/type.scm (number?, complex?, real?)
(rational?, integer?, exact-integer?, exact?, inexact?): Add type
inference for these.
* module/language/tree-il/compile-cps.scm (convert): Add number? checks
before exact? and inexact?. Remove the eager lowering of
exact-integer?; instead rely on folders.
* module/language/tree-il/cps-primitives.scm (number?, complex?)
(real?, rational?, integer?, exact-integer?, exact?, inexact?): Add
primitive decls. Define as "number-type-predicates?", meaning they need
a number? guard.
* module/language/cps/effects-analysis.scm: Mark more predicates as
effect-free. Sort the list.
* module/language/cps/guile-vm/lower-primcalls.scm (procedure?): Reify a
call to a primitive. Sadly we can't elide the $kreceive, as even though
we know that it's single-valued, $call can't continue to $kargs (has to
be $callk). Perhaps is worth relaxing in the future.
* module/language/cps/type-fold.scm: Define a number of additional
folders for disjoint types.
(procedure?): Define a folder for &procedure. Has to include structs,
though.
* module/language/cps/types.scm: Same as for type-fold.scm.
* module/language/tree-il/cps-primitives.scm: Lower procedure? primcalls
to CPS.
* module/language/cps/utils.scm (primcall-raw-representations): Add
sadd, ssub, etc; these are lowered to uadd, usub, etc later for the
guile-vm target, but it is still useful to record their reprs for
pre-lowering analysis.
Recognize `raise-exception` in the same way we recognize `throw`, though
it is a bit less optimized and the boot story is not as complicated.
* doc/ref/vm.texi (Non-Local Control Flow Instructions):
* libguile/jit.c (compile_unreachable):
(compile_unreachable_slow):
* libguile/vm-engine.c (VM_NAME):
* module/language/cps/compile-bytecode.scm (compile-function):
* module/system/vm/assembler.scm (emit-unreachable): Add new
"unreachable" instruction, inserted after a call to non-continuable
`raise-exception`.
* module/language/tree-il/compile-cps.scm (raise-exception):
* module/language/tree-il/primitives.scm
(*interesting-primitive-names*): Recognize raise-exception, and if it is
called with just one argument, prune that branch of the control-flow
graph.
* module/ice-9/pretty-print.scm (pretty-print): We were never indenting
more than 8 spaces. Doh!
* test-suite/tests/print.test (prints?, "pretty-print"): Add test.
* module/ice-9/boot-9.scm (define-inlinable):
* module/srfi/srfi-9.scm (define-tagged-inlinable): Add maybe-unused
declaration. Also require at least one body expr, otherwise the
metadata declaration could escape as the proc body.
* module/language/tree-il/analyze.scm (<reference-graph>): Oh my
goodness, constructor args were reversed relative to field order.
Constructor use was consistent but it was terribly confusing; fixed and
updated uses.
(unused-toplevel-analysis): Add ability for functions to mark themselves
as "maybe-unused"; such functions won't cause unused toplevel warnings.
* module/language/tree-il/compile-bytecode.scm (sanitize-meta):
(compile-closure):
* module/language/tree-il/compile-cps.scm (sanitize-meta): Prevent
maybe-unused from being needlessly written out to the binary.
* module/language/tree-il/compile-cps.scm
(define-custom-primcall-converter): New exported macro, handling
primcalls that need special logic. Fold "throw" and "values" into this
macro. The goal is to allow the Hoot compiler to specially convert an
"inline assembly" primcall.
* module/language/cps/utils.scm (primcall-raw-representations): New
function.
(compute-var-representations): Use #:primcall-raw-representations
keyword arg, which defaults to primcall-raw-representations.
* module/language/cps/utils.scm (compute-var-representations): $code
makes a 'code. bv-contents makes a 'bv-contents.
* module/language/cps/slot-allocation.scm:
* module/language/cps/hoot/tailify.scm:
* module/system/vm/assembler.scm: Adapt.
* module/language/cps/utils.scm (compute-defs-and-uses): Add $prim.
Wasn't needed before because this function was only ever called after
reify-primitives.
* module/language/cps/closure-conversion.scm (convert-one): Add nfree to
the param. This will help the wasm target.
* module/language/cps/effects-analysis.scm (closure-ref, closure-set!):
* module/language/cps/lower-primcalls.scm (closure-ref,closure-set!):
Adapt.
* module/system/base/target.scm (target-runtime): New export.
* module/language/cps/optimize.scm (make-cps-lowerer): Load a
backend-specific lowering module dynamically.
* module/language/cps/guile-vm.scm: New module for lowering to Guile's
VM.
* module/language/cps/guile-vm/loop-instrumentation.scm:
* module/language/cps/guile-vm/lower-primcalls.scm:
* module/language/cps/guile-vm/reify-primitives.scm: Move here, from
parent dir.
* am/bootstrap.am: Update for new file list.
Fixes <https://bugs.gnu.org/62691>.
Reported by Михаил Бахтерев <mike.bakhterev@gmail.com>.
* module/ice-9/threads.scm (call-with-new-thread): Do not use 'set!'
to set object properties while the calling thread is waiting on the
new thread to initialize.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
* module/language/cps/closure-conversion.scm (convert-one): Build
closures with make-closure, cons, and so on; leave lowering to scm-ref
to the backend.
* module/language/cps/effects-analysis.scm (compute-known-allocations):
For a primcall that allocates, sometimes we will synthesize auxiliary
definitions as part of CSE, for example to indicate that if (cons x y)
is bound to z, that a later call to (car z) should give x unless there
might be an intervening set-car!. We had a bug in which aux definitions
attached to allocations were being incorrectly associated with the first
operand. Probably this is a bug in other contexts but it really starts
to hit with the high-level constructors, e.g. `box`.
* module/language/cps/lower-primcalls.scm (f64->scm): Move here...
* module/language/cps/reify-primitives.scm (reify-primitives): from
here. Seems a more fitting place.
* module/language/cps/optimize.scm (lower-cps/generic): Rename from
lower-cps; these are the lowerings that apply to everyone.
(select-opts-for-optimization-level): Factor out of make-cps-lowerer.
(make-backend-cps-lowerer): New procedure. For the Guile VM backend, we
have a few mandatory passes, including the new lower-primitives.
(make-cps-lowerer): Apply backend-specific lowering pass.
This pass will implement the specialized lowering of object accessors to
Guile's VM primitives.
* am/bootstrap.am (SOURCES): Add new file.
* module/language/cps/lower-primcalls.scm: New file.
* module/language/cps/utils.scm (compute-var-representations): For the
wasm target, these values are (ref $kvarargs), not i64. Will need to
distinguish from bytevector pointers at some point, though.
* module/language/cps/compile-bytecode.scm (compile-function):
The rsh/lsh patterns would never match. I think these would end up
dispatching through emit-text though.
* libguile/exceptions.c (exception_epoch_fluid): Rename from
active_exception_handlers_fluid.
(scm_dynwind_throw_handler): Increment exception epoch instead of
resetting active exception handlers.
(scm_init_exceptions): Update.
* module/ice-9/boot-9.scm (with-exception-handler): Rework to associate
an "epoch" fluid with each exception handler.
(with-throw-handler): Establish a new epoch, during the execution of a
throw handler.
(raise-exception): Rework to avoid capturing a list of exception
handlers, and to use epochs as a way to know which handlers have already
been examined and which are on the dispatch stack.
* test-suite/tests/exceptions.test ("throwing within exception
handlers"): New test.