chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-hackers] [PATCH] Some simplification rules for nested ##cor


From: Peter Bex
Subject: Re: [Chicken-hackers] [PATCH] Some simplification rules for nested ##core#inline forms
Date: Sun, 15 Sep 2019 13:15:33 +0200
User-agent: Mutt/1.10.1 (2018-07-13)

On Wed, Sep 04, 2019 at 11:59:31AM +0200, address@hidden wrote:
> The attached patch adds two optimization rules for certain uses of
> ##core#inline. It basically rewrites
> 
> (let ((<var> (##core#inline ...)))
>   (<kont> ... <var> ...))
> 
> into
> 
> (<kont> ... (##core##inline ...) ...)
> 
> plus a variation on this. Removing the intermediate "let" form gives
> more opportunities to merge conditionals into ##core#cond forms,
> which in turn may reduce intermediate CPS lambdas.

I've pushed this patch, but I feel this really exposes a limitation
in the rewrite system because this only fixes this one specific case.

It would be better if we could somehow change the test:

  (if <x>
      (<var> <y>)
      (<var> <z>))

to also recognise:

  (if <x>
      (let ((whatever (##core#inline ...)))
        (let ((whatever2 (##core#inline ...)))
          (<var> <y>)))
      (<var> <z>))

This probably applies to other rewrites as well.  Basically, any chunk
of nested inline lets with a final expression that does something else
should be detectable as being the final expression.

This is not the case for every rewrite, because reordering isn't always
allowed.  It is in this case, though.  This should also catch slightly
different scenarios where there's a sequence of nested inline lets.
Of course, it's nontrivial to determine when rewriting where the let
should go and how to pull apart these expressions.

I don't know how to do this, and probably you've already thought about
this, but I just wanted to put it out there, maybe someone has an idea.

Cheers,
Peter

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]