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

2837 commits

Author SHA1 Message Date
Andy Wingo
0a44542fce Fix DFG compute-reachable bug
* module/language/cps/dfg.scm (compute-reachable): Fix embarassing bug
  where we wouldn't actually iterate to fixpoint.  I haven't seen it
  yet, but that's just luck...
2014-04-01 20:55:31 +02:00
Andy Wingo
f082c5f30a Optimize two-list srfi-1 map
* module/srfi/srfi-1.scm (map): Optimize the two-list variant.
2014-04-01 20:52:15 +02:00
Andy Wingo
545274a035 Speed up compute-label-and-var-ranges
* module/language/cps/dfg.scm (compute-label-and-var-ranges): Duplicate
  the cont-folder cases in the global/not-global cases.  Lets the
  optimizer DTRT.
2014-04-01 18:20:02 +02:00
Andy Wingo
0912202a51 Fix compute-label-and-var-ranges for global DFG computation
* module/language/cps/dfg.scm (compute-label-and-var-ranges): Fix to
  work with global DFGs -- it wasn't taking $letrec into account for var
  ranges.

* module/language/cps/dce.scm (compute-live-code): Use bitvectors to
  represent the live var set.
2014-04-01 18:16:00 +02:00
Andy Wingo
f9bceb770b Renumber doesn't visit unreachable continuations
* module/language/cps/renumber.scm (compute-new-labels-and-vars): Don't
  visit functions that are not reachable.
  (renumber): Reindent.
2014-04-01 17:51:26 +02:00
Andy Wingo
cc8eb19545 Renumber returns label/var counters for use in let-fresh
* module/language/cps/renumber.scm (renumber): Refactor to return the
  label and var counters as additional values.

* module/language/cps/dce.scm (eliminate-dead-code): Use the renumber
  label/var counters to initialize the fresh name state.
2014-04-01 16:47:11 +02:00
Andy Wingo
3269e1b647 Refactor DCE to not build a CFA
* module/language/cps/effects-analysis.scm (compute-effects): Change to
  analyze the effects for a subrange of a DFG's continuations.

* module/language/cps/dce.scm (compute-defs, $fun-data, compute-live-code):
  (process-eliminations, eliminate-dead-code): Renumber before
  eliminating dead code, to avoid computing a CFG and other data.
2014-04-01 16:43:55 +02:00
Andy Wingo
c79c02d694 Simplification renumbers instead of local prune-continuation pass
* module/language/cps/simplify.scm (simplify): Use renumbering instead
  of rolling our own prune-continuations pass.
2014-04-01 15:56:45 +02:00
Andy Wingo
7c4977e699 DFA uses DFG var numbering
* module/language/cps/dfg.scm ($dfa): Instead of a var-map table an a
  syms vector, use the DFG's var numbering.
  (dfa-var-idx, dfa-var-sym, compute-live-variables): Adapt.
2014-04-01 15:42:12 +02:00
Andy Wingo
7dbf40ea8b Allocate-slots avoids building CFA
* module/language/cps/slot-allocation.scm (allocate-slots): Rework to
  avoid computing a CFA, and just relying on the incoming term to have
  sorted labels.
2014-04-01 15:21:28 +02:00
Andy Wingo
a8430ab1d7 Compile-fun takes advantage of sorted output of "renumber", avoids CFA
* module/language/cps/dfg.scm ($dfg): Rename nvars and nlabels fields to
  var-count and label-count.  Export dfg-min-var, dfg-min-label,
  dfg-label-count, dfg-var-count.

* module/language/cps/compile-bytecode.scm (compile-fun): No need to
  build a CFA given the renumbering pass.  Adapt to treat labels as
  ordered small integer in a contiguous vector.
2014-04-01 14:51:05 +02:00
Andy Wingo
09220d215f CPS renumbering pass sorts conts in topological order
* module/language/cps/renumber.scm (sort-conts)
  (compute-new-labels-and-vars): Rework to sort the labels in
  topological order, and to prune any unreachable labels.
2014-04-01 14:51:01 +02:00
Andy Wingo
2c3c086ef3 Add visit-cont-successors helper
* module/language/cps/dfg.scm (lookup-successors, control-point?): Use
  the new helper.

