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

2036 commits

Author SHA1 Message Date
Andy Wingo
cf82943f9f peval: add a bunch of missing maybe-unconst calls
* module/language/tree-il/optimize.scm (peval): Add missing
  maybe-unconst calls.  Things are getting ugly.  They will get better
  in the next commit though.
2011-09-25 02:54:34 +02:00
Andy Wingo
b839233282 peval uses effort counters, propagates lambdas more effectively
* module/language/tree-il/optimize.scm (code-contains-calls?): Remove
  this helper, we will deal with recursion when it happens, not after
  the fact.
  (peval): Add keyword args for various size and effort limits.  Instead
  of keeping a call stack, keep a chain of <counter> records, each with
  an abort continuation.  If ever an inlining attempt is taking too
  long, measured in terms of number of trips through the main loop, the
  counter will abort.  Add new contexts, `operator' and `operand'.  They
  have different default size limits.  In the future we should actually
  use the size counter, instead of these heuristics.

  The <lexical-ref> case is smarter now, and tries to avoid propagating
  too much data.  Perhaps it should be dumber though, and use a
  counter.  That would require changes to the environment structure.

  Inline <lambda> applications to <let>, so that we allow residual
  lexical references to have bindings.  Add a `for-operand' helper, and
  use it for the RHS of `let' expressions.  A `let' is an inlined
  `lambda'.

  `Let' and company no longer elide bindings if the result is a
  constant, as the arguments could have effects.  Peval will still do as
  much as it can, though.

* test-suite/tests/tree-il.test ("partial evaluation"): Update the tests
  for the new expectations.  They are uniformly awesomer, with the
  exception of two cases in which pure but not constant data is not
  propagated.
2011-09-25 02:49:02 +02:00
Andy Wingo
fab137869e prune unused letrec bindings
* module/language/tree-il/optimize.scm (peval): Prune unused `letrec'
  bindings.
2011-09-24 20:37:12 +02:00
Andy Wingo
062bf3aa44 more peval refactoring
* module/language/tree-il/optimize.scm (peval): Rename `var-table' to
  `store', as we're going to put some more things in it.  Rename
  `record-lexical-bindings' to `record-source-expression', which also
  takes the original, pre-renaming expression.  Keep a mapping from new
  expressions to original expressions, available using the
  `source-expression' helper.
2011-09-24 20:34:43 +02:00
Andy Wingo
8018dfdc02 add helpers for effort counters
* module/language/tree-il/optimize.scm (<counter>, abort-counter)
  (record-effort!, record-size!, find-counter, make-top-counter)
  (make-nested-counter, make-recursive-counter): New helpers, as yet
  unused, but which will implement fixed effort bounds on the inlining
  algorithm.
2011-09-24 20:34:33 +02:00
Andy Wingo
ded8ad84a7 peval refactor
* module/language/tree-il/optimize.scm (peval): Add for-value, for-test,
  for-effect, and for-tail helpers.  Use them.
2011-09-24 20:34:12 +02:00
Andy Wingo
f6123e4fda attempt to prune unreferenced bindings
* module/language/tree-il/optimize.scm (peval): Rename `record-lexicals'
  to `record-lexical-bindings'.  Record residualized lexical
  references.  Record lexical references in maybe-unlambda.
  Unfortunately this has the disadvantage that the speculative mapping
  of lambda expressions to lexical references records that reference,
  even if we are not going to residualize it.  After processing a `let',
  prune pure unreferenced bindings.  (We can do better than this in the
  future: we can simply process them for effect.)

