bpt/guile.git
10 years agocompute-max-label-and-var takes letrec vars into account.
Andy Wingo [Wed, 2 Apr 2014 13:48:13 +0000 (15:48 +0200)]
compute-max-label-and-var takes letrec vars into account.

* module/language/cps.scm (compute-max-label-and-var): Fix to take
  letrec vars into account.

10 years agoFix DCE for refactor-introduced borkage
Andy Wingo [Wed, 2 Apr 2014 13:41:14 +0000 (15:41 +0200)]
Fix DCE for refactor-introduced borkage

* module/language/cps/dce.scm ($fun-data, compute-live-code)
  (process-eliminations): Fix clownshoes regarding fun-data field names
  and order.

10 years agoFix prune-top-level-scopes to allow collisions between var, scope, cont names
Andy Wingo [Wed, 2 Apr 2014 13:40:03 +0000 (15:40 +0200)]
Fix prune-top-level-scopes to allow collisions between var, scope, cont names

* module/language/cps/prune-top-level-scopes.scm (compute-referenced-scopes):
  Fix to not assume that scope names, continuation names, and var names
  are mutually unique.
  (prune-top-level-scopes): Better variable names.

10 years agoUpdate old-style REPL code for deprecation
Andy Wingo [Wed, 2 Apr 2014 10:08:48 +0000 (12:08 +0200)]
Update old-style REPL code for deprecation

* module/ice-9/scm-style-repl.scm:
* module/ice-9/save-stack.scm: As the deprecated bindings have been
  removed from the default environment, use #:export instead of
  #:replace.

10 years agoRemove CFA data type
Andy Wingo [Wed, 2 Apr 2014 10:00:09 +0000 (12:00 +0200)]
Remove CFA data type

* module/language/cps/dfg.scm: Remove CFA data type.
  (analyze-reverse-control-flow): Take min-label and label-count as
  args, and return multiple values instead of returning a CFA object.
  (compute-live-variables): Rework to accept multiple values from
  analyze-reverse-control-flow.
  ($dfa): Update comments.

10 years ago$dfa includes CFA fields
Andy Wingo [Wed, 2 Apr 2014 09:45:26 +0000 (11:45 +0200)]
$dfa includes CFA fields

* module/language/cps/dfg.scm ($dfa): Include CFA min-label, k-map, and
  k-order inline.
  (dfa-k-idx, dfa-k-sym, dfa-k-count): Adapt.
  (compute-live-variables): Extract fields of CFA for make-dfa.
  (print-dfa): Adapt (and fix positional record matching).

10 years agoMore CFA removals
Andy Wingo [Wed, 2 Apr 2014 09:23:41 +0000 (11:23 +0200)]
More CFA removals

* module/language/cps/dfg.scm (compute-reachable): Reword docstring.
  (visit-prompt-control-flow): Likewise.
  ($dominator-analysis): Change to store min-label instead of CFA.
  (compute-idoms, compute-join-edges, mark-loop-body, identify-loops):
  Take min-label and label-count, and use the DFG's preds list instead
  of requiring a fresh renumbered one.
  (analyze-dominators): Adapt to use a DFG with a label range instead of
  a CFA.

10 years agoSimplify analyze-reverse-control-flow
Andy Wingo [Wed, 2 Apr 2014 09:04:04 +0000 (11:04 +0200)]
Simplify analyze-reverse-control-flow

* module/language/cps/dfg.scm (analyze-reverse-control-flow): Use the
  DFG's label count and min label analysis instead of rolling our own.

10 years agoanalyze-control-flow only used in reverse direction; make private
Andy Wingo [Wed, 2 Apr 2014 09:01:39 +0000 (11:01 +0200)]
analyze-control-flow only used in reverse direction; make private

* module/language/cps/dfg.scm ($cfa): Use a vector to map labels to
  indices.  Don't export any CFA bindings.
  (cfa-k-idx): Adapt.
  (compute-reachable, find-prompts, compute-interval):
  (find-prompt-bodies, visit-prompt-control-flow): Take a DFG as an
  argument instead of a CFA.
  (analyze-reverse-control-flow): Refactor from analyze-control-flow, as
  it is only used in the reverse case.  Simplify accordingly, inlining
  the RPO sort.
  (compute-live-variables): Adapt to call analyze-reverse-control-flow
  instead.

