doc/manual/Makefile: remove stale variables
[sbcl.git] / make-target-2-load.lisp
blob2d4d4f16d7c4a7f9f526ae149b53e5985dd0f92d
1 ;;; Do warm init without compiling files.
3 ;;; There's a fair amount of machinery which is needed only at cold
4 ;;; init time, and should be discarded before freezing the final
5 ;;; system. We discard it by uninterning the associated symbols.
6 ;;; Rather than using a special table of symbols to be uninterned,
7 ;;; which might be tedious to maintain, instead we use a hack:
8 ;;; anything whose name matches a magic character pattern is
9 ;;; uninterned.
10 ;;; Additionally, you can specify an arbitrary way to destroy
11 ;;; random bootstrap stuff on per-package basis.
12 (defun !unintern-init-only-stuff (&aux result)
13 (dolist (package (list-all-packages))
14 (sb-int:awhen (find-symbol "!REMOVE-BOOTSTRAP-SYMBOLS" package)
15 (funcall sb-int:it)))
16 (dolist (list sb-impl::*!removable-symbols*)
17 (let ((package (find-package (car list))))
18 (dolist (symbol (cdr list))
19 (fmakunbound symbol)
20 (unintern symbol package))))
21 sb-kernel::
22 (flet ((uninternable-p (symbol)
23 (let ((name (symbol-name symbol)))
24 (or (and (>= (length name) 1) (char= (char name 0) #\!))
25 (and (>= (length name) 2) (string= name "*!" :end1 2))
26 (memq symbol
27 '(sb-c::sb!pcl sb-c::sb!impl sb-c::sb!kernel
28 sb-c::sb!c sb-c::sb-int))))))
29 ;; A structure constructor name, in particular !MAKE-SAETP,
30 ;; can't be uninterned if referenced by a defstruct-description.
31 ;; So loop over all structure classoids and clobber any
32 ;; symbol that should be uninternable.
33 (maphash (lambda (classoid layout)
34 (when (structure-classoid-p classoid)
35 (let ((dd (layout-info layout)))
36 (setf (dd-constructors dd)
37 (delete-if (lambda (x)
38 (and (consp x) (uninternable-p (car x))))
39 (dd-constructors dd))))))
40 (classoid-subclasses (find-classoid t)))
41 ;; Todo: perform one pass, then a full GC, then a final pass to confirm
42 ;; it worked. It shoud be an error if any uninternable symbols remain,
43 ;; but at present there are about 13 other "!" symbols with referers.
44 (with-package-iterator (iter (list-all-packages) :internal :external)
45 (loop (multiple-value-bind (winp symbol accessibility package) (iter)
46 (declare (ignore accessibility))
47 (unless winp
48 (return))
49 (when (uninternable-p symbol)
50 ;; Uninternable symbols which are referenced by other stuff
51 ;; can't disappear from the image, but we don't need to preserve
52 ;; their functions, so FMAKUNBOUND them. This doesn't have
53 ;; the intended effect if the function shares a code-component
54 ;; with non-cold-init lambdas. Though the cold-init function is
55 ;; never called post-build, it is not discarded. Also, I suspect
56 ;; that the following loop should print nothing, but it does:
58 (sb-vm::map-allocated-objects
59 (lambda (obj type size)
60 (declare (ignore size))
61 (when (= type sb-vm:code-header-widetag)
62 (let ((name (sb-c::debug-info-name
63 (sb-kernel:%code-debug-info obj))))
64 (when (and (stringp name) (search "COLD-INIT-FORMS" name))
65 (print obj)))))
66 :dynamic)
68 (fmakunbound symbol)
69 (unintern symbol package))))))
70 result)
72 (progn
73 (defvar *compile-files-p* nil)
74 "about to LOAD warm.lisp (with *compile-files-p* = NIL)")
76 (progn
77 (load "src/cold/warm.lisp")
79 ;;; Remove docstrings that snuck in, as will happen with
80 ;;; any file compiled in warm load.
81 #-sb-doc
82 (let ((count 0))
83 (macrolet ((clear-it (place)
84 `(when ,place
85 ,(if (typep place '(cons (eql sb-int:info)))
86 `(sb-int:clear-info ,@(cdr place))
87 `(setf ,place nil))
88 (incf count))))
89 ;; 1. Functions, macros, special operators
90 (sb-vm::map-allocated-objects
91 (lambda (obj type size)
92 (declare (ignore size))
93 (case type
94 (#.sb-vm:code-header-widetag
95 (dotimes (i (sb-kernel:code-n-entries obj))
96 (let ((f (sb-kernel:%code-entry-point obj i)))
97 (clear-it (sb-kernel:%simple-fun-doc f)))))
98 (#.sb-vm:instance-widetag
99 (when (typep obj 'class)
100 (when (slot-boundp obj 'sb-pcl::%documentation)
101 (clear-it (slot-value obj 'sb-pcl::%documentation)))))
102 (#.sb-vm:funcallable-instance-widetag
103 (when (typep obj 'standard-generic-function)
104 (when (slot-boundp obj 'sb-pcl::%documentation)
105 (clear-it (slot-value obj 'sb-pcl::%documentation)))))))
106 :all)
107 ;; 2. Variables, types, and anything else
108 (do-all-symbols (s)
109 (dolist (category '(:variable :type :typed-structure :setf))
110 (clear-it (sb-int:info category :documentation s)))
111 (clear-it (sb-int:info :random-documentation :stuff s))))
112 (when (plusp count)
113 (format t "~&Removed ~D doc string~:P" count)))
115 ;; Remove source forms of compiled-to-memory lambda expressions.
116 ;; The disassembler is the major culprit for retention of these.
117 (sb-vm::map-allocated-objects
118 (lambda (obj type size)
119 (declare (ignore type size))
120 (when (typep obj 'sb-c::debug-source)
121 (unless (sb-c::debug-source-namestring obj)
122 (setf (sb-c::debug-source-form obj) nil))))
123 :all)
125 ;; Fix unknown types in globaldb
126 (let ((l nil))
127 (do-all-symbols (s)
128 (flet ((fixup (kind)
129 (multiple-value-bind (type present)
130 (sb-int:info kind :type s)
131 (when (and present
132 (sb-kernel:contains-unknown-type-p type))
133 (setf (sb-int:info kind :type s)
134 (sb-kernel:specifier-type (sb-kernel:type-specifier type)))
135 (push s l)))))
136 (fixup :function)
137 (fixup :variable)))
138 (unless (sb-impl::!c-runtime-noinform-p)
139 (let ((*print-pretty* nil)
140 (*print-length* nil))
141 (format t "~&; Fixed types: ~S~%" (sort l #'string<)))))
143 ;; Unintern no-longer-needed stuff before the possible PURIFY in
144 ;; SAVE-LISP-AND-DIE.
145 #-(or sb-fluid sb-devel) (!unintern-init-only-stuff)
147 ;; Mark interned immobile symbols so that COMPILE-FILE knows
148 ;; which symbols will always be physically in immobile space.
149 ;; Due to the possibility of interning a symbol that was allocated in dynamic
150 ;; space, it's not the case that all interned symbols are immobile.
151 ;; And we can't promise anything across reload, which makes it impossible
152 ;; for x86-64 codegen to know which symbols are immediate constants.
153 ;; Except that symbols which existed at SBCL build time must be.
154 #+(and immobile-space (not immobile-symbols))
155 (do-all-symbols (symbol)
156 (when (sb-kernel:immobile-space-obj-p symbol)
157 (sb-kernel:set-header-data
158 symbol (logior (sb-kernel:get-header-data symbol)
159 (ash 1 sb-vm::+initial-core-symbol-bit+)))))
161 ;; A symbol whose INFO slot underwent any kind of manipulation
162 ;; such that it now has neither properties nor globaldb info,
163 ;; can have the slot set back to NIL if it wasn't already.
164 (do-all-symbols (symbol)
165 (when (and (sb-kernel:symbol-info symbol)
166 (null (sb-kernel:symbol-info-vector symbol))
167 (null (symbol-plist symbol)))
168 (setf (sb-kernel:symbol-info symbol) nil)))
170 ;; Set doc strings for the standard packages.
171 #+sb-doc
172 (setf (documentation (find-package "COMMON-LISP") t)
173 "public: home of symbols defined by the ANSI language specification"
174 (documentation (find-package "COMMON-LISP-USER") t)
175 "public: the default package for user code and data"
176 (documentation (find-package "KEYWORD") t)
177 "public: home of keywords")
179 "done with warm.lisp, about to GC :FULL T")
181 (sb-ext:gc :full t)
183 ;;; resetting compilation policy to neutral values in preparation for
184 ;;; SAVE-LISP-AND-DIE as final SBCL core (not in warm.lisp because
185 ;;; SB-C::*POLICY* has file scope)
186 (setq sb-c::*policy* (copy-structure sb-c::**baseline-policy**))
188 ;;; Adjust READTABLE-BASE-CHAR-PREFERENCE back to the advertised default.
189 (dolist (rt (list sb-impl::*standard-readtable* *debug-readtable*))
190 (setf (readtable-base-char-preference rt) :symbols))
191 ;;; Change the internal constructor's default too.
192 (let ((dsd sb-kernel::(find 'sb-impl::%readtable-string-preference
193 (dd-slots (find-defstruct-description 'readtable))
194 :key #'dsd-name)))
195 (funcall #'(setf slot-value) 'character dsd 'sb-kernel::default))
197 ;;; Even if /SHOW output was wanted during build, it's probably
198 ;;; not wanted by default after build is complete. (And if it's
199 ;;; wanted, it can easily be turned back on.)
200 #+sb-show (setf sb-int:*/show* nil)
201 ;;; The system is complete now, all standard functions are
202 ;;; defined.
203 ;;; The call to CTYPE-OF-CACHE-CLEAR is probably redundant.
204 ;;; SAVE-LISP-AND-DIE calls DEINIT which calls DROP-ALL-HASH-CACHES.
205 (sb-kernel::ctype-of-cache-clear)
207 ;;; In case there is xref data for internals, repack it here to
208 ;;; achieve a more compact encoding.
210 ;;; However, repacking changes
211 ;;; SB-C::**MOST-COMMON-XREF-NAMES-BY-{INDEX,NAME}** thereby changing
212 ;;; the interpretation of xref data written into and loaded from
213 ;;; fasls. Since fasls should be compatible between images originating
214 ;;; from the same SBCL build, REPACK-XREF is of no use after the
215 ;;; target image has been built.
216 #+sb-xref-for-internals (sb-c::repack-xref :verbose 1)
217 (fmakunbound 'sb-c::repack-xref)
219 (progn
220 (load "src/code/shaketree")
221 (sb-impl::shake-packages
222 ;; Retain all symbols satisfying this predicate
223 #+sb-devel
224 (lambda (symbol accessibility)
225 (declare (ignore accessibility))
226 ;; Retain all symbols satisfying this predicate
227 (or (sb-kernel:symbol-info symbol)
228 (and (boundp symbol) (not (keywordp symbol)))))
229 #-sb-devel
230 (lambda (symbol accessibility)
231 (case (symbol-package symbol)
232 (#.(find-package "SB-VM")
233 (or (eq accessibility :external)
234 ;; overapproximate what we need for contribs and tests
235 (member symbol '(sb-vm::map-referencing-objects
236 sb-vm::map-stack-references
237 sb-vm::thread-profile-data-slot
238 sb-vm::thread-alloc-region-slot
239 ;; Naughty outside-world code uses this.
240 sb-vm::thread-control-stack-start-slot
241 sb-vm::primitive-object-size))
242 (search "-OFFSET" (string symbol))
243 (search "-TN" (string symbol))))
244 ((#.(find-package "SB-C")
245 #.(find-package "SB-ASSEM")
246 #.(find-package "SB-DISASSEM")
247 #.(find-package "SB-IMPL")
248 #.(find-package "SB-KERNEL"))
249 ;; Assume all and only external symbols must be retained
250 (eq accessibility :external))
251 (#.(find-package "SB-FASL")
252 ;; Retain +BACKEND-FASL-FILE-IMPLEMENTATION+ and +FASL-FILE-VERSION+
253 ;; (and anything else otherwise reachable)
254 (and (eq accessibility :external)
255 (constantp symbol)))
256 (#.(find-package "SB-BIGNUM")
257 ;; There are 2 important external symbols for sb-gmp.
258 ;; Other externals can disappear.
259 (member symbol '(sb-bignum:%allocate-bignum
260 sb-bignum:make-small-bignum)))
262 ;; By default, retain any symbol with any attachments
263 (or (sb-kernel:symbol-info symbol)
264 (and (boundp symbol) (not (keywordp symbol)))))))
265 :verbose t :print nil)
266 (unintern 'sb-impl::shake-packages 'sb-impl))
268 ;;; Use historical (stupid) behavior for storing pathname namestrings
269 ;;; in fasls.
270 (setq sb-c::*name-context-file-path-selector* 'truename)
272 ;;; Lock internal packages
273 (dolist (p (list-all-packages))
274 (unless (member p (mapcar #'find-package '("KEYWORD" "CL-USER")))
275 (sb-ext:lock-package p)))
277 ;;; Clean up stray symbols from the CL-USER package.
278 (with-package-iterator (iter "CL-USER" :internal :external)
279 (loop (multiple-value-bind (winp symbol) (iter)
280 (if winp (unintern symbol "CL-USER") (return)))))
282 #+immobile-code (setq sb-c::*compile-to-memory-space* :dynamic)
283 #+sb-fasteval (setq sb-ext:*evaluator-mode* :interpret)
284 ;; See comments in 'readtable.lisp'
285 (setf (readtable-base-char-preference *readtable*) :symbols)
287 "done with warm.lisp, about to SAVE-LISP-AND-DIE"