* test-suite/tests/tree-il.test (pass-if-peval): More debugging.
  ("partial evaluation"): Update to reflect the fact that the `y'
  binding won't be emitted.
2011-09-24 19:08:09 +02:00
Andy Wingo
e43921a982 peval handles lexical-set
* module/language/tree-il/optimize.scm (alpha-rename, peval): Add
  support for lexical-set, while avoiding copy propagation and pruning
  of assigned variables.
2011-09-24 19:02:53 +02:00
Andy Wingo
b8a2b628e9 peval: pre-analyze mutated or reffed-once lexicals
* module/language/tree-il/optimize.scm (<var>, build-var-table, peval):
  Before going into peval, build a table indicating refcounts and a set?
  flag for all lexicals.  Add to the table when introducing new bindings
  (via alpha-renaming).
2011-09-24 19:00:53 +02:00
Andy Wingo
1eb4886ffa peval: don't propagate expressions that access memory
* module/language/tree-il/optimize.scm (peval): Rename
  `pure-expression?' to `constant-expression?', in the sense of GCC's
  `pure' and `const'.  A <toplevel-ref> is not constant, because it can
  be mutated.  A <dynref> isn't constant either, for the same reason.

* test-suite/tests/tree-il.test ("partial evaluation"): Add a test, and
  update existing tests that assumed that toplevel-ref would propagate.
2011-09-24 18:57:59 +02:00
Andy Wingo
8d06538e82 context-specific folding for peval in test and effect contexts
* module/language/tree-il/optimize.scm (peval): Add a "test" context,
  which folds statically decidable values to <const>.  Fold pure
  expressions to <void> in "effect" contexts.  Adapt the <conditional>
  and <sequence> tests to simply look for <const> or <void> expressions,
  respectively.
2011-09-24 17:17:13 +02:00
Andy Wingo
e535a37db8 thread a context through peval
* module/language/tree-il/optimize.scm (peval): Thread a "context"
  through the evaluator.
2011-09-24 17:17:11 +02:00
Andy Wingo
8f6dfb9ad2 paper around `match' bug
* module/ice-9/match.scm (match): Always introduce a lexical binding, to
  avoid http://debbugs.gnu.org/9567.  Real fix ongoing.  Patch and
  original report by Stefan Israelsson Tampe.

* test-suite/tests/match.test: Add test.
2011-09-24 17:16:31 +02:00
Andy Wingo
250991010f peval: various bugfixes
* module/language/tree-il/optimize.scm (alpha-rename): Rename the
  init
  expressions of a <lambda-case>.
  (peval): Coalesce the <let-values> clauses.
  Fix pure-expression? matching of <lambda> clauses.
  Loop over and maybe-unconst the inits of a <lambda-case>.
2011-09-24 17:15:32 +02:00
Andy Wingo
9e8a5b6637 tree-il-any bugfix
* module/language/tree-il/optimize.scm (tree-il-any): Fix to be called
  on all values, including leaves.  It didn't matter for the use case,
  though.
2011-09-24 17:09:40 +02:00
Andy Wingo
dd7ab5d8a4 minor peval style tweak
* module/language/tree-il/optimize.scm (peval): Minor refactor to
  <lexical-ref> copy propagation.
2011-09-24 17:09:40 +02:00
Andy Wingo
c829531a46 fix alpha-rename for kwargs
* module/language/tree-il/optimize.scm (alpha-rename): Fix
  alpha-renaming of keyword arguments.
2011-09-24 17:09:40 +02:00
Ludovic Courtès
ec6e09bee7 peval: Rectify style.
* module/language/tree-il/optimize.scm (peval): Rename `src' to
  `lv-src', and `src2' to `src'; pass `make-let-values' the right source
  locations.  Reindent `let*'.
