* module/language/tree-il/peval.scm (peval): Don't
inline (call-with-values foo (lambda (x) exp)) to (let ((x (foo)))
exp). The idea is that call-with-values sets up an explicit context
in which we are requesting an explicit return arity, and that dropping
extra values when there's not a rest argument is the wrong thing.
Fixes#13966.
* test-suite/tests/peval.test ("partial evaluation"): Update test.
* module/language/tree-il/peval.scm (peval): In test context,
fold (let ((x EXP)) (if x x ALT)) to (if EXP #t ALT). This reduces
the number of boolean literals that the compiler has to reify, by
causing EXP to evaluate in test context instead of value context.
Also, rotate `let' out of the test part of conditionals, for the same
reason.
* libguile/vm-engine.c: Remove add1 and sub1 instructions. Will replace
with add/immediate and sub/immediate.
* module/language/tree-il/peval.scm (peval): If we reify a new
<primcall>, expand it. Removes 1- and similar primcalls.
* module/language/tree-il/primitives.scm: Don't specialize (+ x 1) to 1+.
(expand-primcall): New export, does a single primcall expansion.
(expand-primitives): Use the new helper.
* module/language/cps/effects-analysis.scm:
* module/language/cps/primitives.scm:
* module/language/cps/types.scm:
* module/system/vm/assembler.scm: Remove support for add1 and sub1 CPS
primitives.
* test-suite/tests/peval.test ("partial evaluation"): Adapt tests that
expect 1+/1- to expect +/-.
* module/language/tree-il/peval.scm (<operand>): Rename "alias-value"
field to "alias", which is now an operand and not an expression.
This allows the operand to capture its environment; before, the
alias was being visited in its use environment instead of its
definition environment.
(peval): Adapt to operand change. Fix construction of rest bindings
as well.
* test-suite/tests/peval.test ("partial evaluation"): New test.
Fixes <http://bugs.gnu.org/17634>.
Reported by Josep Portella Florit <jpf@primfilat.com>.
* module/language/tree-il/peval.scm (inlined-application): When inlining
an application whose operator is a lambda expression with optional
arguments that rely on default initializers, expand into a series of
nested let expressions, to ensure that previous arguments are in scope
when the default initializers are evaluated.
* test-suite/tests/peval.test ("partial evaluation"): Add tests.
* module/language/cps/effects-analysis.scm: Add entries for logtest and
logbit?.
* module/language/cps/types.scm (logtest, logbit?): New checkers and
inferrers.
* module/language/tree-il/peval.scm (peval): Convert (zero? (logand a
b)) to (logtest a b), in anticipation of opcode support for logtest.
*
module/language/tree-il/primitives.scm (*interesting-primitive-names*):
(*effect-free-primitives*): Add logtest and logbit?.
* module/language/tree-il/peval.scm (peval): When going to peval a call
whose operator isn't just a lambda but is a let-bound lambda, as one
bound via define-inlinable, don't create a new counter if the lambda
is only referenced once in the source. Avoids needless failure to
inline once-referenced procedures.
* test-suite/tests/peval.test ("partial evaluation"): Wheeeee
Fixes <http://bugs.gnu.org/15533>.
* module/language/tree-il/peval.scm (peval): Final list argument to
`apply' should not be inlined if it is mutable.
* test-suite/tests/peval.test ("partial evaluation"): Add test.
* module/language/tree-il/effects.scm (compile-time-cond):
(define-effects): Make the effects analysis more precise,
distinguishing between different kinds of mutable data. On 64-bit
systems we take advantage of the additional bits to be even more
precise.
(make-effects-analyzer): Inline handlers for all "accessor" primitives
and their corresponding mutators.
* module/language/tree-il/peval.scm (peval): Reflow to remove use of the
"accessor-primitive?" predicate.
* module/language/tree-il/primitives.scm (accessor-primitive?): Remove.
* module/language/tree-il/peval.scm (peval): Fix a bug whereby inlined
function applications with default argument initializers were putting
the initializers in the wrong scope.
* test-suite/tests/peval.test ("partial evaluation"): Add a test.
* module/language/tree-il/peval.scm (peval): Remove abort optimization;
the CPS compiler will do much better here, and it is complicating
things in the meantime.
* module/language/tree-il.scm (<prompt>): Change to have the body and
handler be lambdas, and add an "escape-only?" field. This will make
generic prompts work better in CPS or ANF with the RTL VM, as it
doesn't make sense in that context to capture only part of a frame.
Escape-only prompts can still be fully inlined.
(parse-tree-il, unparse-tree-il): Add escape-only? to the
serialization.
(make-tree-il-folder, pre-post-order): Deal with escape-only?.
* module/language/tree-il/analyze.scm (analyze-lexicals): Handle
escape-only?, and the new expectations for the body and handler.
* module/language/tree-il/canonicalize.scm (canonicalize): Ensure that
the body of an escape-only continuation is a thunk, and that the
handler is always a lambda.
* module/language/tree-il/debug.scm (verify-tree-il): Assert that
escape-only? is a boolean.
* module/language/tree-il/cse.scm (cse):
* module/language/tree-il/effects.scm (make-effects-analyzer):
* module/language/tree-il/peval.scm (peval):
* module/language/tree-il/primitives.scm (*primitive-expand-table*):
* test-suite/tests/peval.test ("partial evaluation"):
* module/language/tree-il/compile-glil.scm (flatten-lambda-case): Adapt
to <prompt> change.
* libguile/vm-i-system.c (push-fluid, pop-fluid):
* doc/ref/vm.texi (Dynamic Environment Instructions): Rename wind-fluids
to push-fluid, and unwind-fluids to pop-fluid. They now only work on
one fluid binding at a time.
* module/ice-9/boot-9.scm (with-fluid*): Implement in Scheme in terms of
primcalls to push-fluid and pop-fluid.
(custom-throw-handler, catch, with-throw-handler): Use with-fluid*
instead of with-fluids, as with-fluids is no longer available before
psyntax is loaded.
(with-fluids): Define in Scheme in terms of with-fluid*.
* libguile/fluids.c (scm_with_fluid): Rename from scm_with_fluids, and
don't expose to Scheme.
* libguile/eval.c (eval): Remove SCM_M_WITH_FLUIDS case.
* libguile/expand.c (expand_with_fluids): Remove with-fluids syntax.
(DYNLET): Remove, no longer defining dynlet in the %expanded-vtables.
* libguile/expand.h: Remove dynlet definitions.
* module/ice-9/eval.scm (primitive-eval): Remove with-fluids case.
* libguile/memoize.c (do_push_fluid, do_pop_fluid): New primitive
helpers, like wind and unwind.
(memoize): Memoize wind and unwind primcalls. Don't memoize dynlet to
with-fluids.
(scm_init_memoize): Initialize push_fluid and pop_fluid here.
* libguile/memoize.h (SCM_M_WITH_FLUIDS): Remove definition.
* module/ice-9/psyntax.scm (build-dynlet): Remove; this just supported
with-fluids, which is now defined in boot-9.
* module/ice-9/psyntax-pp.scm: Regenerate.
* doc/ref/compiler.texi (Tree-IL):
* module/language/tree-il.scm:
* module/language/tree-il/analyze.scm:
* module/language/tree-il/canonicalize.scm:
* module/language/tree-il/compile-glil.scm:
* module/language/tree-il/cse.scm:
* module/language/tree-il/debug.scm:
* module/language/tree-il/effects.scm: Remove <dynlet>. Add cases for
primcalls to push-fluid and pop-fluid in compile-glil.scm and
effects.scm.
* module/language/tree-il/peval.scm (peval): Factor out
with-temporaries; probably a bad idea, but works for now. Factor out
make-begin0 (a better idea). Inline primcalls to with-fluid*, and
remove dynlet cases.
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
Add with-fluid*.
* doc/ref/compiler.texi: Remove mention of <dynwind>.
* libguile/eval.c (eval): Remove SCM_M_DYNWIND case.
* libguile/expand.c: Remove scm_sym_at_dynamic_wind.
* libguile/memoize.c (do_wind, do_unwind): A couple of hacky subrs. If
we see a wind or unwind primcall, we expand to a call of a quoted subr
value. It works and removes a kind of memoized value from the
interpreter. For the compiler,primcalls to wind and unwind are
handled specially.
(MAKMEMO_DYNWIND): Remove.
(scm_tc16_memoizer): Remove. Yay!
(memoize): Remove speculative lookup for toplevels to see if they are
memoizers: there are no more memoizers. Memoize calls to the wind and
unwind primitives.
(m_dynamic_wind): Remove.
(unmemoize): Remove dynwind case.
(scm_init_memoize): Add wind and unwind local definitions.
* module/ice-9/boot-9.scm (dynamic-wind): Reimplement in terms of "wind"
and "unwind" primitives. These primitives are not exposed to other
modules.
* module/ice-9/eval.scm (primitive-eval): Remove dynwind case.
* module/language/scheme/decompile-tree-il.scm (do-decompile):
(choose-output-names): Remove dynwind cases.
* module/language/tree-il.scm: Remove <dynwind>. Yaaay!
* module/language/tree-il/analyze.scm (analyze-lexicals): Remove dynwind
cases.
* module/language/tree-il/compile-glil.scm (*primcall-ops*): Add wind
and unwind.
(flatten-lambda-case): Remove dynwind case. Yay!
* module/language/tree-il/cse.scm (cse):
* module/language/tree-il/debug.scm (verify-tree-il):
* module/language/tree-il/effects.scm (make-effects-analyzer):
* module/language/tree-il/peval.scm (singly-valued-expression?, peval):
Remove <dywind> cases. Inline primcalls to dynamic-wind. Add
constant folding for thunk?.
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
Remove @dynamic-wind, and add procedure? and thunk?.
(*effect+exception-free-primitives*): Add procedure? and thunk?.
(*multiply-valued-primitives*): Remove @dynamic-wind.
Remove @dynamic-wind expander.
* test-suite/tests/peval.test ("partial evaluation"): Update tests for
dynwind desugaring.
* libguile/memoize.h:
* libguile/expand.c (scm_sym_at_call_with_values): Remove.
* libguile/memoize.c (memoize, m_call_values, unmemoize): Adapt to
memoize call-with-values primcalls.
* module/ice-9/boot-9.scm (call-with-values): Expand to a
call-with-values primcall.
* module/language/tree-il/compile-glil.scm (flatten-lambda-case): Expect
call-with-values primcall, without the @, and fall back to a normal
call.
* module/language/tree-il/peval.scm (peval): Match bare
call-with-values.
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
(*multiply-valued-primitives*): Remove @call-with-values.
* libguile/memoize.c (memoize): Recognize a primcall to 'apply as
SCM_M_APPLY.
(@apply): Remove @apply memoizer.
(unmemoize): Unmemoize using "apply", not "@apply".
* libguile/memoize.h:
* libguile/expand.c (scm_sym_atapply): Remove.
* module/ice-9/boot-9.scm (apply): Re-implement using apply primcall.
Use case-lambda, so as to give an appropriate minimum arity.
* module/language/tree-il/compile-glil.scm (flatten-lambda-case):
Compile a primcall of "apply" specially, not "@apply".
* module/language/tree-il/peval.scm (peval): Match primcalls to "apply",
not "@apply". Residualize "apply" primcalls.
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
(*multiply-valued-primitives*): Remove @apply, and apply primitive
expander.
* test-suite/tests/peval.test:
* test-suite/tests/tree-il.test: Update tests to expect residualized
"apply".
* test-suite/tests/procprop.test ("procedure-arity"): Update test for
better apply arity.
* test-suite/tests/strings.test ("string"): Update expected error.
* module/language/tree-il.scm (<tree-il>): Remove pre and post fields
from <dynwind>. A dynwind now assumes that in normal entry and exit,
that the code runs the winders and unwinders using <seq> and
<let-values> and such things.
(parse-tree-il, unparse-tree-il, make-tree-il-folder, pre-post-order):
Adapt <dynwind> users.
* module/language/tree-il/analyze.scm (analyze-lexicals):
* module/language/tree-il/compile-glil.scm (flatten-lambda-case):
* module/language/tree-il/cse.scm (cse):
* module/language/tree-il/debug.scm (verify-tree-il):
* module/language/tree-il/effects.scm (make-effects-analyzer): Adapt.
* module/language/tree-il/peval.scm (peval):
* module/language/tree-il/primitives.scm (*primitive-expand-table*):
Produce tree-il that calls the winder and unwinder. Recognize
singly-valued dynamic-wind expressions.
* test-suite/tests/peval.test ("partial evaluation"): Add tests.
* module/language/tree-il/peval.scm (singly-valued-expression?): Add
support for conditionals. In the future we should add more
expressions here.
(peval): Don't inline values into the body of a dynwind, as that could
cause the consumer to run in the wrong dynamic context.
If the producer is singly-valued and the consumer just has a rest arg,
reduce to "let" and cons up a list in the consumer. This may reduce
further.
* test-suite/tests/peval.test ("partial evaluation"): Add a test.
* module/language/tree-il.scm (tree-il-fold): Implement using
make-tree-il-folder. This is an incompatible change: there is no more
"leaf" procedure, and tree-il-fold only works on tree-il and not
lists.
* module/language/tree-il/analyze.scm (<tree-analysis>, analyze-tree):
Adapt to tree-il-fold change, losing the "leaf" handler.
(unused-variable-analysis, unused-toplevel-analysis)
(unbound-variable-analysis, arity-analysis): Adapt to tree-analysis
change.
* module/language/tree-il/canonicalize.scm (tree-il-any)
* module/language/tree-il/cse.scm (build-assigned-var-table)
* module/language/tree-il/peval.scm (tree-il-any, build-var-table)
(peval): Adapt to tree-il-fold change.
* test-suite/tests/tree-il.test ("tree-il-fold"): Adapt tests for new
interface and expectations.
* module/language/tree-il/peval.scm (peval): let-values with a consumer
that has only one argument is the same as let.
* test-suite/tests/peval.test ("partial evaluation"): Add test.
* module/language/tree-il/peval.scm (peval): Add a special-case inlining
pattern for apply to a let-bound rest arg that preserves effect
ordering.
* test-suite/tests/peval.test ("partial evaluation"): Add a test, and
update an older test with a better result.
* module/language/tree-il/peval.scm (peval): Correct comment on
find-definition, and allow a find-definition to fall back on a source
expression. Avoid copying non-constant expressions.
* test-suite/tests/peval.test ("partial evaluation"): Add a test that
inlining rest arguments works with complicated argument expressions,
and a test that order of effects in rest args is preserved.
* module/language/tree-il/peval.scm (peval): Move up the find-definition
helper. Use it to speculatively destructure conses and lists into the
tail position of an `apply' form.
* test-suite/tests/peval.test ("partial evaluation"): Add tests.
* module/language/tree-il/peval.scm (peval): Gensyms use whitespace as
an infix, not a dash. Helps gensym?-like procedures like those in the
unused lexical analysis.
* module/language/tree-il/peval.scm (<operand>): Instead of having a
`residualize?' field, have it be a use count.
(peval): Adapt to <operand> change. Add function to kill uses of an
operand. Use it in the <prompt> inliner. Add another kind of
degenerate prompt to elide. We should really switch to CPS though, as
that will allow us to contify more aggressively.
* test-suite/tests/peval.test ("partial evaluation"): Adapt (while #t
#t) test, which was sensitive to how far the recursive inlining got.
Add a test for the degenerate prompt elision.
* module/language/tree-il/peval.scm (peval): Inline applications where
we know the contents of the tail.
* test-suite/tests/peval.test ("partial evaluation"): Add tests.
* module/language/tree-il/peval.scm (peval): If we can lift one common
test, see if we can lift others as well.
* test-suite/tests/peval.test: Add a test.
* module/language/tree-il/peval.scm (peval): Optimize common tests in
chains of "if" expressions, like those generated by matchers.
* test-suite/tests/peval.test ("partial evaluation"): Add a test.