mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-05 03:30:24 +02:00
This commit changes to use <operand> structures to hold the context needed to visit lexical bindings lazily, in context, instead of eagerly visiting them for value. This laziness enables inlining of mutually recursive bindings. * module/language/tree-il/peval.scm (<var>): Remove comment about copy propagation having to run build-var-table; things don't work like that any more. (build-var-table): Build <var> entries for all variables, even unreferenced variables. (alpha-rename): Remove. We will rename bindings on-demand now. (peval lookup-var): New helper, to fetch the <var> of a gensym. (peval fresh-gensyms): Fold here, under peval, and in it, handle updating the store to record a mapping between new names and <var> entries from the source program. (peval record-source-expression): Don't call build-var-table on the new expression, as alpha-renaming happens on-demand now. (peval prune-bindings): Rewrite to work with mutually-recursive bindings, while optionally preserving binding order. (peval extend-env): New helper. (peval loop): OK, here goes... Remove the `operand' context, as now we visit operands lazily. Add a `call' context, which does not copy-propagate lambda expressions, used to residualize a call after aborting an inlining attempt. Change the `env' to be a mapping of gensym to <operand>. Instead of looking up the operand's binding then alpha-renaming it, just rely on the fact that visiting the operand will rename it if necessary. If we residualize a lexical, do so with the fresh name from the environment. If we visit an operand and it doesn't turn out to be constant, we will never be able to copy it, and so cache that fact in the operand. If we residualize a binding and we know what the value should be, record that binding so that prune-bindings won't have to visit it again. If the operand folds to a constant, cache that too, to save effort when unrolling loops. For let, letrec, fix, and lambda-case, instead of visiting the bindings eagerly for value, simply record the source expressions and environments in an <operand> and rely on copy-propagation to visit them later in the right context. In the case of letrec and fix, this allows mutually-recursive bindings to be inlined. Refactor folding of "constructors" (which still need renaming) to avoid visiting operands twice in some contexts. For applications, if we have to abort, process the procedure in call context, which allows some folding but avoids copying lambdas. If we find a recursive procedure, mark intervening counters as recursive too, to allow for mutual recursion at the top level. For lambdas, if we are processing for value, record the source expression so we can detect recursion. This was previously done in the lexical-ref copy propagator. * test-suite/tests/tree-il.test ("partial evaluation"): Remove unused recursive lexicals in a couple of cases. Add a couple test cases for pruning. Add a few recursive binding cases. |
||
---|---|---|
.. | ||
lalr | ||
standalone | ||
tests | ||
vm | ||
ChangeLog-2008 | ||
guile-test | ||
lib.scm | ||
Makefile.am | ||
README |
This directory contains some tests for Guile, and some generic test support code. To run these tests, you will need a version of Guile more recent than 15 Feb 1999 --- the tests use the (ice-9 and-let*) and (ice-9 getopt-long) modules, which were added to Guile around then. For information about how to run the test suite, read the usage instructions in the comments at the top of the guile-test script. You can reference the file `lib.scm' from your own code as the module (test-suite lib); it also has comments at the top and before each function explaining what's going on. Please write more Guile tests, and send them to bug-guile@gnu.org. We'll merge them into the distribution. All test suites must be licensed for our use under the GPL, but I don't think I'm going to collect assignment papers for them. Some test suite philosophy: GDB has an extensive test suite --- around 6300 tests. Every time the test suite catches a bug, it's great. GDB is so complicated that folks are often unable to get a solid understanding of the code before making a change --- we just don't have time. You'll see people say things like, "Here's a fix for X; it doesn't cause any regressions." The subtext is, I made a change that looks reasonable, and the test suite didn't complain, so it must be okay. I think this is terrible, because it suggests that the writer is using the test suite as a substitute for having a rock-solid explanation of why their changes are correct. The problem is that any test suite is woefully incomplete. Diligent reasoning about code can catch corner conditions or limitations that no test suite will ever find. Jim's rule for test suites: Every test suite failure should be a complete, mysterious surprise, never a possibility you were prepared for. Any other attitude indicates that you're using the test suite as a crutch, which you need only because your understanding is weak.