[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Hiding Warnings: probs w/prev code



> To: info-mcl
> From: duthen@ircam.fr (Jacques Duthen)
> Subject: Re: Hiding Warnings: probs w/prev code
> Date: 18 Sep 91 08:27:05 GMT
> 
> In article <39743@mimsy.umd.edu> spector@mimsy.umd.edu (Lee Spector) writes:
> >(defmacro without-compiler-warnings (&body body)
> >    `(handler-bind ((compiler-warning
> >                     #'(lambda (condition)
> >                         (muffle-warning condition))))
> >       ,@body))
> >
> >? (without-warnings (defun shoe () (horn)))
> >;Compiler warnings :
> >;   Undefined function HORN, in SHOE inside an anonymous lambda form.
> >SHOE
> 
> The compiler warning type is ccl::compiler-warning, but,
> if you try the following, it seems there is no hope:
> ? (defvar *co*)
> *co*
> ? (handler-bind ((condition #'(lambda (co) (setf *co* co))))
>     (defun shoe () (horn)))
> ;Compiler warnings :
> ;   Undefined function HORN, in SHOE inside an anonymous lambda form.
> SHOE
> ? *co*
> > Error: Unbound variable: *co*
> 
> What else ?     	        	        	[jack]
> 

My WITHOUT-COMPILER-WARNINGS macro was broken in the same way that Lee
Spector's example is broken: the HANDLER-BIND is active at run time, not
compile time.

I have a couple of solutions.  The one you use is a matter of taste.

The first example patches the toplevel-loop with a handler for compiler
warnings.  Its only dependence on undocumented features is that it knows
that the compiler signals conditions of type CCL::COMPILER-WARNING.  Its
drawback is that it needs to throw to toplevel to install itself.

---------------------------------------------------------------------------

(in-package :ccl)

(export *signal-compiler-warnings*)

(defparameter *signal-compiler-warnings* t)

(defun compiler-warning-muffler ()
  (handler-bind ((compiler-warning
                  #'(lambda (condition)
                      (unless *signal-compiler-warnings*
                        (muffle-warning condition)))))
    (toplevel-loop)))

(defun install-compiler-warning-muffler ()
  (unless (eq #'compiler-warning-muffler (%set-toplevel))
    (%set-toplevel #'compiler-warning-muffler)
    (toplevel)))

(install-compiler-warning-muffler)

---------------------------------------------------------------------------

Another way to do this is to patch the internal function that the
compiler calls to signal its warnings. Doing it this way is much more
likely to break in future releases of MCL. I would have used ADVISE,
but the syntax of ADVISE has changed since 2.0b1.

---------------------------------------------------------------------------

(in-package :ccl)

(export *signal-compiler-warnings*)

(defparameter *signal-compiler-warnings* t)

(defvar *compiler-warning-signaller* #'signal-compiler-warning)

(let ((*warn-if-redefine* nil)
      (*warn-if-redefine-kernel* nil))
  (defun signal-compiler-warning (&rest rest)
    (declare (dynamic-extent rest))
    (when *signal-compiler-warnings*
      (apply *compiler-warning-signaller* rest))))

---------------------------------------------------------------------------