[gambit-list] Fix expansion of map and foreach

Marc Feeley feeley at iro.umontreal.ca
Fri Jun 8 11:41:05 EDT 2012


The primitive expansion code has not been moved to _t-univ.scm, it has been moved out of _t-c-2.scm (and into _prims.scm) so that it can be shared by all back-ends.

The issue you mention is related to the problem of ordering the inlining transformations.  Unfortunately, this is done in more than one pass, and if the order of the passes is reversed, some other problems will pop up.

Ideally, the inlining transformations should be done in a single pass.  Could you look into this?  After all you have write-permission on the github repo!

Marc

On 2012-06-01, at 2:40 PM, Bradley Lucier wrote:

> Marc:
> 
> Since you're moving the primitive expansion code to _t-univ.scm, this is a good time to fix the expansions of map and foreach.
> 
> For example, consider the following source code:
> 
> (declare (standard-bindings)
> 	 (extended-bindings)
> 	 (block))
> 
> (define (my-car x)
>   (car x))
> 
> (define (map-car l)
>   (map car l))
> 
> (define (map-my-car l)
>   (map my-car l))
> 
> (define l '((1 2) . 4))
> 
> (pp l)
> 
> (pp 'map-car)
> 
> (pp (map-car l))
> 
> (pp 'map-my-car)
> 
> (pp (map-my-car l))
> 
> I'm not going to show the output of
> 
> heine:~/Desktop> gsc -c -expansion test-map.scm
> 
> but you get the following behavior in the interpreter and the compiler:
> 
> heine:~/Desktop> gsc test-map.scm
> heine:~/Desktop> gsi test-map.scm
> ((1 2) . 4)
> map-car
> *** ERROR IN "test-map.scm"@20.5 -- (Argument 2) LIST expected
> (map '#<procedure #2 car> '((1 2) . 4))
> heine:~/Desktop> gsi test-map
> ((1 2) . 4)
> map-car
> (1)
> map-my-car
> *** ERROR IN | test-map.o3| -- (Argument 2) LIST expected
> (map '#<procedure #2 my-car> '((1 2) . 4))
> 
> And, if you look at the generated C code, map-car unconditionally calls generic car, while map-my-car optimistically expands the call to car.
> 
> In brief, map-car doesn't catch the error, and it's a lot slower than map-my-car.  In my opinion, map-car and map-my-car should have the same code.
> 
> Brad



More information about the Gambit-list mailing list