sbcl.sbcl/tests/load.impure-cload.lisp
Douglas Katzman 565c145870 Compute and memoize the SYMBOL-HASH of all symbols loaded from fasls.
The motivation of this is to allow for a possible enhancement to CASE
statement macroexpansion. Symbol-hash can be used to divide-and-conquer,
wherein selection over a huge set of symbols becomes a decision tree:
  (if (logbitp 1 sym)
      (if (logbitp 2 sym)
          <more-cases>
Within a subtree of fewer than a small number of choices, the tests would
be linear ("if/else/else"). Bits can be picked by the macroexpander
to create a nicely balanced tree since hashes are stable across images.
e.g. if every symbol's 0th hash bit is 1, don't use that bit in the tests.

As a further optimization, we'd like for the CASE statement never to require
computing the hash. For compilation into memory, this is easy to ensure.
(While macroexpander side-effects are generally undesirable, this particular
effect would be invisible at the user level.) For loaded fasl files, the
loader can memoize the result, since doing so is transparent and never wrong.
2015-08-04 23:28:21 -04:00

20 lines
717 B
Common Lisp

;;;; miscellaneous side-effectful tests of LOAD
;;;; This software is part of the SBCL system. See the README file for
;;;; more information.
;;;;
;;;; While most of SBCL is derived from the CMU CL system, the test
;;;; files (like this one) were written from scratch after the fork
;;;; from CMU CL.
;;;;
;;;; This software is in the public domain and is provided with
;;;; absolutely no warranty. See the COPYING and CREDITS files for
;;;; more information.
(defvar *foo* '#:bar)
;; INTERN always computes hashes, so the only thing we need to test
;; is whether uninterned symbols always have a hash.
(with-test (:name :loader-computes-symbol-hash-always)
(assert (not (zerop (sb-kernel:symbol-hash *foo*)))))