d1bd58fa257968a716e06da52b58ca6d2130dc56
[sbcl.git] / src / compiler / ir1tran-lambda.lisp
1 ;;;; This file contains code which does the translation of lambda
2 ;;;; forms from Lisp code to the first intermediate representation
3 ;;;; (IR1).
4
5 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; more information.
7 ;;;;
8 ;;;; This software is derived from the CMU CL system, which was
9 ;;;; written at Carnegie Mellon University and released into the
10 ;;;; public domain. The software is in the public domain and is
11 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
12 ;;;; files for more information.
13
14 (in-package "SB!C")
15
16 ;;;; LAMBDA hackery
17
18 ;;;; Note: Take a look at the compiler-overview.tex section on "Hairy
19 ;;;; function representation" before you seriously mess with this
20 ;;;; stuff.
21
22 ;;; Verify that the NAME is a legal name for a variable and return a
23 ;;; VAR structure for it, filling in info if it is globally special.
24 ;;; If it is losing, we punt with a COMPILER-ERROR. NAMES-SO-FAR is a
25 ;;; list of names which have previously been bound. If the NAME is in
26 ;;; this list, then we error out.
27 (declaim (ftype (sfunction (t list) lambda-var) varify-lambda-arg))
28 (defun varify-lambda-arg (name names-so-far)
29   (declare (inline member))
30   (unless (symbolp name)
31     (compiler-error "The lambda variable ~S is not a symbol." name))
32   (when (member name names-so-far :test #'eq)
33     (compiler-error "The variable ~S occurs more than once in the lambda list."
34                     name))
35   (let ((kind (info :variable :kind name)))
36     (when (or (keywordp name) (eq kind :constant))
37       (compiler-error "The name of the lambda variable ~S is already in use to name a constant."
38                       name))
39     (cond ((eq kind :special)
40            (let ((specvar (find-free-var name)))
41              (make-lambda-var :%source-name name
42                               :type (leaf-type specvar)
43                               :where-from (leaf-where-from specvar)
44                               :specvar specvar)))
45           (t
46            (make-lambda-var :%source-name name)))))
47
48 ;;; Make the default keyword for a &KEY arg, checking that the keyword
49 ;;; isn't already used by one of the VARS.
50 (declaim (ftype (sfunction (symbol list t) symbol) make-keyword-for-arg))
51 (defun make-keyword-for-arg (symbol vars keywordify)
52   (let ((key (if (and keywordify (not (keywordp symbol)))
53                  (keywordicate symbol)
54                  symbol)))
55     (dolist (var vars)
56       (let ((info (lambda-var-arg-info var)))
57         (when (and info
58                    (eq (arg-info-kind info) :keyword)
59                    (eq (arg-info-key info) key))
60           (compiler-error
61            "The keyword ~S appears more than once in the lambda list."
62            key))))
63     key))
64
65 ;;; Parse a lambda list into a list of VAR structures, stripping off
66 ;;; any &AUX bindings. Each arg name is checked for legality, and
67 ;;; duplicate names are checked for. If an arg is globally special,
68 ;;; the var is marked as :SPECIAL instead of :LEXICAL. &KEY,
69 ;;; &OPTIONAL and &REST args are annotated with an ARG-INFO structure
70 ;;; which contains the extra information. If we hit something losing,
71 ;;; we bug out with COMPILER-ERROR. These values are returned:
72 ;;;  1. a list of the var structures for each top level argument;
73 ;;;  2. a flag indicating whether &KEY was specified;
74 ;;;  3. a flag indicating whether other &KEY args are allowed;
75 ;;;  4. a list of the &AUX variables; and
76 ;;;  5. a list of the &AUX values.
77 (declaim (ftype (sfunction (list) (values list boolean boolean list list))
78                 make-lambda-vars))
79 (defun make-lambda-vars (list)
80   (multiple-value-bind (required optional restp rest keyp keys allowp auxp aux
81                         morep more-context more-count)
82       (parse-lambda-list list)
83     (declare (ignore auxp)) ; since we just iterate over AUX regardless
84     (collect ((vars)
85               (names-so-far)
86               (aux-vars)
87               (aux-vals))
88       (flet (;; PARSE-DEFAULT deals with defaults and supplied-p args
89              ;; for optionals and keywords args.
90              (parse-default (spec info)
91                (when (consp (cdr spec))
92                  (setf (arg-info-default info) (second spec))
93                  (when (consp (cddr spec))
94                    (let* ((supplied-p (third spec))
95                           (supplied-var (varify-lambda-arg supplied-p
96                                                            (names-so-far))))
97                      (setf (arg-info-supplied-p info) supplied-var)
98                      (names-so-far supplied-p)
99                      (when (> (length (the list spec)) 3)
100                        (compiler-error
101                         "The list ~S is too long to be an arg specifier."
102                         spec)))))))
103
104         (dolist (name required)
105           (let ((var (varify-lambda-arg name (names-so-far))))
106             (vars var)
107             (names-so-far name)))
108
109         (dolist (spec optional)
110           (if (atom spec)
111               (let ((var (varify-lambda-arg spec (names-so-far))))
112                 (setf (lambda-var-arg-info var)
113                       (make-arg-info :kind :optional))
114                 (vars var)
115                 (names-so-far spec))
116               (let* ((name (first spec))
117                      (var (varify-lambda-arg name (names-so-far)))
118                      (info (make-arg-info :kind :optional)))
119                 (setf (lambda-var-arg-info var) info)
120                 (vars var)
121                 (names-so-far name)
122                 (parse-default spec info))))
123
124         (when restp
125           (let ((var (varify-lambda-arg rest (names-so-far))))
126             (setf (lambda-var-arg-info var) (make-arg-info :kind :rest))
127             (vars var)
128             (names-so-far rest)))
129
130         (when morep
131           (let ((var (varify-lambda-arg more-context (names-so-far))))
132             (setf (lambda-var-arg-info var)
133                   (make-arg-info :kind :more-context))
134             (vars var)
135             (names-so-far more-context))
136           (let ((var (varify-lambda-arg more-count (names-so-far))))
137             (setf (lambda-var-arg-info var)
138                   (make-arg-info :kind :more-count))
139             (vars var)
140             (names-so-far more-count)))
141
142         (dolist (spec keys)
143           (cond
144            ((atom spec)
145             (let ((var (varify-lambda-arg spec (names-so-far))))
146               (setf (lambda-var-arg-info var)
147                     (make-arg-info :kind :keyword
148                                    :key (make-keyword-for-arg spec
149                                                               (vars)
150                                                               t)))
151               (vars var)
152               (names-so-far spec)))
153            ((atom (first spec))
154             (let* ((name (first spec))
155                    (var (varify-lambda-arg name (names-so-far)))
156                    (info (make-arg-info
157                           :kind :keyword
158                           :key (make-keyword-for-arg name (vars) t))))
159               (setf (lambda-var-arg-info var) info)
160               (vars var)
161               (names-so-far name)
162               (parse-default spec info)))
163            (t
164             (let ((head (first spec)))
165               (unless (proper-list-of-length-p head 2)
166                 (error "malformed &KEY argument specifier: ~S" spec))
167               (let* ((name (second head))
168                      (var (varify-lambda-arg name (names-so-far)))
169                      (info (make-arg-info
170                             :kind :keyword
171                             :key (make-keyword-for-arg (first head)
172                                                        (vars)
173                                                        nil))))
174                 (setf (lambda-var-arg-info var) info)
175                 (vars var)
176                 (names-so-far name)
177                 (parse-default spec info))))))
178
179         (dolist (spec aux)
180           (cond ((atom spec)
181                  (let ((var (varify-lambda-arg spec nil)))
182                    (aux-vars var)
183                    (aux-vals nil)
184                    (names-so-far spec)))
185                 (t
186                  (unless (proper-list-of-length-p spec 1 2)
187                    (compiler-error "malformed &AUX binding specifier: ~S"
188                                    spec))
189                  (let* ((name (first spec))
190                         (var (varify-lambda-arg name nil)))
191                    (aux-vars var)
192                    (aux-vals (second spec))
193                    (names-so-far name)))))
194
195         (values (vars) keyp allowp (aux-vars) (aux-vals))))))
196
197 ;;; This is similar to IR1-CONVERT-PROGN-BODY except that we
198 ;;; sequentially bind each AUX-VAR to the corresponding AUX-VAL before
199 ;;; converting the body. If there are no bindings, just convert the
200 ;;; body, otherwise do one binding and recurse on the rest.
201 ;;;
202 ;;; FIXME: This could and probably should be converted to use
203 ;;; SOURCE-NAME and DEBUG-NAME. But I (WHN) don't use &AUX bindings,
204 ;;; so I'm not motivated. Patches will be accepted...
205 (defun ir1-convert-aux-bindings (start next result body aux-vars aux-vals)
206   (declare (type ctran start next) (type (or lvar null) result)
207            (list body aux-vars aux-vals))
208   (if (null aux-vars)
209       (ir1-convert-progn-body start next result body)
210       (let ((ctran (make-ctran))
211             (fun-lvar (make-lvar))
212             (fun (ir1-convert-lambda-body body
213                                           (list (first aux-vars))
214                                           :aux-vars (rest aux-vars)
215                                           :aux-vals (rest aux-vals)
216                                           :debug-name (debug-namify
217                                                        "&AUX bindings " 
218                                                        aux-vars))))
219         (reference-leaf start ctran fun-lvar fun)
220         (ir1-convert-combination-args fun-lvar ctran next result
221                                       (list (first aux-vals)))))
222   (values))
223
224 ;;; This is similar to IR1-CONVERT-PROGN-BODY except that code to bind
225 ;;; the SPECVAR for each SVAR to the value of the variable is wrapped
226 ;;; around the body. If there are no special bindings, we just convert
227 ;;; the body, otherwise we do one special binding and recurse on the
228 ;;; rest.
229 ;;;
230 ;;; We make a cleanup and introduce it into the lexical
231 ;;; environment. If there are multiple special bindings, the cleanup
232 ;;; for the blocks will end up being the innermost one. We force NEXT
233 ;;; to start a block outside of this cleanup, causing cleanup code to
234 ;;; be emitted when the scope is exited.
235 (defun ir1-convert-special-bindings
236     (start next result body aux-vars aux-vals svars)
237   (declare (type ctran start next) (type (or lvar null) result)
238            (list body aux-vars aux-vals svars))
239   (cond
240    ((null svars)
241     (ir1-convert-aux-bindings start next result body aux-vars aux-vals))
242    (t
243     (ctran-starts-block next)
244     (let ((cleanup (make-cleanup :kind :special-bind))
245           (var (first svars))
246           (bind-ctran (make-ctran))
247           (cleanup-ctran (make-ctran)))
248       (ir1-convert start bind-ctran nil
249                    `(%special-bind ',(lambda-var-specvar var) ,var))
250       (setf (cleanup-mess-up cleanup) (ctran-use bind-ctran))
251       (let ((*lexenv* (make-lexenv :cleanup cleanup)))
252         (ir1-convert bind-ctran cleanup-ctran nil '(%cleanup-point))
253         (ir1-convert-special-bindings cleanup-ctran next result
254                                       body aux-vars aux-vals
255                                       (rest svars))))))
256   (values))
257
258 ;;; FIXME: this is the interface of the CMUCL WITH-DYNAMIC-EXTENT
259 ;;; macro.  It is slightly confusing, in that START and BODY-START are
260 ;;; already-existing CTRANs (and FIXME: probably deserve a ONCE-ONLY),
261 ;;; whereas NEXT is a variable naming a CTRAN in the body.  -- CSR,
262 ;;; 2004-03-30.
263 (defmacro with-dynamic-extent ((start body-start next kind) &body body)
264   (declare (ignore kind))
265   (with-unique-names (cleanup next-ctran)
266     `(progn
267       (ctran-starts-block ,body-start)
268       (let ((,cleanup (make-cleanup :kind :dynamic-extent))
269             (,next-ctran (make-ctran))
270             (,next (make-ctran)))
271         (ir1-convert ,start ,next-ctran nil '(%dynamic-extent-start))
272         (setf (cleanup-mess-up ,cleanup) (ctran-use ,next-ctran))
273         (let ((*lexenv* (make-lexenv :cleanup ,cleanup)))
274           (ir1-convert ,next-ctran ,next nil '(%cleanup-point))
275           (locally ,@body))))))
276
277 ;;; Create a lambda node out of some code, returning the result. The
278 ;;; bindings are specified by the list of VAR structures VARS. We deal
279 ;;; with adding the names to the LEXENV-VARS for the conversion. The
280 ;;; result is added to the NEW-FUNCTIONALS in the *CURRENT-COMPONENT*
281 ;;; and linked to the component head and tail.
282 ;;;
283 ;;; We detect special bindings here, replacing the original VAR in the
284 ;;; lambda list with a temporary variable. We then pass a list of the
285 ;;; special vars to IR1-CONVERT-SPECIAL-BINDINGS, which actually emits
286 ;;; the special binding code.
287 ;;;
288 ;;; We ignore any ARG-INFO in the VARS, trusting that someone else is
289 ;;; dealing with &NONSENSE, except for &REST vars with DYNAMIC-EXTENT.
290 ;;;
291 ;;; AUX-VARS is a list of VAR structures for variables that are to be
292 ;;; sequentially bound. Each AUX-VAL is a form that is to be evaluated
293 ;;; to get the initial value for the corresponding AUX-VAR.
294 (defun ir1-convert-lambda-body (body
295                                 vars
296                                 &key
297                                 aux-vars
298                                 aux-vals
299                                 (source-name '.anonymous.)
300                                 debug-name
301                                 (note-lexical-bindings t))
302   (declare (list body vars aux-vars aux-vals))
303
304   ;; We're about to try to put new blocks into *CURRENT-COMPONENT*.
305   (aver-live-component *current-component*)
306
307   (let* ((bind (make-bind))
308          (lambda (make-lambda :vars vars
309                   :bind bind
310                   :%source-name source-name
311                   :%debug-name debug-name))
312          (result-ctran (make-ctran))
313          (result-lvar (make-lvar))
314          (dx-rest nil))
315
316     (awhen (lexenv-lambda *lexenv*)
317       (push lambda (lambda-children it))
318       (setf (lambda-parent lambda) it))
319
320     ;; just to check: This function should fail internal assertions if
321     ;; we didn't set up a valid debug name above.
322     ;;
323     ;; (In SBCL we try to make everything have a debug name, since we
324     ;; lack the omniscient perspective the original implementors used
325     ;; to decide which things didn't need one.)
326     (functional-debug-name lambda)
327
328     (setf (lambda-home lambda) lambda)
329     (collect ((svars)
330               (new-venv nil cons))
331
332       (dolist (var vars)
333         ;; As far as I can see, LAMBDA-VAR-HOME should never have
334         ;; been set before. Let's make sure. -- WHN 2001-09-29
335         (aver (not (lambda-var-home var)))
336         (setf (lambda-var-home var) lambda)
337         (let ((specvar (lambda-var-specvar var)))
338           (cond (specvar
339                  (svars var)
340                  (new-venv (cons (leaf-source-name specvar) specvar)))
341                 (t
342                  (when note-lexical-bindings
343                    (note-lexical-binding (leaf-source-name var)))
344                  (new-venv (cons (leaf-source-name var) var)))))
345         (let ((info (lambda-var-arg-info var)))
346           (when (and info
347                      (eq (arg-info-kind info) :rest)
348                      (leaf-dynamic-extent var))
349             (setq dx-rest t))))
350
351       (let ((*lexenv* (make-lexenv :vars (new-venv)
352                                    :lambda lambda
353                                    :cleanup nil)))
354         (setf (bind-lambda bind) lambda)
355         (setf (node-lexenv bind) *lexenv*)
356
357         (let ((block (ctran-starts-block result-ctran)))
358           (let ((return (make-return :result result-lvar :lambda lambda))
359                 (tail-set (make-tail-set :funs (list lambda))))
360             (setf (lambda-tail-set lambda) tail-set)
361             (setf (lambda-return lambda) return)
362             (setf (lvar-dest result-lvar) return)
363             (link-node-to-previous-ctran return result-ctran)
364             (setf (block-last block) return))
365           (link-blocks block (component-tail *current-component*)))
366
367         (with-component-last-block (*current-component*
368                                     (ctran-block result-ctran))
369           (let ((prebind-ctran (make-ctran))
370                 (postbind-ctran (make-ctran)))
371             (ctran-starts-block prebind-ctran)
372             (link-node-to-previous-ctran bind prebind-ctran)
373             (use-ctran bind postbind-ctran)
374             (if dx-rest
375                 (with-dynamic-extent (postbind-ctran result-ctran dx :rest)
376                   (ir1-convert-special-bindings dx result-ctran result-lvar
377                                                 body aux-vars aux-vals
378                                                 (svars)))
379                 (ir1-convert-special-bindings postbind-ctran result-ctran
380                                               result-lvar body
381                                               aux-vars aux-vals (svars)))))))
382
383     (link-blocks (component-head *current-component*) (node-block bind))
384     (push lambda (component-new-functionals *current-component*))
385
386     lambda))
387
388 ;;; Entry point CLAMBDAs have a special kind
389 (defun register-entry-point (entry dispatcher)
390   (declare (type clambda entry)
391            (type optional-dispatch dispatcher))
392   (setf (functional-kind entry) :optional)
393   (setf (leaf-ever-used entry) t)
394   (setf (lambda-optional-dispatch entry) dispatcher)
395   entry)
396
397 ;;; Create the actual entry-point function for an optional entry
398 ;;; point. The lambda binds copies of each of the VARS, then calls FUN
399 ;;; with the argument VALS and the DEFAULTS. Presumably the VALS refer
400 ;;; to the VARS by name. The VALS are passed in the reverse order.
401 ;;;
402 ;;; If any of the copies of the vars are referenced more than once,
403 ;;; then we mark the corresponding var as EVER-USED to inhibit
404 ;;; "defined but not read" warnings for arguments that are only used
405 ;;; by default forms.
406 (defun convert-optional-entry (fun vars vals defaults)
407   (declare (type clambda fun) (list vars vals defaults))
408   (let* ((fvars (reverse vars))
409          (arg-vars (mapcar (lambda (var)
410                              (make-lambda-var
411                               :%source-name (leaf-source-name var)
412                               :type (leaf-type var)
413                               :where-from (leaf-where-from var)
414                               :specvar (lambda-var-specvar var)))
415                            fvars))
416          (fun (collect ((default-bindings)
417                         (default-vals))
418                 (dolist (default defaults)
419                   (if (constantp default)
420                       (default-vals default)
421                       (let ((var (gensym)))
422                         (default-bindings `(,var ,default))
423                         (default-vals var))))
424                 (ir1-convert-lambda-body `((let (,@(default-bindings))
425                                              (%funcall ,fun
426                                                        ,@(reverse vals)
427                                                        ,@(default-vals))))
428                                          arg-vars
429                                          :debug-name
430                                          (debug-namify "&OPTIONAL processor "
431                                                        (gensym))
432                                          :note-lexical-bindings nil))))
433     (mapc (lambda (var arg-var)
434             (when (cdr (leaf-refs arg-var))
435               (setf (leaf-ever-used var) t)))
436           fvars arg-vars)
437     fun))
438
439 ;;; This function deals with supplied-p vars in optional arguments. If
440 ;;; the there is no supplied-p arg, then we just call
441 ;;; IR1-CONVERT-HAIRY-ARGS on the remaining arguments, and generate a
442 ;;; optional entry that calls the result. If there is a supplied-p
443 ;;; var, then we add it into the default vars and throw a T into the
444 ;;; entry values. The resulting entry point function is returned.
445 (defun generate-optional-default-entry (res default-vars default-vals
446                                         entry-vars entry-vals
447                                         vars supplied-p-p body
448                                         aux-vars aux-vals
449                                         source-name debug-name
450                                         force)
451   (declare (type optional-dispatch res)
452            (list default-vars default-vals entry-vars entry-vals vars body
453                  aux-vars aux-vals))
454   (let* ((arg (first vars))
455          (arg-name (leaf-source-name arg))
456          (info (lambda-var-arg-info arg))
457          (default (arg-info-default info))
458          (supplied-p (arg-info-supplied-p info))
459          (force (or force
460                     (not (sb!xc:constantp (arg-info-default info)))))
461          (ep (if supplied-p
462                  (ir1-convert-hairy-args
463                   res
464                   (list* supplied-p arg default-vars)
465                   (list* (leaf-source-name supplied-p) arg-name default-vals)
466                   (cons arg entry-vars)
467                   (list* t arg-name entry-vals)
468                   (rest vars) t body aux-vars aux-vals
469                   source-name debug-name
470                   force)
471                  (ir1-convert-hairy-args
472                   res
473                   (cons arg default-vars)
474                   (cons arg-name default-vals)
475                   (cons arg entry-vars)
476                   (cons arg-name entry-vals)
477                   (rest vars) supplied-p-p body aux-vars aux-vals
478                   source-name debug-name
479                   force))))
480
481     ;; We want to delay converting the entry, but there exist
482     ;; problems: hidden references should not be established to
483     ;; lambdas of kind NIL should not have (otherwise the compiler
484     ;; might let-convert or delete them) and to variables.
485     (if (or force
486             supplied-p-p ; this entry will be of kind NIL
487             (and (lambda-p ep) (eq (lambda-kind ep) nil)))
488         (convert-optional-entry ep
489                                 default-vars default-vals
490                                 (if supplied-p
491                                     (list default nil)
492                                     (list default)))
493         (delay
494          (register-entry-point
495            (convert-optional-entry (force ep)
496                                    default-vars default-vals
497                                    (if supplied-p
498                                        (list default nil)
499                                        (list default)))
500            res)))))
501
502 ;;; Create the MORE-ENTRY function for the OPTIONAL-DISPATCH RES.
503 ;;; ENTRY-VARS and ENTRY-VALS describe the fixed arguments. REST is
504 ;;; the var for any &REST arg. KEYS is a list of the &KEY arg vars.
505 ;;;
506 ;;; The most interesting thing that we do is parse keywords. We create
507 ;;; a bunch of temporary variables to hold the result of the parse,
508 ;;; and then loop over the supplied arguments, setting the appropriate
509 ;;; temps for the supplied keyword. Note that it is significant that
510 ;;; we iterate over the keywords in reverse order --- this implements
511 ;;; the CL requirement that (when a keyword appears more than once)
512 ;;; the first value is used.
513 ;;;
514 ;;; If there is no supplied-p var, then we initialize the temp to the
515 ;;; default and just pass the temp into the main entry. Since
516 ;;; non-constant &KEY args are forcibly given a supplied-p var, we
517 ;;; know that the default is constant, and thus safe to evaluate out
518 ;;; of order.
519 ;;;
520 ;;; If there is a supplied-p var, then we create temps for both the
521 ;;; value and the supplied-p, and pass them into the main entry,
522 ;;; letting it worry about defaulting.
523 ;;;
524 ;;; We deal with :ALLOW-OTHER-KEYS by delaying unknown keyword errors
525 ;;; until we have scanned all the keywords.
526 (defun convert-more-entry (res entry-vars entry-vals rest morep keys)
527   (declare (type optional-dispatch res) (list entry-vars entry-vals keys))
528   (collect ((arg-vars)
529             (arg-vals (reverse entry-vals))
530             (temps)
531             (body))
532
533     (dolist (var (reverse entry-vars))
534       (arg-vars (make-lambda-var :%source-name (leaf-source-name var)
535                                  :type (leaf-type var)
536                                  :where-from (leaf-where-from var))))
537
538     (let* ((n-context (gensym "N-CONTEXT-"))
539            (context-temp (make-lambda-var :%source-name n-context))
540            (n-count (gensym "N-COUNT-"))
541            (count-temp (make-lambda-var :%source-name n-count
542                                         :type (specifier-type 'index))))
543
544       (arg-vars context-temp count-temp)
545
546       (when rest
547         (arg-vals `(%listify-rest-args
548                     ,n-context ,n-count ,(leaf-dynamic-extent rest))))
549       (when morep
550         (arg-vals n-context)
551         (arg-vals n-count))
552
553       (when (optional-dispatch-keyp res)
554         (let ((n-index (gensym "N-INDEX-"))
555               (n-key (gensym "N-KEY-"))
556               (n-value-temp (gensym "N-VALUE-TEMP-"))
557               (n-allowp (gensym "N-ALLOWP-"))
558               (n-losep (gensym "N-LOSEP-"))
559               (allowp (or (optional-dispatch-allowp res)
560                           (policy *lexenv* (zerop safety))))
561               (found-allow-p nil))
562
563           (temps `(,n-index (1- ,n-count)) n-key n-value-temp)
564           (body `(declare (fixnum ,n-index) (ignorable ,n-key ,n-value-temp)))
565
566           (collect ((tests))
567             (dolist (key keys)
568               (let* ((info (lambda-var-arg-info key))
569                      (default (arg-info-default info))
570                      (keyword (arg-info-key info))
571                      (supplied-p (arg-info-supplied-p info))
572                      (n-value (gensym "N-VALUE-"))
573                      (clause (cond (supplied-p
574                                     (let ((n-supplied (gensym "N-SUPPLIED-")))
575                                       (temps n-supplied)
576                                       (arg-vals n-value n-supplied)
577                                       `((eq ,n-key ',keyword)
578                                         (setq ,n-supplied t)
579                                         (setq ,n-value ,n-value-temp))))
580                                    (t
581                                     (arg-vals n-value)
582                                     `((eq ,n-key ',keyword)
583                                       (setq ,n-value ,n-value-temp))))))
584                 (when (and (not allowp) (eq keyword :allow-other-keys))
585                   (setq found-allow-p t)
586                   (setq clause
587                         (append clause `((setq ,n-allowp ,n-value-temp)))))
588
589                 (temps `(,n-value ,default))
590                 (tests clause)))
591
592             (unless allowp
593               (temps n-allowp n-losep)
594               (unless found-allow-p
595                 (tests `((eq ,n-key :allow-other-keys)
596                          (setq ,n-allowp ,n-value-temp))))
597               (tests `(t
598                        (setq ,n-losep (list ,n-key)))))
599
600             (body
601              `(when (oddp ,n-count)
602                 (%odd-key-args-error)))
603
604             (body
605              `(locally
606                 (declare (optimize (safety 0)))
607                 (loop
608                   (when (minusp ,n-index) (return))
609                   (setf ,n-value-temp (%more-arg ,n-context ,n-index))
610                   (decf ,n-index)
611                   (setq ,n-key (%more-arg ,n-context ,n-index))
612                   (decf ,n-index)
613                   (cond ,@(tests)))))
614
615             (unless allowp
616               (body `(when (and ,n-losep (not ,n-allowp))
617                        (%unknown-key-arg-error (car ,n-losep))))))))
618
619       (let ((ep (ir1-convert-lambda-body
620                  `((let ,(temps)
621                      ,@(body)
622                      (%funcall ,(optional-dispatch-main-entry res)
623                                ,@(arg-vals))))
624                  (arg-vars)
625                  :debug-name "&MORE processing"
626                  :note-lexical-bindings nil)))
627         (setf (optional-dispatch-more-entry res)
628               (register-entry-point ep res)))))
629
630   (values))
631
632 ;;; This is called by IR1-CONVERT-HAIRY-ARGS when we run into a &REST
633 ;;; or &KEY arg. The arguments are similar to that function, but we
634 ;;; split off any &REST arg and pass it in separately. REST is the
635 ;;; &REST arg var, or NIL if there is no &REST arg. KEYS is a list of
636 ;;; the &KEY argument vars.
637 ;;;
638 ;;; When there are &KEY arguments, we introduce temporary gensym
639 ;;; variables to hold the values while keyword defaulting is in
640 ;;; progress to get the required sequential binding semantics.
641 ;;;
642 ;;; This gets interesting mainly when there are &KEY arguments with
643 ;;; supplied-p vars or non-constant defaults. In either case, pass in
644 ;;; a supplied-p var. If the default is non-constant, we introduce an
645 ;;; IF in the main entry that tests the supplied-p var and decides
646 ;;; whether to evaluate the default or not. In this case, the real
647 ;;; incoming value is NIL, so we must union NULL with the declared
648 ;;; type when computing the type for the main entry's argument.
649 (defun ir1-convert-more (res default-vars default-vals entry-vars entry-vals
650                              rest more-context more-count keys supplied-p-p
651                              body aux-vars aux-vals
652                              source-name debug-name)
653   (declare (type optional-dispatch res)
654            (list default-vars default-vals entry-vars entry-vals keys body
655                  aux-vars aux-vals))
656   (collect ((main-vars (reverse default-vars))
657             (main-vals default-vals cons)
658             (bind-vars)
659             (bind-vals))
660     (when rest
661       (main-vars rest)
662       (main-vals '()))
663     (when more-context
664       (main-vars more-context)
665       (main-vals nil)
666       (main-vars more-count)
667       (main-vals 0))
668
669     (dolist (key keys)
670       (let* ((info (lambda-var-arg-info key))
671              (default (arg-info-default info))
672              (hairy-default (not (sb!xc:constantp default)))
673              (supplied-p (arg-info-supplied-p info))
674              (n-val (make-symbol (format nil
675                                          "~A-DEFAULTING-TEMP"
676                                          (leaf-source-name key))))
677              (key-type (leaf-type key))
678              (val-temp (make-lambda-var
679                         :%source-name n-val
680                         :type (if hairy-default
681                                   (type-union key-type (specifier-type 'null))
682                                   key-type))))
683         (main-vars val-temp)
684         (bind-vars key)
685         (cond ((or hairy-default supplied-p)
686                (let* ((n-supplied (gensym "N-SUPPLIED-"))
687                       (supplied-temp (make-lambda-var
688                                       :%source-name n-supplied)))
689                  (unless supplied-p
690                    (setf (arg-info-supplied-p info) supplied-temp))
691                  (when hairy-default
692                    (setf (arg-info-default info) nil))
693                  (main-vars supplied-temp)
694                  (cond (hairy-default
695                         (main-vals nil nil)
696                         (bind-vals `(if ,n-supplied ,n-val ,default)))
697                        (t
698                         (main-vals default nil)
699                         (bind-vals n-val)))
700                  (when supplied-p
701                    (bind-vars supplied-p)
702                    (bind-vals n-supplied))))
703               (t
704                (main-vals (arg-info-default info))
705                (bind-vals n-val)))))
706
707     (let* ((main-entry (ir1-convert-lambda-body
708                         body (main-vars)
709                         :aux-vars (append (bind-vars) aux-vars)
710                         :aux-vals (append (bind-vals) aux-vals)
711                         :debug-name (debug-namify
712                                      "varargs entry for " source-name debug-name)))
713            (last-entry (convert-optional-entry main-entry default-vars
714                                                (main-vals) ())))
715       (setf (optional-dispatch-main-entry res)
716             (register-entry-point main-entry res))
717       (convert-more-entry res entry-vars entry-vals rest more-context keys)
718
719       (push (register-entry-point
720              (if supplied-p-p
721                 (convert-optional-entry last-entry entry-vars entry-vals ())
722                 last-entry)
723              res)
724             (optional-dispatch-entry-points res))
725       last-entry)))
726
727 ;;; This function generates the entry point functions for the
728 ;;; OPTIONAL-DISPATCH RES. We accomplish this by recursion on the list
729 ;;; of arguments, analyzing the arglist on the way down and generating
730 ;;; entry points on the way up.
731 ;;;
732 ;;; DEFAULT-VARS is a reversed list of all the argument vars processed
733 ;;; so far, including supplied-p vars. DEFAULT-VALS is a list of the
734 ;;; names of the DEFAULT-VARS.
735 ;;;
736 ;;; ENTRY-VARS is a reversed list of processed argument vars,
737 ;;; excluding supplied-p vars. ENTRY-VALS is a list things that can be
738 ;;; evaluated to get the values for all the vars from the ENTRY-VARS.
739 ;;; It has the var name for each required or optional arg, and has T
740 ;;; for each supplied-p arg.
741 ;;;
742 ;;; VARS is a list of the LAMBDA-VAR structures for arguments that
743 ;;; haven't been processed yet. SUPPLIED-P-P is true if a supplied-p
744 ;;; argument has already been processed; only in this case are the
745 ;;; DEFAULT-XXX and ENTRY-XXX different.
746 ;;;
747 ;;; The result at each point is a lambda which should be called by the
748 ;;; above level to default the remaining arguments and evaluate the
749 ;;; body. We cause the body to be evaluated by converting it and
750 ;;; returning it as the result when the recursion bottoms out.
751 ;;;
752 ;;; Each level in the recursion also adds its entry point function to
753 ;;; the result OPTIONAL-DISPATCH. For most arguments, the defaulting
754 ;;; function and the entry point function will be the same, but when
755 ;;; SUPPLIED-P args are present they may be different.
756 ;;;
757 ;;; When we run into a &REST or &KEY arg, we punt out to
758 ;;; IR1-CONVERT-MORE, which finishes for us in this case.
759 (defun ir1-convert-hairy-args (res default-vars default-vals
760                                entry-vars entry-vals
761                                vars supplied-p-p body aux-vars
762                                aux-vals
763                                source-name debug-name
764                                force)
765   (declare (type optional-dispatch res)
766            (list default-vars default-vals entry-vars entry-vals vars body
767                  aux-vars aux-vals))
768   (cond ((not vars)
769          (if (optional-dispatch-keyp res)
770              ;; Handle &KEY with no keys...
771              (ir1-convert-more res default-vars default-vals
772                                entry-vars entry-vals
773                                nil nil nil vars supplied-p-p body aux-vars
774                                aux-vals source-name debug-name)
775              (let ((fun (ir1-convert-lambda-body
776                          body (reverse default-vars)
777                          :aux-vars aux-vars
778                          :aux-vals aux-vals
779                          :debug-name (debug-namify
780                                       "hairy arg processor for "
781                                       source-name
782                                       debug-name))))
783                (setf (optional-dispatch-main-entry res) fun)
784                (register-entry-point fun res)
785                (push (if supplied-p-p
786                          (register-entry-point
787                           (convert-optional-entry fun entry-vars entry-vals ())
788                           res)
789                           fun)
790                      (optional-dispatch-entry-points res))
791                fun)))
792         ((not (lambda-var-arg-info (first vars)))
793          (let* ((arg (first vars))
794                 (nvars (cons arg default-vars))
795                 (nvals (cons (leaf-source-name arg) default-vals)))
796            (ir1-convert-hairy-args res nvars nvals nvars nvals
797                                    (rest vars) nil body aux-vars aux-vals
798                                    source-name debug-name
799                                    nil)))
800         (t
801          (let* ((arg (first vars))
802                 (info (lambda-var-arg-info arg))
803                 (kind (arg-info-kind info)))
804            (ecase kind
805              (:optional
806               (let ((ep (generate-optional-default-entry
807                          res default-vars default-vals
808                          entry-vars entry-vals vars supplied-p-p body
809                          aux-vars aux-vals
810                          source-name debug-name
811                          force)))
812                 ;; See GENERATE-OPTIONAL-DEFAULT-ENTRY.
813                 (push (if (lambda-p ep)
814                           (register-entry-point
815                            (if supplied-p-p
816                                (convert-optional-entry ep entry-vars entry-vals ())
817                                ep)
818                            res)
819                           (progn (aver (not supplied-p-p))
820                                  ep))
821                       (optional-dispatch-entry-points res))
822                 ep))
823              (:rest
824               (ir1-convert-more res default-vars default-vals
825                                 entry-vars entry-vals
826                                 arg nil nil (rest vars) supplied-p-p body
827                                 aux-vars aux-vals
828                                 source-name debug-name))
829              (:more-context
830               (ir1-convert-more res default-vars default-vals
831                                 entry-vars entry-vals
832                                 nil arg (second vars) (cddr vars) supplied-p-p
833                                 body aux-vars aux-vals
834                                 source-name debug-name))
835              (:keyword
836               (ir1-convert-more res default-vars default-vals
837                                 entry-vars entry-vals
838                                 nil nil nil vars supplied-p-p body aux-vars
839                                 aux-vals source-name debug-name)))))))
840
841 ;;; This function deals with the case where we have to make an
842 ;;; OPTIONAL-DISPATCH to represent a LAMBDA. We cons up the result and
843 ;;; call IR1-CONVERT-HAIRY-ARGS to do the work. When it is done, we
844 ;;; figure out the MIN-ARGS and MAX-ARGS.
845 (defun ir1-convert-hairy-lambda (body vars keyp allowp aux-vars aux-vals
846                                       &key
847                                       (source-name '.anonymous.)
848                                       (debug-name (debug-namify
849                                                    "OPTIONAL-DISPATCH "
850                                                    vars)))
851   (declare (list body vars aux-vars aux-vals))
852   (let ((res (make-optional-dispatch :arglist vars
853                                      :allowp allowp
854                                      :keyp keyp
855                                      :%source-name source-name
856                                      :%debug-name debug-name
857                                      :plist `(:ir1-environment
858                                               (,*lexenv*
859                                                ,*current-path*))))
860         (min (or (position-if #'lambda-var-arg-info vars) (length vars))))
861     (aver-live-component *current-component*)
862     (push res (component-new-functionals *current-component*))
863     (ir1-convert-hairy-args res () () () () vars nil body aux-vars aux-vals
864                             source-name debug-name nil)
865     (setf (optional-dispatch-min-args res) min)
866     (setf (optional-dispatch-max-args res)
867           (+ (1- (length (optional-dispatch-entry-points res))) min))
868
869     res))
870
871 ;;; Convert a LAMBDA form into a LAMBDA leaf or an OPTIONAL-DISPATCH leaf.
872 (defun ir1-convert-lambda (form &key (source-name '.anonymous.)
873                            debug-name
874                            allow-debug-catch-tag)
875
876   (unless (consp form)
877     (compiler-error "A ~S was found when expecting a lambda expression:~%  ~S"
878                     (type-of form)
879                     form))
880   (unless (eq (car form) 'lambda)
881     (compiler-error "~S was expected but ~S was found:~%  ~S"
882                     'lambda
883                     (car form)
884                     form))
885   (unless (and (consp (cdr form)) (listp (cadr form)))
886     (compiler-error
887      "The lambda expression has a missing or non-list lambda list:~%  ~S"
888      form))
889
890   (let ((*allow-debug-catch-tag* (and *allow-debug-catch-tag* allow-debug-catch-tag)))
891     (multiple-value-bind (vars keyp allow-other-keys aux-vars aux-vals)
892         (make-lambda-vars (cadr form))
893       (multiple-value-bind (forms decls) (parse-body (cddr form))
894         (binding* (((*lexenv* result-type)
895                     (process-decls decls (append aux-vars vars) nil))
896                    (forms (if (and *allow-debug-catch-tag*
897                                    (policy *lexenv* (>= insert-debug-catch 2)))
898                               `((catch (make-symbol "SB-DEBUG-CATCH-TAG")
899                                   ,@forms))
900                               forms))
901                    (forms (if (eq result-type *wild-type*)
902                               forms
903                               `((the ,result-type (progn ,@forms)))))
904                    (res (if (or (find-if #'lambda-var-arg-info vars) keyp)
905                             (ir1-convert-hairy-lambda forms vars keyp
906                                                       allow-other-keys
907                                                       aux-vars aux-vals
908                                                       :source-name source-name
909                                                       :debug-name debug-name)
910                             (ir1-convert-lambda-body forms vars
911                                                      :aux-vars aux-vars
912                                                      :aux-vals aux-vals
913                                                      :source-name source-name
914                                                      :debug-name debug-name))))
915           (setf (functional-inline-expansion res) form)
916           (setf (functional-arg-documentation res) (cadr form))
917           res)))))
918
919 ;;; helper for LAMBDA-like things, to massage them into a form
920 ;;; suitable for IR1-CONVERT-LAMBDA.
921 ;;;
922 ;;; KLUDGE: We cons up a &REST list here, maybe for no particularly
923 ;;; good reason.  It's probably lost in the noise of all the other
924 ;;; consing, but it's still inelegant.  And we force our called
925 ;;; functions to do full runtime keyword parsing, ugh.  -- CSR,
926 ;;; 2003-01-25
927 (defun ir1-convert-lambdalike (thing &rest args
928                                &key (source-name '.anonymous.)
929                                debug-name allow-debug-catch-tag)
930   (declare (ignorable source-name debug-name allow-debug-catch-tag))
931   (ecase (car thing)
932     ((lambda) (apply #'ir1-convert-lambda thing args))
933     ((instance-lambda)
934      (let ((res (apply #'ir1-convert-lambda
935                        `(lambda ,@(cdr thing)) args)))
936        (setf (getf (functional-plist res) :fin-function) t)
937        res))
938     ((named-lambda)
939      (let ((name (cadr thing)))
940        (if (legal-fun-name-p name)
941            (let ((defined-fun-res (get-defined-fun name))
942                  (res (apply #'ir1-convert-lambda `(lambda ,@(cddr thing))
943                              :source-name name
944                              :debug-name nil
945                              args)))
946              (assert-global-function-definition-type name res)
947              (setf (defined-fun-functional defined-fun-res)
948                    res)
949              (unless (eq (defined-fun-inlinep defined-fun-res) :notinline)
950                (substitute-leaf-if
951                 (lambda (ref)
952                   (policy ref (> recognize-self-calls 0)))
953                 res defined-fun-res))
954              res)
955            (apply #'ir1-convert-lambda `(lambda ,@(cddr thing))
956                   :debug-name name args))))
957     ((lambda-with-lexenv) (apply #'ir1-convert-inline-lambda thing args))))
958 \f
959 ;;;; defining global functions
960
961 ;;; Convert FUN as a lambda in the null environment, but use the
962 ;;; current compilation policy. Note that FUN may be a
963 ;;; LAMBDA-WITH-LEXENV, so we may have to augment the environment to
964 ;;; reflect the state at the definition site.
965 (defun ir1-convert-inline-lambda (fun &key
966                                       (source-name '.anonymous.)
967                                       debug-name
968                                       allow-debug-catch-tag)
969   (declare (ignore allow-debug-catch-tag))
970   (destructuring-bind (decls macros symbol-macros &rest body)
971                       (if (eq (car fun) 'lambda-with-lexenv)
972                           (cdr fun)
973                           `(() () () . ,(cdr fun)))
974     (let ((*lexenv* (make-lexenv
975                      :default (process-decls decls nil nil
976                                              (make-null-lexenv))
977                      :vars (copy-list symbol-macros)
978                      :funs (mapcar (lambda (x)
979                                      `(,(car x) .
980                                        (macro . ,(coerce (cdr x) 'function))))
981                                    macros)
982                      :policy (lexenv-policy *lexenv*))))
983       (ir1-convert-lambda `(lambda ,@body)
984                           :source-name source-name
985                           :debug-name debug-name
986                           :allow-debug-catch-tag nil))))
987
988 ;;; Get a DEFINED-FUN object for a function we are about to define. If
989 ;;; the function has been forward referenced, then substitute for the
990 ;;; previous references.
991 (defun get-defined-fun (name)
992   (proclaim-as-fun-name name)
993   (let ((found (find-free-fun name "shouldn't happen! (defined-fun)")))
994     (note-name-defined name :function)
995     (cond ((not (defined-fun-p found))
996            (aver (not (info :function :inlinep name)))
997            (let* ((where-from (leaf-where-from found))
998                   (res (make-defined-fun
999                         :%source-name name
1000                         :where-from (if (eq where-from :declared)
1001                                         :declared :defined)
1002                         :type (leaf-type found))))
1003              (substitute-leaf res found)
1004              (setf (gethash name *free-funs*) res)))
1005           ;; If *FREE-FUNS* has a previously converted definition
1006           ;; for this name, then blow it away and try again.
1007           ((defined-fun-functional found)
1008            (remhash name *free-funs*)
1009            (get-defined-fun name))
1010           (t found))))
1011
1012 ;;; Check a new global function definition for consistency with
1013 ;;; previous declaration or definition, and assert argument/result
1014 ;;; types if appropriate. This assertion is suppressed by the
1015 ;;; EXPLICIT-CHECK attribute, which is specified on functions that
1016 ;;; check their argument types as a consequence of type dispatching.
1017 ;;; This avoids redundant checks such as NUMBERP on the args to +, etc.
1018 (defun assert-new-definition (var fun)
1019   (let ((type (leaf-type var))
1020         (for-real (eq (leaf-where-from var) :declared))
1021         (info (info :function :info (leaf-source-name var))))
1022     (assert-definition-type
1023      fun type
1024      ;; KLUDGE: Common Lisp is such a dynamic language that in general
1025      ;; all we can do here in general is issue a STYLE-WARNING. It
1026      ;; would be nice to issue a full WARNING in the special case of
1027      ;; of type mismatches within a compilation unit (as in section
1028      ;; 3.2.2.3 of the spec) but at least as of sbcl-0.6.11, we don't
1029      ;; keep track of whether the mismatched data came from the same
1030      ;; compilation unit, so we can't do that. -- WHN 2001-02-11
1031      :lossage-fun #'compiler-style-warn
1032      :unwinnage-fun (cond (info #'compiler-style-warn)
1033                           (for-real #'compiler-notify)
1034                           (t nil))
1035      :really-assert
1036      (and for-real
1037           (not (and info
1038                     (ir1-attributep (fun-info-attributes info)
1039                                     explicit-check))))
1040      :where (if for-real
1041                 "previous declaration"
1042                 "previous definition"))))
1043
1044 ;;; Convert a lambda doing all the basic stuff we would do if we were
1045 ;;; converting a DEFUN. In the old CMU CL system, this was used both
1046 ;;; by the %DEFUN translator and for global inline expansion, but
1047 ;;; since sbcl-0.pre7.something %DEFUN does things differently.
1048 ;;; FIXME: And now it's probably worth rethinking whether this
1049 ;;; function is a good idea.
1050 ;;;
1051 ;;; Unless a :INLINE function, we temporarily clobber the inline
1052 ;;; expansion. This prevents recursive inline expansion of
1053 ;;; opportunistic pseudo-inlines.
1054 (defun ir1-convert-lambda-for-defun (lambda var expansion converter)
1055   (declare (cons lambda) (function converter) (type defined-fun var))
1056   (let ((var-expansion (defined-fun-inline-expansion var)))
1057     (unless (eq (defined-fun-inlinep var) :inline)
1058       (setf (defined-fun-inline-expansion var) nil))
1059     (let* ((name (leaf-source-name var))
1060            (fun (funcall converter lambda
1061                          :source-name name))
1062            (fun-info (info :function :info name)))
1063       (setf (functional-inlinep fun) (defined-fun-inlinep var))
1064       (assert-new-definition var fun)
1065       (setf (defined-fun-inline-expansion var) var-expansion)
1066       ;; If definitely not an interpreter stub, then substitute for
1067       ;; any old references.
1068       (unless (or (eq (defined-fun-inlinep var) :notinline)
1069                   (not *block-compile*)
1070                   (and fun-info
1071                        (or (fun-info-transforms fun-info)
1072                            (fun-info-templates fun-info)
1073                            (fun-info-ir2-convert fun-info))))
1074         (substitute-leaf fun var)
1075         ;; If in a simple environment, then we can allow backward
1076         ;; references to this function from following top level forms.
1077         (when expansion (setf (defined-fun-functional var) fun)))
1078       fun)))
1079
1080 ;;; the even-at-compile-time part of DEFUN
1081 ;;;
1082 ;;; The INLINE-EXPANSION is a LAMBDA-WITH-LEXENV, or NIL if there is
1083 ;;; no inline expansion.
1084 (defun %compiler-defun (name lambda-with-lexenv compile-toplevel)
1085
1086   (let ((defined-fun nil)) ; will be set below if we're in the compiler
1087
1088     (when compile-toplevel
1089       ;; better be in the compiler
1090       (aver (boundp '*lexenv*)) 
1091       (when sb!xc:*compile-print*
1092         (compiler-mumble "~&; recognizing DEFUN ~S~%" name))
1093       (remhash name *free-funs*)
1094       (setf defined-fun (get-defined-fun name))
1095
1096       (aver (fasl-output-p *compile-object*))
1097       (if (member name *fun-names-in-this-file* :test #'equal)
1098           (compiler-warn "~@<Duplicate definition for ~S found in ~
1099                           one static unit (usually a file).~@:>"
1100                          name)
1101           (push name *fun-names-in-this-file*)))
1102
1103     (become-defined-fun-name name)
1104     
1105     (cond (lambda-with-lexenv
1106            (setf (info :function :inline-expansion-designator name)
1107                  lambda-with-lexenv)
1108            (when defined-fun
1109              (setf (defined-fun-inline-expansion defined-fun)
1110                    lambda-with-lexenv)))
1111           (t
1112            (clear-info :function :inline-expansion-designator name)))
1113
1114     ;; old CMU CL comment:
1115     ;;   If there is a type from a previous definition, blast it,
1116     ;;   since it is obsolete.
1117     (when (and defined-fun
1118                (eq (leaf-where-from defined-fun) :defined))
1119       (setf (leaf-type defined-fun)
1120             ;; FIXME: If this is a block compilation thing, shouldn't
1121             ;; we be setting the type to the full derived type for the
1122             ;; definition, instead of this most general function type?
1123             (specifier-type 'function))))
1124
1125   (values))
1126
1127 \f
1128 ;;; Entry point utilities
1129
1130 ;;; Return a function for the Nth entry point.
1131 (defun optional-dispatch-entry-point-fun (dispatcher n)
1132   (declare (type optional-dispatch dispatcher)
1133            (type unsigned-byte n))
1134   (let* ((env (getf (optional-dispatch-plist dispatcher) :ir1-environment))
1135          (*lexenv* (first env))
1136          (*current-path* (second env)))
1137     (force (nth n (optional-dispatch-entry-points dispatcher)))))