Subject: bug#61660: closed (Re: bug#61660: [feature request] optimization of case-lambda)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 27 Feb 2023 17:20:02 +0000

Your bug report

#61660: [feature request] optimization of case-lambda

which was filed against the guile package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
61660: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=61660
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#61660: [feature request] optimization of case-lambda
From: lloda <[email-masked]>
To: Ludovic Courtès <[email-masked]>
Cc: [email-masked]
Date: Mon, 27 Feb 2023 18:19:42 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

> On 27 Feb 2023, at 11:11, Ludovic Courtès <[email-masked]> wrote:
> 
> Hi Daniel,
> 
> lloda <[email-masked]> skribis:
> 
>> From 61ed612fb36108e395bdee4b1bbb46b49ef017b3 Mon Sep 17 00:00:00 2001
>> From: Daniel Llorens <[email-masked]>
>> Date: Thu, 23 Feb 2023 17:38:10 +0100
>> Subject: [PATCH] peval reduces some inlined case-lambda calls
>> 
>> * module/language/tree-il/peval.scm (peval): Reduce multiple case lambda
>>  in <call> trees according to the number of arguments. Do not try to
>>  reduce case-lambda using keyword arguments.
>> * test-suite/tests/peval.test: Tests.
> 
> [...]
> 
>> +++ b/module/language/tree-il/peval.scm
>> @@ -1668,6 +1668,29 @@ top-level bindings from ENV and return the resulting expression."
>> 
>>                   (log 'inline-end result exp)
>>                   result)))))
>> +           (($ <lambda> src-proc meta orig-body)
>> +            ;; If there are multiple cases and one matches nargs, omit all the others.
>> +            (or (and
>> +                 (lambda-case-alternate orig-body)
>> +                 (let ((nargs (length orig-args)))
>> +                   (let loop ((body orig-body))
>> +                     (match body
>> +                       (#f #f) ;; No matching case; an error.
>> +                       (($ <lambda-case> src-case req opt rest kw inits gensyms case-body alt)
>> +                        (cond (kw
>> +                               ;; FIXME: Not handling keyword cases.
>> +                               #f)
> 
> Maybe s/FIXME/XXX/ since it’s at most a limitation, certainly not a bug.
> 
> It LGTM and Andy already approved it on IRC, so go ahead!
> 
> Ludo’.

Apologies for not seeing this earlier. Pushed to 3b47f87618047ebb8812788c64a44877a4f2e0dd. Thanks!

  - Daniel

Subject: [feature request] optimization of case-lambda
From: lloda <[email-masked]>
To: "[email-masked]" <[email-masked]>
Date: Mon, 20 Feb 2023 18:56:25 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

On 3.0.9

> ,optimize ((case-lambda (() 0)))
= 0

but 

> ,optimize ((case-lambda (() 0) ((a) 1)))
= ((case-lambda (() 0) ((a) 1)))

The problem with this is that when the output of a macro contains case-lambda, recursive application results in geometrical increase of code size. It seems that it should be possible to resolve the application on the spot; at last to reduce the case-lambda to a simple lambda when the arity is available (which now only happens when the case-lambda contains a single clause).

Thanks

  Daniel