Opened 13 years ago

Closed 13 years ago

#852 closed defect (fixed)

csi segfaults when playing with modules and macros

Reported by: megane Owned by: sjamaan
Priority: minor Milestone: 4.9.0
Component: unknown Version: 4.7.x
Keywords: Cc:
Estimated difficulty:

Description

Crashes with master (Version 4.7.5 (rev 5fe91ae)) when run with the interpreter.

If run compiled it just raises the expected error:
"Error: unbound variable: define25"


(module foo

(bar)
(import chicken scheme)


(define-syntax bar

(ir-macro-transformer

(lambda (e i c)

`(list define)))))

(module a

*
(import chicken scheme)
(import foo)

(bar))

Change History (5)

comment:1 Changed 13 years ago by sjamaan

The problem here is that bar returns the actual macro transformer procedure bound to define. In the compiler, that doesn't work because macro transformers aren't available as first-class procedures in the compiler (unless you make them available somehow).

You *might* be able to see this by modifying it to an er-macro-transformer:

 (module foo
  (bar)
  (import chicken scheme)

  (define-syntax bar
    (er-macro-transformer
     (lambda (e r c)
       `(,(r 'list) ,(r 'define))))))

 (module a
  *
  (import chicken scheme)
  (import foo)

  (bar))

This code crashes in master (w/ debugbuild), but shows the following in 4.7.0 (w/o debugbuild):

(((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((syntax-rules ((synta......

That's how macro transformers are currently printed ;)

The segfault is a problem in the printer, not in the macro transformer.

comment:2 Changed 13 years ago by felix winkelmann

Milestone: 4.8.04.9.0

comment:3 Changed 13 years ago by sjamaan

I retract that statement: the printer's fine. The macro expander's fine too. It's the interpreter (closure compiler) which goes wrong when finally trying to look up the variable in the syntactic environment after the macro has been expanded.

It finds the actual macro transformer object there, but it shouldn't return that. The compiler does something similar but it pretends not to find anything since macros aren't first-class so can't be returned as variables.

A fix has been posted to chicken-hackers.

comment:4 Changed 13 years ago by sjamaan

Owner: set to sjamaan
Status: newaccepted

comment:5 Changed 13 years ago by megane

Resolution: fixed
Status: acceptedclosed

Works on Version 4.7.5 (rev bd1d0fc).

Note: See TracTickets for help on using tickets.