mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 20:00:19 +02:00
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.
This commit is contained in:
parent
870dfc609b
commit
1e8ace33d1
2 changed files with 35 additions and 3 deletions
|
@ -251,9 +251,10 @@ it should be called before `fix-letrec'."
|
|||
(args (map (cut loop <> env calls) orig-args))
|
||||
(args* (map maybe-unconst orig-args args))
|
||||
(app (make-application src proc args*)))
|
||||
;; If ARGS are constants and this call hasn't already been
|
||||
;; expanded before (to avoid infinite recursion), then
|
||||
;; expand it (todo: emit an infinite recursion warning.)
|
||||
;; If at least one of ARGS is static (to avoid infinite
|
||||
;; inlining) and this call hasn't already been expanded
|
||||
;; before (to avoid infinite recursion), then expand it
|
||||
;; (todo: emit an infinite recursion warning.)
|
||||
(if (and (any const*? args)
|
||||
(not (member (cons proc args) calls)))
|
||||
(match proc
|
||||
|
|
|
@ -943,6 +943,37 @@
|
|||
(apply (toplevel frob!) (lexical x _))
|
||||
(lexical x _))))
|
||||
|
||||
(pass-if-peval
|
||||
;; Inlining stops at recursive calls with dynamic arguments.
|
||||
(let loop ((x x))
|
||||
(if (< x 0) x (loop (1- x))))
|
||||
(letrec (loop) (_) ((lambda (_)
|
||||
(lambda-case
|
||||
(((x) #f #f #f () (_))
|
||||
(if _ _
|
||||
(apply (lexical loop _)
|
||||
(apply (primitive 1-)
|
||||
(lexical x _))))))))
|
||||
(apply (lexical loop _) (toplevel x))))
|
||||
|
||||
(pass-if-peval
|
||||
;; Inlining stops at recursive calls (mixed static/dynamic arguments).
|
||||
(let loop ((x x) (y 0))
|
||||
(if (> y 0)
|
||||
(loop (1+ x) (1+ y))
|
||||
(if (< x 0) x (loop (1- x)))))
|
||||
(letrec (loop) (_) ((lambda (_)
|
||||
(lambda-case
|
||||
(((x y) #f #f #f () (_ _))
|
||||
(if (apply (primitive >)
|
||||
(lexical y _) (const 0))
|
||||
_ _)))))
|
||||
;; call to (loop x 0) is inlined & specialized
|
||||
(if (apply (primitive <) (toplevel x) (const 0))
|
||||
(toplevel x)
|
||||
(apply (lexical loop _)
|
||||
(apply (primitive 1-) (toplevel x))))))
|
||||
|
||||
(pass-if-peval
|
||||
;; Infinite recursion: `peval' gives up and leaves it as is.
|
||||
(letrec ((f (lambda (x) (g (1- x))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue