vindarel / cl-str

Modern, simple and consistent Common Lisp string manipulation library.
https://vindarel.github.io/cl-str/
MIT License
305 stars 37 forks source link

match: add type annotation to enable optimization level 3 #122

Closed ccqpein closed 2 months ago

ccqpein commented 2 months ago

I added a type annotation to the match macro so that the compiler won't complain when the optimization level is 3.

Example:

(ql:quickload "str")

(declaim (optimize (speed 3)))

(defun aa ()
  (str:match ""
    ((a "a") a)))

In the current code, the compiler (sbcl) will print notes:

; in: DEFUN AA
;     (STR:MATCH ""
;       ((A "a") A))
; --> MULTIPLE-VALUE-BIND MULTIPLE-VALUE-CALL FUNCTION WHEN IF LET SETF
; --> SETQ THE
; ==>
;   (ELT #:G2 0)
; 
; note: unable to
;   optimize
; due to type uncertainty:
;   The first argument is a (OR CONS VECTOR
;                               SB-KERNEL:EXTENDED-SEQUENCE), not a (SIMPLE-ARRAY
;                                                                    * (*)).
; 
; note: unable to
;   optimize
; due to type uncertainty:
;   The first argument is a (OR CONS VECTOR
;                               SB-KERNEL:EXTENDED-SEQUENCE), not a LIST.
; 
; compilation unit finished
;   printed 2 notes

After this PR, sbcl will be happy with it.

kilianmh commented 2 months ago

On my sbcl 2.4.5 I do not get this note. On which sbcl you get this note?

But type declarations are always good :)

ccqpein commented 2 months ago

@kilianmh Interesting, my sbcl version is 2.4.5 too. Through homebrew on macos

brew info sbcl
==> sbcl: stable 2.4.5 (bottled), HEAD Steel Bank Common Lisp system