unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Compiler warning for unused local top-level variables
@ 2010-01-11  1:02 Ludovic Courtès
  2010-01-11 21:04 ` Andy Wingo
  0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2010-01-11  1:02 UTC (permalink / raw)
  To: guile-devel

Hello,

With the new ‘-Wunused-toplevel’ the compiler warns about unused
module-local top-level variables [0].

It works well, but has the following limitations:

  - 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.

  - 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?

Thanks,
Ludo’.

[0] http://git.sv.gnu.org/cgit/guile.git/commit/?id=bcae9a98b0dd82b7be93e90134a01a03b44b4af7





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Compiler warning for unused local top-level variables
  2010-01-11  1:02 Compiler warning for unused local top-level variables Ludovic Courtès
@ 2010-01-11 21:04 ` Andy Wingo
  2010-01-11 22:00   ` Ludovic Courtès
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Wingo @ 2010-01-11 21:04 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

On Mon 11 Jan 2010 02:02, ludo@gnu.org (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/




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Compiler warning for unused local top-level variables
  2010-01-11 21:04 ` Andy Wingo
@ 2010-01-11 22:00   ` Ludovic Courtès
  0 siblings, 0 replies; 3+ messages in thread
From: Ludovic Courtès @ 2010-01-11 22:00 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guile-devel

Howdy,

Andy Wingo <wingo@pobox.com> writes:

> On Mon 11 Jan 2010 02:02, ludo@gnu.org (Ludovic Courtès) writes:

[...]

>>   - 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.

You mean consider that no variables is unused when a module exports one
or more macros?

I was thinking about somehow “opening” syntax objects.

This expression ‘(define-syntax baz (syntax-rules () ((_) asinh)))’
compiles to:

--8<---------------cut here---------------start------------->8---
(define baz
  (apply (@@ (guile) make-syntax-transformer)
         (const baz)
         (const macro)

[...]

                                             (const #(syntax-object
                                                      asinh
                                                      ((top)
                                                       #(ribcage
                                                         #(dummy)
                                                         #((m69 top))
                                                         #("i74"))
--8<---------------cut here---------------end--------------->8---

If we had, say, ‘syntax-object-toplevel?’ to check whether a syntax
object captures a top-level binding, that’d be enough.  Then we could
use ‘syntax->datum’ to get the symbol, and voilà.

What am I missing?  :-)

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-01-11 22:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-11  1:02 Compiler warning for unused local top-level variables Ludovic Courtès
2010-01-11 21:04 ` Andy Wingo
2010-01-11 22:00   ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).