* module/language/cps.scm (visit-cont-successors): New helper.
2014-04-01 11:59:03 +02:00
Andy Wingo
6e5e9ffb75 Fix analyze-control-flow to preserve order among unordered labels
* module/language/cps/dfg.scm (analyze-control-flow): Sort blocks to
  preserve order among unordered successors.
  (lookup-successors): Choose a more natural order, now that it doesn't
  matter.
2014-03-31 18:54:19 +02:00
Andy Wingo
90dce16db4 Use Tree-IL-like case-lambda clause chaining in CPS
* module/language/cps.scm ($kclause, $kentry): Instead of having an
  entry continuation contain a list of clauses, have the clauses contain
  clauses (as in Tree-IL).  In some ways it's not as convenient but it
  does reflect the continuation tree correctly.

* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/constructors.scm:
* module/language/cps/contification.scm:
* module/language/cps/dce.scm:
* module/language/cps/dfg.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/prune-top-level-scopes.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/renumber.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt aaaaaaall users.
2014-03-31 18:54:12 +02:00
Andy Wingo
a3a45279c0 Rewrite control-point? to avoid consing
* module/language/cps/dfg.scm (control-point?): Rewrite to avoid consing
  a successors list.
2014-03-31 18:21:04 +02:00
Andy Wingo
4bf757b810 Remove succs from DFG
* module/language/cps/dfg.scm ($dfg): Remove "succs" from DFG.  Instead
  we can compute the successors set on-demand.
  (lookup-successors): Adapt.
2014-03-31 18:21:04 +02:00
Andy Wingo
4926024cfb Simplify boot-9 and srfi-1 map
* module/ice-9/boot-9.scm (map):
* module/srfi/srfi-1.scm (map): Simplify the implementations to check
  for list? beforehand.  It's faster, and it will be needed if we decide
  to go recursive.
2014-03-31 18:21:04 +02:00
Andy Wingo
de3cbadcc0 Avoid consing in compute-label-and-var-ranges.
* module/language/cps/dfg.scm (compute-label-and-var-ranges): Avoid
  consing.
2014-03-31 18:21:04 +02:00
Andy Wingo
5fc403911e Scope and scope-level in DFG vector
* module/language/cps/dfg.scm ($dfg): Hoist scopes and scope levels out
  of $block and into $dfg.  Adapt all callers.
2014-03-31 18:21:04 +02:00
Andy Wingo
21d6d183a9 Predecessors and successors in DFG vectors
* module/language/cps/dfg.scm ($dfg, $block): Record predecessors and
  successors in vectors instead of in $block data structures.  Adapt
  users.
2014-03-31 18:21:04 +02:00
Andy Wingo
f49e994b52 DFG refactor
* module/language/cps/dfg.scm (lookup-cont, lookup-block):
  (lookup-def, constant-needs-allocation?): Rework these accessors to
  avoid completely destructuring the $dfg.
2014-03-31 18:21:04 +02:00
Andy Wingo
62b7180bfd Renumber functions before emitting code
* module/language/cps/compile-bytecode.scm (compile-bytecode): Renumber
  a function before going to compile it, so that the vars and labels are
  contiguous within each function.
2014-03-31 18:21:04 +02:00
Andy Wingo
f05517b24e Add renumber module
* module/language/cps/renumber.scm: New module.
* module/Makefile.am: Add to build.

fix renumber
2014-03-31 18:21:04 +02:00
Andy Wingo
98c5b69fa0 Replace use-map in DFG with separate def / use vectors
* module/language/cps/dfg.scm ($dfg, $use-map): Replace use-map vector
  with "defs" and "uses" vectors.  Adapt callers.
2014-03-31 18:21:04 +02:00
Andy Wingo
b99553301c Remove "sym" from $use-map
* module/language/cps/dfg.scm ($use-map): Remove "sym" from use-map;
  it's redundant.  Adapt callers.
2014-03-31 18:21:04 +02:00
Andy Wingo
cec43eb8f6 $use-map no longer has name member
* module/language/cps/dfg.scm ($use-map): Remove name member.  Adapt
  users.
2014-03-31 18:21:04 +02:00
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
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