bpt/guile.git
10 years agoReplace all let-gensyms uses with let-fresh
Andy Wingo [Fri, 28 Mar 2014 15:29:16 +0000 (16:29 +0100)]
Replace all let-gensyms uses with let-fresh

* .dir-locals.el: Add with-fresh-name-state.
* module/language/cps.scm (fresh-label, fresh-var): Signal an error if
  the counters are not initialized.
  (with-fresh-name-state): New macro.
  (make-cont-folder): New macro, generates an n-ary folder.
  (compute-max-label-and-var): New function, uses make-cont-folder.
  (fold-conts): Use make-cont-folder.
  (let-gensyms): Remove.

* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/constructors.scm:
* module/language/cps/dce.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/specialize-primcalls.scm: Use let-fresh instead of
  let-gensyms, and wrap in a with-fresh-name-state as needed.

* module/language/tree-il/compile-cps.scm: Remove hack to avoid
  importing let-gensyms from (language tree-il).

10 years agoRemove unneeded local exact-integer? definition
Andy Wingo [Fri, 28 Mar 2014 13:23:51 +0000 (14:23 +0100)]
Remove unneeded local exact-integer? definition

* module/system/vm/assembler.scm (link-debug): Remove unneeded
  exact-integer? definition.

10 years agoContinuation labels and variable identifiers may be integers
Andy Wingo [Fri, 28 Mar 2014 13:21:06 +0000 (14:21 +0100)]
Continuation labels and variable identifiers may be integers

* module/language/cps.scm (label-counter, var-counter): New parameters,
  for producing fresh label and var names.
  (fresh-label, fresh-var): New procedures.
  (let-fresh): New macro, will replace let-gensyms.
  (build-cps-term): Use let-fresh.

* module/language/tree-il/compile-cps.scm: Use let-fresh to generate
  fresh names.

* module/system/vm/assembler.scm (make-meta, begin-kw-arity): Allow
  exact integers as labels.
  (link-debug): Explicitly mark low-pc as being an "addr" value.

10 years agoSloppier matching in setitimer tests
Andy Wingo [Wed, 26 Mar 2014 09:47:40 +0000 (10:47 +0100)]
Sloppier matching in setitimer tests

* test-suite/tests/signals.test: Update setitimer tests to sloppily
  match both times -- it seems that the interval can also be sloppy on
  some platforms, sadly.

10 years agoAdapt test-out-of-memory to work on 32-bit systems
Andy Wingo [Wed, 26 Mar 2014 09:35:53 +0000 (10:35 +0100)]
Adapt test-out-of-memory to work on 32-bit systems

* test-suite/standalone/test-out-of-memory (*limit*): Reduce limit to 50 MB.
  Adapt vector test to avoid exceeding maximum vector size on 32-bit
  systems.

10 years agoFix compile warnings
Andy Wingo [Sat, 22 Mar 2014 15:06:39 +0000 (16:06 +0100)]
Fix compile warnings

* libguile/throw.c (catch): Fix bad declarations.

* libguile/stackchk.c (reset_scm_stack_checking_enabled_p): Remove
  unused static function.

10 years agoOut-of-memory situations raise exceptions instead of aborting
Andy Wingo [Sat, 22 Mar 2014 14:49:31 +0000 (15:49 +0100)]
Out-of-memory situations raise exceptions instead of aborting

* libguile/gc.c (scm_oom_fn, scm_init_gc): Install an out-of-memory
  handler that raises an unwind-only out-of-memory exception.
  (scm_gc_warn_proc, scm_init_gc): Install a warning proc that tries to
  print to the current warning port, if the current warning port is a
  file port.
  (scm_gc_after_nonlocal_exit): New interface.  Should be called after a
  nonlocal return to potentially collect memory; otherwise allocations
  could try to expand again when they should collect.

* libguile/continuations.c (scm_i_make_continuation):
* libguile/eval.c (eval):
* libguile/throw.c (catch):
* libguile/vm.c (scm_call_n): Call scm_gc_after_nonlocal_exit after
  nonlocal returns.

* libguile/throw.c (abort_to_prompt, throw_without_pre_unwind): Rework
  to avoid allocating memory.
  (scm_report_out_of_memory): New interface.
  (scm_init_throw): Pre-allocate the arguments for stack-overflow and
  out-of-memory errors.

* module/ice-9/boot-9.scm: Add an out-of-memory exception printer.
* module/system/repl/error-handling.scm (call-with-error-handling): Add
  out-of-memory to the report-keys set.

