From c7d5a764409c8eb77c0b3059b28e66545d5b65bd Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 26 Nov 2022 10:46:12 -0800 Subject: compiler: runaway recursion in constant folding call. When an invalid call expression is constant folded, such as (call 'abs 1 2), runaway recursion occurs. This is because due to the wrong number of arguments being passed to abs, the safe-const-reduce function returns the expression unmodified. The comp-apply-call method then passes it to compile, wrongly assuming a reduction had taken place, and so everything repeats. * stdlib/compiler.tl (comp-apply-call): Detect when safe-const-reduce has hit a fixed point by returning the input form. In that case, we don't call the compiler top-level entry point, but the comp-fun-form method directly; the wrong function call will be compiled without constant folding and throw an error at run-time. --- stdlib/compiler.tl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stdlib/compiler.tl b/stdlib/compiler.tl index 087ea283..7ab25be3 100644 --- a/stdlib/compiler.tl +++ b/stdlib/compiler.tl @@ -1391,7 +1391,10 @@ (let ((op (safe-const-eval (car args)))) (or [%const-foldable% op] (not (bindable op))))) - me.(compile oreg env (safe-const-reduce form))) + (let ((crform (safe-const-reduce form))) + (if (eq crform form) + me.(comp-fun-form oreg env crform) + me.(compile oreg env crform)))) (t (tree-case (car args) ((op arg . more) (caseq op -- cgit v1.2.3