From 2c0fdfcbee44186ee6a6c251eb6687d7ae08574e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 27 Mar 2021 13:28:34 -0700 Subject: compiler: fix: careless constant folding of call. * share/txr/stdlib/compiler.tl (compiler comp-apply-call): The conditions for constant-folding a call expressions are too weak. The first argument could be a quoted symbol, which is a constant expression, and so we end up wrongly evaluating an expression like (call 'print '3) at compile time. We can constant-fold if the first expression evaluates to a symbol, which names a constant-foldable function, or else if it evaluates to something which is not a bindable symbol. --- share/txr/stdlib/compiler.tl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl index 65202e9e..21721ad6 100644 --- a/share/txr/stdlib/compiler.tl +++ b/share/txr/stdlib/compiler.tl @@ -1362,7 +1362,10 @@ (cond ((and (plusp olev) (eq sym 'call) - [all args constantp]) + [all args constantp] + (let ((op (eval (car args)))) + (or [%const-foldable% op] + (not (bindable op))))) me.(compile oreg env (eval form))) (t (tree-case (car args) ((op arg . more) -- cgit v1.2.3