* 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/system/vm/assembler.scm: Change define encoders for all of the
kinds of instructions and have the emit-foo procedures call the common
encoders. No change to public interface. This decreases the amount
of generated code in the assembler.
* 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.
* module/system/vm/assembler.scm (check-urange, check-srange): New
helpers.
(pack-u8-u24, pack-u8-s24, pack-u1-u7-u24, pack-u8-u12-u12):
(pack-u8-u8-u16, pack-u8-u8-u8-u8): Use the new helpers. Not only
makes the code nicer but also reduces register pressure.
* module/system/vm/assembler.scm (<asm>): Instead of writing words into
a list of fixed-size buffers, use a growable vector.
(expand, emit): Instead of assuming that there is enough space for
only one word, check that there is space for the entire instruction at
the beginning.
* 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.
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Add word
types for immediate f64 and u64 values.
(TYPE_WIDTH): Bump up by a bit, now that we have 32 word types.
(NOP, parse_instruction): Use 64-bit meta type.
* libguile/vm-engine.c (load-f64, load-u64): New instructions.
* module/language/bytecode.scm (compute-instruction-arity): Add parser
for new instruction word types.
* module/language/cps/compile-bytecode.scm (compile-function): Add
special-cased assemblers for new instructions, and also for scm->u64
and u64->scm which I missed before.
* module/language/cps/effects-analysis.scm (load-f64, load-u64): New
instructions.
* module/language/cps/slot-allocation.scm (compute-needs-slot): load-f64
and load-u64 don't need slots.
(compute-var-representations): Update for new instructions.
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
Specialize scm->f64 and scm->u64 to make-f64 and make-u64.
* module/language/cps/types.scm (load-f64, load-u64): Wire up to type
inference, though currently type inference only runs before
specialization.
* module/language/cps/utils.scm (compute-defining-expressions): For some
reason I don't understand, it's possible to see two definitions that
are equal but not equal? here. Allow for now.
(compute-constant-values): Punch through type conversions to get
constant u64/f64 values.
* module/system/vm/assembler.scm (assembler): Support for new word
types. Export the new assemblers.
* libguile/vm-engine.c (add/immediate, sub/immediate)
(uadd/immediate, usub/immediate, umul/immediate): New instructions.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/slot-allocation.scm (compute-needs-slot):
* module/language/cps/types.scm:
* module/system/vm/assembler.scm (system):
* module/language/cps/effects-analysis.scm: Support
for new instructions.
* module/language/cps/optimize.scm (optimize-first-order-cps): Move
primcall specialization to the last step -- the only benefit of doing
it earlier was easier reasoning about side effects, and we're already
doing that in a more general way with (language cps types).
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
Specialize add and sub to add/immediate and sub/immediate, and
specialize u64 addition as well. U64 specialization doesn't work now
though because computing constant values doesn't work for U64s; oh
well.
* libguile/vm-engine.c: Remove add1 and sub1 instructions. Will replace
with add/immediate and sub/immediate.
* module/language/tree-il/peval.scm (peval): If we reify a new
<primcall>, expand it. Removes 1- and similar primcalls.
* module/language/tree-il/primitives.scm: Don't specialize (+ x 1) to 1+.
(expand-primcall): New export, does a single primcall expansion.
(expand-primitives): Use the new helper.
* module/language/cps/effects-analysis.scm:
* module/language/cps/primitives.scm:
* module/language/cps/types.scm:
* module/system/vm/assembler.scm: Remove support for add1 and sub1 CPS
primitives.
* test-suite/tests/peval.test ("partial evaluation"): Adapt tests that
expect 1+/1- to expect +/-.
* module/language/cps/types.scm (vector-ref, vector-set!)
(string-ref, string-set!, struct-ref, struct-set!)
(define-bytevector-accessors, define-bytevector-uaccessors): Clamp
range of object and index to be within the range of indices, with a
maximum of *max-size-t*.
* module/language/cps/types.scm (*max-size-t*): New definition.
(type-entry-saturating-union): Saturate more slowly, first stopping at
[0,*max-size-t*] then at [&range-min, &range-max] before saturating to
[-inf.0, +inf.0]. This allows most offset phi variables to have their
range inferred within the u64 range.
* module/language/cps/specialize-numbers.scm
(compute-specializable-vars): Refactor to work on any kind of
unboxable value, not just f64 values.
(compute-specializable-f64-vars, compute-specializable-u64-vars): New
helpers.
(apply-specialization): Support for u64 values.
* module/language/cps/specialize-numbers.scm
(compute-specializable-u64-vars): New stub.
* module/language/cps/specialize-numbers.scm
(compute-specializable-phis): Rename from
compute-specializable-f64-phis, and return an intmap instead of an
intset. The values distinguish f64 from u64 vars.
* module/language/cps/specialize-numbers.scm (apply-specialization):
Start of u64 phi unboxing.
* module/language/cps/specialize-numbers.scm (specialize-phis):
(specialize-numbers): Adapt.
* module/language/cps/specialize-numbers.scm
(specialize-u64-comparison): New function.
* module/language/cps/specialize-numbers.scm (specialize-operations):
Rename from specialize-f64-operations, as it will specialize both
kinds. Add a case to specialize u64 comparisons.
* module/language/cps/specialize-numbers.scm (specialize-numbers): Adapt
to specialize-operations name change.
* module/language/tree-il/compile-cps.scm (convert): bv-f32-ref,
bv-f32-set!, bv-f64-ref, and bv-f64-set! take the index as an untagged
u64 value.
* module/language/cps/types.scm (define-bytevector-uaccessors): New
helper, used while migrating bytevectors to take unboxed indexes.
Adapt f32/f64 accessors to use this definition helper.
* libguile/vm-engine.c (BV_FLOAT_REF, BV_FLOAT_SET): The index is
unboxed.
* module/language/cps/types.scm (*min-s32*, *max-s32*): Remove unused
definitions.
(&range-min, &range-max): New definitions, replacing min-fixnum and
max-fixnum as the bounds of precise range analysis.
(type-entry-min, type-entry-max): Store inf values directly as
-inf.0/+inf.0.
(type-entry-clamped-min, type-entry-clamped-max): Remove, as they are
no longer needed.
(clamp-min, clamp-max, make-type-entry): Clamp minimum and maximum
half-ranges in different ways.
(type-entry-union, type-entry-saturating-union)
(type-entry-intersection): Adapt to type-entry-min / type-entry-max
change.
(bv-u32-ref, bv-u32-set!):
(bv-s32-ref, bv-s32-set!):
(bv-u64-ref, bv-u64-set!):
(bv-s64-ref, bv-s64-set!): Precise range inference. This will allow
robust unboxing.
(ash): Infer 64-bit shifts.
* module/system/repl/debug.scm (frame->module): Remove. Has been broken
for a while, had no callers, and was calling frame-procedure. We can
revive again in a better way, like ice-9 local-eval.
* module/system/vm/traps.scm (frame-matcher): Always match on a
procedure's code, instead of the value in slot 0. Prevents confusion
with closure-optimized procedures, re-use of slot 0, and untagged
values in slot 0.
(trap-at-procedure-call, trap-in-procedure)
(trap-instructions-in-procedure, trap-at-procedure-ip-in-range)
(trap-at-source-location, trap-in-dynamic-extent)
(trap-calls-in-dynamic-extent, trap-instructions-in-dynamic-extent):
Update to adapt to frame-matcher change and remove #:closure?
argument, effectively changing the default behavior to #:closure? #t.
* doc/ref/api-debug.texi (Low-Level Traps): Update documentation.
* doc/ref/scheme-using.texi (Debug Commands):
* module/system/repl/command.scm (procedure): Remove REPL command.
Since there is a closure binding and we have improved the ,registers
output, this is no longer necessary and by removing it we remove
another bogus use of frame-procedure.
* module/system/vm/frame.scm (frame-call-representation): Never use
frame-procedure, as we don't know that slot 0 is a SCM value and even
if it were, we don't know that it corresponds to the procedure being
applied, except in the case of primcalls. Print _ as the procedure
name if we don't know it, instead of #f.
* libguile/frames.c (frame_procedure_name_var): New static definition.
(init_frame_procedure_name_var): New helper.
(scm_frame_procedure_name): New function that returns the name of the
frame's procedure, as frame-procedure is to be deprecated.
* libguile/frames.h (scm_frame_procedure_name): Export.
* module/ice-9/boot-9.scm (exception-printers): Use frame-procedure-name
instead of procedure-name on frame-procedure.
* module/system/vm/frame.scm (frame-procedure-name): New private
function, implementing scm_frame_procedure_name.
(frame-call-representation): Use frame-procedure-name to get the
procedure name to print.
We need to be able to identify frames that are primitive applications
without assuming that slot 0 in a frame is an SCM value and without
assuming that value is the procedure being applied.
* libguile/gsubr.c (scm_i_primitive_code_p): New helper.
(scm_i_primitive_arity): Use the new helper.
* libguile/gsubr.h: Declare the new helper.
* libguile/programs.h:
* libguile/programs.c (scm_program_code_p): New function, replacing
scm_primitive_p.
(scm_primitive_call_ip): Fix FUNC_NAME definition.
* module/statprof.scm (sample-stack-procs, count-call): Identify
primitive frames from the IP, not the frame-procedure. Avoids the
assumption that slot 0 in a frame is a SCM value.
(statprof-proc-call-data): Adapt to primitive-code? change.
* module/system/vm/frame.scm (frame-call-representation): Identify
primitive frames from the IP, not the closure. Still more work to do
here to avoid assuming slot 0 is a procedure.
* module/system/vm/program.scm: Export primitive-code? instead of
primitive?.
(program-arguments-alist, program-arguments-alists): Identify
primitives from the code instead of the flags on the program. Not
sure this is a great change, but it does avoid having to define a
primitive? predicate in Scheme.
* module/language/cps/compile-bytecode.scm (compile-function): Always
define a 'closure binding in slot 0.
* module/system/vm/frame.scm (available-bindings): No need to futz
around not having a closure binding.
* module/system/vm/debug.scm (arity-arguments-alist): Expect a closure
binding.
* test-suite/tests/rtl.test: Emit definitions for the closure.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/primitives.scm (*branching-primcall-arities*):
* module/language/cps/type-fold.scm (equal?):
* module/language/cps/types.scm (equal?):
* module/language/tree-il/compile-cps.scm (convert): `equal?' is no
longer a branching primcall, because it isn't inline. The
implementation could lead to bad backtraces also, as it didn't save
the IP, and actually could lead to segfaults as it didn't reload the
SP after the return. There is an eqv? fast-path, though.
* module/system/vm/assembler.scm (br-if-equal): Remove interface.
* module/system/vm/disassembler.scm (code-annotation):
(compute-labels): No need to handle br-if-equal.
* module/ice-9/eval.scm (primitive-eval): Specialize lexical-ref for
depths 0, 1, and 2. Speeds up this test by around 13%:
(primitive-eval '(let lp ((n 0)) (when (< n #e1e7) (lp (1+ n)))))
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION):
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump
bytecode version to prevent 2.1.1 users from thinking that they don't
need to make clean after pulling.
* module/language/cps/specialize-numbers.scm (apply-f64-specialization):
Remove printout. I didn't see any when compiling Guile, which means
that probably this optimization doesn't hit for any code in Guile
itself, sadly :P