1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 04:10:18 +02:00
Commit graph

2797 commits

Author SHA1 Message Date
Andy Wingo
0534735314 Remove unneeded local exact-integer? definition
* module/system/vm/assembler.scm (link-debug): Remove unneeded
  exact-integer? definition.
2014-03-31 18:20:55 +02:00
Andy Wingo
9a1dfb7d2e 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.
2014-03-31 18:20:55 +02:00
Andy Wingo
c2247b782a 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.
2014-03-22 15:49:31 +01:00
Andy Wingo
0463a927c4 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!.
2014-03-22 15:42:15 +01:00
Andy Wingo
48c2a5395a DFG inlines uses of for-each
* module/language/cps/dfg.scm (for-each, for-each/2): Define inline
  versions of these.  Adapt callers.
2014-03-17 10:10:36 +01:00
Andy Wingo
f883ae59a0 Optimize srfi-1 for-each with two lists.
* module/srfi/srfi-1.scm (for-each): Optimize for the two-list case.
2014-03-16 19:58:30 +01:00
Andy Wingo
ed59b70a54 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.
2014-03-16 19:48:48 +01:00
Andy Wingo
f87a7327a5 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!
2014-03-16 19:41:51 +01:00
Andy Wingo
22806c244a 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.
2014-03-16 15:32:39 +01:00
Andy Wingo
f764e2590f 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.
2014-03-12 17:18:13 +01:00
Andy Wingo
3c3de73d4d 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.
2014-03-02 12:05:32 +01:00
Andy Wingo
1a95246a39 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.
2014-03-02 12:04:18 +01:00
Andy Wingo
6bceec326f ,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.
2014-03-01 16:09:30 +01:00
Andy Wingo
1145f4069b 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.
2014-03-01 15:54:47 +01:00
Andy Wingo
ee3f9604dd 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.
2014-03-01 13:18:04 +01:00
Andy Wingo
e3997e709b 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.
2014-02-28 19:42:04 +01:00
Andy Wingo
cd073eb4a9 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.
2014-02-28 19:31:46 +01:00
Andy Wingo
3f9f4a2d59 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.
2014-02-28 18:35:25 +01:00
Andy Wingo
ce47749045 (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.
2014-02-28 17:42:45 +01:00
Andy Wingo
188e2ae36b Update statprof commentary
* module/statprof.scm: Update commentary.
2014-02-28 17:18:19 +01:00
Andy Wingo
13a977dd79 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.
2014-02-28 17:17:46 +01:00
Andy Wingo
3072d7624f 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.
2014-02-28 17:17:46 +01:00
Andy Wingo
91db6c4f9c 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.
2014-02-28 17:17:38 +01:00
Andy Wingo
a7ede58d01 Slight gcprof refactor
* module/statprof.scm (gcprof): Refactor a bit.
2014-02-28 10:48:41 +01:00
Andy Wingo
e68ed8397d statprof uses new setitimer magical usecs ability
* module/statprof.scm (sample-stack-procs): Take advantage of setitimer
  allowing usecs >= 1e6.
2014-02-28 10:36:21 +01:00
Andy Wingo
fc2b8f6c6d 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.
2014-02-27 17:16:29 +01:00
Andy Wingo
fd953d7a10 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.
2014-02-25 22:46:32 +01:00
Andy Wingo
19bf8caff3 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.
2014-02-25 22:40:32 +01:00
Andy Wingo
fd5dfcce80 statprof and gcprof procedures use a fresh statprof state
* module/statprof.scm (statprof, gcprof): Create a fresh statprof
  state.
2014-02-25 22:16:49 +01:00
Andy Wingo
4b3d7a2b7c 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.
2014-02-25 21:32:36 +01:00
Andy Wingo
546efe2514 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.
2014-02-22 17:02:53 +01:00
Andy Wingo
3476a3692e 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.
2014-02-22 16:31:31 +01:00
Andy Wingo
90c8094aec 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.
2014-02-22 15:34:46 +01:00
Andy Wingo
e4a8775ddb 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.
2014-02-22 15:09:54 +01:00
Andy Wingo
e70a42d4c9 statprof: call-data is a record type
* module/statprof.scm (call-data): Reimplement as a record type.
2014-02-22 14:59:21 +01:00
Andy Wingo
cad444e31a statprof: when/unless instead of if.
* module/statprof.scm: Use when or unless instead of if, where
  appropriate.
2014-02-22 14:54:17 +01:00
Andy Wingo
d20dd74eca add a statprof fixme
* module/statprof.scm: Add a fixme.
2014-02-21 22:18:02 +01:00
Andy Wingo
4d0c358b4c 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.
2014-02-21 22:12:47 +01:00
Andy Wingo
4eb1fb9b8a 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.
2014-02-21 21:56:01 +01:00
Andy Wingo
45a7de8268 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.
2014-02-21 21:43:39 +01:00
Andy Wingo
56bfce7c5d inside-profiler? to parameter instead of global variable
* module/statprof.scm (<state>): Add inside-profiler? member.  Move
  mutations of inside-profiler? here.
2014-02-21 21:25:50 +01:00
Andy Wingo
62fd93e242 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.
2014-02-21 21:01:10 +01:00
Andy Wingo
998f8494b7 reform statprof commentary
* module/statprof.scm: Reformat the commentary.
2014-02-21 19:20:16 +01:00
Andy Wingo
7e2fd4e7f5 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.
2014-02-20 09:45:01 +01:00
Andy Wingo
5d20fd49fe %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.
2014-02-19 21:57:40 +01:00
Andy Wingo
0f0b6f2d86 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.
2014-02-19 19:43:48 +01:00
Andy Wingo
440392fa2d 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.
2014-02-19 16:54:45 +01:00
Andy Wingo
82490a665c 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
2014-02-17 22:23:40 +01:00
Andy Wingo
26c19d79d9 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.
2014-02-17 14:15:34 +01:00
Andy Wingo
3c08b6c1b2 Add elf-symbol-value-offset, for properly relocating symtab entries
* module/system/vm/elf.scm (elf-symbol-value-offset): New export.
2014-02-16 15:58:44 +01:00