* module/language/cps/types.scm (define-binary-result!): Arithmetic
where one argument is a flonum may produce a complex.
* test-suite/tests/compiler.test: Add test.
* module/language/cps/specialize-numbers.scm (compute-significant-bits):
Always revisit predecessors after first visit. Avoids situation where
predecessor of an unvisited phi var could default to 0 significant
bits and never be revisited. Fixes (format #f "~2f" 9.9).
* libguile/vm-engine.c (fluid-set!): Fix name of opcode to correspond
with name of Tree-IL primitive. Fixes compilation of fluid-set! to
actually use the fluid-set! opcode.
* doc/ref/vm.texi (Dynamic Environment Instructions): Update.
* module/language/cps/compile-bytecode.scm (compile-function): Add
fluid-set! case.
* module/system/vm/assembler.scm: Update export name for
emit-fluid-set!.
The compiler was producing `((toplevel foo))' instead of `(toplevel foo)'.
Changed to use `call' form with target type and spliced constructor
arguments.
* module/language/ecmascript/compile-tree-il.scm (comp): Replace `@impl'
shorthand with `call' + `@implv' for better control over resulting
tree-il.
* test-suite/tests/ecmascript.test (compiler): Add test for "new Object();"
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
* module/language/cps/slot-allocation.scm
(add-prompt-control-flow-edges): Fix to add links from prompt bodies
to handlers, even in cases where the handler can reach the body but
the body can't reach the handler.
* test-suite/tests/compiler.test ("prompt body slot allocation"): Add
test case.
* doc/ref/vm.texi (Inlined Atomic Instructions): New section.
* libguile/vm-engine.c (VM_VALIDATE_ATOMIC_BOX, make-atomic-box)
(atomic-box-ref, atomic-box-set!, atomic-box-swap!)
(atomic-box-compare-and-swap!): New instructions.
* libguile/vm.c: Include atomic and atomics-internal.h.
(vm_error_not_a_atomic_box): New function.
* module/ice-9/atomic.scm: Register primitives with the compiler.
* module/language/cps/compile-bytecode.scm (compile-function): Add
support for atomic ops.
* module/language/cps/effects-analysis.scm: Add comment about why no
effects analysis needed.
* module/language/cps/reify-primitives.scm (primitive-module): Add case
for (ice-9 atomic).
* module/language/tree-il/primitives.scm (*effect-free-primitives*):
(*effect+exception-free-primitives*): Add atomic-box?.
* module/system/vm/assembler.scm: Add new instructions.
* test-suite/tests/atomic.test: Test with compilation and
interpretation.
* module/language/tree-il/primitives.scm
(character-comparison-expander): Expand out char<? and friends to <,
unboxing the char arguments.
* module/language/cps/types.scm:
* module/language/cps/effects-analysis.scm: Remove mention of char<? and
friends as we won't see them any more. Also fixes#24318.
* module/language/cps/specialize-numbers.scm (truncate-u64): New helper,
truncates a SCM value.
(specialize-u64-binop): Add ulogxor case.
(sigbits-union, sigbits-intersect, sigbits-intersect3)
(next-power-of-two, range->sigbits, inferred-sigbits)
(significant-bits-handlers, define-significant-bits-handler):
(significant-bits-handler, compute-significant-bits): Add facility to
compute the bits in a value that are significant.
(specialize-operations): Unbox in more cases, when only u64 bits are
significant. Unbox logxor. Elide logand where it has no effect.
* module/language/cps/rotate-loops.scm (rotate-loops-in-function): Don't
attempt to rotate a loop whose header is a $prompt. Fixes use of
`continue' in `while'. Thanks to Nala Ginrut for the report :)
* doc/ref/vm.texi (Top-Level Environment Instructions): Update
documentation.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump, sadly.
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.
* libguile/vm-engine.c (define!): Change to store variable in dst slot.
* module/language/tree-il/compile-cps.scm (convert):
* module/language/cps/compile-bytecode.scm (compile-function): Adapt to
define! change.
* module/language/cps/effects-analysis.scm (current-module): Fix define!
effects. Incidentally here was the bug: in Guile 2.2 you can't have
effects on different object kinds in one instruction, without
reverting to &unknown-memory-kinds.
* test-suite/tests/compiler.test ("regression tests"): Add a test.
* module/language/tree-il/peval.scm (peval): Don't
inline (call-with-values foo (lambda (x) exp)) to (let ((x (foo)))
exp). The idea is that call-with-values sets up an explicit context
in which we are requesting an explicit return arity, and that dropping
extra values when there's not a rest argument is the wrong thing.
Fixes#13966.
* test-suite/tests/peval.test ("partial evaluation"): Update test.
* module/language/cps/types.scm (type-entry-saturating-union): Fix range
saturation in the negative direction. Previously we were artificially
truncating negative range ends to zero.
* module/language/cps/optimize.scm (cps-default-optimization-options):
Add missing #:simplify? option. Otherwise the simplification pass was
running even at -O0.
* module/language/tree-il/peval.scm (peval): In test context,
fold (let ((x EXP)) (if x x ALT)) to (if EXP #t ALT). This reduces
the number of boolean literals that the compiler has to reify, by
causing EXP to evaluate in test context instead of value context.
Also, rotate `let' out of the test part of conditionals, for the same
reason.
* module/language/cps/simplify.scm (compute-eta-reductions): Eta-reduce
branches as well, so that passing a constant to a branch will fold to
the true or false branch, provided that the test variable was just
used in the branch.
* module/language/cps/reify-primitives.scm (primitive-module): Add cases
for SRFI-4 primitives. These primitives are only treated as such for
the purposes of Tree-IL primitive expansion; perhaps the right fix is
elsewhere, but it's here for now.
* module/language/cps/types.scm (&min/0, &min/s64, &max/s64, &max/size)
(&max/u64, &max/vector): New clamped variable range accessors. Use
them in type inferrers.
* module/language/cps/utils.scm (intmap-map): Use transient intmap-add!
on an empty intmap to build the result instead of intmap-replace! on
the argument. Avoids spooky action-at-a-distance mutation of the
argument if it happens to be a transient -- although the intmap-fold
will correctly traverse a snapshot of the argument and the result will
be correct, the argument value would be modified in place, causing
strange results to calling code that passes in a transient.
* module/language/cps/intmap.scm: Remove srfi-18 import. We just need
current-thread which is actually defined in (guile), and
importing (srfi srfi-18) raises an error if Guile is compiled without
threads support.
* libguile/vm-engine.c (BR_U64_SCM_COMPARISON): New helper.
(br-if-u64-<=-scm, br-if-u64-<-scm, br-if-u64-=-scm)
(br-if-u64->-scm, br-if-u64->=-scm): New instructions, to compare an
untagged u64 with a tagged SCM. Avoids many u64->scm operations.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/type-fold.scm:
* module/system/vm/assembler.scm:
* module/system/vm/disassembler.scm (code-annotation, compute-labels):
* module/language/cps/primitives.scm (*branching-primcall-arities*): Add
support for new opcodes.
* module/language/cps/specialize-numbers.scm
(specialize-u64-scm-comparison): New helper.
* module/language/cps/specialize-numbers.scm (specialize-operations):
Specialize u64 comparisons.
* module/language/cps/types.scm (true-comparison-restrictions): New helper.
(define-comparison-inferrer): Use the new helper. Add support for
u64-<-scm et al.
* libguile/vm-engine.c (logsub): New op.
* module/language/cps/effects-analysis.scm (logsub):
* module/language/cps/types.scm (logsub):
* module/system/vm/assembler.scm (system): Add support for the new op.
* module/language/tree-il/compile-cps.scm (canonicalize):
Rewrite (logand x (lognot y)) to (logsub x y).
* libguile/vm-engine.c (bv-s8-ref, bv-s16-ref, bv-s32-ref, bv-s64-ref):
Unbox index and return unboxed S32 value.
(bv-s8-set!, bv-s16-set!, bv-s32-set!, bv-s64-set!): Unbox index and
take unboxed S32 value.
(bv-u8-ref, bv-u16-ref, bv-u32-ref, bv-u64-ref)
(bv-s8-set!, bv-s16-set!, bv-s32-set!, bv-s64-set!): Likewise, but
with unsigned values.
(bv-f32-ref, bv-f32-set!, bv-f64-ref, bv-f64-set!): Use memcpy to
access the value so we don't have to think about alignment. GCC will
inline this to a single instruction on architectures that support
unaligned access.
* libguile/vm.c (vm_error_out_of_range_uint64)
(vm_error_out_of_range_int64): New helpers.
* module/language/cps/slot-allocation.scm (compute-var-representations):
All bytevector ref operations produce untagged values.
* module/language/cps/types.scm (define-bytevector-accessors): Update
for bytevector untagged indices and values.
* module/language/cps/utils.scm (compute-constant-values): Fix s64
case.
* module/language/tree-il/compile-cps.scm (convert): Box results of all
bytevector accesses, and unbox incoming indices and values.