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