I have observed some strange compiler behavior while developing the sdl2
egg, and now I have finally gotten an idea of what is causing it.
If you use define-foreign-type and provide argconvert and retconvert
procedures, but never use that foreign type in a function binding as a
return type or argument type, the compiler will print out messages such
as "Note: global variable `foo#g11' is only locally visible and never used".
One or two messages like that are printed for every unused foreign type,
depending on whether it is used as a return type, an argument type, or
neither. For an egg like sdl2, which has many foreign types, this causes
over a dozen messages to be printed when the egg is compiled. This is
not a big problem, but it is a bit annoying and confusing. It can cause
the developer or users to wonder if something is wrong, and how to fix
it. It is especially perplexing because these seem to be gensyms, which
are never found in the original source code, so you can't search to find
where in your code they might be coming from.
Example: Create file foo.scm containing this code:
(module foo ()
(import scheme chicken foreign)
(define (unwrap x) x)
(define (wrap x) x)
(define-foreign-type my-type c-pointer unwrap wrap)
)
Compile with: csc -v foo.scm
Compilation succeeds, but the following messages are printed:
Note: global variable `foo#g11' is only locally visible and never used
Note: global variable `foo#g10' is only locally visible and never used
I would like it if the compiler did not print these messages. Perhaps
the compiler could automatically (declare (unused g10 g11)) or
something. Alternatively, the compiler could print a more informative
message, such as "foreign type `my-type' is never used", so that it is
more obvious what is causing the messages. But personally, I would
rather just silence the messages, and that is probably easier to
implement anyway.
I have reproduced this issue with CHICKEN 4.9.0.1 and 4.10.0. I have not
tried other versions yet. I am using Mac OS X 10.10.5. `chicken
-version` says:
Version 4.10.0 (rev b259631)
macosx-unix-clang-x86-64 [ 64bit manyargs dload ptables ]
compiled 2015-08-04 on yves.more-magic.net (Linux)
Some observations:
These messages are only printed if you provide an argconvert or
retconvert procedure to define-foreign-type. They are not printed if you
pass only the first two arguments, e.g. (define-foreign-type my-type
c-pointer)
These messages are not printed if you actually use the foreign type as
both a return type and an argument type of foreign lambdas. If you use
the foreign type only as a return type, or only as an argument type, the
compiler will print only one message.
Looking at CHICKEN's compiler.scm around line 1055, I see this in the
code related to define-foreign-type:
(let ([arg (gensym)]
[ret (gensym)] )
(##sys#hash-table-set! foreign-type-table name (vector type arg ret))
(mark-variable arg '##compiler#always-bound)
(mark-variable ret '##compiler#always-bound)
(hide-variable arg)
(hide-variable ret)
...
This seems like the compiler is already trying to declare the gensyms as
unused/hidden/whatever. So, I'm not sure why the messages are still
being printed. Maybe those declarations are not sufficient, or maybe the
cause is elsewhere.
I hope this information helps fix the cause of these confusing messages. :)
Thanks!
- John Croisant
_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users