Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#893 closed defect (fixed)

problem with type annotations and modules

Reported by: megane Owned by:
Priority: critical Milestone: 4.9.0
Component: unknown Version: 4.7.x
Keywords: modules types Cc:
Estimated difficulty:

Description

(define (baz a) (add1 a))

(define-syntax foo
  (ir-macro-transformer
   (lambda (e i c)
     `((the (procedure (*) fixnum) baz) 1))))

(print (foo))

(module
 m
 (bar)
 (import chicken scheme)
 (define-syntax bar
  (ir-macro-transformer
   (lambda (e i c)
     `((the (procedure (*) fixnum) baz) 1)))))

(import m)
(print (bar))

;; $ csc -debug 2 -specialize foo.scm
;; [canonicalized]
;; (##core#callunit "library")

;; (##core#callunit "eval")

;; (##core#undefined)

;; (set! baz (##core#lambda (a1) (add1 a1)))

;; (##core#undefined)

;; (print (let ((g1516 (##core#the (procedure (*) fixnum) #t baz))) (g1516 '1)))

;; (##core#undefined)

;; (##core#undefined)

;; (print (let ((g4041 (##core#the #f #t baz))) (g4041 '1)))

;; ((##sys#implicit-exit-handler))

;; (##core#undefined)


;; Error: invalid type specification: #f


Attachments (1)

0001-Fix-implicit-renaming-to-avoid-using-core-aliases-di.patch (2.1 KB ) - added by sjamaan 13 years ago.
Proper fix for implicit renames of core aliases

Download all attachments as: .zip

Change History (5)

comment:1 by sjamaan, 13 years ago

The real problem isn't in type annotations. It's the fact that macros look up "primitive aliases" in the environment, which means they lose their original symbol name. Here's a simplified example:

(module m
 (bar)
 (import chicken scheme)
 (define-syntax bar
   (ir-macro-transformer
    (lambda (e r c) '(quote *)))))

(import m)
(assert (eq? '* (bar)))

This assertion should be true, but it isn't. If you (print (bar)), it'll show #%* which is wrong. ##sys#strip-syntax can't strip the syntax off {{#%*}} because it's not a gensym, and it might actually be the real symbol the user typed, so we can't just resolve that back to * again.

comment:2 by sjamaan, 13 years ago

A simple workaround should be to either inject the symbols (since the doesn't care about their lexical meaning, just about the literal symbol), or use er-macro-transformers.

by sjamaan, 13 years ago

Proper fix for implicit renames of core aliases

comment:3 by Mario Domenech Goulart, 13 years ago

Resolution: fixed
Status: newclosed

Fixed by 1564a4600c69c0db6b9be97bbda518e725121f75

comment:4 by felix winkelmann, 13 years ago

Milestone: 4.8.04.9.0

Milestone 4.8.0 deleted

Note: See TracTickets for help on using tickets.