Re: SBCL tells me it is deleting unreachable code that is almost surely reachable

Raymond Toy <[email protected]>
Newsgroups gmane.comp.mathematics.maxima.general
Message-ID <[email protected]>
On 4/15/26 10:12 AM, Stavros Macrakis wrote:

> Of course, this:
>> ((memq sgn '($neg _*'*_$zero _*'*_$pos)) sgn)
> should be
>> ((memq sgn '($neg $zero $pos)) sgn)
> and might as well be
>> ((member sgn '($neg $zero $pos)) sgn)
How silly of me! I didn’t notice the args in the wrong order.
> If the compiler is so incompetent that it doesn't recognize it can't 
> use *eq* for a list of symbols, the compiler should be fixed!
> And, as Ray suggests, it will almost certainly inline *member/eq* for 
> a length-3 list: that is both faster and smaller than calling *member 
> *on most (all?) Lisp systems.
> And *memq* is already declaimed *inline* in *clmacs.lisp*, line 232.
Ah, I’m used to seeing the inline declaration just before the function, 
so I didn’t look.
>
> Looking at the generated code, I see that with *optimize speed:0 
> space:3*, SBCL calls *member-eq*, even though that takes more space. 
> Apparently it uses an inaccurate heuristic to estimate space usage.
Surely a simple function call to member-eq takes less space than 
inlining 3 comparisons and branches?
>
>    -s
>
> On Wed, Apr 15, 2026 at 12:10 PM Raymond Toy <[email protected]> 
> wrote:
>
>     On 4/15/26 8:25 AM, Barton Willis via Maxima-discuss wrote:
>
>>     Here is a revision of a function in hayat. The revision
>>     eliminates or helps to eliminate two testsuite failures.
>>
>>     The SBCL (2.4.7)  compiler tells me that
>>
>>     ; file: C:/Users/barton/maxima-code-pure/maxima-code/src/./hayat.lisp
>>     ; in: DEFUN COEF-SIGN
>>     ;     (EQ MAXIMA::SGN 'MAXIMA::$POS)
>>     ;
>>     ; note: deleting unreachable code
>>
>>     I think that is rubbish—likely, I'll commit the (commented out)
>>     memq version.
>
>     Check to see what |$csign| returns? Or rather what csign-impl
>     returns. For me, I see the return type is * (anything).
>
>     |memq| should do exactly the same as testing |(or (eq sgn '$neg)
>     (eq sgn '$zero) (eq sgn '$pos))|. Well, it would if it were
>     declared inline, but it’s not.
>
>     Seems to me that it would be easy to test if that code were
>     actually deleted by calling |coef-sign| with an arg that is known
>     to be |$pos|.
>
>>
>>     (defun coef-sign (coef)
>>       (let ((sgn ($csign coef)))
>>         (cond ((or (eq sgn '$complex) (eq sgn '$imaginary)) '$im)
>>               ;((memq sgn '($neg '$zero '$pos)) sgn)
>>               ((or (eq sgn '$neg) (eq sgn '$zero) (eq sgn '$pos)) sgn)
>>               (t
>>                  (let ((asgn ($asksign coef)))
>>                     ;; When sgn is zero and limit is active, record
>>     this fact as a noun equality
>>                     ;; in *limit-assumptions*.
>>                  (when (and *limit-assumptions* (eq asgn '$zero))
>>                    (push (ftake '$equal coef 0) *limit-assumptions*))
>>                 asgn)))))
>>
>>
>>
>>     _______________________________________________
>>     Maxima-discuss mailing list
>>     [email protected]
>>     https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>     &#8203;
>     _______________________________________________
>     Maxima-discuss mailing list
>     [email protected]
>     https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>
&#8203;

_______________________________________________
Maxima-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maxima-discuss
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.