Hi!
I have a LOOP statement in a time-critical part of my code which looks
like this:
(loop for matcher in all-matchers
thereis (funcall matcher start-pos))
If I compile this with CMUCL (18d) I get a note telling me
(FUNCALL MATCHER START-POS)
--> C::%FUNCALL IF
==>
(KERNEL:%COERCE-TO-FUNCTION FUNCTION)
Note: Unable to optimize because:
Might be a symbol, so must call FDEFINITION at runtime.
So I thought I better tell CMUCL about the type of MATCHER...
(loop for matcher of-type function in all-matchers
thereis (funcall matcher start-pos))
...but I still get the same note. If I try to be more specific...
(loop for matcher of-type (function (fixnum) (or fixnum null)) in all-matchers
thereis (funcall matcher start-pos))
...I get an error:
Error in function COMMON-LISP::%%TYPEP:
Function types are not a legal argument to TYPEP:
(FUNCTION (FIXNUM) (OR FIXNUM NULL))
Now I thought I was clever and wrote...
(loop for matcher in all-matchers
thereis (locally (declare (ftype (function (fixnum) (or fixnum null)) matcher))
(funcall matcher start-pos)))
...but got an error telling me
(LOCALLY (DECLARE (FTYPE # MATCHER)) (FUNCALL MATCHER START-POS))
Warning: Undefined function: MATCHER
Huh? Why is it undefined? I thought it was defined by the line above?
I'm confused...
What's the right way to get rid of this note and help CMUCL in
optimizing the code?
Thanks,
Edi.