2011-09-23 18:12:28 +02:00
Andy Wingo
d851e32fdc prevent propagation for memory-dependent operations like `car'
* module/language/tree-il/primitives.scm (*primitive-constructors*):
  Record car, cdr, vector-ref, and struct-ref as "constructors".
  Comment to come later.
  (*effect-free-primitives*): Update.

* test-suite/tests/tree-il.test ("partial evaluation"): Add tests.
2011-09-23 18:02:05 +02:00
Andy Wingo
40bd6a7e57 peval comment & reindentation
* module/language/tree-il/optimize.scm (peval): Add a comment regarding
  failure modes, and reindent one clause.
2011-09-21 08:58:27 +02:00
Andy Wingo
9581febbb0 fix comment regarding alpha-renaming
* module/language/tree-il/optimize.scm (peval): Fix comment regarding
  alpha-renaming: it's not simply the allocator that needs unique names;
  rather, all transformations depend on it.
2011-09-21 08:58:27 +02:00
Andy Wingo
2605b6ba27 better pure-expression?
* module/language/tree-il/optimize.scm (peval): Allow dynref, fix, and
  let-values to be pure expressions.
2011-09-21 08:58:27 +02:00
Andy Wingo
ddbee5c00f more alpha-rename robustness
* module/language/tree-il/optimize.scm (alpha-rename): Handle all kinds
  of tree-il, with the current exceptions of lexical set!, prompt, and
  abort.
2011-09-21 08:58:27 +02:00
Andy Wingo
5d5e4f399a more robust alpha-renaming
* module/language/tree-il/optimize.scm (fresh-gensyms): New helper.
  (alpha-rename): Name the new gensyms using the old names as templates,
  not the old gensyms.  This prevents accidental collisions between
  gensyms, if #{x 1}# becomes #{x 12}# instead of #{x 2}#.
2011-09-21 08:58:27 +02:00
Andy Wingo
4f33b47591 peval: inlining of let-values
* module/language/tree-il/optimize.scm (peval): Add support for
  let-values.  Try to inline the consumer into the body of the producer,
  if there is only one return point, and we can figure out how many
  values are being returned, and that number is compatible with the
  consumer.
2011-09-21 08:58:09 +02:00
Andy Wingo
65a3265525 peval support for more forms
* module/language/tree-il/optimize.scm (peval): Add support for fix,
  dynwind, dynlet, dynref, module-set, and toplevel-set.  (Mutating a
  variable directly is similar to calling a function that does so behind
  our backs, so this presents no additional problem.)
2011-09-21 08:56:09 +02:00
Andy Wingo
03026d0fb8 add singly-valued-primitive?
* module/language/tree-il/primitives.scm (singly-valued-primitive?): New
  predicate, for primitives that return exactly one value.
2011-09-21 08:53:06 +02:00
Andy Wingo
d111abd0f6 more optimize.scm factoring
* module/language/tree-il/optimize.scm (vlist-any): New helper.
  (peval): Use it here.
2011-09-21 05:37:07 +02:00
Andy Wingo
0c448ef47b optimize.scm refactor
* module/language/tree-il/optimize.scm (let/ec, tree-il-any): New
  helpers.
  (code-contains-calls?): Use them here.
2011-09-21 05:37:07 +02:00
Daniel Llorens
78295f242a Fix compilation of untyped arrays of rank not 1
* module/language/glil/compile-assembly.scm: vector-fold2 expects vector.
2011-09-21 05:37:07 +02:00
Ludovic Courtès
72b2ca55f6 peval: Abort inlining when the residual code contains recursive calls.
* module/language/tree-il/optimize.scm (code-contains-calls?): New
  procedure.
  (peval): Use it and abort inlining if the residual code of a procedure
  application contains recursive calls.  Suggested by Wingo, Waddell,
  and Dybvig.  Fixes <http://debbugs.gnu.org/9542>.

* test-suite/tests/tree-il.test ("partial evaluation"): Update 2 tests
  that relied on the previous behavior.  Add 1 another test.
2011-09-18 23:01:51 +02:00
Ludovic Courtès
2b0b09fed4 peval: Typo.
* module/language/tree-il/optimize.scm (peval)[maybe-unlambda]: Fix
  typo in comment.
2011-09-17 16:53:23 +02:00
Ludovic Courtès
2ae0775e40 peval: Alpha-rename anonymous lambdas that are duplicated.
* module/language/tree-il/optimize.scm (alpha-rename): New procedure.
  (peval)[maybe-unlambda]: Use it.

* test-suite/tests/tree-il.test ("partial evaluation"): Add two test
  cases for <https://lists.gnu.org/archive/html/bug-guile/2011-09/msg00019.html>.
2011-09-17 16:49:41 +02:00
Ludovic Courtès
3f2d6efc7b peval: Use `resolve-primitives!'.
* module/language/tree-il/optimize.scm (peval): Add `cenv' optional
  argument; caller updated.
  Use `resolve-primitives!' to resolve <primitive-ref> expressions.
