Generic functions that can be sealed on certain domains for performance.

Usage example:

(defgeneric binary-+ (x y) (:generic-function-class fast-generic-function)) (defmethod binary-+ ((x number) (y number)) (declare (method-properties inlineable)) (+ x y)) (seal-domain #'binary-+ '(number number)) (defun generic-+ (&rest things) (cond ((null things) 0) ((null (rest things)) (first things)) (t (reduce #'binary-+ things)))) (define-compiler-macro generic-+ (&rest things) (cond ((null things) 0) ((null (rest things)) (first things)) (t (reduce (lambda (a b) `(binary-+ ,a ,b)) things)))) (disassemble (compile nil '(lambda (x y z) (declare (single-float x y z)) (generic-+ x y z)))) ;; => ;; disassembly for (lambda (x y z)) ;; Size: 38 bytes. Origin: #x52FD9354 ;; 54: 498B4510 mov RAX, [R13+16] ;; 58: 488945F8 mov [RBP-8], RAX ;; 5C: 0F28CC movaps XMM1, XMM4 ;; 5F: F30F58CB addss XMM1, XMM3 ;; 63: F30F58CA addss XMM1, XMM2 ;; 67: 660F7ECA movd EDX, XMM1 ;; 6B: 48C1E220 shl RDX, 32 ;; 6F: 80CA19 or DL, 25 ;; 72: 488BE5 mov RSP, RBP ;; 75: F8 clc ;; 76: 5D pop RBP ;; 77: C3 ret ;; 78: CC10 int3 16

Once a fast generic function has been sealed, it is not possible to add, remove, or redefine methods within the sealed domain. Outside of the sealed domain, it behaves just like a standard generic function.

Depends on sealable-metaobjects by the same author.

Repository: GitHub

License: MIT

See Also: inlined-generic-function

Topics: language extension