From 5b40c0d8ad81ed99a952df12e96061f912142b95 Mon Sep 17 00:00:00 2001 From: okamsn <28612288+okamsn@users.noreply.github.com> Date: Fri, 16 Aug 2024 01:15:19 +0000 Subject: [PATCH] Silence byte compiler warnings. (#201) - Add `name` to `ignore` in `loopy--defaccumulation`. Identified in #200. - Remove unused `cmd` from `loopy--parse-set-command`. - Remove unused `cmd` from `loopy--parse-set-prev-command`. - Add `loopy--pcase-flip` as a wrapper for `pcase--flip`, which was obsoleted in Emacs 30. - Add documentation strings to `loopy--seq-length>` and `loopy--seq-length=`. - Use `static-if`, new in Emacs 30 and provided by Compat, when modifying code base on `emacs-major-version`. --- loopy-commands.el | 6 ++--- loopy-destructure.el | 57 ++++++++++++++++++++++++++------------------ loopy-misc.el | 3 ++- tests/misc-tests.el | 16 ++++++------- tests/tests.el | 2 +- 5 files changed, 48 insertions(+), 36 deletions(-) diff --git a/loopy-commands.el b/loopy-commands.el index 34cb6aca..90f1e18e 100644 --- a/loopy-commands.el +++ b/loopy-commands.el @@ -139,7 +139,7 @@ handled by `loopy-iter'." ;;;;; Genereric Evaluation ;;;;;; Set -(cl-defun loopy--parse-set-command ((&whole cmd _ var &rest vals)) +(cl-defun loopy--parse-set-command ((_ var &rest vals)) "Parse the `set' command. - VAR is the variable to assign. @@ -190,7 +190,7 @@ handled by `loopy-iter'." ;; being known at compile time (but still only being evaluated once.) ;; (#194) (cl-defun loopy--parse-set-prev-command - ((&whole cmd _ var val &key back)) + ((_ var val &key back)) "Parse the `set-prev' command as (set-prev VAR VAL &key back). VAR is set to a version of VAL in a past loop cycle. With BACK, @@ -1777,7 +1777,7 @@ you can use in the instructions: args (nreverse args-holding)) (setq args parser-args))) - (ignore args opts) + (ignore name args opts) (let ((arg-length (length args))) (cond diff --git a/loopy-destructure.el b/loopy-destructure.el index 085ac09e..4dc46113 100644 --- a/loopy-destructure.el +++ b/loopy-destructure.el @@ -384,6 +384,15 @@ Type is one of `list' or `array'." ;;;; Pcase pattern +(defun loopy--pcase-flip (fn arg2) + "Wrapper macro for compatibility with obsoletion of `pcase--flip'. + +FN is the function. ARG2 is the argument to move to the second +postion of the call to FN in the pattern." + (static-if (>= emacs-major-version 30) + `(,fn _ ,arg2) + `(pcase--flip ,fn ,arg2))) + (defun loopy--get-var-pattern (var) "Get the correct variable pattern. @@ -397,7 +406,7 @@ return `(loopy VAR)'. In all other cases, VAR is returned." ;; TODO: Use this in `list' pattern. (defun loopy--pcase-let-nil-list (pat) - "Return a list of patterns binding variables in PAT to `nil'." + "Return a list of patterns binding variables in PAT to nil." ;; Need to quote `nil' for it to be a `pcase' pattern. (pcase pat (`(loopy ,(and (pred seqp) seq)) @@ -422,7 +431,7 @@ MAP-OR-KEY-VARS is whether there are map or key variables." (cdr pos-vars) opt-vars rest-var map-or-key-vars)))) (opt-vars (loopy--pcase-let-workaround (var default supplied) - (pcase-let* ((`(,var ,default ,supplied ,length) + (pcase-let* ((`(,var ,default ,supplied ,_length) (loopy--get-&optional-spec (car opt-vars))) (var2 (loopy--get-var-pattern var))) `(and (pred listp) @@ -457,10 +466,10 @@ MAP-OR-KEY-VARS is whether there are map or key variables." (opt-len (length opt-vars))) ;; We allow the variable form to be shorter than the ;; destructured sequence. - `(and (pred (pcase--flip ,(compat-function length>) ,(1- pos-len))) + `(and (pred ,(loopy--pcase-flip (compat-function length>) (1- pos-len))) ,@(cl-loop for var in pos-vars for idx from 0 - collect `(app (pcase--flip aref ,idx) + collect `(app ,(loopy--pcase-flip 'aref idx) ,(loopy--get-var-pattern var))) ,@(when opt-vars (let ((opt-var-specs (seq-into (mapcar #'loopy--get-&optional-spec @@ -477,8 +486,8 @@ MAP-OR-KEY-VARS is whether there are map or key variables." ;; the one variable was not supplied and we ;; need to check the remaining ones. `(and ,(if use->= - `(pred (pcase--flip ,(compat-function length>) ,(1- checked-len))) - `(pred (pcase--flip ,(compat-function length=) ,checked-len))) + `(pred ,(loopy--pcase-flip (compat-function length>) (1- checked-len))) + `(pred ,(loopy--pcase-flip (compat-function length=) checked-len))) ;; Variables that should be bound with the value in ;; the array. ,@(cl-loop @@ -488,10 +497,10 @@ MAP-OR-KEY-VARS is whether there are map or key variables." (aref opt-var-specs spec-idx2)) (var3 (loopy--get-var-pattern var2))) (if (= len2 3) - `((app (pcase--flip aref ,arr-idx) + `((app ,(loopy--pcase-flip 'aref arr-idx) ,var3) (let ,supplied2 t)) - `((app (pcase--flip aref ,arr-idx) + `((app ,(loopy--pcase-flip 'aref arr-idx) ,var3))))) ;; Variables that should be bound to nil or their ;; default. @@ -529,18 +538,20 @@ MAP-OR-KEY-VARS is whether there are map or key variables." (rest-pat (loopy--get-var-pattern rest-var)) (seqsym (gensym "seqsym"))) ;; Rec-checking the length is fast for arrays. - `((or (and (pred (pcase--flip ,(compat-function length>) ,len-sum)) - (app (pcase--flip substring ,len-sum) ; 0-indexed + `((or (and (pred ,(loopy--pcase-flip (compat-function length>) len-sum)) + (app ,(loopy--pcase-flip 'substring len-sum) ; 0-indexed ,rest-pat)) (app (lambda (,seqsym) (substring ,seqsym 0 0)) ,rest-pat)))))))) (defun loopy--seq-length= (seq n) + "Check whether the length of SEQ is equal to N." (if (sequencep seq) (compat-call length= seq n) (= (seq-length seq) n))) (defun loopy--seq-length> (seq n) + "Check whether the length of SEQ is greater than to N." (cond ((sequencep seq) (compat-call length> seq n)) @@ -567,14 +578,14 @@ MAP-OR-KEY-VARS is whether there are map or key variables." (cl-labels ((make-pos-pats () (cl-loop for v in pos-vars for i from 0 - collect `(app (pcase--flip seq-elt ,i) + collect `(app ,(loopy--pcase-flip 'seq-elt i) ,(loopy--get-var-pattern v))))) `(and ;; If there are optional values, then we can avoid the length check here ;; by running the length check for the optional values, which we need to ;; do anyway. ,@(when (null opt-vars) - `((pred (pcase--flip loopy--seq-length> ,(1- pos-len))) + `((pred ,(loopy--pcase-flip 'loopy--seq-length> (1- pos-len))) ,@(make-pos-pats))) ;; Optional variables may or may not be expensive for generic ;; sequences. This is the same logic as for arrays, just using the @@ -595,8 +606,8 @@ MAP-OR-KEY-VARS is whether there are map or key variables." ;; the one variable was not supplied and we ;; need to check the remaining ones. `(and ,(if use->= - `(pred (pcase--flip loopy--seq-length> ,(1- checked-len))) - `(pred (pcase--flip loopy--seq-length= ,checked-len))) + `(pred ,(loopy--pcase-flip 'loopy--seq-length> (1- checked-len))) + `(pred ,(loopy--pcase-flip 'loopy--seq-length= checked-len))) ,@(when pos-vars (make-pos-pats)) ;; Variables that should be bound with the value in @@ -607,10 +618,10 @@ MAP-OR-KEY-VARS is whether there are map or key variables." append (pcase-let* ((`(,var2 ,_ ,supplied2) (aref opt-var-specs spec-idx2)) (var3 (loopy--get-var-pattern var2))) (if supplied2 - `((app (pcase--flip seq-elt ,arr-idx) + `((app ,(loopy--pcase-flip 'seq-elt arr-idx) ,var3) (let ,supplied2 t)) - `((app (pcase--flip seq-elt ,arr-idx) + `((app ,(loopy--pcase-flip 'seq-elt arr-idx) ,var3))))) ;; Variables that should be bound to nil or their ;; default. @@ -630,7 +641,7 @@ MAP-OR-KEY-VARS is whether there are map or key variables." )))))) ;; A pattern for when nothing matches. (and ,@(cl-loop for spec across opt-var-specs - append (pcase-let* ((`(,var2 ,default2 ,supplied2 ,len2) spec) + append (pcase-let* ((`(,var2 ,default2 ,supplied2 ,_len2) spec) (var3 (loopy--get-var-pattern var2))) `(,@(when supplied2 `((let ,supplied2 nil))) @@ -643,10 +654,10 @@ MAP-OR-KEY-VARS is whether there are map or key variables." ;; `((let ,var3 ,default2)))) ))) ,@(when pos-vars - `((pred (pcase--flip loopy--seq-length> ,(1- pos-len))) + `((pred ,(loopy--pcase-flip 'loopy--seq-length> (1- pos-len))) ,@(make-pos-pats)))))))) ,@(when rest-var - `((app (pcase--flip seq-drop ,(+ pos-len opt-len)) + `((app ,(loopy--pcase-flip 'seq-drop (+ pos-len opt-len)) ,(loopy--get-var-pattern rest-var)))))))) (defun loopy--pcase-pat-&key-pattern (key-vars allow-other-keys) @@ -684,7 +695,7 @@ holding the property list." ,default))) ,var)) (t - `(app (pcase--flip plist-get ,key) + `(app ,(loopy--pcase-flip 'plist-get key) ,var))))) key-vars)) ;; If we are checking whether there are no other keys in EXPVAL, @@ -770,7 +781,7 @@ holding the property list." `(app (lambda (,mapsym) (map-elt ,mapsym ,key ,default)) ,var)) (t - `(app (pcase--flip map-elt ,key) ,var)))))) + `(app ,(loopy--pcase-flip 'map-elt key) ,var)))))) map-vars)))) (defun loopy--pcase-pat-&aux-pattern (aux-vars) @@ -858,8 +869,8 @@ See the Info node `(loopy)Basic Destructuring'." `(app (lambda (_) ,rest-var) ,(loopy--pcase-pat-&map-pattern map-vars))) ((or pos-vars opt-vars) - `(app (pcase--flip seq-drop ,(+ (length pos-vars) - (length opt-vars))) + `(app ,(loopy--pcase-flip 'seq-drop (+ (length pos-vars) + (length opt-vars))) ,(loopy--pcase-pat-&map-pattern map-vars))) (t (loopy--pcase-pat-&map-pattern map-vars)))) diff --git a/loopy-misc.el b/loopy-misc.el index 75eb521d..d7203f45 100644 --- a/loopy-misc.el +++ b/loopy-misc.el @@ -457,11 +457,12 @@ KEY transforms those elements and ELEMENT." Prior to Emacs 28, it was not guaranteed that `pcase-let' bound unmatched variables." (declare (indent 1)) - (if (eval-when-compile (< emacs-major-version 28)) + (static-if (< emacs-major-version 28) `(let ,(mapcar (lambda (sym) `(,sym nil)) variables) ,(cons 'ignore variables) ,form) + (ignore variables) form)) (provide 'loopy-misc) diff --git a/tests/misc-tests.el b/tests/misc-tests.el index 4dfd1193..d48bcaa0 100644 --- a/tests/misc-tests.el +++ b/tests/misc-tests.el @@ -1167,14 +1167,14 @@ The valid keys are: ;; FIXME: This test fails on Emacs 27 because the tests don't install the ;; correct version of Map.el. -(when (> emacs-major-version 27) - (loopy-def-pcase-test pcase-tests-loopy-&optional-ignored-6 - :result (list 1 2 [] 14 nil) - :val (vector 1 2) - :var (a b e k1 k2) - :pat [a b &optional _ _ &rest e &map [:k1 k1 14] (:k2 k2)] - :list nil - :convert nil)) +(static-if (> emacs-major-version 27) + (loopy-def-pcase-test pcase-tests-loopy-&optional-ignored-6 + :result (list 1 2 [] 14 nil) + :val (vector 1 2) + :var (a b e k1 k2) + :pat [a b &optional _ _ &rest e &map [:k1 k1 14] (:k2 k2)] + :list nil + :convert nil)) (loopy-def-pcase-test pcase-tests-loopy-&whole-1 :result (list (list 1 2 3) 1 2 3) diff --git a/tests/tests.el b/tests/tests.el index dbc1c997..f254dbcf 100644 --- a/tests/tests.el +++ b/tests/tests.el @@ -5803,7 +5803,7 @@ Otherwise, `loopy' should return t." ;; Emacs 27 had a byte-compilation error that was fixed in ;; commit a0f60293d79cda858c033db4ae074e5e5560aab2. ;; See: https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=a0f60293d97cda858c033db4ae074e5e5560aab2. - :expected-result (if (= emacs-major-version 27) + :expected-result (static-if (= emacs-major-version 27) :failed :passed) (should