Clozure / ccl

Clozure Common Lisp
http://ccl.clozure.com
Apache License 2.0
840 stars 105 forks source link

Clean up gc-hook mechanisms #453

Open svspire opened 11 months ago

svspire commented 11 months ago

MCL had a mechanism for automatically executing user code both before and after a garbage collection via the variables *pre-gc-hook*, *post-gc-hook*, and the functions #'add-gc-hook and #'remove-gc-hook.

CCL no longer seems to support *pre-gc-hook* although it does continue to support *post-gc-hook*. In CCL, adding a function to *pre-gc-hook* (either directly or by calling #'add-gc-hook with an argument of :pre-gc) is effectively a no-op because no current CCL code pays any attention to *pre-gc-hook*.

I don't know for sure why *pre-gc-hook* is no longer supported but I can speculate: Running user code at pre-gc time is asking for trouble because by definition that code runs when the system is out of memory. Supporting *post-gc-hook* on the other hand is easy.

I suspect that *pre-gc-hook* remains in the code only for backward compatibility with MCL.

I propose the following:

  1. We document how *post-gc-hook* works (since it's never been properly documented) and make it clear that there's no longer any such thing as *pre-gc-hook*.
  2. We remove all code that defines and supports *pre-gc-hook* from the code base. I rather doubt there's any old MCL code being run in CCL that depends on it. MCL itself seemed to stop supporting it around version 4.3 or even before. (I say this because a very old MCL example file called #P"edit-callers.lisp" was changed to no longer use *pre-gc-hook* around version 4.3. I don't have complete source code for those old versions so I can't say for sure when that variable stopped being read.)
  3. We remove the file #P"ccl:library;macptr-termination.lisp" because it doesn't get loaded by anybody any more. It seems to be an MCL-specific file. Am I wrong about this?

Comments welcome.