Fix warning under cmucl host
[sbcl.git] / src / cold / defun-load-or-cload-xcompiler.lisp
blobbd3f377dc0be002697caad0fec8b710b4cb0f8ff
1 ;;;; This software is part of the SBCL system. See the README file for
2 ;;;; more information.
3 ;;;;
4 ;;;; This software is derived from the CMU CL system, which was
5 ;;;; written at Carnegie Mellon University and released into the
6 ;;;; public domain. The software is in the public domain and is
7 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
8 ;;;; files for more information.
10 (in-package "SB-COLD")
12 (defparameter *full-calls-to-warn-about*
13 '(;mask-signed-field ;; Too many to fix
16 ;;; Set of function names whose definition will never be seen in make-host-2,
17 ;;; as they are deferred until warm load.
18 ;;; The table is populated later in this file.
19 (defparameter *undefined-fun-whitelist* (make-hash-table :test 'equal))
21 (defvar *symbol-values-for-genesis*)
22 (export '*symbol-values-for-genesis*)
23 (let ((pathname "output/init-symbol-values.lisp-expr"))
24 (setq *symbol-values-for-genesis*
25 (and (probe-file pathname) (read-from-file pathname)))
26 (defun save-initial-symbol-values ()
27 (with-open-file (f pathname :direction :output :if-exists :supersede)
28 (write *symbol-values-for-genesis* :stream f :readably t))))
30 (when (make-host-1-parallelism)
31 (require :sb-posix))
32 #+#.(cl:if (cl:find-package "SB-POSIX") '(and) '(or))
33 (defun parallel-make-host-1 (max-jobs)
34 (let ((subprocess-count 0)
35 (subprocess-list nil))
36 (flet ((wait ()
37 (multiple-value-bind (pid status) (sb-posix:wait)
38 (format t "~&; Subprocess ~D exit status ~D~%" pid status)
39 (setq subprocess-list (delete pid subprocess-list)))
40 (decf subprocess-count)))
41 (do-stems-and-flags (stem flags)
42 (unless (position :not-host flags)
43 (when (>= subprocess-count max-jobs)
44 (wait))
45 (let ((pid (sb-posix:fork)))
46 (when (zerop pid)
47 (in-host-compilation-mode
48 (lambda () (compile-stem stem flags :host-compile)))
49 ;; FIXME: convey exit code based on COMPILE result.
50 (sb-sys:os-exit 0))
51 (push pid subprocess-list)
52 (incf subprocess-count)
53 ;; Do not wait for the compile to finish. Just load as source.
54 (let ((source (merge-pathnames (stem-remap-target stem)
55 (make-pathname :type "lisp"))))
56 (let ((sb-ext:*evaluator-mode* :interpret))
57 (in-host-compilation-mode
58 (lambda ()
59 (load source :verbose t :print nil))))))))
60 (loop (if (plusp subprocess-count) (wait) (return)))))
62 ;; We want to load compiled files, because that's what this function promises.
63 ;; Reloading is tricky because constructors for interned ctypes will construct
64 ;; new objects via their LOAD-TIME-VALUE forms, but globaldb already stored
65 ;; some objects from the interpreted pre-load.
66 ;; So wipe everything out that causes problems down the line.
67 ;; (Or perhaps we could make their effects idempotent)
68 (format t "~&; Parallel build: Clearing globaldb~%")
69 (do-all-symbols (s)
70 (when (get s :sb-xc-globaldb-info)
71 (remf (symbol-plist s) :sb-xc-globaldb-info)))
72 (fill (symbol-value 'sb!c::*info-types*) nil)
73 (clrhash (symbol-value 'sb!kernel::*forward-referenced-layouts*))
74 (setf (symbol-value 'sb!kernel:*type-system-initialized*) nil)
75 (makunbound 'sb!c::*backend-primitive-type-names*)
76 (makunbound 'sb!c::*backend-primitive-type-aliases*)
78 (format t "~&; Parallel build: Reloading compilation artifacts~%")
79 ;; Now it works to load fasls.
80 (in-host-compilation-mode
81 (lambda ()
82 (handler-bind ((sb-kernel:redefinition-warning #'muffle-warning))
83 (do-stems-and-flags (stem flags)
84 (unless (position :not-host flags)
85 (load (stem-object-path stem flags :host-compile)
86 :verbose t :print nil))))))
87 (format t "~&; Parallel build: Fasl loading complete~%"))
89 ;;; Either load or compile-then-load the cross-compiler into the
90 ;;; cross-compilation host Common Lisp.
91 (defun load-or-cload-xcompiler (load-or-cload-stem)
93 (declare (type function load-or-cload-stem))
95 ;; The running-in-the-host-Lisp Python cross-compiler defines its
96 ;; own versions of a number of functions which should not overwrite
97 ;; host-Lisp functions. Instead we put them in a special package.
99 ;; The common theme of the functions, macros, constants, and so
100 ;; forth in this package is that they run in the host and affect the
101 ;; compilation of the target.
102 (let ((package-name "SB-XC"))
103 (make-package package-name :use nil :nicknames nil)
104 (dolist (name '(;; the constants (except for T and NIL which have
105 ;; a specially hacked correspondence between
106 ;; cross-compilation host Lisp and target Lisp)
107 "ARRAY-DIMENSION-LIMIT"
108 "ARRAY-RANK-LIMIT"
109 "ARRAY-TOTAL-SIZE-LIMIT"
110 "BOOLE-1"
111 "BOOLE-2"
112 "BOOLE-AND"
113 "BOOLE-ANDC1"
114 "BOOLE-ANDC2"
115 "BOOLE-C1"
116 "BOOLE-C2"
117 "BOOLE-CLR"
118 "BOOLE-EQV"
119 "BOOLE-IOR"
120 "BOOLE-NAND"
121 "BOOLE-NOR"
122 "BOOLE-ORC1"
123 "BOOLE-ORC2"
124 "BOOLE-SET"
125 "BOOLE-XOR"
126 "CALL-ARGUMENTS-LIMIT"
127 "CHAR-CODE-LIMIT"
128 "DOUBLE-FLOAT-EPSILON"
129 "DOUBLE-FLOAT-NEGATIVE-EPSILON"
130 "INTERNAL-TIME-UNITS-PER-SECOND"
131 "LAMBDA-LIST-KEYWORDS"
132 "LAMBDA-PARAMETERS-LIMIT"
133 "LEAST-NEGATIVE-DOUBLE-FLOAT"
134 "LEAST-NEGATIVE-LONG-FLOAT"
135 "LEAST-NEGATIVE-NORMALIZED-DOUBLE-FLOAT"
136 "LEAST-NEGATIVE-NORMALIZED-LONG-FLOAT"
137 "LEAST-NEGATIVE-NORMALIZED-SHORT-FLOAT"
138 "LEAST-NEGATIVE-NORMALIZED-SINGLE-FLOAT"
139 "LEAST-NEGATIVE-SHORT-FLOAT"
140 "LEAST-NEGATIVE-SINGLE-FLOAT"
141 "LEAST-POSITIVE-DOUBLE-FLOAT"
142 "LEAST-POSITIVE-LONG-FLOAT"
143 "LEAST-POSITIVE-NORMALIZED-DOUBLE-FLOAT"
144 "LEAST-POSITIVE-NORMALIZED-LONG-FLOAT"
145 "LEAST-POSITIVE-NORMALIZED-SHORT-FLOAT"
146 "LEAST-POSITIVE-NORMALIZED-SINGLE-FLOAT"
147 "LEAST-POSITIVE-SHORT-FLOAT"
148 "LEAST-POSITIVE-SINGLE-FLOAT"
149 "LONG-FLOAT-EPSILON"
150 "LONG-FLOAT-NEGATIVE-EPSILON"
151 "MOST-NEGATIVE-DOUBLE-FLOAT"
152 "MOST-NEGATIVE-FIXNUM"
153 "MOST-NEGATIVE-LONG-FLOAT"
154 "MOST-NEGATIVE-SHORT-FLOAT"
155 "MOST-NEGATIVE-SINGLE-FLOAT"
156 "MOST-POSITIVE-DOUBLE-FLOAT"
157 "MOST-POSITIVE-FIXNUM"
158 "MOST-POSITIVE-LONG-FLOAT"
159 "MOST-POSITIVE-SHORT-FLOAT"
160 "MOST-POSITIVE-SINGLE-FLOAT"
161 "MULTIPLE-VALUES-LIMIT"
162 "PI"
163 "SHORT-FLOAT-EPSILON"
164 "SHORT-FLOAT-NEGATIVE-EPSILON"
165 "SINGLE-FLOAT-EPSILON"
166 "SINGLE-FLOAT-NEGATIVE-EPSILON"
168 ;; everything else which needs a separate
169 ;; existence in xc and target
170 "BOOLE"
171 "BOOLE-CLR" "BOOLE-SET" "BOOLE-1" "BOOLE-2"
172 "BOOLE-C1" "BOOLE-C2" "BOOLE-AND" "BOOLE-IOR"
173 "BOOLE-XOR" "BOOLE-EQV" "BOOLE-NAND" "BOOLE-NOR"
174 "BOOLE-ANDC1" "BOOLE-ANDC2" "BOOLE-ORC1" "BOOLE-ORC2"
175 "BUILT-IN-CLASS"
176 "BYTE" "BYTE-POSITION" "BYTE-SIZE"
177 "CHAR-CODE"
178 "CLASS" "CLASS-NAME" "CLASS-OF"
179 "CODE-CHAR"
180 "COMPILE-FILE"
181 "COMPILE-FILE-PATHNAME"
182 "*COMPILE-FILE-PATHNAME*"
183 "*COMPILE-FILE-TRUENAME*"
184 "*COMPILE-PRINT*"
185 "*COMPILE-VERBOSE*"
186 "COMPILER-MACRO-FUNCTION"
187 "CONSTANTP"
188 "DEFCONSTANT"
189 "DEFINE-MODIFY-MACRO"
190 "DEFINE-SETF-EXPANDER"
191 "DEFMACRO" "DEFSETF" "DEFSTRUCT" "DEFTYPE"
192 "DEPOSIT-FIELD" "DPB"
193 "FBOUNDP" "FDEFINITION" "FMAKUNBOUND"
194 "FIND-CLASS"
195 "GENSYM" "*GENSYM-COUNTER*"
196 "GET-SETF-EXPANSION"
197 "LDB" "LDB-TEST"
198 "LISP-IMPLEMENTATION-TYPE" "LISP-IMPLEMENTATION-VERSION"
199 "MACRO-FUNCTION"
200 "MACROEXPAND" "MACROEXPAND-1" "*MACROEXPAND-HOOK*"
201 "MAKE-LOAD-FORM"
202 "MAKE-LOAD-FORM-SAVING-SLOTS"
203 "MASK-FIELD"
204 "PROCLAIM"
205 "SPECIAL-OPERATOR-P"
206 "STANDARD-CLASS"
207 "STRUCTURE-CLASS"
208 "SUBTYPEP"
209 "TYPE-OF" "TYPEP"
210 "UPGRADED-ARRAY-ELEMENT-TYPE"
211 "UPGRADED-COMPLEX-PART-TYPE"
212 "WITH-COMPILATION-UNIT"))
213 (export (intern name package-name) package-name)))
214 ;; don't watch:
215 (dolist (package (list-all-packages))
216 (when (= (mismatch (package-name package) "SB!") 3)
217 (shadowing-import
218 (mapcar (lambda (name) (find-symbol name "SB-XC"))
219 '("BYTE" "BYTE-POSITION" "BYTE-SIZE"
220 "DPB" "LDB" "LDB-TEST"
221 "DEPOSIT-FIELD" "MASK-FIELD"
223 "BOOLE"
224 "BOOLE-CLR" "BOOLE-SET" "BOOLE-1" "BOOLE-2"
225 "BOOLE-C1" "BOOLE-C2" "BOOLE-AND" "BOOLE-IOR"
226 "BOOLE-XOR" "BOOLE-EQV" "BOOLE-NAND" "BOOLE-NOR"
227 "BOOLE-ANDC1" "BOOLE-ANDC2" "BOOLE-ORC1" "BOOLE-ORC2"))
228 package)))
230 ;; Build a version of Python to run in the host Common Lisp, to be
231 ;; used only in cross-compilation.
233 ;; Note that files which are marked :ASSEM, to cause them to be
234 ;; processed with SB!C:ASSEMBLE-FILE when we're running under the
235 ;; cross-compiler or the target lisp, are still processed here, just
236 ;; with the ordinary Lisp compiler, and this is intentional, in
237 ;; order to make the compiler aware of the definitions of assembly
238 ;; routines.
239 (if (and (make-host-1-parallelism)
240 (eq load-or-cload-stem #'host-cload-stem))
241 (funcall (intern "PARALLEL-MAKE-HOST-1" 'sb-cold)
242 (make-host-1-parallelism))
243 (do-stems-and-flags (stem flags)
244 (unless (find :not-host flags)
245 (funcall load-or-cload-stem stem flags)
246 #!+sb-show (warn-when-cl-snapshot-diff *cl-snapshot*))))
248 ;; If the cross-compilation host is SBCL itself, we can use the
249 ;; PURIFY extension to freeze everything in place, reducing the
250 ;; amount of work done on future GCs. In machines with limited
251 ;; memory, this could help, by reducing the amount of memory which
252 ;; needs to be juggled in a full GC. And it can hardly hurt, since
253 ;; (in the ordinary build procedure anyway) essentially everything
254 ;; which is reachable at this point will remain reachable for the
255 ;; entire run.
257 ;; (Except that purifying actually slows down GENCGC). -- JES, 2006-05-30
258 #+(and sbcl (not gencgc))
259 (sb-ext:purify)
261 (values))
263 ;; Keep these in order by package, then symbol.
264 (dolist (sym
265 (append
266 ;; CL, EXT, KERNEL
267 '(allocate-instance
268 compute-applicable-methods
269 slot-makunbound
270 make-load-form-saving-slots
271 sb!ext:run-program
272 sb!kernel:profile-deinit)
273 ;; CLOS implementation
274 '(sb!mop:class-finalized-p
275 sb!mop:class-prototype
276 sb!mop:class-slots
277 sb!mop:eql-specializer-object
278 sb!mop:finalize-inheritance
279 sb!mop:generic-function-name
280 sb!mop:slot-definition-allocation
281 sb!mop:slot-definition-name
282 sb!pcl::%force-cache-flushes
283 sb!pcl::check-wrapper-validity
284 sb!pcl::class-has-a-forward-referenced-superclass-p
285 sb!pcl::class-wrapper
286 sb!pcl::compute-gf-ftype
287 sb!pcl::definition-source
288 sb!pcl:ensure-class-finalized)
289 ;; CLOS-based packages
290 '(sb!gray:stream-clear-input
291 sb!gray:stream-clear-output
292 sb!gray:stream-file-position
293 sb!gray:stream-finish-output
294 sb!gray:stream-force-output
295 sb!gray:stream-fresh-line
296 sb!gray:stream-line-column
297 sb!gray:stream-line-length
298 sb!gray:stream-listen
299 sb!gray:stream-peek-char
300 sb!gray:stream-read-byte
301 sb!gray:stream-read-char
302 sb!gray:stream-read-char-no-hang
303 sb!gray:stream-read-line
304 sb!gray:stream-read-sequence
305 sb!gray:stream-terpri
306 sb!gray:stream-unread-char
307 sb!gray:stream-write-byte
308 sb!gray:stream-write-char
309 sb!gray:stream-write-sequence
310 sb!gray:stream-write-string
311 sb!sequence:concatenate
312 sb!sequence:copy-seq
313 sb!sequence:count
314 sb!sequence:count-if
315 sb!sequence:count-if-not
316 sb!sequence:delete
317 sb!sequence:delete-duplicates
318 sb!sequence:delete-if
319 sb!sequence:delete-if-not
320 (setf sb!sequence:elt)
321 sb!sequence:elt
322 sb!sequence:emptyp
323 sb!sequence:fill
324 sb!sequence:find
325 sb!sequence:find-if
326 sb!sequence:find-if-not
327 (setf sb!sequence:iterator-element)
328 sb!sequence:iterator-endp
329 sb!sequence:iterator-step
330 sb!sequence:length
331 sb!sequence:make-sequence-iterator
332 sb!sequence:make-sequence-like
333 sb!sequence:map
334 sb!sequence:merge
335 sb!sequence:mismatch
336 sb!sequence:nreverse
337 sb!sequence:nsubstitute
338 sb!sequence:nsubstitute-if
339 sb!sequence:nsubstitute-if-not
340 sb!sequence:position
341 sb!sequence:position-if
342 sb!sequence:position-if-not
343 sb!sequence:reduce
344 sb!sequence:remove
345 sb!sequence:remove-duplicates
346 sb!sequence:remove-if
347 sb!sequence:remove-if-not
348 sb!sequence:replace
349 sb!sequence:reverse
350 sb!sequence:search
351 sb!sequence:sort
352 sb!sequence:stable-sort
353 sb!sequence:subseq
354 sb!sequence:substitute
355 sb!sequence:substitute-if
356 sb!sequence:substitute-if-not)
357 ;; Fast interpreter
358 #!+sb-fasteval
359 '(sb!interpreter:%fun-type
360 sb!interpreter:env-policy
361 sb!interpreter:eval-in-environment
362 sb!interpreter:find-lexical-fun
363 sb!interpreter:find-lexical-var
364 sb!interpreter::flush-everything
365 sb!interpreter::fun-lexically-notinline-p
366 sb!interpreter:lexenv-from-env
367 sb!interpreter::lexically-unlocked-symbol-p
368 sb!interpreter:list-locals
369 sb!interpreter:prepare-for-compile
370 sb!interpreter::reconstruct-syntactic-closure-env)
371 ;; Other
372 '(sb!debug::find-interrupted-name-and-frame
373 sb!impl::encapsulate-generic-function
374 sb!impl::encapsulated-generic-function-p
375 sb!impl::get-processes-status-changes
376 sb!impl::step-form
377 sb!impl::step-values
378 sb!impl::unencapsulate-generic-function)))
379 (setf (gethash sym *undefined-fun-whitelist*) t))