* libguile/gc-malloc.c (scm_realloc): Call scm_report_out_of_memory if
  realloc fails.

* libguile/error.h:
* libguile/error.c:
* libguile/deprecated.h:
* libguile/deprecated.c (scm_memory_error): Deprecate.

* test-suite/standalone/Makefile.am:
* test-suite/standalone/test-out-of-memory: New test case.

10 years agoDefine a C fluid for current-warning-port
Andy Wingo [Sat, 22 Mar 2014 14:42:15 +0000 (15:42 +0100)]
Define a C fluid for current-warning-port

* libguile/ports.c (scm_current_input_port, scm_current_output_port)
  (scm_current_error_port): Fix declarations to C99.
  (scm_current_warning_port, scm_set_current_warning_port): Rework to
  use a C fluid, like scm_current_error_port.
  (scm_init_ports): Initialize and define the warning port fluid.

* libguile/init.c (scm_init_standard_ports): Init the current warning
  port.

* module/ice-9/boot-9.scm: Remove definitions for current-warning-port.
  Instead, steal it from the boot objtable with port-parameterize!.

10 years agoDFG inlines uses of for-each
Andy Wingo [Mon, 17 Mar 2014 09:10:36 +0000 (10:10 +0100)]
DFG inlines uses of for-each

* module/language/cps/dfg.scm (for-each, for-each/2): Define inline
  versions of these.  Adapt callers.

10 years agoOptimize srfi-1 for-each with two lists.
Andy Wingo [Sun, 16 Mar 2014 18:58:30 +0000 (19:58 +0100)]
Optimize srfi-1 for-each with two lists.

* module/srfi/srfi-1.scm (for-each): Optimize for the two-list case.

10 years agoSimplify boot-9 for-each with two lists
Andy Wingo [Sun, 16 Mar 2014 18:48:48 +0000 (19:48 +0100)]
Simplify boot-9 for-each with two lists

* module/ice-9/boot-9.scm (for-each): Simplify the two-argument case in
  the same way as the one-argument case.

10 years agoMore for-each micro-optimizations
Andy Wingo [Sun, 2 Mar 2014 11:38:32 +0000 (12:38 +0100)]
More for-each micro-optimizations

* module/ice-9/boot-9.scm (for-each):
* module/srfi/srfi-1.scm (for-each): Re-implement one-list case using an
  explicit check for list? instead of the tortoise-hare thing.  Seems to
  be faster!

10 years agoDoc and NEWS updates
Andy Wingo [Sun, 16 Mar 2014 15:28:28 +0000 (16:28 +0100)]
Doc and NEWS updates

* NEWS: Update section on dynamic stacks.  Add link for intptr
  interfaces.
* doc/ref/api-data.texi (Integers): Add intptr interfaces.

10 years agoDebug options doc fix.
Andy Wingo [Sun, 16 Mar 2014 14:50:27 +0000 (15:50 +0100)]
Debug options doc fix.

* doc/ref/api-debug.texi (Debug Options): Fix.

10 years agoRefine unwind-only exception message.
Andy Wingo [Sun, 16 Mar 2014 14:46:28 +0000 (15:46 +0100)]
Refine unwind-only exception message.

* libguile/throw.c (throw_without_pre_unwind): Refine warning message.

10 years agoDocument stack-overflow handlers, limits, and unwind-only exceptions
Andy Wingo [Sun, 16 Mar 2014 14:27:26 +0000 (15:27 +0100)]
Document stack-overflow handlers, limits, and unwind-only exceptions

* module/system/repl/error-handling.scm (call-with-error-handling): Add
  #:report-keys kwarg, so that unwind-only exceptions (stack-overflow in
  particular) get reported.

* doc/ref/api-debug.texi (Pre-Unwind Debugging): Add documentation for
  #:report-keys kwarg of call-with-error-handling.
  (Stack Overflow): New subsubsection.
  (Debug Options): Remove discussion of stack overflow.

10 years agoAdd call-with-stack-overflow-handler tests
Andy Wingo [Sat, 15 Mar 2014 18:30:26 +0000 (19:30 +0100)]
Add call-with-stack-overflow-handler tests

* test-suite/tests/eval.test ("stack overflow handlers"): Add
  call-with-stack-overflow-handler tests, replacing the old stack
  overflow test.

10 years agoAdd stack overflow test
Andy Wingo [Sat, 15 Mar 2014 17:56:18 +0000 (18:56 +0100)]
Add stack overflow test