2011-09-13 23:34:07 +02:00
Ludovic Courtès
af1c6e424f peval: Clarify `pure-expression?'.
* module/language/tree-il/optimize.scm (peval)[pure-expression?]:
  Clarify the comment.
2011-09-13 23:30:22 +02:00
Ludovic Courtès
735249513a peval: Inline thunks.
* module/language/tree-il/optimize.scm (peval): Inline thunks.

* test-suite/tests/tree-il.test ("partial evaluation"): Add test.
2011-09-13 18:54:01 +02:00
Ludovic Courtès
61237fa4b9 peval: Use the right scope when replacing a lambda by a lexical-ref.
* module/language/tree-il/optimize.scm (peval)[maybe-unlambda]: New
  procedures.
  Use it to de-duplicate named lambdas.  This fixes the scoping bug
  described at <https://lists.gnu.org/archive/html/bug-guile/2011-09/msg00019.html>.

* test-suite/tests/tree-il.test ("partial evaluation"): Add tests to
  reproduce the bug.
2011-09-13 18:25:09 +02:00
Ludovic Courtès
1e8ace33d1 peval: Add tests for inlining with both static & dynamic arguments.
* module/language/tree-il/optimize.scm (peval): Improve comment on the
  inlining heuristics.

* test-suite/tests/tree-il.test ("partial evaluation"): Add two tests.
2011-09-13 16:00:24 +02:00
Ludovic Courtès
870dfc609b peval: Propagate only pure expressions to lambdas.
* module/language/tree-il/optimize.scm (peval): Propagate ARGS to BODY
  only when all of ARGS are pure.  Change APP to use `maybe-unconst' for
  its arguments.

* test-suite/tests/tree-il.test ("partial evaluation"): Add tests for
  mutability preservation and non-propagation of non-constant arguments
  to lambdas.
2011-09-11 00:43:23 +02:00
Ludovic Courtès
89436781e8 peval: Try hard to preserve mutability.
* module/language/tree-il/optimize.scm (peval)[make-values]: Distinguish
  between 1 or another number of values.
  [mutable?, make-value-construction, maybe-unconst]: New procedures.
  Use it in <let>, <letrec>, <toplevel-define>, and <lambda-case>.

* test-suite/tests/tree-il.test ("partial evaluation"): Add tests
  for mutability preservation.
2011-09-11 00:43:23 +02:00
Ian Price
cb7bcfca35 RFC 822 allows single digit days of the month
* module/web/http.scm (parse-rfc-822-date): Add single digit day
  conditional.
* test-suite/tests/web-http.test("general headers"): Add test.
2011-09-10 11:12:04 -07:00
Ian Price
86b4309b71 Fix --listen option to allow other ports
* module/ice-9/command-line.scm (compile-shell-switches): Fix
  off-by-one error in 'substring', and swap branches of conditional.
2011-09-10 11:06:32 -07:00
Ludovic Courtès
c8286111e0 Clarify --debug' vs. --no-debug'.
* module/ice-9/command-line.scm (*usage*): Attempt to suggest that
  `--no-debug' doesn't inhibit debugging support.

* doc/ref/guile-invoke.texi (Command-line Options): Make it clear that
  `--no-debug' doesn't inhibit debugging support.  Reported by Manuel
  Serrano.
2011-09-09 00:05:42 +02:00
Ludovic Courtès
11671bbacb Add a partial evaluator for use in the compiler.
Thanks to William R. Cook for his excellent tutorial,
<http://softlang.uni-koblenz.de/dsl11/>.

