GNU bug report logs - #61660
[feature request] optimization of case-lambda

Previous Next

Package: guile;

Reported by: lloda <lloda <at> sarc.name>

Date: Mon, 20 Feb 2023 17:57:02 UTC

Severity: wishlist

Tags: patch

Done: lloda <lloda <at> sarc.name>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 61660 in the body.
You can then email your comments to 61660 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#61660; Package guile. (Mon, 20 Feb 2023 17:57:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to lloda <lloda <at> sarc.name>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Mon, 20 Feb 2023 17:57:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: lloda <lloda <at> sarc.name>
To: "bug-guile <at> gnu.org" <bug-guile <at> gnu.org>
Subject: [feature request] optimization of case-lambda
Date: Mon, 20 Feb 2023 18:56:25 +0100
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






Information forwarded to bug-guile <at> gnu.org:
bug#61660; Package guile. (Thu, 23 Feb 2023 19:01:02 GMT) Full text and rfc822 format available.

Message #8 received at 61660 <at> debbugs.gnu.org (full text, mbox):

From: lloda <lloda <at> sarc.name>
To: 61660 <at> debbugs.gnu.org
Subject: Re: [feature request] optimization of case-lambda
Date: Thu, 23 Feb 2023 20:00:04 +0100
[Message part 1 (text/plain, inline)]
Patch attached, tests tbd. Thoughts?

[0001-peval-reduces-some-inlined-case-lambda-calls.patch (application/octet-stream, attachment)]

Information forwarded to bug-guile <at> gnu.org:
bug#61660; Package guile. (Fri, 24 Feb 2023 17:27:01 GMT) Full text and rfc822 format available.

Message #11 received at 61660 <at> debbugs.gnu.org (full text, mbox):

From: lloda <lloda <at> sarc.name>
To: 61660 <at> debbugs.gnu.org
Subject: Re: bug#61660: [feature request] optimization of case-lambda
Date: Fri, 24 Feb 2023 18:26:29 +0100
[Message part 1 (text/plain, inline)]
Fixed patch handling rest & #:optional, with test cases.

[0001-peval-reduces-some-inlined-case-lambda-calls.patch (application/octet-stream, attachment)]

Added tag(s) patch. Request was from Ludovic Courtès <ludo <at> gnu.org> to control <at> debbugs.gnu.org. (Mon, 27 Feb 2023 10:07:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-guile <at> gnu.org:
bug#61660; Package guile. (Mon, 27 Feb 2023 10:12:02 GMT) Full text and rfc822 format available.

Message #16 received at 61660 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: lloda <lloda <at> sarc.name>
Cc: 61660 <at> debbugs.gnu.org
Subject: Re: bug#61660: [feature request] optimization of case-lambda
Date: Mon, 27 Feb 2023 11:11:29 +0100
Hi Daniel,

lloda <lloda <at> sarc.name> skribis:

> From 61ed612fb36108e395bdee4b1bbb46b49ef017b3 Mon Sep 17 00:00:00 2001
> From: Daniel Llorens <lloda <at> sarc.name>
> 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’.




Reply sent to lloda <lloda <at> sarc.name>:
You have taken responsibility. (Mon, 27 Feb 2023 17:20:01 GMT) Full text and rfc822 format available.

Notification sent to lloda <lloda <at> sarc.name>:
bug acknowledged by developer. (Mon, 27 Feb 2023 17:20:02 GMT) Full text and rfc822 format available.

Message #21 received at 61660-done <at> debbugs.gnu.org (full text, mbox):

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

> On 27 Feb 2023, at 11:11, Ludovic Courtès <ludo <at> gnu.org> wrote:
> 
> Hi Daniel,
> 
> lloda <lloda <at> sarc.name> skribis:
> 
>> From 61ed612fb36108e395bdee4b1bbb46b49ef017b3 Mon Sep 17 00:00:00 2001
>> From: Daniel Llorens <lloda <at> sarc.name>
>> 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







bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 28 Mar 2023 11:24:11 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 29 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.