* libguile/throw.c (throw_without_pre_unwind): Newline after the
  unwind-only warning.

* test-suite/standalone/Makefile.am:
* test-suite/standalone/test-stack-overflow: New test to handle
  mmap/malloc failure.

10 years agoRemove default soft stack limit; add call-with-stack-overflow-handler
Andy Wingo [Wed, 12 Mar 2014 16:18:13 +0000 (17:18 +0100)]
Remove default soft stack limit; add call-with-stack-overflow-handler

* libguile/vm.h:
* libguile/vm.c (default_max_stack_size, initialize_default_stack_size):
  Remove the default stack limit.  In this way, programs run from the
  command line or outside of the REPL will have no soft stack limit.
  (make_vm): Change `max_stack_size' field to be a stack of limits and
  handlers.
  (current_overflow_size, should_handle_stack_overflow)
  (reset_stack_limit, wind_overflow_handler, unwind_overflow_handler)
  (vm_expand_stack): If the stack surpasses a user-set limit, call the
  user-specified handler within its outer stack limit.
  (call-with-stack-overflow-handler): New interface.

* module/system/vm/vm.scm: Export call-with-stack-overflow-handler.

10 years agoPort unrolled one-argument for-each from boot-9 to srfi-1
Andy Wingo [Sun, 2 Mar 2014 11:05:32 +0000 (12:05 +0100)]
Port unrolled one-argument for-each from boot-9 to srfi-1

* module/srfi/srfi-1.scm (for-each): Port unrolled one-argument
  implementation here from the boot-9 version.

10 years agoFix for-each bug detecting not-a-list
Andy Wingo [Sun, 2 Mar 2014 11:04:18 +0000 (12:04 +0100)]
Fix for-each bug detecting not-a-list

* module/ice-9/boot-9.scm (for-each): Fix detection of not-a-list in the
  unrolled one-argument case.

* test-suite/tests/eval.test ("for-each"): Add a test.

10 years ago,profile, statprof, gcprof have an outer stack cut
Andy Wingo [Sat, 1 Mar 2014 15:09:30 +0000 (16:09 +0100)]
,profile, statprof, gcprof have an outer stack cut

* module/statprof.scm (<state>): Add outer-cut member.
  (fresh-profiler-state): Add outer-cut kwarg.
  (sample-stack-procs): Stop when the stack-length is zero, which will
  be before the frames run out if there is an outer cut.
  (profile-signal-handler): Use the outer cut when capturing the stack.
  (call-thunk): New helper, for use as an outer cut.
  (statprof, gcprof): Call the thunk within call-thunk, and use
  call-thunk as an outer cut.

10 years agoStatprof commentings
Andy Wingo [Sat, 1 Mar 2014 14:54:47 +0000 (15:54 +0100)]
Statprof commentings

* module/statprof.scm: Add a big ol' comment.
  (sample-stack-procs): If slot 0 isn't a primitive, use the IP to
  mark.  In the future we will see more non-procedures in slot 0 as we
  start to use call-label and tail-call-label.

10 years agostatprof-display prints source locations
Andy Wingo [Sat, 1 Mar 2014 11:59:58 +0000 (12:59 +0100)]
statprof-display prints source locations

* module/statprof.scm (call-data): Source is after printable.
  (addr->printable): Just produce a name, without source.  Anonymous
  printables get "anon " prefixed.
  (stack-samples->procedure-data): Adapt to call-data change.
  (stats): Add "proc-source" element.
  (statprof-call-data->stats): Give a source to the call-data.
  (statprof-display): Print source also.

10 years agoRefactorings: call-data has source, stats is a record
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.

10 years agoStatprof uses stack trace buffer to always provide full stacks
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.

10 years agoStatprof always stores full stack traces
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.

10 years ago(system vm program) exports primitive?
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.

10 years agoImprove statprof test
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.

10 years agoUpdate statprof commentary
Andy Wingo [Fri, 28 Feb 2014 10:57:12 +0000 (11:57 +0100)]
Update statprof commentary

* module/statprof.scm: Update commentary.

10 years agoMore state-related refactors in statprof
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.

10 years agoStatprof restores previous sigprof handler when stopping
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.

10 years agoMore statprof refactors
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.

10 years agoSlight gcprof refactor
Andy Wingo [Fri, 28 Feb 2014 09:48:41 +0000 (10:48 +0100)]
Slight gcprof refactor

* module/statprof.scm (gcprof): Refactor a bit.

10 years agostatprof uses new setitimer magical usecs ability
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.

10 years agoFix setitimer documentation. Allow microseconds >= 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.

10 years agoFix newline preservation in @example with lines beginning with @
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.

10 years agogcprof tweaks
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.

10 years agoRefactor representation of sampling periods in statprof
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.

10 years agostatprof and gcprof procedures use a fresh statprof state
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.

10 years agoSimplification pass prunes all unreachable continuations
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.

10 years agosimplify profile-signal-handler
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.

10 years agostatprof: accumulated-time is in jiffies
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.

10 years agoZero-offset branches are backward branches; fix "br" backward branches
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!

10 years agoAvoid attempting to eta-reduce self-loops.
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.

10 years agoPass state around statprof in more places
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.

10 years agostatprof: call-data is a record type
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.

10 years agostatprof: when/unless instead of if.
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.

10 years agoadd a statprof fixme
Andy Wingo [Fri, 21 Feb 2014 21:18:02 +0000 (22:18 +0100)]
add a statprof fixme

* module/statprof.scm: Add a fixme.

10 years agostatprof-active? instead of checking profile level
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.

10 years agostatprof-reset creates a new state
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.

10 years agoMore statprof state refactorings
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.

10 years agoinside-profiler? to parameter instead of global variable
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.

10 years agoBeginnings of statprof threadsafety
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.

10 years agoreform statprof commentary
Andy Wingo [Fri, 21 Feb 2014 18:20:16 +0000 (19:20 +0100)]
reform statprof commentary

* module/statprof.scm: Reformat the commentary.

10 years agoFix segfault in thread_mark
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.

10 years agoThreadsafe stack relocation
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.

10 years agoassertion refactor in the vm
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.

10 years agoFix "VM never extends vp->sp ..." commit
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.

10 years agoRemove the hard stack size limit
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.

10 years agoVM never extends vp->sp beyond mapped region of stack
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.

10 years agoUnwind-only stack overflow exceptions
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.

10 years ago%exception-handler fluid refactor
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.

10 years agoReimplement catch, throw, and with-throw-handler
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.

10 years agoboot-9 boot order refactor for catch, throw, and such
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.

10 years agoFix scm_i_vm_capture_stack comment.
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.

10 years agoDefault stack size is one page.
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.

10 years agoMore robust stack expansion and contraction
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.

10 years agoDon't peval-penalize let-bound lambdas only referenced once
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

10 years agoPT_DYNAMIC inside some other PT_LOAD segment
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.

10 years agoAdd elf-symbol-value-offset, for properly relocating symtab entries
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.

10 years agoELF linker can produce objects with native ABI
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.

10 years agobytevector-length reifies to correct module
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.

10 years agobytevector-length is an interesting primitive.
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.

10 years agosqrt and abs are interesting primitives
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.

10 years agoAdd prune-top-level-scopes pass
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.

10 years agoBytevector f32 an f64 ops actually map to VM primitives
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.

10 years agoguile.m4 tweaks
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.

10 years agoarray-contents returns root for empty arrays with empty root
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.

10 years agoAdd tests for more kinds of typed arrays.
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.

10 years agoPreallocate index list in scm_array_index_map_x
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.

10 years agoMatch types used in arrays.c to struct field types
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.

10 years agoDon't use ASET in scm_array_index_map_x
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.

10 years agoIn scm_ramapc, only check unrolled axes for emptiness
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.

10 years agoFix corner cases of scm_ramapc
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!.

10 years agoRewrite scm_ramapc()
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.

10 years agoFactor out make1array() in scm_ramapc()
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.

10 years agoCheck more cases of array-contents
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.

10 years agoRefactor array-contents
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.

10 years agoCheck the documented matching behavior of array-map!/copy!
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.

10 years agoReindent scm_ramapc
Andy Wingo [Sun, 9 Feb 2014 20:11:08 +0000 (21:11 +0100)]
Reindent scm_ramapc

* libguile/array-map.c (scm_ramapc): Reindent.

10 years agoRaw pointer loop in array-copy! for vector/vector case
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.

10 years agoSimplify scm_array_get_handle for tc7-arrays
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.

10 years agoTest that typed-array? returns #f with non-array argument
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.

10 years agoReplace SCM_IMP in array-map.c
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.

10 years agoRemove array impl. registry; instead, hard-code array handle creation
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.

10 years agoFix array map functions with empty arguments
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.

10 years agoFix empty array bug in array-index-map!
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.

10 years agoAdd "vector" member to scm_t_array_handle
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.

10 years agoRemove "impl" member of array handles.
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.