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