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