From 3f53b5cec29b18fb9bbf8451414d590ae7be9574 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 1 Nov 2021 23:38:56 -0700 Subject: compiler: don't lift top-level lambdas. The compiler is lifting top-level lambdas, such as those generated by defun, using the load-time mechanism. This has the undesireable effect of unnecessarily placing the lambdas into a D register. * stdlib/compiler.tl (*top-level*): New special variable. This indicates that the compiler is compiling code that is outside of any lambda. (compiler comp-lambda-impl): Bind *top-level* to nil when compiling lambda, so its interior is no longer at the top level. (compiler comp-lambda): Suppress the unnecessary lifting optimization if the lambda expression is in the top-level, outside of any other lambda, indicated by *top-level* being true. (compile-toplevel): Bind *top-level* to t. --- stdlib/compiler.tl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/stdlib/compiler.tl b/stdlib/compiler.tl index c27cc040..69696b15 100644 --- a/stdlib/compiler.tl +++ b/stdlib/compiler.tl @@ -308,6 +308,8 @@ (defvar *load-time*) +(defvar *top-level*) + ;; 0 - no optimization ;; 1 - constant folding, algebraics. ;; 2 - block elimination, frame elimination @@ -1039,6 +1041,7 @@ closure-spies me.closure-spies) (compile-with-fresh-tregs me (let* ((*load-time* nil) + (*top-level* nil) (pars (new (fun-param-parser par-syntax form))) (need-frame (or (plusp pars.nfix) pars.rest)) (nenv (if need-frame (new env up env co me) env)) @@ -1144,7 +1147,7 @@ pars))))))))))) (defmeth compiler comp-lambda (me oreg env form) - (if (or *load-time* (< *opt-level* 3)) + (if (or *load-time* *top-level* (< *opt-level* 3)) me.(comp-lambda-impl oreg env form) (let* ((snap me.(snapshot)) (lambda-frag me.(comp-lambda-impl oreg env form)) @@ -2106,6 +2109,7 @@ (as (new assembler)) (*dedup* (or *dedup* (hash))) (*load-time* nil) + (*top-level* t) (*opt-level* (or *opt-level* 0))) (let* ((oreg co.(alloc-treg)) (xexp (if expanded-p -- cgit v1.2.3