* module/language/tree-il/optimize.scm (optimize!): Call `peval' unless
  the #:partial-eval? option asks otherwise.
  (peval): New procedure.

* module/language/tree-il/inline.scm: Add comment.

* module/language/tree-il/primitives.scm (*primitive-constructors*): New
  variable.
  (*effect-free-primitives*): Use it.
  (constructor-primitive?): New primitive.

* test-suite/tests/tree-il.test (assert-tree-il->glil): Extend to
  support `with-partial-evaluation', `without-partial-evaluation', and
  `with-options'.
  (peval): New binding.
  (pass-if-peval): New macro.
  ("lexical refs"): Run tests without partial evaluation.
  ("letrec"): Likewise.
  ("the or hack"): Likewise.
  ("conditional"): Likewise, for some tests.
  ("sequence"): Adjust to new generated code.
  ("partial evaluation"): New test prefix.
2011-09-09 00:05:34 +02:00
Ludovic Courtès
16a3b31611 Use (ice-9 match) instead of `record-case' where it improves readability.
* module/language/tree-il/analyze.scm (goops-toplevel-definition, const-fmt):
  Replace `record-case' by `match'.
  (format-analysis): Likewise, partially.
2011-09-06 00:18:36 +02:00
Ludovic Courtès
5fcb7b3cc5 Update (ice-9 match) from Chibi-Scheme.
* module/ice-9/match.scm (slot-ref, slot-set!, is-a?): New macros.

* module/ice-9/match.upstream.scm: Update from Chibi-Scheme.

* test-suite/Makefile.am (SCM_TESTS): Add `tests/match.test.upstream'.

* test-suite/tests/match.test (rtd-2-slots, rtd-3-slots): New record
  types.
  ("matches")["records"]: New test prefix.
  ("doesn't match")["records"]: New test prefix.
  Include `match.test.upstream'.

* test-suite/vm/t-match.scm (matches?): Fix `$' example.
2011-09-03 22:18:02 +02:00
Andy Wingo
df08fc359c fix srfi-67 compilation
* module/srfi/srfi-67/compare.scm: Fix define-syntax-rule conversion.
2011-09-02 19:49:26 +02:00
Andy Wingo
eddd81f465 fix some cache consistency issues with goops and extended generics
* module/oop/goops.scm (extended-by!, not-extended-by!)
  (upgrade-accessor, merge-generics): Invalidate the method cache after
  munging "extends" or "methods" fields.
  (invalidate-method-cache!): A new wrapper around
  %invalidate-method-cache!, that will also invalidate the caches of
  "extended-by" generics.
  (internal-add-method!, remove-class-accessors!): Use the new
  invalidate-method-cache!.
2011-09-02 13:17:19 +02:00
Andy Wingo
0c65f52c6d more define-syntax-rule usage
* module/ice-9/boot-9.scm:
* module/ice-9/control.scm:
* module/ice-9/futures.scm:
* module/ice-9/optargs.scm:
* module/ice-9/poll.scm:
* module/ice-9/receive.scm:
* module/ice-9/threads.scm:
* module/ice-9/vlist.scm:
* module/language/assembly/compile-bytecode.scm:
* module/language/ecmascript/compile-tree-il.scm:
* module/language/tree-il.scm:
* module/oop/goops.scm:
* module/oop/goops/simple.scm:
* module/oop/goops/stklos.scm:
* module/srfi/srfi-1.scm:
* module/srfi/srfi-35.scm:
* module/srfi/srfi-39.scm:
* module/srfi/srfi-45.scm:
* module/srfi/srfi-67/compare.scm:
* module/sxml/match.scm:
* module/system/repl/error-handling.scm:
* module/system/repl/repl.scm:
* module/system/vm/inspect.scm:
* module/texinfo.scm:
* module/web/server.scm: Use define-syntax-rule, where it makes sense.
2011-09-02 11:36:14 +02:00
Andy Wingo
1bbe0a631c psyntax uses define-syntax-rule
* module/ice-9/psyntax.scm: Use define-syntax-rule.

* module/ice-9/psyntax-pp.scm: Regenerate.
2011-09-02 11:34:00 +02:00