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