Ticket #518 (closed defect: fixed)

Opened 2 years ago

Last modified 8 months ago

strip-syntax returns wrong value for renamed symbols exported form a module

Reported by: syn Owned by: sjamaan
Priority: major Milestone: 4.9.0
Component: unknown Version: 4.6.x
Keywords: Cc:

Description

Stripping syntax from symbols in a macro that have previously been renamed and happen to have the same name as a symbol exported by the module the macro is defined in returns the symbol prefixed with the module name. This is particularly annoying with IR macros which rename all symbols implicitly and thus this problem is likely to occur.

The problem can be reproduces using the following program. It outputs "no: foo#baz" when it should actually output "yes: baz".

(module foo

;; not exporting baz makes it work as expected
(bar baz)

(import chicken scheme)

(define baz 'qux)

(define-syntax bar
  (er-macro-transformer
   (lambda (x r c)
     (let ((e (strip-syntax (r (cadr x)))))
       (if (eq? 'baz e)
           (display "yes: ")
           (display "no: "))
       (display e)
       '(void)))))
)

(import foo)
(bar baz)

Change History

Changed 2 years ago by sjamaan

  • owner set to sjamaan
  • status changed from new to accepted

Changed 2 years ago by sjamaan

This looks related to #444

Changed 2 years ago by sjamaan

Please try da667f1 (in expander-simplifications)

Changed 2 years ago by sjamaan

hm, this appears to break tests/compiler-test.scm because the "assert" and "not" macros are expanding to "bar" instead of "foo#bar".

This suggests another problem with core primitives, too:

(print (strip-syntax '#%+))
(print (strip-syntax 'foo#bar))

(module foo 
   (bar)
 (import chicken scheme)
 (define bar 1))

(print (strip-syntax '#%+))
(print (strip-syntax 'foo#bar))

Output:

#%+
foo#bar
+
bar

I don't know if this should be possible or not, but if not then we should have a long, hard look at how things work right now. Putting system properties on non-gensymed symbols is probably a bad idea if it causes such issues.

Changed 2 years ago by sjamaan

The fix for #444 could be rolled back and the code simplified (and made slightly faster) if we also set ##core#real-name in ##sys#primitive-alias. It saves us one property access call in ##sys#strip-syntax

Changed 2 years ago by sjamaan

Actually, it's quote which strips syntax in the test.

If you remove strip-syntax in the example code in my previous comment, you'll notice that when compiled, the output is the same. When interpreted, it is not. This should probably be fixed.

Why does quote not strip syntax in the same way in the compiler as in the interpreter?

Changed 2 years ago by sjamaan

Another, hopefully better fix at caa54d2 in expander-simplifications. Need to fix quasiquotation first, then this can be tested properly

Changed 2 years ago by sjamaan

The remaining problem with core primitives is now fixed too, in 39cf6a5 (also expander-simplifications).

All testcases in this ticket now respond with the expected output!

Changed 2 years ago by felix

  • status changed from accepted to closed
  • resolution set to fixed

Changed 2 years ago by felix

  • milestone changed from 4.7.0 to 4.8.0

Milestone 4.7.0 deleted

Changed 8 months ago by felix

  • milestone changed from 4.8.0 to 4.9.0

Milestone 4.8.0 deleted

Note: See TracTickets for help on using tickets.