Make INFO's compiler-macro more forgiving.
[sbcl.git] / make-host-2.lisp
blob56768c63fe810cc28d18f934ce21e05b9003b0a0
1 ;;; Set up the cross-compiler.
2 (setf *print-level* 5 *print-length* 5)
3 (load "src/cold/shared.lisp")
4 (in-package "SB-COLD")
5 ;;; FIXME: these prefixes look like non-pathnamy ways of defining a
6 ;;; relative pathname. Investigate whether they can be made relative
7 ;;; pathnames.
8 (setf *host-obj-prefix* "obj/from-host/"
9 *target-obj-prefix* "obj/from-xc/")
10 (load "src/cold/set-up-cold-packages.lisp")
11 (load "src/cold/defun-load-or-cload-xcompiler.lisp")
12 (load-or-cload-xcompiler #'host-load-stem)
14 (defun proclaim-target-optimization ()
15 (let ((debug (if (position :sb-show *shebang-features*) 2 1)))
16 (sb-xc:proclaim
17 `(optimize
18 (compilation-speed 1) (debug ,debug)
19 ;; CLISP's pretty-printer is fragile and tends to cause stack
20 ;; corruption or fail internal assertions, as of 2003-04-20; we
21 ;; therefore turn off as many notes as possible.
22 (sb!ext:inhibit-warnings #-clisp 2 #+clisp 3)
23 ;; SAFETY = SPEED (and < 3) should provide reasonable safety,
24 ;; but might skip some unreasonably expensive stuff
25 ;; (e.g. %DETECT-STACK-EXHAUSTION in sbcl-0.7.2).
26 (safety 2) (space 1) (speed 2)
27 ;; sbcl-internal optimization declarations:
29 ;; never insert stepper conditions
30 (sb!c:insert-step-conditions 0)
31 ;; save FP and PC for alien calls -- or not
32 (sb!c:alien-funcall-saves-fp-and-pc #!+x86 3 #!-x86 0)))))
33 (compile 'proclaim-target-optimization)
35 (defun in-target-cross-compilation-mode (fun)
36 "Call FUN with everything set up appropriately for cross-compiling
37 a target file."
38 (let (;; In order to increase microefficiency of the target Lisp,
39 ;; enable old CMU CL defined-function-types-never-change
40 ;; optimizations. (ANSI says users aren't supposed to
41 ;; redefine our functions anyway; and developers can
42 ;; fend for themselves.)
43 #!-sb-fluid
44 (sb!ext:*derive-function-types* t)
45 ;; Let the target know that we're the cross-compiler.
46 (*features* (cons :sb-xc *features*))
47 ;; We need to tweak the readtable..
48 (*readtable* (copy-readtable)))
49 ;; ..in order to make backquotes expand into target code
50 ;; instead of host code.
51 ;; FIXME: Isn't this now taken care of automatically by
52 ;; toplevel forms in the xcompiler backq.lisp file?
53 (set-macro-character #\` #'sb!impl::backquote-charmacro)
54 (set-macro-character #\, #'sb!impl::comma-charmacro)
56 (set-dispatch-macro-character #\# #\+ #'she-reader)
57 (set-dispatch-macro-character #\# #\- #'she-reader)
58 ;; Control optimization policy.
59 (proclaim-target-optimization)
60 ;; Specify where target machinery lives.
61 (with-additional-nickname ("SB-XC" "SB!XC")
62 (funcall fun))))
63 (compile 'in-target-cross-compilation-mode)
66 ;; Supress function/macro redefinition warnings under clisp.
67 #+clisp (setf custom:*suppress-check-redefinition* t)
69 (setf *target-compile-file* #'sb-xc:compile-file)
70 (setf *target-assemble-file* #'sb!c:assemble-file)
71 (setf *in-target-compilation-mode-fn* #'in-target-cross-compilation-mode)
73 ;;; Run the cross-compiler to produce cold fasl files.
74 ;; ... and since the cross-compiler hasn't seen a DEFMACRO for QUASIQUOTE,
75 ;; make it think it has, otherwise it fails more-or-less immediately.
76 (setf (sb!int:info :function :kind 'sb!int:quasiquote) :macro
77 (sb!int:info :function :macro-function 'sb!int:quasiquote)
78 (cl:macro-function 'sb!int:quasiquote))
79 (setq sb!c::*track-full-called-fnames* :minimal) ; Change this as desired
80 (progn ; Should be: sb-xc:with-compilation-unit () ... but
81 ;; leaving aside the question of building in any host - which shouldn't
82 ;; matter - building SBCL in SBCL can hang in a way I haven't tracked down.
83 (load "src/cold/compile-cold-sbcl.lisp"))
85 (when sb!c::*track-full-called-fnames*
86 (let (possibly-suspicious likely-suspicious)
87 (sb!c::call-with-each-globaldb-name
88 (lambda (name)
89 (let* ((cell (sb!int:info :function :emitted-full-calls name))
90 (inlinep (eq (sb!int:info :function :inlinep name) :inline))
91 (info (sb!int:info :function :info name)))
92 (if (and cell
93 (or inlinep
94 (and info (sb!c::fun-info-templates info))
95 (sb!int:info :function :compiler-macro-function name)
96 (sb!int:info :function :source-transform name)))
97 (if inlinep
98 ;; A full call to an inline function almost always indicates
99 ;; an out-of-order definition. If not an inline function,
100 ;; the call could be due to an inapplicable transformation.
101 (push (cons name cell) likely-suspicious)
102 (push (cons name cell) possibly-suspicious))))))
103 (flet ((show (label list)
104 (format t "~%~A suspicious calls:~:{~%~*~4d ~0@*~S~*~@{~% ~S~}~}~%"
105 label (sort list #'> :key #'cadr))))
106 ;; Called inlines not in the presence of a declaration to the contrary
107 ;; indicate that perhaps the function definition appeared too late.
108 (show "Likely" likely-suspicious)
109 ;; Failed transforms are considered not quite as suspicious
110 ;; because it could either be too late, or that the transform failed.
111 (show "Possibly" possibly-suspicious))))
113 ;; After cross-compiling, show me a list of types that checkgen
114 ;; would have liked to use primitive traps for but couldn't.
115 #+nil
116 (let ((l (sb-impl::%hash-table-alist sb!c::*checkgen-used-types*)))
117 (format t "~&Types needed by checkgen: ('+' = has internal error number)~%")
118 (setq l (sort l #'> :key #'cadr))
119 (loop for (type-spec . (count . interr-p)) in l
120 do (format t "~:[ ~;+~] ~5D ~S~%" interr-p count type-spec))
121 (format t "~&Error numbers not used by checkgen:~%")
122 (loop for (spec . symbol) across sb!c::*backend-internal-errors*
123 when (and (not (stringp spec))
124 (not (gethash spec sb!c::*checkgen-used-types*)))
125 do (format t " ~S~%" spec)))
127 ;; Print some information about how well the function caches performed
128 (when sb!impl::*profile-hash-cache*
129 (sb!impl::show-hash-cache-statistics))
131 Sample output
132 -------------
133 Seek Hit (%) Evict (%) Size full
134 23698219 18382256 ( 77.6%) 5313915 ( 22.4%) 2048 100.0% TYPE=-CACHE
135 23528751 23416735 ( 99.5%) 46242 ( 0.2%) 1024 20.1% VALUES-SPECIFIER-TYPE-CACHE
136 16755212 13072420 ( 78.0%) 3681768 ( 22.0%) 1024 100.0% CSUBTYPEP-CACHE
137 9913114 8374965 ( 84.5%) 1537893 ( 15.5%) 256 100.0% MAKE-VALUES-TYPE-CACHED-CACHE
138 7718160 4702069 ( 60.9%) 3675019 ( 47.6%) 512 100.0% TYPE-INTERSECTION2-CACHE
139 5184706 1626512 ( 31.4%) 3557973 ( 68.6%) 256 86.3% %TYPE-INTERSECTION-CACHE
140 5156044 3986450 ( 77.3%) 1169338 ( 22.7%) 256 100.0% VALUES-SUBTYPEP-CACHE
141 4550163 2969409 ( 65.3%) 1580498 ( 34.7%) 256 100.0% VALUES-TYPE-INTERSECTION-CACHE
142 3544211 2607658 ( 73.6%) 936300 ( 26.4%) 256 98.8% %TYPE-UNION-CACHE
143 2545070 2110741 ( 82.9%) 433817 ( 17.0%) 512 100.0% PRIMITIVE-TYPE-AUX-CACHE
144 2164841 1112785 ( 51.4%) 1706097 ( 78.8%) 256 100.0% TYPE-UNION2-CACHE
145 1568022 1467575 ( 93.6%) 100191 ( 6.4%) 256 100.0% TYPE-SINGLETON-P-CACHE
146 779941 703208 ( 90.2%) 76477 ( 9.8%) 256 100.0% %COERCE-TO-VALUES-CACHE
147 618605 448427 ( 72.5%) 169922 ( 27.5%) 256 100.0% VALUES-TYPE-UNION-CACHE
148 145805 29403 ( 20.2%) 116206 ( 79.7%) 256 76.6% %%MAKE-UNION-TYPE-CACHED-CACHE
149 118634 76203 ( 64.2%) 42188 ( 35.6%) 256 94.9% %%MAKE-ARRAY-TYPE-CACHED-CACHE
150 12319 12167 ( 98.8%) 47 ( 0.4%) 128 82.0% WEAKEN-TYPE-CACHE
151 10416 9492 ( 91.1%) 668 ( 6.4%) 256 100.0% TYPE-NEGATION-CACHE
154 ;;; miscellaneous tidying up and saving results
155 (let ((filename "output/object-filenames-for-genesis.lisp-expr"))
156 (ensure-directories-exist filename :verbose t)
157 ;; save the initial-symbol-values before writing the object filenames.
158 (save-initial-symbol-values)
159 (with-open-file (s filename :direction :output :if-exists :supersede)
160 (write *target-object-file-names* :stream s :readably t)))
162 ;;; Let's check that the type system was reasonably sane. (It's easy
163 ;;; to spend a long time wandering around confused trying to debug
164 ;;; cold init if it wasn't.)
165 (when (position :sb-test *shebang-features*)
166 (load "tests/type.after-xc.lisp"))
168 ;;; If you're experimenting with the system under a cross-compilation
169 ;;; host which supports CMU-CL-style SAVE-LISP, this can be a good
170 ;;; time to run it. The resulting core isn't used in the normal build,
171 ;;; but can be handy for experimenting with the system. (See slam.sh
172 ;;; for an example.)
173 (when (position :sb-after-xc-core *shebang-features*)
174 #+cmu (ext:save-lisp "output/after-xc.core" :load-init-file nil)
175 #+sbcl (sb-ext:save-lisp-and-die "output/after-xc.core")
176 #+openmcl (ccl::save-application "output/after-xc.core")
177 #+clisp (ext:saveinitmem "output/after-xc.core"))
178 #+cmu (ext:quit)
179 #+clisp (ext:quit)
180 #+abcl (ext:quit)