Andy Wingo [Fri, 28 Feb 2014 18:42:04 +0000 (19:42 +0100)]
Refactorings: call-data has source, stats is a record
* module/statprof.scm (call-data): Add source member.
(stack-samples->procedure-data): Populate source member
(stats): Convert to record from vector.
(statprof-call-data->stats): Adapt to produce a record.
Andy Wingo [Fri, 28 Feb 2014 18:31:46 +0000 (19:31 +0100)]
Statprof uses stack trace buffer to always provide full stacks
* module/statprof.scm (<state>): Remove record-full-stacks? and stacks
members. The stack trace buffer is sufficient.
(fresh-profiler-state): Adapt.
(sample-stack-procs): Don't save stacks.
(statprof-reset): Deprecate the full-stacks? argument.
(stack-samples->procedure-data): Remove a needless vector-ref.
(stack-samples->callee-lists): New helper.
(statprof-fetch-stacks): Use stack-samples->callee-lists.
(statprof-fetch-call-tree): Use stack-samples->callee-lists, and
implement our own callee->string helper.
(statprof, with-statprof, gcprof): Deprecate full-stacks? argument.
Andy Wingo [Fri, 28 Feb 2014 17:35:25 +0000 (18:35 +0100)]
Statprof always stores full stack traces
* module/statprof.scm (<state>): Instead of a boolean count-calls?,
treat the presence of a call-counts hash table as indicating a need to
count calls. That hash table maps callees to call counts. A "callee"
is either the IP of the entry of a program, the symbolic name of a
primitive, or the identity of a non-program.
New members "buffer" and "buffer-pos" replace "procedure-data".
We try to avoid analyzing things at runtime, instead just recording
the stack traces into a buffer. This will let us do smarter things
when post-processing.
(fresh-buffer, expand-buffer): New helpers.
(fresh-profiler-state): Adapt to <state> changes.
(sample-stack-procs): Instead of updating the procedure-data
table (which no longer exists), instead trace the stack into the
buffer.
(count-call): Update to update the call-counts table instead of the
procedure-data table.
(statprof-start, statprof-start): Adapt to call-counts change.
(call-data): Move lower in the file. Add "name" and "printable"
members, and no longer store a proc.
(source->string, program-debug-info-printable, addr->pdi)
(addr->printable): New helpers.
(stack-samples->procedure-data): New procedure to process stack trace
buffer into a hash table of the same format as the old procedure-data
table.
(statprof-fold-call-data, statprof-proc-call-data): Use
stack-samples->procedure-data instead of procedure-data.
(statprof-call-data->stats): Adapt to count-calls change.
(statprof-display, statprof-display-anomalies): Adapt.
Andy Wingo [Fri, 28 Feb 2014 16:42:45 +0000 (17:42 +0100)]
(system vm program) exports primitive?
* module/system/vm/program.scm: Export primitive?. Primitive
program-code doesn't map uniquely to the primitive, which may be of
interest to various meta-level utilities like statprof.
Andy Wingo [Fri, 28 Feb 2014 16:15:42 +0000 (17:15 +0100)]
Improve statprof test
* test-suite/tests/statprof.test ("statistical sample counts within
expected range"): Increase number of calls, as the computer speed
increases and VM/compiler speed increases have meant that we get fewer
samples than before. Also, compare the maximum deviation to the
square root of the expected value. I don't actually know what the
right statistical check is here, but this is closer to an "all points
fall within a standard deviation" than our previous 30% check. Print
a nicer warning when the check fails.
Andy Wingo [Fri, 28 Feb 2014 10:57:12 +0000 (11:57 +0100)]
Update statprof commentary
* module/statprof.scm: Update commentary.
Andy Wingo [Fri, 28 Feb 2014 10:27:56 +0000 (11:27 +0100)]
More state-related refactors in statprof
* module/statprof.scm (statprof-start, statprof-stop): Take optional
state arg.
(statprof-reset): Return no values.
(statprof): Take port keyword arg. Since statprof-reset is now the
same as parameterizing profiler-state, there's no need to call
statprof-reset. Pass the state argument explicitly to statprof-start,
statprof-stop, and statprof-display.
Andy Wingo [Fri, 28 Feb 2014 10:17:37 +0000 (11:17 +0100)]
Statprof restores previous sigprof handler when stopping
* module/statprof.scm (<state>): Add field for the previous SIGPROF
handler.
(statprof-start, statprof-stop, statprof-reset): Instead of setting
the SIGPROF handler in statprof-reset, set it when the profiler
becomes active, and actually restore it when the profiler becomes
inactive.
Andy Wingo [Fri, 28 Feb 2014 10:06:55 +0000 (11:06 +0100)]
More statprof refactors
* module/statprof.scm (statprof-display, statprof-display-anomalies)
(statprof-accumulated-time, statprof-sample-count)
(statprof-fetch-stacks, statprof-fetch-call-tree): Take optional state
argument.
(statprof-display-anomolies): Deprecate this mis-spelling.
(statprof): Just compute usecs for the period.
Andy Wingo [Fri, 28 Feb 2014 09:48:41 +0000 (10:48 +0100)]
Slight gcprof refactor
* module/statprof.scm (gcprof): Refactor a bit.
Andy Wingo [Fri, 28 Feb 2014 09:36:21 +0000 (10:36 +0100)]
statprof uses new setitimer magical usecs ability
* module/statprof.scm (sample-stack-procs): Take advantage of setitimer
allowing usecs >= 1e6.
Andy Wingo [Fri, 28 Feb 2014 09:31:12 +0000 (10:31 +0100)]
Fix setitimer documentation. Allow microseconds >= 1e6.
* doc/ref/posix.texi (Signals): Fix the documentation for setitimer; it
was wrong.
* libguile/scmsigs.c (pack_tv): New helper. Allow usecs >= 1e6.
(unpack_tv): New helper.
(scm_setitimer): Use the new helpers.
* test-suite/tests/signals.test: Add setitimer tests.
Andy Wingo [Thu, 27 Feb 2014 16:16:29 +0000 (17:16 +0100)]
Fix newline preservation in @example with lines beginning with @
* module/texinfo.scm (read-char-data): Preserve newlines in @example and
similar environments in the case when the next line starts with an @.
* test-suite/tests/texinfo.test ("test-texinfo->stexinfo"): Add a test.
Andy Wingo [Tue, 25 Feb 2014 21:46:32 +0000 (22:46 +0100)]
gcprof tweaks
* module/statprof.scm (gcprof): No need to reset in gcprof; the fresh
profiler state and the parameterize handle that. Fix mistaken
set-vm-trace-level! as well.
Andy Wingo [Tue, 25 Feb 2014 21:40:32 +0000 (22:40 +0100)]
Refactor representation of sampling periods in statprof
* module/statprof.scm (<state>): The sampling frequency is actually a
period; label it as such, and express in microseconds instead of as a
pair. Likewise for remaining-prof-time.
(fresh-profiler-state): Adapt.
(reset-sigprof-timer): New helper.
(profile-signal-handler): Use the new helper.
(statprof-start): Use the new helper.
(statprof-stop): Here too.
(statprof-reset): Adapt to <state> change.
(gcprof): Set remaining prof time to 0.
Andy Wingo [Tue, 25 Feb 2014 21:16:49 +0000 (22:16 +0100)]
statprof and gcprof procedures use a fresh statprof state
* module/statprof.scm (statprof, gcprof): Create a fresh statprof
state.
Andy Wingo [Tue, 25 Feb 2014 20:32:36 +0000 (21:32 +0100)]
Simplification pass prunes all unreachable continuations
* module/language/cps/simplify.scm (prune-continuations): Prune
continuations as a post-pass with a fresh DFG. Using a
pre-eta-conversion DFG as we were doing before missed some cases.
Andy Wingo [Sat, 22 Feb 2014 16:02:53 +0000 (17:02 +0100)]
simplify profile-signal-handler
* module/statprof.scm (profile-signal-handler): Don't bother detecting
if we were in a count-call call or not; it doesn't matter, and we
should accumulate time in any case.
Andy Wingo [Sat, 22 Feb 2014 15:31:31 +0000 (16:31 +0100)]
statprof: accumulated-time is in jiffies
* module/statprof.scm (fresh-profiler-state): accumulated-time and
gc-time-taken are in jiffies, not seconds, so they are exact.
(statprof-accumulated-time): Divide by 1.0 so that we get a flonum.
Also refactor use of assq to get the gc-time-taken.
Andy Wingo [Sat, 22 Feb 2014 14:39:29 +0000 (15:39 +0100)]
Zero-offset branches are backward branches; fix "br" backward branches
* libguile/vm-engine.c (BR_UNARY, BR_BINARY, BR_ARITHMETIC): A jump with
a zero offset is also a backward branch, in the sense that it's not a
forward branch.
("br"): We forgot to VM_HANDLE_INTERRUPTS here on backwards branches.
Oops!
Andy Wingo [Sat, 22 Feb 2014 14:34:46 +0000 (15:34 +0100)]
Avoid attempting to eta-reduce self-loops.
* module/language/cps/simplify.scm (compute-eta-reductions): Avoid
trying to eta-reduce a jump-to-self, as in (let lp () (lp)). This
caused the compiler to hang.
Andy Wingo [Sat, 22 Feb 2014 14:09:54 +0000 (15:09 +0100)]
Pass state around statprof in more places
* module/statprof.scm (get-call-data, sample-stack-procs): Take the
state as an argument.
(profile-signal-handler, count-call, statprof-proc-call-data)
(gcprof): Adapt.
Andy Wingo [Sat, 22 Feb 2014 13:59:21 +0000 (14:59 +0100)]
statprof: call-data is a record type
* module/statprof.scm (call-data): Reimplement as a record type.
Andy Wingo [Sat, 22 Feb 2014 13:54:17 +0000 (14:54 +0100)]
statprof: when/unless instead of if.
* module/statprof.scm: Use when or unless instead of if, where
appropriate.
Andy Wingo [Fri, 21 Feb 2014 21:18:02 +0000 (22:18 +0100)]
add a statprof fixme
* module/statprof.scm: Add a fixme.
Andy Wingo [Fri, 21 Feb 2014 21:12:47 +0000 (22:12 +0100)]
statprof-active? instead of checking profile level
* module/statprof.scm (statprof-reset, statprof-fold-call-data):
(statprof-proc-call-data, statprof-accumulated-time):
(statprof-sample-count): Refactor some things to use statprof-active?
instead of checking the profile level manually.
Andy Wingo [Fri, 21 Feb 2014 20:56:01 +0000 (21:56 +0100)]
statprof-reset creates a new state
* module/statprof.scm (fresh-profiler-state): New helper.
(ensure-profiler-state): Use it.
(accumulate-time): No need to add 0.0 here.
(statprof-reset): Create a new state instead of mutating the existing
one.
Andy Wingo [Fri, 21 Feb 2014 20:43:39 +0000 (21:43 +0100)]
More statprof state refactorings
* module/statprof.scm (existing-profiler-state): New helper, gets the
profiler state or fails if there is no state.
(sample-stack-procs, profile-signal-handler, count-call)
(statprof-fold-call-data, statprof-proc-call-data)
(statprof-call-data->stats, statprof-display)
(statprof-display-anomolies, statprof-accumulated-time)
(statprof-sample-count, statprof-fetch-stacks)
(statprof-fetch-call-tree): Use the new helper.
(statprof-active?): Don't create a state if there isn't one already.
Andy Wingo [Fri, 21 Feb 2014 20:25:50 +0000 (21:25 +0100)]
inside-profiler? to parameter instead of global variable
* module/statprof.scm (<state>): Add inside-profiler? member. Move
mutations of inside-profiler? here.
Andy Wingo [Fri, 21 Feb 2014 20:01:10 +0000 (21:01 +0100)]
Beginnings of statprof threadsafety
* module/statprof.scm (<state>, profiler-state, ensure-profiler-state):
A mostly-mechanical refactor to encapsulate profiler state in a
parameter and a record instead of global variables.
Andy Wingo [Fri, 21 Feb 2014 18:20:16 +0000 (19:20 +0100)]
reform statprof commentary
* module/statprof.scm: Reformat the commentary.
Andy Wingo [Fri, 21 Feb 2014 13:42:24 +0000 (14:42 +0100)]
Fix segfault in thread_mark
* libguile/threads.c (thread_mark): There is a window in which the
thread has a handle but doesn't yet have the set of pointerless
freelists, so don't unconditionally dereference
t->pointerless_freelists.
Andy Wingo [Thu, 20 Feb 2014 20:09:08 +0000 (21:09 +0100)]
Threadsafe stack relocation
* libguile/vm.c (vm_return_to_continuation, vm_expand_stack):
(vm_reinstate_partial_continuation): Hold the GC lock while relocating
the stack.
Andy Wingo [Thu, 20 Feb 2014 18:57:47 +0000 (19:57 +0100)]
assertion refactor in the vm
* libguile/vm.c:
* libguile/vm-engine.c: Change the one use of
VM_ENABLE_PARANOID_ASSERTIONS to ASSERT. That becomes the one use of
VM_ENABLE_ASSERTIONS, so disable that too.
Andy Wingo [Thu, 20 Feb 2014 09:43:40 +0000 (10:43 +0100)]
Fix "VM never extends vp->sp ..." commit
* libguile/vm.c (vm_expand_stack): Make sure the new SP is visible to
vm_error if we throw because of stack overflow.
Andy Wingo [Thu, 20 Feb 2014 09:21:51 +0000 (10:21 +0100)]
Remove the hard stack size limit
* libguile/vm.c (vm_expand_stack): Remove the hard stack size limit.
Andy Wingo [Thu, 20 Feb 2014 09:17:51 +0000 (10:17 +0100)]
VM never extends vp->sp beyond mapped region of stack
* libguile/vm-engine.c (ALLOC_FRAME): Fold CHECK_OVERFLOW into this
routine, and rework to not extend vp->sp until the stack has been
expanded.
* libguile/vm.c (vm_increase_sp): Likewise, don't extend vp->sp until
the stack has expanded.
(vm_expand_stack): Rework to take the new stack pointer as an
argument, and also to update vp->sp_max_since_gc and vp->sp.
Andy Wingo [Thu, 20 Feb 2014 08:45:01 +0000 (09:45 +0100)]
Unwind-only stack overflow exceptions
* module/ice-9/boot-9.scm (catch): Signal an early error if the handler
or pre-unwind handler types aren't right. This is more important than
it was, given that we dispatch on type now when finding matching catch
clauses.
* libguile/vm.c (vm_expand_stack): Use the standard
scm_report_stack_overflow to signal stack overflow. This will avoid
running pre-unwind handlers.
* libguile/throw.h: Move scm_report_stack_overflow here.
* libguile/throw.c (catch): Define a version of catch in C.
(throw_without_pre_unwind): New helper. Besides serving as the
pre-boot "throw" binding, it allows stack overflow to throw without
running pre-unwind handlers.
(scm_catch, scm_catch_with_pre_unwind_handler)
(scm_with_throw_handler): Use the new catch in C.
(scm_report_stack_overflow): Moved from stackchk.c; throws an
unwind-only exception.
* libguile/stackchk.h:
* libguile/stackchk.c: Remove the scm_report_stack_overflow bits.
Andy Wingo [Wed, 19 Feb 2014 20:56:48 +0000 (21:56 +0100)]
%exception-handler fluid refactor
* libguile/throw.c (scm_init_throw): Define %exception-handler here.
* module/ice-9/boot-9.scm (%eh): Use the incoming %exception-handler,
and then delete it. This way we should be able to do unwind-only
exceptions from C.
Andy Wingo [Wed, 19 Feb 2014 18:43:48 +0000 (19:43 +0100)]
Reimplement catch, throw, and with-throw-handler
* module/ice-9/boot-9.scm: Reimplement catch, throw, and
with-throw-handler in such a way that the exception handler is
threaded not through the exception-handling closures, but through a
data structure in the exception-handler fluid. This will allow us to
do unwind-only exception dispatch on stack overflow.
Andy Wingo [Wed, 19 Feb 2014 15:54:40 +0000 (16:54 +0100)]
boot-9 boot order refactor for catch, throw, and such
* module/ice-9/boot-9.scm: Move error-handling initialization after
psyntax initialization. Only "throw" is used before psyntax, and both
throw and catch have pre-boot variants in C.
Andy Wingo [Wed, 19 Feb 2014 10:19:10 +0000 (11:19 +0100)]
Fix scm_i_vm_capture_stack comment.
* libguile/vm.c (scm_i_vm_capture_stack): Fix a comment.
Andy Wingo [Wed, 19 Feb 2014 10:11:46 +0000 (11:11 +0100)]
Default stack size is one page.
* libguile/vm.c (initialize_default_stack_size): Initial stack size is
one page.
Andy Wingo [Wed, 19 Feb 2014 10:01:39 +0000 (11:01 +0100)]
More robust stack expansion and contraction
* libguile/vm.c (allocate_stack, expand_stack): Return NULL on
allocation failure instead of throwing an exception. Throwing an
exception is tricky to get right, and we need more context to do it
correctly.
(return_unused_stack_to_os): Try again if madvise returns -EAGAIN. If
madvise fails, print an error message.
(vm_expand_stack): Abort if stack expansion fails. We'll fix this in
a future patch.
(make_vm): Abort if we can't mmap a single page.
Andy Wingo [Mon, 17 Feb 2014 21:23:40 +0000 (22:23 +0100)]
Don't peval-penalize let-bound lambdas only referenced once
* module/language/tree-il/peval.scm (peval): When going to peval a call
whose operator isn't just a lambda but is a let-bound lambda, as one
bound via define-inlinable, don't create a new counter if the lambda
is only referenced once in the source. Avoids needless failure to
inline once-referenced procedures.
* test-suite/tests/peval.test ("partial evaluation"): Wheeeee
Andy Wingo [Mon, 17 Feb 2014 13:15:30 +0000 (14:15 +0100)]
PT_DYNAMIC inside some other PT_LOAD segment
* libguile/loader.c (load_thunk_from_memory): Only load PT_LOAD
segments, as libc does. The PT_DYNAMIC segment should be inside some
other PT_LOAD segment.
* module/system/vm/linker.scm (segment-kind): Give the .dynamic segment
PT_LOAD kind, so that it is written in a PT_LOAD segment.
(count-segments): Add one if there is a SHT_DYNAMIC segment.
(allocate-segment): Set the paddr to the addr, as binutils do.
(record-special-segments): New routine, to write out special segments
like PT_DYNAMIC.
(allocate-elf): Call record-special-segments.
Andy Wingo [Sun, 16 Feb 2014 14:58:44 +0000 (15:58 +0100)]
Add elf-symbol-value-offset, for properly relocating symtab entries
* module/system/vm/elf.scm (elf-symbol-value-offset): New export.
Andy Wingo [Sun, 16 Feb 2014 11:18:44 +0000 (12:18 +0100)]
ELF linker can produce objects with native ABI
* module/system/vm/elf.scm: Define more ABI types and ELF object types.
Export the ABI, object type, and machine type values.
* module/system/vm/linker.scm (<linker-reloc>, process-reloc): Allow
rel32/1 relocs.
(add-elf-objects, allocate-elf, link-elf): Allow the user to set an
ABI, type, and machine-type.
Andy Wingo [Fri, 14 Feb 2014 09:49:45 +0000 (10:49 +0100)]
bytevector-length reifies to correct module
* module/language/cps/reify-primitives.scm (primitive-module): Whoops,
bytevector-length is needs to map to the (rnrs bytevectors) module.
Andy Wingo [Thu, 13 Feb 2014 16:51:11 +0000 (17:51 +0100)]
bytevector-length is an interesting primitive.
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
(*effect-free-primitives*):
* module/language/cps/effects-analysis.scm: bytevector-length is an
interesting primitive.
Andy Wingo [Thu, 13 Feb 2014 10:04:55 +0000 (11:04 +0100)]
sqrt and abs are interesting primitives
* module/language/cps/effects-analysis.scm:
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
(*effect-free-primitives*): Add sqrt and abs.
Andy Wingo [Thu, 13 Feb 2014 08:30:39 +0000 (09:30 +0100)]
Add prune-top-level-scopes pass
* module/language/cps/prune-top-level-scopes.scm: New pass, to prune
unneeded "cache-current-module!" forms.
* module/language/cps/compile-bytecode.scm:
* module/Makefile.am: Add the new pass to the build and enable by
default.
Andy Wingo [Tue, 11 Feb 2014 20:54:05 +0000 (21:54 +0100)]
Bytevector f32 an f64 ops actually map to VM primitives
* module/language/cps/primitives.scm (*instruction-aliases*): Whoops!
Fix mapping of f32 and f64 instructions to VM primitives.
Andy Wingo [Tue, 11 Feb 2014 19:59:38 +0000 (20:59 +0100)]
guile.m4 tweaks
* meta/guile.m4 (GUILE_PKG): Don't print "checking for guile 2.0" if
we've already found 2.2. Print the correct effective version at the
end.
(GUILE_PROGS): Allow prereleases, whose micro version does not yet
match the effective version. Default to the already-chosen effective
version.
Daniel Llorens [Wed, 8 May 2013 14:06:40 +0000 (16:06 +0200)]
array-contents returns root for empty arrays with empty root
This fixes a compiler issue where (uniform-array->bytevector #2f64())
failed because of the stricter definition of uniform-vector? on this branch.
Perhaps it would be better if uniform-array->bytevector didn't require
a contiguous argument.
* libguile/arrays.c: (scm_array_contents): return the root regardless of
the value of SCM_I_ARRAY_DIMS (ra)->inc.
* test-suite/tests/arrays.test: check.
Daniel Llorens [Thu, 2 May 2013 09:43:31 +0000 (11:43 +0200)]
Add tests for more kinds of typed arrays.
* test-suite/tests/arrays.test: Add more type array tests.
Daniel Llorens [Tue, 30 Apr 2013 14:11:07 +0000 (16:11 +0200)]
Preallocate index list in scm_array_index_map_x
* libguile/array-map.c
- (scm_array_index_map_x): preallocate the index list instead of
constructing it on each rank-1 iteration.
- (ramap, rafe): use SCM_I_ARRAY_V just once.
Daniel Llorens [Mon, 29 Apr 2013 12:19:52 +0000 (14:19 +0200)]
Match types used in arrays.c to struct field types
* libguile/arrays.c
- scm_shared_array_root: check for SCM_I_ARRAYP first.
- scm_i_shap2ra:
* check valid bounds in the '(lbnd ubnd) case. This makes
(make-array 0 '(4 -3)) fail with a 'bad dimension' instead of
with a 'wrong index' error.
* use ssize_t for lbnd/ubnd/inc, not long.
- scm_make_shared_array: use ssize_t for indices, not long.
- scm_transpose_array: use size_t for ndim, not ulong.
- scm_i_print_array: idem.
Daniel Llorens [Fri, 26 Apr 2013 11:02:38 +0000 (13:02 +0200)]
Don't use ASET in scm_array_index_map_x
* libguile/array-map.c: (scm_array_index_map_x): replace ASET by direct
use of handle->impl.
Daniel Llorens [Fri, 26 Apr 2013 00:05:22 +0000 (02:05 +0200)]
In scm_ramapc, only check unrolled axes for emptiness
* libguile/array-map.c: (scm_ramapc)
- Don't check emptiness while preparing ra0, but only after kroll is known,
and only before kroll. len = 0 will be caught by the unrolled loop.
- Use ra0 axis length in unroll check depth for rest args, not ra1's.
- Recover early exit feature when cproc returns 0.
Daniel Llorens [Thu, 25 Apr 2013 13:18:05 +0000 (15:18 +0200)]
Fix corner cases of scm_ramapc
* libguile/array-map.c
- (scm_ramapc): mismatched axes limit unrollk (kroll). Reorganize
the function to do all checking as we go.
- (scm_ra_matchp): unused; remove.
- (find_unrollk): inlined in scm_ramapc; remove.
- (klen): inlined in scm_ramapc; remove.
- (rafill): n is size_t.
- (racp): n is size_t. Use n and not i0end to bound the loop.
- (ramap): Use n and not i0end to bound the loop. This is needed for the rank
0 case to work with the new scm_ramapc, as inc may be set to 0 in that case.
- (rafe): idem.
* test-suite/tests/ramap.test
- check that size mismatch prevents unrolling (matching behavior III) with
both array-copy! and array-map!.
- check that non-contiguous stride in non-ref args prevents unrolling
(rank 2, discontinuous) with both array-copy! and array-map!.
- check rank 0 cases with array-for-each, array-map!.
- Test the 0-inc, non empty case for both array-map! and array-copy!.
Daniel Llorens [Wed, 24 Apr 2013 21:29:48 +0000 (23:29 +0200)]
Rewrite scm_ramapc()
* libguile/array-map.c
- (cind): replace by cindk, that operates only on the unrolled index set.
- (klen): new function.
- (make1array): take extra inc argument.
- (scm_ramapc): rewrite to unroll as many axes as possible instead of just all
or one.
- (AREF): lbnd is known to be 0: remove.
- (ASET): v is known to come from SCM_I_ARRAY_V; assume base, inc, lbnd.
- (racp): use ssize_t instead of long for the indices.
- (scm_array_index_map_x): build the index list at the last-but-one axis, then
set the car of the last element, instead of building the list at the last axis.
* test-suite/tests/ramap.test
- add array-map! test with offset arguments.
Daniel Llorens [Fri, 19 Apr 2013 14:44:48 +0000 (16:44 +0200)]
Factor out make1array() in scm_ramapc()
* libguile/array-map.c: (scm_ramapc): factor out vector->array conversion
to aux function make1array.
Daniel Llorens [Wed, 24 Apr 2013 15:13:56 +0000 (17:13 +0200)]
Check more cases of array-contents
* libguile/arrays.c: (scm_array_contents): fix comment.
* test-suite/tests/arrays.test: add cases that depend on correct
setting of CONTIGUOUS_FLAG.
Daniel Llorens [Fri, 19 Apr 2013 23:27:42 +0000 (01:27 +0200)]
Refactor array-contents
* libguile/arrays.c (scm_array_contents): Branch cases not on
scm_is_generalized_vector but on SCM_I_ARRAYP. Thus lbnd!=0, which
could happen with scm_is_generalized_vector, never appears in the
output.
* test-suite/tests/arrays.test: Test array-contents.
Daniel Llorens [Wed, 24 Apr 2013 14:34:31 +0000 (16:34 +0200)]
Check the documented matching behavior of array-map!/copy!
* test-suite/tests/arrays.test: move array-copy! tests to ramap.test.
* test-suite/tests/ramap.test: check the dissimilar matching behavior of
array-copy! and array-map! with arguments of different size.
Andy Wingo [Sun, 9 Feb 2014 20:11:08 +0000 (21:11 +0100)]
Reindent scm_ramapc
* libguile/array-map.c (scm_ramapc): Reindent.
Daniel Llorens [Fri, 19 Apr 2013 12:53:34 +0000 (14:53 +0200)]
Raw pointer loop in array-copy! for vector/vector case
This special case improves
(define a (make-array 1.
1000000 10))
(define b (make-array *unspecified*
1000000 10))
(define c (transpose-array (make-array *unspecified* 10
1000000) 1 0))
,time (array-copy! a b)
,time (array-copy! a c)
from 0.041598s / 0.072561 to 0.012164s / 0.041886s on a i7-3930K.
* libguile/array-map.c: (racp): if both src and dst are on vectors, use
the element pointers to do the copy.
Andy Wingo [Sun, 9 Feb 2014 19:56:55 +0000 (20:56 +0100)]
Simplify scm_array_get_handle for tc7-arrays
* libguile/array-handle.c (scm_array_get_handle): Simplify for the array
case, as suggested by Daniel Llorens.
Daniel Llorens [Wed, 17 Apr 2013 12:33:40 +0000 (14:33 +0200)]
Test that typed-array? returns #f with non-array argument
* test-suite/tests/arrays.test: ditto.
Daniel Llorens [Wed, 17 Apr 2013 08:19:26 +0000 (10:19 +0200)]
Replace SCM_IMP in array-map.c
* libguile/array-map.c
- scm_ramapc: check scm_array_contents with scm_is_false.
Andy Wingo [Sun, 9 Feb 2014 11:31:59 +0000 (12:31 +0100)]
Remove array impl. registry; instead, hard-code array handle creation
* libguile/array-handle.h (scm_t_vector_ref, scm_t_vector_set): Rename
from scm_t_array_ref, scm_t_array_set. These were named
scm_i_t_array_ref and scm_i_t_array_set in 1.8 and 2.0. Change to
take the vector directly, instead of the array handle. In this way,
generic array handles are layered on top of specific implementations
of backing stores.
Remove scm_t_array_implementation, introduced in 2.0 but never
documented. It was a failed attempt to layer the array implementation
that actually introduced too many layers, as it prevented the "vref"
and "vset" members of scm_t_array_handle (called "ref" and "set" in
1.8, not present in 2.0) from specializing on array backing stores.
(scm_i_register_array_implementation) (scm_i_array_implementation_for_obj):
Remove these internal interfaces.
(scm_t_array_handle): Adapt to scm_t_vector_ref / scm_t_vector_set
change.
(scm_array_handle_ref, scm_array_handle_set): Adapt to change in
vref/vset prototype.
* libguile/array-handle.c (scm_array_get_handle): Inline all the
necessary initializations here for all specific array types.
* libguile/array-map.c (rafill, racp, ramap, rafe, array_index_map_1):
* libguile/arrays.c: Remove array implementation code.
* libguile/bitvectors.h:
* libguile/bitvectors.c: Remove array implementation code.
(scm_i_bitvector_bits): New internal interface.
* libguile/bytevectors.c: Remove array implementation code.
* libguile/srfi-4.h: Remove declarations for internal procedures that
don't exist (!).
* libguile/strings.c: Remove array implementation code.
* libguile/vectors.c: Remove array implementation code.
Daniel Llorens [Fri, 19 Apr 2013 10:57:13 +0000 (12:57 +0200)]
Fix array map functions with empty arguments
* libguile/array-map.c
- scm_ra_matchp: look for empty axes and return new case 5 if so. Use
array handles to remove the SCM_I_ARRAYP / not branch.
- scm_ramapc: Heed case 5.
* test-suite/tests/ramap.test
- test empty arguments for array-copy! and array-for-each. Note those
that failed in 2.0.9.
Daniel Llorens [Fri, 19 Apr 2013 08:42:40 +0000 (10:42 +0200)]
Fix empty array bug in array-index-map!
* libguile/array-map.c: (scm_array_index_map_x): bail out if any one of the
axes is empty.
* test-suite/tests/ramap.test: add tests for empty array-case of
array-index-map!. The 'f64 case with not-last emtpy axis is broken in 2.0.9.
Andy Wingo [Sat, 8 Feb 2014 21:11:36 +0000 (22:11 +0100)]
Add "vector" member to scm_t_array_handle
* libguile/array-handle.h (scm_t_array_handle): Add "vector" member.
* libguile/array-handle.c (scm_array_get_handle): Initialize the vector
member.
Andy Wingo [Sat, 8 Feb 2014 20:51:52 +0000 (21:51 +0100)]
Remove "impl" member of array handles.
* libguile/array-handle.h (scm_t_array_handle): Remove "impl" member.
* libguile/array-handle.c (scm_array_get_handle): Adapt.
Andy Wingo [Sat, 8 Feb 2014 20:42:53 +0000 (21:42 +0100)]
Inline scm_i_array_implementation_for_obj in scm_i_array
* libguile/generalized-arrays.c (scm_is_array, scm_is_typed_array): In
preparation for removing the registry of array implementations, remove
a couple uss of scm_i_array_implementation_for_obj.
Andy Wingo [Sat, 8 Feb 2014 20:02:48 +0000 (21:02 +0100)]
vref, vset members of scm_t_array_handle
* libguile/array-handle.h (scm_t_array_ref, scm_t_array_set): Rename
from scm_i_t_array_ref, scm_i_t_array_set.
(scm_t_array_handle): Copy vref and vset from impl to handle.
(scm_array_handle_ref, scm_array_handle_set):
* libguile/array-map.c (racp, ramap, rafe, rafill, array_index_map_1):
* libguile/array-handle.c (scm_array_get_handle): Adapt.
Daniel Llorens [Thu, 11 Apr 2013 16:11:35 +0000 (18:11 +0200)]
Change uses of scm_is_simple_vector to scm_is_vector
* libguile/filesys.c, libguile/random.c, libguile/stime.c, libguile/trees.c,
libguile/validate.h: use scm_is_vector instead of scm_is_simple_vector.
* libguile/sort.c (scm_sort_x, scm_sort, scm_stable_sort_x)
(scm_stable_sort): Remove scm_is_vector check; scm_is_array is
sufficient.
* test-suite/tests/arrays.test: Fix header.
* test-suite/tests/random.test: New coverage test covering
random:normal-vector!.
* test-suite/Makefile.am: Include random.test in make check.
Andy Wingo [Sat, 8 Feb 2014 16:14:47 +0000 (17:14 +0100)]
SCM_I_IS_VECTOR only true for tc7_vector, not weak vectors
* libguile/tags.h (SCM_TYP7S, SCM_HAS_TYP7S): Remove these, as we no
longer do the differs-by-one-bit thing for vectors and weak vectors.
* libguile/vectors.h (SCM_I_IS_VECTOR): Use SCM_HAS_TYP7.
(SCM_I_IS_NONWEAK_VECTOR): Remove.
* libguile/vm-engine.c (vector-length, vector-ref, vector-set!)
(vector-ref/immediate, vector-set!/immediate): We can inline these
instructions completely now.
* libguile/vm.c (vm_error_not_a_vector, vm_error_out_of_range): New
error conditions.
Andy Wingo [Sat, 8 Feb 2014 16:00:32 +0000 (17:00 +0100)]
Merge commit '
24cac6554073bb6e691605cd6ac6196f3c0851a3'
Conflicts:
libguile/vectors.c
Andy Wingo [Sat, 8 Feb 2014 15:54:01 +0000 (16:54 +0100)]
Merge commit '
5cfeff11cc58148c58a85a879fd7a3e7cfbbe8e2'
Conflicts:
libguile/vectors.c
Andy Wingo [Sat, 8 Feb 2014 15:13:54 +0000 (16:13 +0100)]
Deprecate the use of the vector interface on arrays
* libguile/vectors.c (scm_is_vector): Deprecate use on weak vectors and
arrays.
(scm_is_simple_vector): Deprecate use on weak vectors.
(scm_vector_length, scm_c_vector_ref, scm_c_vector_set_x): Deprecate
use on arrays.
* libguile/sort.c: Adapt to check explicitly for arrays.
Andy Wingo [Sat, 8 Feb 2014 15:02:59 +0000 (16:02 +0100)]
Deprecate use of vector-length, vector-ref, vector-set! as primitive-generics
* libguile/vectors.c (scm_vector_length, scm_c_vector_ref):
(scm_c_vector_set_x): Deprecate the use of vector-length, vector-ref,
and vector-set! as primitive generics.
Andy Wingo [Sat, 8 Feb 2014 14:31:37 +0000 (15:31 +0100)]
Merge commit '
fb7dd00169304a5922838e4d2f25253640a35def'
This commit also renames uniform-vector-element-type-code to
array-type-code.
Conflicts:
libguile/uniform.c
libguile/uniform.h
test-suite/tests/arrays.test
Andy Wingo [Sat, 8 Feb 2014 13:56:16 +0000 (14:56 +0100)]
Merge commit '
dc65b88d839c326889618112c4870ad3a64e9446'
Conflicts:
libguile/srfi-4.c
Andy Wingo [Sat, 8 Feb 2014 13:55:16 +0000 (14:55 +0100)]
Merge commit '
b9b88351ea2c4b43a6f90938554dc5693b17e328'
Conflicts:
libguile/deprecated.h
test-suite/tests/00-socket.test
Andy Wingo [Sat, 8 Feb 2014 13:48:56 +0000 (14:48 +0100)]
Andy Wingo [Sat, 8 Feb 2014 13:48:48 +0000 (14:48 +0100)]
Merge commit '
495cea0c931de23f074892b3f32808e676712a18'
Conflicts:
libguile/weaks.c
Andy Wingo [Sat, 8 Feb 2014 13:46:31 +0000 (14:46 +0100)]
Merge commit '
b86069c1308a6ca36f3a3bc56134b3f8fd693592'
Conflicts:
libguile/hashtab.c
Andy Wingo [Sat, 8 Feb 2014 13:44:23 +0000 (14:44 +0100)]
Andy Wingo [Sat, 8 Feb 2014 13:44:11 +0000 (14:44 +0100)]
Merge commit '
2f3b7e9a41677bfe802e8a1ee851827297384c58'
Conflicts:
module/ice-9/pretty-print.scm
Andy Wingo [Sat, 8 Feb 2014 13:31:42 +0000 (14:31 +0100)]
Andy Wingo [Sat, 8 Feb 2014 13:18:40 +0000 (14:18 +0100)]
Deprecate general "uniform-vector" interface
* libguile/uniform.h:
* libguile/uniform.c (scm_is_uniform_vector, scm_uniform_vector_p)
(scm_c_uniform_vector_length, scm_uniform_vector_length)
(scm_uniform_vector_element_type, scm_uniform_vector_element_size)
(scm_c_uniform_vector_ref, scm_uniform_vector_ref):
(scm_c_uniform_vector_set_x, scm_uniform_vector_set_x):
(scm_uniform_vector_to_list)
(scm_uniform_vector_elements, scm_uniform_vector_writable_elements):
Deprecate. This interface lacked both generality and specificity.
The general replacement is array-length, array-ref, and friends on the
scheme side, or the array handle interface on the C side. On the
specific side of things, there are the specific bytevector, srfi-4,
and bitvector interfaces.
* test-suite/tests/arrays.test:
* test-suite/tests/bitvectors.test:
* test-suite/tests/ports.test:
* test-suite/tests/srfi-4.test: Update to use array interfaces.
* doc/ref/api-foreign.texi (Void Pointers and Byte Access):
* doc/ref/srfi-modules.texi (SRFI-4): Update.
Andy Wingo [Sat, 8 Feb 2014 12:52:21 +0000 (13:52 +0100)]
Simplify srfi-4 C implementation
* libguile/srfi-4.c (DEFINE_SRFI_4_C_FUNCS): In the raw element
accessors (e.g scm_u32vector_writable_elements), only permit
bytevectors, as the constructors will only make bytevectors. This
harmonizes with the Scheme interfaces as well, which expect packed
bytevectors.
(scm_make_srfi_4_vector): Knowing that the new value is a bytevector
with base 0 and inc 1, simplify initialization.
Andy Wingo [Sat, 8 Feb 2014 13:27:49 +0000 (14:27 +0100)]
Deprecate htons, htonl, ntohs, ntohl
* libguile/sockets.h:
* libguile/sockets.c:
* libguile/deprecated.h:
* libguile/deprecated.c (scm_htons, scm_htonl, scm_ntohs, scm_ntohl):
Deprecate. Bytevectors adequately subsume their functionality.
* doc/ref/posix.texi:
* test-suite/tests/00-socket.test: Update.
Mark H Weaver [Sat, 8 Feb 2014 02:42:28 +0000 (21:42 -0500)]
Improve handling of locales in the test suite.
* test-suite/guile-test (run-tests): Load each test file within
(with-locale "C" ...).
* test-suite/tests/encoding-iso88591.test:
* test-suite/tests/encoding-iso88597.test:
* test-suite/tests/encoding-utf8.test:
* test-suite/tests/srfi-14.test: Remove broken code to save and restore
the previous locale.
* test-suite/tests/bytevectors.test:
* test-suite/tests/format.test:
* test-suite/tests/regexp.test:
* test-suite/tests/srfi-19.test:
* test-suite/tests/tree-il.test: Make sure 'setlocale' is defined before
calling it.
Mark H Weaver [Sat, 8 Feb 2014 01:05:17 +0000 (20:05 -0500)]
Avoid using 'eval-when' with 'expand' in (oop goops).
* module/oop/goops.scm: Avoid using 'eval-when' with 'expand'.
Mark H Weaver [Fri, 7 Feb 2014 21:53:48 +0000 (16:53 -0500)]
Better error reporting in 'weak-vector-ref' and 'weak-vector-set!'.
* libguile/weaks.c (scm_c_weak_vector_ref, scm_c_weak_vector_set_x):
Pass procedure name to 'scm_out_of_range'.
Mark H Weaver [Fri, 7 Feb 2014 21:38:58 +0000 (16:38 -0500)]
Make size argument optional to 'make-doubly-weak-hash-table'; fix docs.
* libguile/hashtab.c (scm_make_doubly_weak_hash_table): Make 'size'
argument optional, like the weak hash table constructors.
* doc/ref/api-memory.texi (Weak hash tables): Document that 'size'
argument is optional for the weak hash table constructors.