Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shouldn't symbol-immutable! clear the symbol from the global checked variables table? #477

Open
jpellegrini opened this issue Mar 5, 2023 · 2 comments

Comments

@jpellegrini
Copy link
Contributor

jpellegrini commented Mar 5, 2023

Hi @egallesio!

Shouldn't this have triggered an error before finishing the loop, when i is 4?

(define a 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?).

@jpellegrini 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
@jpellegrini
Copy link
Contributor Author

Or maybe UGLOBAL_SET should check for immutability, but I'm not sure hoe to do this (still looking into it)

@jpellegrini
Copy link
Contributor Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant