* 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/statprof.scm: Remove most of the commentary, as it was
duplicated in the manual and was getting out of date.
(stats): Remove self-secs-per-call and cum-secs-per-call fields as
they can be computed from the other fields.
(statprof-call-data->stats): Adapt.
(statprof-stats-self-secs-per-call):
(statprof-stats-cum-secs-per-call): New functions.
(statprof-display/flat): Don't print the seconds-per-call fields, as
we are no longer stopping the clock around call counters. Anyway
these times were quite misleading.
(with-statprof): Deprecate. It took its keyword arguments at the
beginning; very complicated! Better to use the `statprof' function.
(`statprof' was introduced after `with-statprof' and then
`with-statprof' was adapted to use it.)
* doc/ref/statprof.texi (Statprof): Port this documentation away from
the automatically generated text and update it for the new interfaces
like #:display-style.
* module/system/base/syntax.scm (record-case): Remove comment that
referenced with-statprof. Add comment indicating that record-case
should be replaced.
* doc/ref/scheme-using.texi (Profile Commands): Update to mention
keyword arguments and to link to the statprof documentation.
* module/statprof.scm: Update commentary.
(count-call): Don't bother stopping and starting the timer. The
overhead of call counting perturbs timing too much already, and
somewhat paradoxically stopping and starting the timer takes too much
time.
(skip-count-call): New function.
(stack-samples->procedure-data, stack-samples->callee-lists): If we
are counting calls, skip any part of the stack that is inside
count-call.
* module/system/repl/debug.scm (print-locals): Adapt to
frame-binding-ref change.
* module/system/vm/frame.scm (<binding>): Add `frame' field.
(available-bindings): Capture the frame.
(binding-ref, binding-set!): New functions, accessing a local variable
value directly from a frame.
(frame-binding-ref, frame-binding-set!): Remove. As these are very
low-level debugging interfaces introduced in 2.0, never documented,
and quite tied to the VM, we feel comfortable making this change.
(frame-call-representation): Adapt to available-bindings change.
(frame-environment, frame-object-binding): Adapt to binding-ref
interface change.
* doc/ref/vm.texi (Stack Layout): Mention that slots can be re-used.
Update disassembly in example.
* doc/ref/api-debug.texi (Frames): Remove documentation for
frame-local-ref, frame-local-set!, and frame-num-locals. Replace with
documentation for frame-bindings, binding accessors, and binding-ref /
binding-set!.
* libguile/frames.h (scm_frame_num_locals, scm_frame_local_ref)
(scm_frame_local_set_x): Remove. As long as we are changing the
interface in a backward-incompatible way, we might as well remove
these.
* libguile/frames.c (scm_frame_num_locals, scm_frame_local_ref)
(scm_frame_local_set_x, scm_init_frames_builtins, scm_init_frames):
Arrange to make frame-local-ref et al private to frames.scm.
* module/system/vm/frame.scm: Load scm_init_frames_builtins extensions.
(frame-instruction-pointer-or-primitive-procedure-name): New public
function.
(frame-binding-ref, frame-binding-set!): Allow binding objects as
vars.
* module/system/repl/debug.scm (print-locals): Pass binding directly to
frame-binding-ref.
* module/statprof.scm (sample-stack-procs, count-call): Use new
frame-instruction-pointer-or-primitive-procedure-name function.
* module/system/vm/assembler.scm (define-byte-order-swapper): New
helper.
(byte-swap/2!, byte-swap/4!, byte-swap/8!): New functions.
(link-data): Swap bytes in uniform vectors on foreign byte orders.
* module/system/vm/assembler.scm (immediate-bits): Rename from
immediate?, and return the bits. Take asm argument so that we measure
what's an immediate not on the host but for the target. Adapt all
callers.
(write-immediate): Take bits instead of SCM object. Adapt callers.
(write-placeholder): New helper, to write bits for #f. Adapt callers
that wrote #f to use write-placeholder.
* module/statprof.scm (statprof-fetch-call-tree): Add #:precise? keyword
argument, defaulting to false. Search for cycles after computing
printable source locations instead of doing so over addresses -- it
could be that two addresses map to the same source location, and from
the user's perspective they are then indistinguishable in the
printout.
* module/statprof.scm (statprof-display/flat): Rename from
statprof-display. Use real format; we have it.
(statprof-display-anomalies): Likewise use real format.
(procedure=?): Remove unused function.
(collect-cycles): New helper.
(statprof-fetch-call-tree): Fix to root the trees correctly -- it was
interpreting them in the wrong order. Detect cycles so that it's not
so terrible. Use precise locations for source locations. Probably
need to add an option to go back to the per-function behavior.
(statprof-display/tree): New helper, uses statprof-fetch-call-tree to
display a profile in a nested tree.
(statprof-display): Add #:style argument, which can be `flat',
`anomalies', or `tree'.
(statprof): Add #:display-style argument, proxying to #:style,
defaulting to 'flat.
* module/web/http.scm (parse-entity-tag): Be less strict, accepting
unquoted strings as well.
* test-suite/tests/web-http.test ("response headers"): Add a test for
etag parsing.
* 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/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.