chicken-hackers
[Top][All Lists]
Advanced

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

[Chicken-hackers] [PATCH] Fix a regression in body canonicalization


From: Peter Bex
Subject: [Chicken-hackers] [PATCH] Fix a regression in body canonicalization
Date: Thu, 27 Apr 2017 18:14:36 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

Hi all,

While talking to Demosthenex in #chicken, I decided it would be cool
to compare the performance of the "json" egg in CHICKEN 5 with that
in CHICKEN 4.  However, I got some errors when building the egg,
which have to do with the way the "packrat" egg expands its bodies.

It turns out that packrat-parser expands into this sort of pattern:

(let ()
  (define nonterminal1 (lambda (results) ...)) 
  (define nonterminal2 (lambda (results) ...)) 
  body)

And in json.scm, the json-read parser uses something like

(packrat-parser (begin (define (helper1 results) ...)
                       (define (helper2 results) ...)
                       the-parser)
                (the-parser ((helper1 ...))))

So the final output is like

(let ()
  (define parse (lambda (results) (helper1 ..))) 
  (begin (define (helper1 results) ...)
         (define (helper2 results) ...)
         parse))

And if the begin starts a new letrec, this causes the helpers
to be unavailable from "parse".

Now, the spec disallows this (I think..), but we typically treat
begin as a sort of no-op, so in the above example, all 3 defines
should be in one letrec sequence.  I also noticed that if we
create a macro that's basically an alias for define, it starts
a new letrec.

This is all due a simplification I added in c9220247d that I thought
shouldn't cause problems: I removed the macro-expansion in the main
loop of canonicalize-body because "there already was one in the
secondary loop" (and the check for the macro being a member of
"vars" seemed a bit iffy to me as well).  Technically that's true,
but I hadn't thought through the implications of this resulting in
a new letrec.

So attached is a relatively simple patch which restores the old macro
expansion behaviour in canonicalize-body, plus two regression tests
for these situations.

PS: It turns out the json egg was slightly slower to parse the benchmark
file with CHICKEN 5 than with CHICKEN 4 but it used less memory.

Cheers,
Peter

Attachment: 0001-Restore-macro-expansion-in-canonicalize-body-s-main-.patch
Description: Text Data

Attachment: signature.asc
Description: Digital signature


reply via email to

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