Previous: , Up: Local Call   [Contents][Index]


5.6.5 Return Values

One of the more subtle costs of full call comes from allowing arbitrary numbers of return values. This overhead can be avoided in local calls to functions that always return the same number of values. For efficiency reasons (as well as stylistic ones), you should write functions so that they always return the same number of values. This may require passing extra nil arguments to values in some cases, but the result is more efficient, not less so.

When efficiency notes are enabled (see efficiency-notes), and the compiler wants to use known values return, but can’t prove that the function always returns the same number of values, then it will print a note like this:

In: DEFUN GRUE
  (DEFUN GRUE (X) (DECLARE (FIXNUM X)) (COND (# #) (# NIL) (T #)))
Note: Return type not fixed values, so can't use known return convention:
  (VALUES (OR (INTEGER -536870912 -1) NULL) &REST T)

In order to implement proper tail recursion in the presence of known values return (see tail-recursion), the compiler sometimes must prove that multiple functions all return the same number of values. When this can’t be proven, the compiler will print a note like this:

In: DEFUN BLUE
  (DEFUN BLUE (X) (DECLARE (FIXNUM X)) (COND (# #) (# #) (# #) (T #)))
Note: Return value count mismatch prevents known return from
      these functions:
  BLUE
  SNOO

See number-local-call for the interaction between local call and the representation of numeric types.


Previous: Local Tail Recursion, Up: Local Call   [Contents][Index]