Subject: bug#12883: [2.0.6] CSE bug

From: Stefan Israelsson Tampe <[email-masked]>
Date: Mon, 19 Nov 2012 12:33:17 +0100

I will send an updated patch later, but to explain

I'm not the author of this so I need you to follow my analyze or we will
wait for
the author to check this!

The intention of unroll is to scan db to check that a commutative property
for an item going into the function holds for all elements in db up to
h==h* is
found. Now at each symbol db-len* is the length of db when created so
(- db-len db-len*) is the length of all elements in db created after the
symbol name.
now db-len* will in the loop lp be decreasing so this length is increasing
and the base = m
is the position in db where we scan to last time, the fix was to make sure
we scan up to
the db-len* 'index' e.g. niter had to be corrected by the base m. Otherwise
we could scan out of
the length of db* and the error we saw was introduced. Another fix is for
unroll to return #t
if the length is out of the db length but this is probably a bandage, not
the bug, the bug is most probably
fixed by this patch.

Is things more clear now?

Anyway you can add traces to check how the fuction scans db as in my first
mail, that shows how the system
worked and it shows the consistency with the first iteration of the loop
which is unaffected by the fix

/Stefan

On Mon, Nov 19, 2012 at 12:07 AM, Ludovic Courtès <[email-masked]> wrote:

> Hi Stefan,
>
> Stefan Israelsson Tampe <[email-masked]> skribis:
>
> > --- a/module/language/tree-il/cse.scm
> > +++ b/module/language/tree-il/cse.scm
> > @@ -324,10 +324,11 @@
> >                 (and (< n env-len)
> >                      (match (vlist-ref env n)
> >                        ((#(exp* name sym db-len*) . h*)
> > -                       (and (unroll db m (- db-len db-len*))
> > -                            (if (and (= h h*) (tree-il=? exp* exp))
> > -                                (make-lexical-ref (tree-il-src exp)
> name sym)
> > -                                (lp (1+ n) (- db-len db-len*))))))))))))
> > +                       (let ((niter (- (- db-len db-len*) m)))
> > +                         (and (unroll db m niter)
> > +                              (if (and (= h h*) (tree-il=? exp* exp))
> > +                                  (make-lexical-ref (tree-il-src exp)
> name sym)
> > +                                  (lp (1+ n) (- db-len
> db-len*)))))))))))))
> >
> >    (define (lookup-lexical sym env)
> >      (let ((env-len (vlist-length env)))
>
> I can confirm it solves the problem, but I don’t fully understand what’s
> going on here.  Could you elaborate?  :-)
>
> Also, it would be great if you could send a ‘git format-patch’ kind of
> patch, with the original test case (and possibly others) added to
> cse.test, along with the URL of this bug, and a proper ChangeLog-style
> commit log.
>
> TIA,  :-)
> Ludo’.
>