Lisp HUG Maillist Archive

"Eliminating a test of a variable with a declared type"

Hi!

I have some code that compiles and works fine with CMUCL and ACL. With
Lispworks it also does what it's supposed to do but I get a lot of
"Eliminating a test of a variable with a declared type" warnings when
compiling. I have no idea what this means and don't know where to look
at in the docs to find more information about this message.

Could somebody shed a light on this?

Thanks in advance,
Edi.


Re: "Eliminating a test of a variable with a declared type"

Unable to parse email body. Email id is 650

Re: "Eliminating a test of a variable with a declared type"

davef@xanalys.com writes:

> Code like this:
> 
> (DEFMETHOD OBJECT-LENGTH ((X STRING)) (WHEN X (LENGTH X)))
> 
> generates such a warning when compiled. The type of x is known to the
> compiler, because the specialization effectively declares the type. It
> means there is an unnecessary IF/WHEN/UNLESS test such as
>  
>  (WHEN X ...)
> 
> above and the compiler is removing the test. There are other ways in
> which the type can be inferred and this optimization is performed.

Thanks for the quick reply. This was exactly what I was looking for
and it helped me to find a couple of places in my code where indeed
unnecessary tests where happening (remnants from earlier version of
the program).

> The warning is rather mysterious in LispWorks 4.2.0 when the
> declaration is not explicit because it doesn't say which variable and
> type. You are not the first to be confused by it. In LW4.2.6 we added
> the variable to the warning and in LW4.2.7 we added the type as
> well. So now the warning is better:
> 
> ;;;*** Warning in (METHOD OBJECT-LENGTH (STRING)): Eliminating a test of a variable with a declared type : X [type STRING]
> 
> which should help you to locate the unnecessary tests.

Er, yes, I _am_ using LW pro 4.2.7, so I got the more verbose
messages. I still was to0 confused to get it myself. (Or let's say I
didn't expect the compiler to be that smart - shame on me.)

Thanks again,
Edi.


Updated at: 2020-12-10 09:01 UTC