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

3371 commits

Author SHA1 Message Date
Andy Wingo
29619661e4 $dfa no longer includes name vector (can get that from dfg)
* module/language/cps/dfg.scm ($dfa, dfa-var-name):
  (compute-live-variables, print-dfa): Remove "names" from DFAs.
2014-03-31 18:21:04 +02:00
Andy Wingo
5e89790896 DFG stores conts, blocks, and use-maps in vectors
* module/language/cps/dfg.scm ($dfg): Change to store conts, blocks, and
  use-maps as vectors.  A DFG also records the minimum label, minimum
  variable, and the number of labels and variables.  The first entry in
  one of these vectors corresponds to the minimum.  This can be
  optimum in the local case if the conts and variables have been renamed
  appropriately.

  Adapt callers.

  (compute-live-variables): Adapt.  This is currently suboptimal but it
  works, so it's a useful base for optimization.
2014-03-31 18:21:04 +02:00
Andy Wingo
fbdb69b21c lookup-cont takes a DFG as its argument
* module/language/cps/dfg.scm (lookup-cont): Change to take a DFG
  instead of a cont table.
  (build-cont-table): Change to return a vector.

* module/language/cps/arities.scm:
* module/language/cps/contification.scm:
* module/language/cps/dce.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm: Adapt to lookup-cont and
  build-cont-table changes.
2014-03-31 18:21:04 +02:00
Andy Wingo
a6f823bd02 Public make-cont-folder
* module/language/cps.scm (make-cont-folder): Add global? parameter, and
  make public.
  (fold-conts): Adapt.
  (fold-local-conts): Use make-cont-folder, and take a function instead
  of a continuation.

* module/language/cps/arities.scm (fix-clause-arities, fix-arities*):
* module/language/cps/compile-bytecode.scm (collect-conts):
* module/language/cps/elide-values.scm (elide-values*): Adapt to
  fold-local-conts change.
2014-03-31 18:21:04 +02:00
Andy Wingo
1eda52c8ad Vars and labels are separate namespaces
* module/language/cps.scm (fresh-var, with-fresh-name-state): Vars have
  their own namespace.
2014-03-31 18:21:04 +02:00
Andy Wingo
b9e601d20d Prepare for decoupling of var/label name uniqueness
* module/language/cps/simplify.scm (compute-beta-reductions):
  (beta-reduce): Separate state into two tables, so we can relax current
  guarantee that vars and labels are mutually unique.
2014-03-31 18:21:04 +02:00
Andy Wingo
eb60b4136b Update verify-cps
* module/language/cps/verify.scm (verify-cps): Vars should only be exact
  integers now.
2014-03-31 18:21:04 +02:00
Andy Wingo
e6cf744ab4 CPS conversion renames incoming gensyms to small integers
* module/language/tree-il/compile-cps.scm (fold-formals)
  (unbound?, init-default-value, convert): Arrange to rename incoming
  gensyms as small integers.
  (canonicalize): Convert vector and abort here too.
2014-03-31 18:20:55 +02:00
Andy Wingo
699ed8ce29 Less copying in tree-il pre-order / post-order.
* module/language/tree-il.scm (pre-post-order): If the pre handler
  doesn't modify the components of a tree-il expression, avoid copying a
  new one.
2014-03-31 18:20:55 +02:00
Andy Wingo
ef58442a05 Prompt-related refactor in compile-cps
* module/language/tree-il/compile-cps.scm (fix-prompts): New procedure.
  Eta-expand prompts before compiling to ensure that they have inline
  handlers.
2014-03-31 18:20:55 +02:00
Andy Wingo
cd72929e71 DCE uses fresh-var instead of gensym
* module/language/cps/dce.scm (eliminate-dead-code): Use fresh-var
  instead of gensym.
2014-03-31 18:20:55 +02:00
Andy Wingo
39056a81fc Adapt verify-cps to CPS changes
* module/language/cps/verify.scm (verify-cps): Update to expect integer
  labels, and to allow integer variables.
2014-03-31 18:20:55 +02:00
Andy Wingo
828ed94469 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).
2014-03-31 18:20:55 +02:00
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
Nathaniel Alderson
8d124d2077 Calculate usecs correctly in thread-sleep!
* module/srfi/srfi-18.scm (thread-sleep!): Correctly compute
  microseconds.

* test-suite/tests/srfi-18.test: Add test.
2014-03-23 21:58:54 +01: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
Mark H Weaver
5dcbcfcef8 Fix (rnrs io simple) to open file ports in textual mode.
Fixes <http://bugs.gnu.org/17044>.
Reported and diagnosed by Xin Wang <dram.wang@gmail.com>.

* module/rnrs/io/simple.scm (open-input-file, open-output-file): Pass
  missing buffer-mode argument to open-file-{input,output}-port.
  Previously, (native-transcoder) was incorrectly passed as the
  buffer-mode argument, so no transcoder was provided, thus creating a
  binary port.
2014-03-19 23:36:46 -04:00
Andy Wingo
b7faf399c1 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-03-17 21:49:16 +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
Mark H Weaver
f2de4fac88 Fix (system base types) on big-endian systems.
* module/system/base/types.scm (cell->object): When reading stringbufs,
  use UTF-32BE on big-endian systems.
2014-03-15 13:23:21 -04: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
Mark H Weaver
c3c3032608 Make snarfing tools more robust to varied C preprocessor behavior.
* libguile/guile-snarf.in (modern_snarf): Rewrite sed script to cope
  with newlines in the snarfed code segments, or multiple code segments
  on the same line.

* module/scripts/snarf-check-and-output-texi.scm (process-stream):
  Strip all 'hash' tokens from the stream.
  (do-command): Remove special cases that handled 'hash' tokens
  in a few places.
2014-03-06 17:25:55 -05:00
Mark H Weaver
bf0d59e54d SRFI-19: Update the table of leap seconds.
* module/srfi/srfi-19.scm (leap-second-table): Update to include the two
  most recent leap seconds.
2014-03-03 17:31:51 -05: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
Mark H Weaver
6587bcfa53 SRFI-18: Export 'current-thread'.
Fixes <http://debbugs.gnu.org/16890>.
Reported by Xin Wang <dram.wang@gmail.com>.

* module/srfi/srfi-18.scm: Reexport 'current-thread'.
* THANKS: Add "Xin Wang" to fixes section.
2014-02-27 22:38:53 -05: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