[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

how can I make calls to SIGNAL ignored for code elimination ?

Jim Newton

6/2/2016 2:30:00 PM

I have code that makes several calculations each of which have several intermediate results.
I'd like to use the CL condition system to signal the intermediate results.
However, using SIGNAL in this ways, makes all the variable "used", so the code is not
optimizable. I don't want these calls to signal to make the optimizer think that
the results are "used".

Is there a way to represent this?

E.g.,

(lambda (x)
(let ((a (1+ x))
(b (+ 3 x))
(c (+ a b)))
(signal 'condition-notify :variable 'a :value a)
(signal 'condition-notify :variable 'b :value b)
(signal 'condition-notify :variable 'c :value c)
(+ 3 b)))

In this code only the value b is "really used", I'd be happy if
the optimizer eliminated the calculations of a and b, AND
if it would also eliminate the calls 1st and 3rd calls to signal.


I think what I'm asking for is impossible. Any thoughts?
5 Answers

Rob Harris

1/4/2009 12:55:00 AM

0

On Jan 3, 5:24 pm, "a425couple" <a425cou...@hotmail.com> wrote:
> "a425couple" <a425cou...@hotmail.com> wrote ...
snip the logical flow of U.S. policy.

a425couple -

right here you listed a series of factors pulling the U.S. in,
logically building on each other. Many of these could have a affected
a surviving FDR.

That, and the fact that the what-ifs about US decisionmaking on
Vietnam have been done several times, made me turn to French
decisionmaking, to see if there is less, dare I say, inevitability,
there.

Didier Verna

6/2/2016 2:43:00 PM

0

Jim Newton wrote:

> I think what I'm asking for is impossible. Any thoughts?

There's no way to know at compile time that the condition is not
handled, so it's impossible to remove that code. Also, there could be
handlers, all declining to handle the condition but still performing
side-effects.

--
Resistance is futile. You will be jazzimilated.

Lisp, Jazz, Aïkido: http://www.didier...

Barry Margolin

6/2/2016 2:47:00 PM

0

In article <cf76072e-3286-4908-960e-84f51f95c8cd@googlegroups.com>,
Jim Newton <jimka.issy@gmail.com> wrote:

> I have code that makes several calculations each of which have several
> intermediate results.
> I'd like to use the CL condition system to signal the intermediate results.
> However, using SIGNAL in this ways, makes all the variable "used", so the
> code is not
> optimizable. I don't want these calls to signal to make the optimizer think
> that
> the results are "used".
>
> Is there a way to represent this?
>
> E.g.,
>
> (lambda (x)
> (let ((a (1+ x))
> (b (+ 3 x))
> (c (+ a b)))
> (signal 'condition-notify :variable 'a :value a)
> (signal 'condition-notify :variable 'b :value b)
> (signal 'condition-notify :variable 'c :value c)
> (+ 3 b)))
>
> In this code only the value b is "really used", I'd be happy if
> the optimizer eliminated the calculations of a and b, AND

Did you mean "a and c"?

> if it would also eliminate the calls 1st and 3rd calls to signal.

I don't understand, why should it eliminate them? Why are you calling it
if you don't want them to be executed?

Is this supposed to be a debugging feature that should only be enabled
in development mode? How about using a macro that generates the signal
calls only if a variable is set at compile time.

(defmacro debug-signal (&rest args)
(if *debug*
`(signal ,@args)
`(progn)))

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Pascal J. Bourguignon

6/2/2016 6:50:00 PM

0

Jim Newton <jimka.issy@gmail.com> writes:

> I have code that makes several calculations each of which have several intermediate results.
> I'd like to use the CL condition system to signal the intermediate results.
> However, using SIGNAL in this ways, makes all the variable "used", so the code is not
> optimizable. I don't want these calls to signal to make the optimizer think that
> the results are "used".
>
> Is there a way to represent this?
>
> E.g.,
>
> (lambda (x)
> (let ((a (1+ x))
> (b (+ 3 x))
> (c (+ a b)))
> (signal 'condition-notify :variable 'a :value a)
> (signal 'condition-notify :variable 'b :value b)
> (signal 'condition-notify :variable 'c :value c)
> (+ 3 b)))
>
> In this code only the value b is "really used", I'd be happy if
> the optimizer eliminated the calculations of a and b, AND
> if it would also eliminate the calls 1st and 3rd calls to signal.
>
>
> I think what I'm asking for is impossible. Any thoughts?

You're lucky, it's relatively easy to compute the free variables of an
expression (but it still requires a code walker, so I won't define the
correct complete CL function here).

(defmacro notify-let ((&rest bindings) &body body)
(let ((free-variables (compute-free-variables `(progn ,@body)))
(bound-variables (bindings-variables bindings))
(initial-expressions (bindings-expresions bindings)))
`(let ,(mapcan (lambda (var init)
(when (member var free-variables)
(list (list var init))))
bound-variables initial-expressions)
,@(mapcan (lambda (var)
(when (member var free-variables)
(list `(signal 'condition-notify
:variable (quote ,var)
:value ,var))))
bound-variables)
,@body)))



--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Marco Antoniotti

6/3/2016 2:25:00 PM

0

On Thursday, June 2, 2016 at 2:49:35 PM UTC-4, informatimago wrote:
> Jim Newton <jimka.issy@gmail.com> writes:
>
....
>
> You're lucky, it's relatively easy to compute the free variables of an
> expression (but it still requires a code walker, so I won't define the
> correct complete CL function here).

CLAST is on the way.

Cheers
--
MA