Clean up cross-compilation package creation, part 2 of 2
[sbcl.git] / src / cold / defun-load-or-cload-xcompiler.lisp
blob4f9e83fe909a14a24ccb4ae0c9c1493815a6d833
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 (when (make-host-1-parallelism)
22 (require :sb-posix))
23 #+#.(cl:if (cl:find-package "SB-POSIX") '(and) '(or))
24 (defun parallel-make-host-1 (max-jobs)
25 (let ((subprocess-count 0)
26 (subprocess-list nil))
27 (flet ((wait ()
28 (multiple-value-bind (pid status) (sb-posix:wait)
29 (format t "~&; Subprocess ~D exit status ~D~%" pid status)
30 (setq subprocess-list (delete pid subprocess-list)))
31 (decf subprocess-count)))
32 (do-stems-and-flags (stem flags)
33 (unless (position :not-host flags)
34 (when (>= subprocess-count max-jobs)
35 (wait))
36 (let ((pid (sb-posix:fork)))
37 (when (zerop pid)
38 (in-host-compilation-mode
39 (lambda () (compile-stem stem flags :host-compile)))
40 ;; FIXME: convey exit code based on COMPILE result.
41 #.(if (eq :external
42 (nth-value 1 (find-symbol "OS-EXIT" :sb-sys)))
43 `(,(find-symbol "OS-EXIT" :sb-sys) 0)
44 `(sb-unix:unix-exit 0)))
45 (push pid subprocess-list)
46 (incf subprocess-count)
47 ;; Do not wait for the compile to finish. Just load as source.
48 (let ((source (merge-pathnames (stem-remap-target stem)
49 (make-pathname :type "lisp"))))
50 (let ((sb-ext:*evaluator-mode* :interpret))
51 (in-host-compilation-mode
52 (lambda ()
53 (load source :verbose t :print nil))))))))
54 (loop (if (plusp subprocess-count) (wait) (return)))))
56 ;; We want to load compiled files, because that's what this function promises.
57 ;; Reloading is tricky because constructors for interned ctypes will construct
58 ;; new objects via their LOAD-TIME-VALUE forms, but globaldb already stored
59 ;; some objects from the interpreted pre-load.
60 ;; So wipe everything out that causes problems down the line.
61 ;; (Or perhaps we could make their effects idempotent)
62 (format t "~&; Parallel build: Clearing globaldb~%")
63 (do-all-symbols (s)
64 (when (get s :sb-xc-globaldb-info)
65 (remf (symbol-plist s) :sb-xc-globaldb-info)))
66 (fill (symbol-value 'sb!impl::*info-types*) nil)
67 (clrhash (symbol-value 'sb!kernel::*forward-referenced-layouts*))
68 (setf (symbol-value 'sb!kernel:*type-system-initialized*) nil)
69 (makunbound 'sb!c::*backend-primitive-type-names*)
70 (makunbound 'sb!c::*backend-primitive-type-aliases*)
72 (format t "~&; Parallel build: Reloading compilation artifacts~%")
73 ;; Now it works to load fasls.
74 (in-host-compilation-mode
75 (lambda ()
76 (handler-bind ((sb-kernel:redefinition-warning #'muffle-warning))
77 (do-stems-and-flags (stem flags)
78 (unless (position :not-host flags)
79 (load (stem-object-path stem flags :host-compile)
80 :verbose t :print nil))))))
81 (format t "~&; Parallel build: Fasl loading complete~%"))
83 ;;; Either load or compile-then-load the cross-compiler into the
84 ;;; cross-compilation host Common Lisp.
85 (defun load-or-cload-xcompiler (load-or-cload-stem)
86 (declare (type function load-or-cload-stem))
87 ;; Build a version of Python to run in the host Common Lisp, to be
88 ;; used only in cross-compilation.
90 ;; Note that files which are marked :ASSEM, to cause them to be
91 ;; processed with SB!C:ASSEMBLE-FILE when we're running under the
92 ;; cross-compiler or the target lisp, are still processed here, just
93 ;; with the ordinary Lisp compiler, and this is intentional, in
94 ;; order to make the compiler aware of the definitions of assembly
95 ;; routines.
96 (if (and (make-host-1-parallelism)
97 (eq load-or-cload-stem #'host-cload-stem))
98 (funcall (intern "PARALLEL-MAKE-HOST-1" 'sb-cold)
99 (make-host-1-parallelism))
100 (do-stems-and-flags (stem flags)
101 (unless (find :not-host flags)
102 (funcall load-or-cload-stem stem flags)
103 #!+sb-show (warn-when-cl-snapshot-diff *cl-snapshot*))))
105 ;; If the cross-compilation host is SBCL itself, we can use the
106 ;; PURIFY extension to freeze everything in place, reducing the
107 ;; amount of work done on future GCs. In machines with limited
108 ;; memory, this could help, by reducing the amount of memory which
109 ;; needs to be juggled in a full GC. And it can hardly hurt, since
110 ;; (in the ordinary build procedure anyway) essentially everything
111 ;; which is reachable at this point will remain reachable for the
112 ;; entire run.
114 ;; (Except that purifying actually slows down GENCGC). -- JES, 2006-05-30
115 #+(and sbcl (not gencgc))
116 (sb-ext:purify)
118 (values))
120 ;; Keep these in order by package, then symbol.
121 (dolist (sym
122 (append
123 ;; CL, EXT, KERNEL
124 '(allocate-instance
125 compute-applicable-methods
126 slot-makunbound
127 make-load-form-saving-slots
128 sb!ext:run-program
129 sb!kernel::choose-code-component-order
130 sb!kernel:profile-deinit)
131 ;; CLOS implementation
132 '(sb!mop:class-finalized-p
133 sb!mop:class-prototype
134 sb!mop:class-slots
135 sb!mop:eql-specializer-object
136 sb!mop:finalize-inheritance
137 sb!mop:generic-function-name
138 sb!mop:slot-definition-allocation
139 sb!mop:slot-definition-name
140 sb!pcl::%force-cache-flushes
141 sb!pcl::check-wrapper-validity
142 sb!pcl::class-has-a-forward-referenced-superclass-p
143 sb!pcl::class-wrapper
144 sb!pcl::compute-gf-ftype
145 sb!pcl::definition-source
146 sb!pcl::ensure-accessor
147 sb!pcl:ensure-class-finalized)
148 ;; CLOS-based packages
149 '(sb!gray:stream-clear-input
150 sb!gray:stream-clear-output
151 sb!gray:stream-file-position
152 sb!gray:stream-finish-output
153 sb!gray:stream-force-output
154 sb!gray:stream-fresh-line
155 sb!gray:stream-line-column
156 sb!gray:stream-line-length
157 sb!gray:stream-listen
158 sb!gray:stream-peek-char
159 sb!gray:stream-read-byte
160 sb!gray:stream-read-char
161 sb!gray:stream-read-char-no-hang
162 sb!gray:stream-read-line
163 sb!gray:stream-read-sequence
164 sb!gray:stream-terpri
165 sb!gray:stream-unread-char
166 sb!gray:stream-write-byte
167 sb!gray:stream-write-char
168 sb!gray:stream-write-sequence
169 sb!gray:stream-write-string
170 sb!sequence:concatenate
171 sb!sequence:copy-seq
172 sb!sequence:count
173 sb!sequence:count-if
174 sb!sequence:count-if-not
175 sb!sequence:delete
176 sb!sequence:delete-duplicates
177 sb!sequence:delete-if
178 sb!sequence:delete-if-not
179 (setf sb!sequence:elt)
180 sb!sequence:elt
181 sb!sequence:emptyp
182 sb!sequence:fill
183 sb!sequence:find
184 sb!sequence:find-if
185 sb!sequence:find-if-not
186 (setf sb!sequence:iterator-element)
187 sb!sequence:iterator-endp
188 sb!sequence:iterator-step
189 sb!sequence:length
190 sb!sequence:make-sequence-iterator
191 sb!sequence:make-sequence-like
192 sb!sequence:map
193 sb!sequence:merge
194 sb!sequence:mismatch
195 sb!sequence:nreverse
196 sb!sequence:nsubstitute
197 sb!sequence:nsubstitute-if
198 sb!sequence:nsubstitute-if-not
199 sb!sequence:position
200 sb!sequence:position-if
201 sb!sequence:position-if-not
202 sb!sequence:reduce
203 sb!sequence:remove
204 sb!sequence:remove-duplicates
205 sb!sequence:remove-if
206 sb!sequence:remove-if-not
207 sb!sequence:replace
208 sb!sequence:reverse
209 sb!sequence:search
210 sb!sequence:sort
211 sb!sequence:stable-sort
212 sb!sequence:subseq
213 sb!sequence:substitute
214 sb!sequence:substitute-if
215 sb!sequence:substitute-if-not)
216 ;; Fast interpreter
217 #!+sb-fasteval
218 '(sb!interpreter:%fun-type
219 sb!interpreter:env-policy
220 sb!interpreter:eval-in-environment
221 sb!interpreter:find-lexical-fun
222 sb!interpreter:find-lexical-var
223 sb!interpreter::flush-everything
224 sb!interpreter::fun-lexically-notinline-p
225 sb!interpreter:lexenv-from-env
226 sb!interpreter::lexically-unlocked-symbol-p
227 sb!interpreter:list-locals
228 sb!interpreter:prepare-for-compile
229 sb!interpreter::reconstruct-syntactic-closure-env)
230 ;; Other
231 '(sb!debug::find-interrupted-name-and-frame
232 sb!impl::encapsulate-generic-function
233 sb!impl::encapsulated-generic-function-p
234 sb!impl::get-processes-status-changes
235 sb!impl::step-form
236 sb!impl::step-values
237 sb!impl::stringify-package-designator
238 sb!impl::stringify-string-designator
239 sb!impl::stringify-string-designators
240 sb!impl::unencapsulate-generic-function)))
241 (setf (gethash sym *undefined-fun-whitelist*) t))