0.7.1.20:
[sbcl.git] / src / cold / warm.lisp
1 ;;;; "warm initialization": initialization which comes after cold init
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
11
12 (in-package "COMMON-LISP-USER")
13 \f
14 ;;;; general warm init compilation policy
15
16 ;;; Without generational GC, GC gets really slow unless we collect in
17 ;;; large chunks. For small chunks, efficiency tends to grow roughly
18 ;;; linearly with chunk size. Later we hit diminishing returns as we
19 ;;; approach the total amount of RAM we use, or we can even get into
20 ;;; performance trouble by clobbering cache and VM systems too hard.
21 ;;; But modern machines tend to think of 20 Mb as a moderate amount of
22 ;;; memory, and it's of the same order of magnitude as the amount of
23 ;;; RAM we need for the build, so it seems like a plausible chunk size.
24 #-gencgc
25 (progn
26   (sb!ext:gc-off)
27   (setf (sb!ext:bytes-consed-between-gcs) (* 20 (expt 10 6)))
28   (sb!ext:gc-on))
29
30 (proclaim '(optimize (compilation-speed 1)
31                      (debug #+sb-show 2 #-sb-show 1)
32                      (inhibit-warnings 2)
33                      (safety 1)
34                      (space 1)
35                      (speed 2)))
36 \f
37 ;;;; KLUDGE: Compile and load files which really belong in cold load but are
38 ;;;; here for various unsound reasons. We handle them here, before the package
39 ;;;; hacking below, because they use the SB!FOO cold package name convention
40 ;;;; instead of the SB-FOO final package name convention (since they really
41 ;;;; do belong in cold load and will hopefully make it back there reasonably
42 ;;;; soon). -- WHN 19991207
43
44 (dolist (stem '(;; FIXME: The assembly files here probably belong in
45                 ;; cold load instead of warm load. They ended up here
46                 ;; as a quick hack to work around the consequences of
47                 ;; my misunderstanding how ASSEMBLE-FILE works when I
48                 ;; wrote the cold build code. The cold build code
49                 ;; expects only one FASL filename per source file,
50                 ;; when it turns out we really need one FASL file for
51                 ;; ASSEMBLE-FILE output and another for COMPILE-FILE
52                 ;; output. It would probably be good to redo the cold
53                 ;; build code so that the COMPILE-FILE stuff generated
54                 ;; here can be loaded at the same time as the
55                 ;; ASSEMBLE-FILE stuff generated there.
56                 "src/assembly/target/assem-rtns"
57                 "src/assembly/target/array"
58                 "src/assembly/target/arith"
59                 "src/assembly/target/alloc"))
60   ;; KLUDGE: Cut-and-paste programming, the sign of a true professional.:-|
61   ;; (Hopefully this will go away as we move the files above into cold load.)
62   ;; -- WHN 19991214
63   (let ((fullname (concatenate 'string stem ".lisp")))
64     ;; (Now that we use byte compiler for interpretation, /SHOW
65     ;; doesn't get compiled properly until the src/assembly files have
66     ;; been loaded, so we use PRINT instead.)
67     #+sb-show (print "/about to compile src/assembly file")
68     #+sb-show (print fullname)
69     (multiple-value-bind
70         (compiled-truename compilation-warnings-p compilation-failure-p)
71         (compile-file fullname)
72       (declare (ignore compilation-warnings-p))
73       #+sb-show (print "/done compiling src/assembly file")
74       (if compilation-failure-p
75           (error "COMPILE-FILE of ~S failed." fullname)
76           (unless (load compiled-truename)
77             (error "LOAD of ~S failed." compiled-truename))))))
78 \f
79 ;;;; package hacking
80
81 ;;; Our cross-compilation host is out of the picture now, so we no longer need
82 ;;; to worry about collisions between our package names and cross-compilation
83 ;;; host package names, so now is a good time to rename any package with a
84 ;;; bootstrap-only name SB!FOO to its permanent name SB-FOO.
85 ;;;
86 ;;; (In principle it might be tidier to do this when dumping the cold image in
87 ;;; genesis, but in practice the logic might be a little messier because
88 ;;; genesis dumps both symbols and packages, and we'd need to make that dumped
89 ;;; symbols were renamed in the same way as dumped packages. Or we could do it
90 ;;; in cold init, but it's easier to experiment with and debug things here in
91 ;;; warm init than in cold init, so we do it here instead.)
92 (let ((boot-prefix "SB!")
93       (perm-prefix "SB-"))
94   (dolist (package (list-all-packages))
95     (let ((old-package-name (package-name package)))
96       (when (and (>= (length old-package-name) (length boot-prefix))
97                  (string= boot-prefix old-package-name
98                           :end2 (length boot-prefix)))
99         (let ((new-package-name (concatenate 'string
100                                              perm-prefix
101                                              (subseq old-package-name
102                                                      (length boot-prefix)))))
103           (rename-package package
104                           new-package-name
105                           (package-nicknames package)))))))
106
107 ;;; FIXME: This nickname is a deprecated hack for backwards
108 ;;; compatibility with code which assumed the CMU-CL-style
109 ;;; SB-ALIEN/SB-C-CALL split. That split went away and was deprecated
110 ;;; in 0.7.0, so we should get rid of this nickname after a while.
111 (let ((package (find-package "SB-ALIEN")))
112   (rename-package package
113                   (package-name package)
114                   (cons "SB-C-CALL" (package-nicknames package))))
115
116 ;;; KLUDGE: This is created here (instead of in package-data-list.lisp-expr)
117 ;;; because it doesn't have any symbols in it, so even if it's
118 ;;; present at cold load time, genesis thinks it's unimportant
119 ;;; and doesn't dump it. There's gotta be a better way, but for now
120 ;;; I'll just do it here. (As noted below, I'd just as soon have this
121 ;;; go away entirely, so I'm disinclined to fiddle with it too much.)
122 ;;; -- WHN 19991206
123 ;;;
124 ;;; FIXME: Why do slot accessor names need to be interned anywhere? For
125 ;;; low-level debugging? Perhaps this should go away, or at least
126 ;;; be optional, controlled by SB-SHOW or something.
127 (defpackage "SB-SLOT-ACCESSOR-NAME"
128   (:use))
129 \f
130 ;;;; compiling and loading more of the system
131
132 ;;; KLUDGE: In SBCL, almost all in-the-flow-of-control package hacking has
133 ;;; gone away in favor of package setup controlled by tables. However, that
134 ;;; mechanism isn't smart enough to handle shadowing, and since this shadowing
135 ;;; is inherently a non-ANSI KLUDGE anyway (i.e. there ought to be no
136 ;;; difference between e.g. CL:CLASS and SB-PCL:CLASS) there's not much
137 ;;; point in trying to polish it by implementing a non-KLUDGEy way of
138 ;;; setting it up. -- WHN 19991203
139 (let ((*package* (the package (find-package "SB-PCL"))))
140   (shadow '(;; CLASS itself and operations thereon
141             "CLASS" "CLASS-NAME" "CLASS-OF" "FIND-CLASS"
142             ;; some system classes
143             "BUILT-IN-CLASS" "STANDARD-CLASS" "STRUCTURE-CLASS"))
144   ;; Of the shadowing symbols above, these are external symbols in CMU CL ca.
145   ;; 19991203. I'm not sure what's the basis of the decision to export some and
146   ;; not others; we'll just follow along..
147   (export (mapcar #'intern '("CLASS-NAME" "CLASS-OF" "FIND-CLASS"))))
148
149 ;;; FIXME: CMU CL's pclcom.lisp had extra optional stuff wrapped around
150 ;;; COMPILE-PCL, at least some of which we should probably have too:
151 ;;;
152 ;;; (with-compilation-unit
153 ;;;     (:optimize '(optimize (debug #+(and (not high-security) small) .5
154 ;;;                               #-(or high-security small) 2
155 ;;;                               #+high-security 3)
156 ;;;                        (speed 2) (safety #+(and (not high-security) small) 0
157 ;;;                                          #-(or high-security small) 2
158 ;;;                                          #+high-security 3)
159 ;;;                        (inhibit-warnings 2))
160 ;;;      :optimize-interface '(optimize-interface #+(and (not high-security) small)
161 ;;; (safety 1)
162 ;;;                                            #+high-security (safety 3))
163 ;;;      :context-declarations
164 ;;;      '((:external (declare (optimize-interface (safety #-high-security 2 #+high-
165 ;;; security 3)
166 ;;;                                             (debug #-high-security 1 #+high-s
167 ;;; ecurity 3))))
168 ;;;     ((:or :macro (:match "$EARLY-") (:match "$BOOT-"))
169 ;;;     (declare (optimize (speed 0))))))
170 ;;;
171 ;;; FIXME: This has mutated into a hack which crudely duplicates
172 ;;; functionality from the existing mechanism to load files from
173 ;;; build-order.lisp-expr, without being quite parallel. (E.g. object
174 ;;; files end up alongside the source files instead of ending up in
175 ;;; parallel directory trees.) Maybe we could merge the filenames here
176 ;;; into build-order.lisp-expr with some new flag (perhaps :WARM) to
177 ;;; indicate that the files should be handled not in cold load but
178 ;;; afterwards. 
179 (dolist (stem '(;; CLOS, derived from the PCL reference implementation
180                 ;;
181                 ;; This PCL build order is based on a particular
182                 ;; linearization of the declared build order
183                 ;; dependencies from the old PCL defsys.lisp
184                 ;; dependency database.
185                 "src/pcl/walk"
186                 ;; "src/pcl/iterate" removed 2001-12-20 njf
187                 "src/pcl/early-low"
188                 "src/pcl/macros"
189                 "src/pcl/compiler-support"
190                 "src/pcl/low"
191                 ;; "src/pcl/fin" merged into "src/pcl/low" in 0.6.11.43
192                 "src/pcl/defclass"
193                 "src/pcl/defs"
194                 "src/pcl/fngen"
195                 "src/pcl/cache"
196                 "src/pcl/dlisp"
197                 "src/pcl/dlisp2"
198                 "src/pcl/boot"
199                 "src/pcl/vector"
200                 "src/pcl/slots-boot"
201                 "src/pcl/combin"
202                 "src/pcl/dfun"
203                 "src/pcl/fast-init"
204                 "src/pcl/braid"
205                 "src/pcl/dlisp3"
206                 "src/pcl/generic-functions"
207                 "src/pcl/slots"
208                 "src/pcl/init"
209                 "src/pcl/std-class"
210                 "src/pcl/cpl"
211                 "src/pcl/fsc"
212                 "src/pcl/methods"
213                 "src/pcl/fixup"
214                 "src/pcl/defcombin"
215                 "src/pcl/ctypes"
216                 "src/pcl/env"
217                 "src/pcl/documentation"
218                 "src/pcl/print-object"
219                 "src/pcl/precom1"
220                 "src/pcl/precom2"
221
222                 ;; miscellaneous functionality which depends on CLOS
223                 "src/code/force-delayed-defbangmethods"
224
225                 ;; CLOS-level support for the Gray OO streams
226                 ;; extension (which is also supported by various
227                 ;; lower-level hooks elsewhere in the code)
228                 "src/pcl/gray-streams-class"
229                 "src/pcl/gray-streams"
230
231                 ;; other functionality not needed for cold init, moved
232                 ;; to warm init to reduce peak memory requirement in
233                 ;; cold init
234                 "src/code/describe"
235                 "src/code/inspect"
236                 "src/code/profile"
237                 "src/code/ntrace"
238                 "src/code/foreign"
239                 "src/code/run-program"
240
241                 ;; Code derived from PCL's pre-ANSI DESCRIBE-OBJECT
242                 ;; facility is still used in our ANSI DESCRIBE
243                 ;; facility, and should be compiled and loaded after
244                 ;; our DESCRIBE facility is compiled and loaded.
245                 "src/pcl/describe"))
246
247   (let ((fullname (concatenate 'string stem ".lisp")))
248     (sb-int:/show "about to compile" fullname)
249     (multiple-value-bind
250         (compiled-truename compilation-warnings-p compilation-failure-p)
251         (compile-file fullname)
252       (declare (ignore compilation-warnings-p))
253       (sb-int:/show "done compiling" fullname)
254       (cond (compilation-failure-p
255              (error "COMPILE-FILE of ~S failed." fullname))
256             (t
257              (unless (load compiled-truename)
258                (error "LOAD of ~S failed." compiled-truename))
259              (sb-int:/show "done loading" compiled-truename))))))
260 \f
261 ;;;; setting package documentation
262
263 ;;; While we were running on the cross-compilation host, we tried to
264 ;;; be portable and not overwrite the doc strings for the standard
265 ;;; packages. But now the cross-compilation host is only a receding
266 ;;; memory, and we can have our way with the doc strings.
267 (sb-int:/show "setting package documentation")
268 #+sb-doc (setf (documentation (find-package "COMMON-LISP") t)
269 "public: home of symbols defined by the ANSI language specification")
270 #+sb-doc (setf (documentation (find-package "COMMON-LISP-USER") t)
271                "public: the default package for user code and data")
272 #+sb-doc (setf (documentation (find-package "KEYWORD") t)
273                "public: home of keywords")
274
275 ;;; KLUDGE: It'd be nicer to do this in the table with the other
276 ;;; non-standard packages. -- WHN 19991206
277 #+sb-doc (setf (documentation (find-package "SB-SLOT-ACCESSOR-NAME") t)
278                "private: home of CLOS slot accessor internal names")
279
280 ;;; FIXME: There doesn't seem to be any easy way to get package doc strings
281 ;;; through the cold boot process. They need to be set somewhere. Maybe the
282 ;;; easiest thing to do is to read them out of package-data-list.lisp-expr
283 ;;; now?
284 \f
285 ;;;; restoring compilation policy to neutral values in preparation for
286 ;;;; SAVE-LISP-AND-DIE as final SBCL core
287
288 (sb-int:/show "setting compilation policy to neutral values")
289 (proclaim '(optimize (compilation-speed 1)
290                      (debug 1)
291                      (inhibit-warnings 1)
292                      (safety 1)
293                      (space 1)
294                      (speed 1)))