I want to write something like the following (it defines s struct, and
gets some efficient compilation hints from s1.lisp...)
(load "s1.lisp")
(defstruct s1
(a))
(defun ref (a b)
"This is the function I am trying to optimize"
(list "ref" a b))
(defun test1 (x)
"fast form."
(declare (type s1 x))
(ref x "a"))
(defun test2 (x)
"slow form (punt)"
(ref x "a"))
(compile 'test1)
(compile 'test2)
(defun x ()
(let ((v (make-s1)))
(setf (s1-a v) 12)
(list
(test1 v)
(test2 v))))
Where s1.lisp looks something like:
(in-package "C") ;; needed for continuation stuff
(defknown ref (t t) t)
(deftransform ref ((x y) (s1 t) t)
"With a known string (y) convert to a slot accessor."
(unless (constant-continuation-p y)
(give-up))
(let ((acc (read-from-string (format nil "~sl-~a" (continuation-value
y)))))
`(,acc x)))
However, defknown/deftransform don't find my hints...
*(x)
(("ref" #S(s1 :a 12) "a") ("ref" #S(s1 :a 12) "a"))
I can dump everything into the wrong (C) package and get the effect I
want:
(in-package "C")
(defstruct s1
(a))
(defun ref (a b)
(list "ref" a b))
(defknown ref (t t) t)
(deftransform ref ((x y) (s1 t) t)
(unless (constant-continuation-p y)
(give-up))
(let ((acc (read-from-string (format nil "s1-~a" (continuation-value
y)))))
`(,acc x)))
(defun test1 (x)
(declare (type s1 x))
(ref x "a"))
(defun test2 (x)
(ref x "a"))
(compile 'test1)
(compile 'test2)
(defun x ()
(let ((v (make-s1)))
(setf (s1-a v) 12)
(list
(test1 v)
(test2 v))))
* (in-package :c)
* (x)
(12 ("ref" #S(s1 :a 12) "a"))
Obviously, I have a basic misconception here. What am I doing wrong?
Thanks,
Michael