On 12/19/23 20:19, Waldek Hebisch wrote:
On Tue, Dec 19, 2023 at 05:58:37PM +0800, Qian Yun wrote:
On 12/19/23 08:01, Waldek Hebisch wrote:
Well, original had:
while savedTimerStack ^= $timedNameStack repeat
stopTimingProcess peekTimedName()
'stopTimingProcess' calls 'updateTimedName' which was/is needed
to update counters. IIUC without this statistics will be wrong
(time will be "charged" to different use).
'stopTimingProcess' will run only when exceptions are thrown and
catched. In this case, stats are already messed up.
I do not think so. More preciesely, 'startTimingProcess' adds
position to '$timedNameStack' and causes timing to be charged
to given name up to point of another 'startTimingProcess'
or 'stopTimingProcess'. When 'THROW' happens time is still
charged to code responible for 'THROW' which is more or less
resonable. Normal return would call 'stopTimingProcess', the
loop simulates this.
I can agree on this part.
Waldek, what's your opinion on fixing this bug?
AFAICS loop here and in interpretTopLevel where right. I am not
sure if the loop is really necessary, but we need to do proper
accounting and the loop is "obviously correct" way of doing this.
Another approach may easily get broken by changes.
IMO proper fix for this bug involves making sure that we always
have valid '$timedNameStack' and that it is in sync with other
variables. One way to ensure this is doing "push" on init,
instead of assignment.
OK, to recap on this problem:
We need to make sure '$timedNameStack' is valid.
'$timedNameStack' can be messed up in two cases:
1. recursion
2. thrown and catch exceptions
For 1, correct way is to use dynamic bindings.
Dynamic bindings would be good if the loop was not present. We
need to make sure that variables are still valid when we execute
the loop.
I think that simplest solution is to avoid _assignment to
'$timedNameStack'. Instead initialization should push, so
that when there is timing in progress poping will get old value.
If you want to use "push", then what happens to not catched errors,
for example "1/0"?
Then '$timedNameStack' will keep growing.
So I think use assignment to initialize this dynamic variable
is the correct approach.
- Qian
For 2, I believe simple assignment is enough. Or keep current
code if we fix problem 1.
Simplest way is to keep current loops. More complicated way
could put UNWIND-PROTECT in strategic places and use cleanup
part to handle '$timedNameStack'.
--
You received this message because you are subscribed to the Google Groups "FriCAS -
computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/fricas-devel/01ee031d-380c-4719-b65f-b38371b1351c%40gmail.com.