You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Shouldn't this have triggered an error before finishing the loop, when i is 4?
(definea 0)
(begin
(dotimes (i 10)
(when (> i 3) (symbol-immutable! 'a))
(set! a i))
a) => 9, so it didn't see the effect of symbol-immutable!
(set! a 5) ;; An error is signaled, a is not mutable!
I think it doesn't because the code patches itself and turns GLOBAL_SET into UGLOBAL_SET, and the mutability check is not performed anymore... Then, after the current form (the begin) is evaluated, a goes away from the checked table, and its mutability is seen again (is this right?).
The text was updated successfully, but these errors were encountered:
jpellegrini
changed the title
symbol-immutable! should clear the symbol from the global checked variables table...
Shouldn't symbol-immutable! clear the symbol from the global checked variables table?
Mar 6, 2023
but I'm not sure hoe to do this (still looking into it)
I'm not sure about this, but it seems tricky. As far as I can see (correct me please), the global constants table holds only the values of the globals, without their SCM headers (UGLOBAL_SET cannot access the stk_header of those variables, so it can't check if they're mutable or not).
And symbol-immutable! can't remove a variable from the table, because it would have to invalidate the index (and we have only 50 of them). Compacting the table is impossible, because patched code may exist anywhere with the existing indices...
So perhaps a solution (for the future, perhaps not for 2.0) is to also store the header in the global table?
Hi @egallesio!
Shouldn't this have triggered an error before finishing the loop, when
i
is 4?I think it doesn't because the code patches itself and turns
GLOBAL_SET
intoUGLOBAL_SET
, and the mutability check is not performed anymore... Then, after the current form (thebegin
) is evaluated,a
goes away from the checked table, and its mutability is seen again (is this right?).The text was updated successfully, but these errors were encountered: