1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-26 05:00:28 +02:00

Recognize append as a primcall and optimize it

* module/language/tree-il/primitives.scm (*primitive-constructors*):
(append): Recognize append and reduce it to only the two-operand form.
* module/language/tree-il/peval.scm (peval): Add optimizations to
append.
This commit is contained in:
Andy Wingo 2023-11-27 14:25:23 +01:00
parent 38e9bd7a2f
commit d7cf5bf373
3 changed files with 58 additions and 2 deletions

View file

@ -1588,5 +1588,26 @@
(pass-if-peval (begin (cons 1 (values)) #f)
(seq (primcall values (primcall values))
(const #f)))
(pass-if-peval (begin 1 (values) #f)
(const #f)))
(with-test-prefix "append"
(pass-if-peval (append '() 42)
(const 42))
(pass-if-peval (append '(1 2) 42)
(primcall cons (const 1)
(primcall cons (const 2) (const 42))))
(pass-if-peval (append (list 1 2) 42)
(primcall cons (const 1)
(primcall cons (const 2) (const 42))))
(pass-if-peval (append (cons* 1 2 '()) 42)
(primcall cons (const 1)
(primcall cons (const 2) (const 42))))
(pass-if-peval (append (cons 1 2) 42)
(primcall cons (const 1)
(primcall append (const 2) (const 42)))))