10 years agoFix DFG compute-reachable bug
Andy Wingo [Tue, 1 Apr 2014 18:55:31 +0000 (20:55 +0200)]
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...

10 years agoOptimize two-list srfi-1 map
Andy Wingo [Tue, 1 Apr 2014 18:52:15 +0000 (20:52 +0200)]
Optimize two-list srfi-1 map

* module/srfi/srfi-1.scm (map): Optimize the two-list variant.

10 years agoSpeed up compute-label-and-var-ranges
Andy Wingo [Tue, 1 Apr 2014 16:20:02 +0000 (18:20 +0200)]
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.

10 years agoFix compute-label-and-var-ranges for global DFG computation
Andy Wingo [Tue, 1 Apr 2014 16:16:00 +0000 (18:16 +0200)]
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.

10 years agoRenumber doesn't visit unreachable continuations
Andy Wingo [Tue, 1 Apr 2014 15:51:26 +0000 (17:51 +0200)]
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.

10 years agoRenumber returns label/var counters for use in let-fresh
Andy Wingo [Tue, 1 Apr 2014 14:47:11 +0000 (16:47 +0200)]
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.

10 years agoRefactor DCE to not build a CFA
Andy Wingo [Tue, 1 Apr 2014 14:43:55 +0000 (16:43 +0200)]
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.

10 years agoSimplification renumbers instead of local prune-continuation pass
Andy Wingo [Tue, 1 Apr 2014 13:56:45 +0000 (15:56 +0200)]
Simplification renumbers instead of local prune-continuation pass

* module/language/cps/simplify.scm (simplify): Use renumbering instead
  of rolling our own prune-continuations pass.

10 years agoDFA uses DFG var numbering
Andy Wingo [Tue, 1 Apr 2014 13:42:12 +0000 (15:42 +0200)]
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.

10 years agoAllocate-slots avoids building CFA
Andy Wingo [Tue, 1 Apr 2014 13:21:28 +0000 (15:21 +0200)]
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.

10 years agoCompile-fun takes advantage of sorted output of "renumber", avoids CFA
Andy Wingo [Tue, 1 Apr 2014 10:42:09 +0000 (12:42 +0200)]
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.

10 years agoCPS renumbering pass sorts conts in topological order
Andy Wingo [Tue, 1 Apr 2014 10:03:37 +0000 (12:03 +0200)]
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.

10 years agoAdd visit-cont-successors helper
Andy Wingo [Tue, 1 Apr 2014 09:59:03 +0000 (11:59 +0200)]
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.

10 years agoFix analyze-control-flow to preserve order among unordered labels
Andy Wingo [Mon, 31 Mar 2014 16:08:11 +0000 (18:08 +0200)]
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.

10 years agoUse Tree-IL-like case-lambda clause chaining in CPS
Andy Wingo [Mon, 31 Mar 2014 14:38:53 +0000 (16:38 +0200)]
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.

10 years agoRewrite control-point? to avoid consing
Andy Wingo [Mon, 31 Mar 2014 10:10:08 +0000 (12:10 +0200)]
Rewrite control-point? to avoid consing

* module/language/cps/dfg.scm (control-point?): Rewrite to avoid consing
  a successors list.

10 years agoRemove succs from DFG
Andy Wingo [Mon, 31 Mar 2014 10:09:46 +0000 (12:09 +0200)]
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.

10 years agoSimplify boot-9 and srfi-1 map
Andy Wingo [Sun, 30 Mar 2014 20:28:07 +0000 (22:28 +0200)]
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.

10 years agoAvoid consing in compute-label-and-var-ranges.
Andy Wingo [Sun, 30 Mar 2014 19:28:10 +0000 (21:28 +0200)]
Avoid consing in compute-label-and-var-ranges.

* module/language/cps/dfg.scm (compute-label-and-var-ranges): Avoid
  consing.

10 years agoScope and scope-level in DFG vector
Andy Wingo [Sun, 30 Mar 2014 19:14:31 +0000 (21:14 +0200)]
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.

