[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Compiler warning for unused local top-level variables
From: |
Andy Wingo |
Subject: |
Re: Compiler warning for unused local top-level variables |
Date: |
Mon, 11 Jan 2010 22:04:11 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux) |
On Mon 11 Jan 2010 02:02, address@hidden (Ludovic Courtès) writes:
> With the new ‘-Wunused-toplevel’ the compiler warns about unused
> module-local top-level variables [0].
Cool!
> - Public variables exported with ‘define-public’, ‘export’, or anything
> other than the ‘#:export’ option of ‘define-module’ is considered
> private, and thus possibly misdiagnosed as unused.
>
> This is because ‘export’ et al. are only evaluated at run-time, not
> at compile-time, unlike ‘define-module’. This is something we could
> change, though.
I see you've fixed this already, cool.
> - Local variables used only by a macro are incorrectly flagged as
> unused. Example:
>
> (define (bar) 'foo)
> (define-syntax baz
> (syntax-rules () ((_) (bar))))
>
> Here ‘bar’ is incorrectly flagged as unused. This is because the
> definition of ‘baz’ expands to ‘(define baz (make-syntax-transformer
> ...))’ and this code doesn’t contain any literal
> ‘(toplevel-ref bar)’. Instead, the reference to ‘bar’ is buried in
> an opaque syntax object.
>
> Andy: any idea how to work around this?
No, I don't think it's possible to work around this. At least, nothing
comes to mind. You could disable the check if a module exports macros.
This seems fundamental in some way.
As an example:
(define-syntax baz
(lambda (x)
#`(,(call-with-input-file "/tmp/foo" read))))
You really can do any kind of computation at macro-expansion time.
Regards,
Andy
--
http://wingolog.org/