* 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.
* 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.
* 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.
* 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.
* 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.
* module/language/tree-il/optimize.scm (alpha-rename, peval): Add
support for lexical-set, while avoiding copy propagation and pruning
of assigned variables.
* 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).
* 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.
* 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.
* 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.
* 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>.
* 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*'.
* 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.
* 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.
* 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}#.
* 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.
* 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.)
* 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.
* 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.
* 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.
* 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.
* 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.
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.
* 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.
* 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!.