10 years agoPredecessors and successors in DFG vectors
Andy Wingo [Sun, 30 Mar 2014 18:55:57 +0000 (20:55 +0200)]
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.

10 years agoDFG refactor
Andy Wingo [Sun, 30 Mar 2014 18:27:31 +0000 (20:27 +0200)]
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.

10 years agoRenumber functions before emitting code
Andy Wingo [Sun, 30 Mar 2014 17:31:07 +0000 (19:31 +0200)]
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.

10 years agoAdd renumber module
Andy Wingo [Sun, 30 Mar 2014 17:09:40 +0000 (19:09 +0200)]
Add renumber module

* module/language/cps/renumber.scm: New module.
* module/Makefile.am: Add to build.

fix renumber

10 years agoReplace use-map in DFG with separate def / use vectors
Andy Wingo [Sun, 30 Mar 2014 09:48:47 +0000 (11:48 +0200)]
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.

10 years agoRemove "sym" from $use-map
Andy Wingo [Sun, 30 Mar 2014 09:36:59 +0000 (11:36 +0200)]
Remove "sym" from $use-map

* module/language/cps/dfg.scm ($use-map): Remove "sym" from use-map;
  it's redundant.  Adapt callers.

10 years ago$use-map no longer has name member
Andy Wingo [Sun, 30 Mar 2014 09:25:23 +0000 (11:25 +0200)]
$use-map no longer has name member

* module/language/cps/dfg.scm ($use-map): Remove name member.  Adapt
  users.

10 years ago$dfa no longer includes name vector (can get that from dfg)
Andy Wingo [Sun, 30 Mar 2014 09:23:51 +0000 (11:23 +0200)]
$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.

10 years agoDFG stores conts, blocks, and use-maps in vectors
Andy Wingo [Sun, 30 Mar 2014 09:14:45 +0000 (11:14 +0200)]
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.

10 years agolookup-cont takes a DFG as its argument
Andy Wingo [Sun, 30 Mar 2014 08:41:31 +0000 (10:41 +0200)]
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.

10 years agoPublic make-cont-folder
Andy Wingo [Sat, 29 Mar 2014 06:56:08 +0000 (07:56 +0100)]
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.

10 years agoVars and labels are separate namespaces
Andy Wingo [Fri, 28 Mar 2014 21:27:48 +0000 (22:27 +0100)]
Vars and labels are separate namespaces

* module/language/cps.scm (fresh-var, with-fresh-name-state): Vars have
  their own namespace.

10 years agoPrepare for decoupling of var/label name uniqueness
Andy Wingo [Fri, 28 Mar 2014 20:55:46 +0000 (21:55 +0100)]
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.

10 years agoUpdate verify-cps
Andy Wingo [Fri, 28 Mar 2014 20:32:26 +0000 (21:32 +0100)]
Update verify-cps

* module/language/cps/verify.scm (verify-cps): Vars should only be exact
  integers now.

10 years agoCPS conversion renames incoming gensyms to small integers
Andy Wingo [Fri, 28 Mar 2014 20:30:55 +0000 (21:30 +0100)]
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.

10 years agoLess copying in tree-il pre-order / post-order.
Andy Wingo [Fri, 28 Mar 2014 18:17:22 +0000 (19:17 +0100)]
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.

10 years agoPrompt-related refactor in compile-cps
Andy Wingo [Fri, 28 Mar 2014 16:51:37 +0000 (17:51 +0100)]
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.

10 years agoDCE uses fresh-var instead of gensym
Andy Wingo [Fri, 28 Mar 2014 15:57:40 +0000 (16:57 +0100)]
DCE uses fresh-var instead of gensym

* module/language/cps/dce.scm (eliminate-dead-code): Use fresh-var
  instead of gensym.

10 years agoAdapt verify-cps to CPS changes
Andy Wingo [Fri, 28 Mar 2014 15:55:15 +0000 (16:55 +0100)]
Adapt verify-cps to CPS changes

* module/language/cps/verify.scm (verify-cps): Update to expect integer
  labels, and to allow integer variables.

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.