From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.devel Subject: Can't compile `or' pcase pattern Date: Thu, 11 May 2017 18:04:00 +0200 Message-ID: <877f1nmlcf.fsf@drachen> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1494518655 15169 195.159.176.226 (11 May 2017 16:04:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 11 May 2017 16:04:15 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: Emacs Development Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu May 11 18:04:12 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d8qZV-0003lQ-3O for ged-emacs-devel@m.gmane.org; Thu, 11 May 2017 18:04:09 +0200 Original-Received: from localhost ([::1]:49189 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8qZa-0005rt-Jy for ged-emacs-devel@m.gmane.org; Thu, 11 May 2017 12:04:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8qZP-0005q7-IJ for emacs-devel@gnu.org; Thu, 11 May 2017 12:04:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8qZL-0007DD-EU for emacs-devel@gnu.org; Thu, 11 May 2017 12:04:03 -0400 Original-Received: from mout.web.de ([212.227.15.14]:62423) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d8qZL-0007Ct-2h for emacs-devel@gnu.org; Thu, 11 May 2017 12:03:59 -0400 Original-Received: from drachen.dragon ([92.208.83.149]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LxOF0-1e6lVe1CFm-016wKn; Thu, 11 May 2017 18:03:56 +0200 X-Provags-ID: V03:K0:p0gyG+ZG5VpUeSDmKAsZPDWrNjMg37AYRxZHKvfgG1q0vGDEt1q 0o1JT0orgcE0fTviSy1zBGhp9vWezp+kLNdPHTWkuoS7pRZCXGW31CxDCXa2C3Occlhzkp3 EYvOGDKiPAHEvLlT089z+irZmJHV3j8oJQSDPmYrbQrrynCp0J+cuykmlLYnTgOvqk4cs3G ASjz3XxNwq+9ZGqlgvtVg== X-UI-Out-Filterresults: notjunk:1;V01:K0:/qpJdDO8+qk=:i+7HWO3hS5JjyLq/1lJAd6 K4lU2A9RiA1ufSNGpaQP5rkSQQoj6IavT7I/SXpXrYRo17Re1UdVvGZcEMiZyY08fhLM0JQY4 qEOfj04emiavQcq74mwaxKDKX2Zmv6JnXyaP4Qtm9UExrD9Jp8dOnbsCOXxszbch6Rkn87066 es4uyBu2zZGaHGL50n26EigREnGmMT3aZwLpJkUwxZVuKlKJcVEHDBvQe2hPdvdHi2NwTZUPt s3fqugCeVv2BMWo616RLps8Qe4hq9QrZ66CCjTmd47vCAzS0x8XeIfZlFyFOmCiUUPQSFLiaZ ZDO014J+jsBVRyb/F2Pt8JiLRR9HpvRO5VBXt5/tfz0yVUjyW8jCsBU1Ad72WMj2uzKo21/zg jTjtxlPxN+aX3NoGqYu0gFufSF6HdEttpa2ZqhO1tueOB8T38NBhdNNYhbuOkEdHHKTcS3V7I L/Mf7ni7Z/1fkvhaVQ0wyEO5mlGMk+2zi8z7Fkh3dKkIQgFuAcfOiCg8deXe5xTWzoyt9Q8Ri EE9rihYLsbTuyXCHAzKBPaDNW03cKrrj/zSjdmr72laFmE4S5Ye9jkeoRmtv4jbk9pIsZ4B3M jR7xTqG9/DH3OaB1SGZkr/cOGoiq0ajdKpWFvtsmgCJxWj1UVKdoHwx9AItKjpbF3VWQIdWlm gY4FtvQTn+DkmlS15SijBrZXfGmSOHEK183U0+ZXXw1cRtjzcudfoTAe72IwKEJuTXTXfu+vo 0JeOP/E8ZrWltMlkUnJZpai4m38ecNrEfu4shKdLH0QzeJtitZU/xpx2kfo= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.15.14 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:214796 Archived-At: --=-=-= Content-Type: text/plain Hello, Stefan, probably, I have found a problem while working on el-search: The following form F: #+begin_src emacs-lisp (el-search--matcher '(or (l ^ defstruct object) (l ^ (and (symbol "def") (or (pred macrop) (pred special-form-p))) object))) #+end_src should compile a lambda which contains a pcase form containing the given `or' pattern: #+begin_src emacs-lisp (defun el-search--matcher (pattern &optional result) (eval (let ((expression (make-symbol "expression"))) `(el-search--with-additional-pcase-macros (let ((byte-compile-debug t) ;make undefined pattern types raise an error (warning-suppress-log-types '((bytecomp))) (pcase--dontwarn-upats (cons '_ pcase--dontwarn-upats))) (byte-compile (lambda (,expression) (pcase ,expression (,pattern ,(or result t)) (_ nil))))))))) #+end_src where `el-search--with-additional-pcase-macros' just temporarily adds some pattern definitions to the pcase macro environment. The problem is that the call of `el-search--matcher' in F takes over one minute of time and then gives up with | byte-compile-lapcode: Bytecode overflow Similar cases also take extremely long also but don't cause an overflow. AFAICT the expansion of the pattern does not produce extraordinarily dumb code. Even stranger: Calling `el-search--matcher' with any of the 2 patterns inside the `or', i.e., #+begin_src emacs-lisp (el-search--matcher '(l ^ defstruct object)) #+end_src and #+begin_src emacs-lisp (el-search--macroexpand '(l ^ (and (symbol "def") (or (pred macrop) (pred special-form-p))) object)) #+end_src instantly succeed. Have I hit some weak point in the implementation of `pcase's `or'? Is there some way to avoid this problem? Simplifying the semantics of `l' seems to help a bit. But I would like to understand what the problem is and how I could avoid it. This is on master, but with emacs-25 I see same issue. Quitting with debug-on-quit -> t doesn't look like there is an infinite recursion while compiling or code walking (though the recursion depth is not small). For reference I attach the macroexpansion of the pattern in F. Thanks, Michael. --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=bug.el Content-Transfer-Encoding: quoted-printable (el-search--macroexpand '(or (l ^ defstruct object) (l ^ (and (symbol "def") (or (pred macrop) (pred special-form-p))) ob= ject))) ;; =3D=3D> (or (and #12=3D(pred listp) (app #f(compiled-function (&rest args2) "\n\n(fn &rest ARGS2)" #) (and #5=3D(pred consp) (app car (and #5# (app car (or (and #8=3D(pred symbolp) (app symbol-name (and #9=3D(pred stringp) (pred #f(compiled-function (#:string) #))))) (and #5# (app car 'quote) (app cdr (and #5# (app car (and #8# (app symbol-name (and #9# (pred #f= (compiled-function = (#:string) = #)))))) (app cdr 'nil)))) (and #5# (app car 'function) (app cdr (and #5# (app car (and #8# (app symbol-name (and #9# (pred #f= (compiled-function = (#:string) = #)))))) (app cdr 'nil)))))) (app cdr 'nil))) (app cdr (and #5# (app car (and #12# (app #f(compiled-function (&rest args2) "\n\n(fn &rest ARGS2)" #) (and #5# (app car (and #5# (app car (or (and #8# (app sym= bol-name (an= d #9# = (pred #f(compiled-function = (#:string) = #))))) (and #5# (app car= 'quote) (app cdr (an= d #5# = (app car = (and #8# = (app symbol-name = (and #9# = (pred #f(compiled-function = (#:string) = #)))))) = (app cdr 'nil)))) (and #5# (app car= 'function) (app cdr (an= d #5# = (app car = (and #8# = (app symbol-name = (and #9# = (pred #f(compiled-function = (#:string) = #)))))) = (app cdr 'nil)))))) (app cdr 'nil))) (app cdr (and #5# (app car _) (app cdr 'nil))))))) (app cdr 'nil)))))) (and #12# (app #f(compiled-function (&rest args2) "\n\n(fn &rest ARGS2)" #) (and #5# (app car (and #5# (app car (and (and #8# (app symbol-name (and #9# (pred #f(compiled-function (#:string) #))))) (or (pred macrop) (pred special-form-p)))) (app cdr 'nil))) (app cdr (and #5# (app car (and #12# (app #f(compiled-function (&rest args2) "\n\n(fn &rest ARGS2)" #) (and #5# (app car (and #5# (app car (or (and #8# (app sym= bol-name (an= d #9# = (pred #f(compiled-function = (#:string) = #))))) (and #5# (app car= 'quote) (app cdr (an= d #5# = (app car = (and #8# = (app symbol-name = (and #9# = (pred #f(compiled-function = (#:string) = #)))))) = (app cdr 'nil)))) (and #5# (app car= 'function) (app cdr (an= d #5# = (app car = (and #8# = (app symbol-name = (and #9# = (pred #f(compiled-function = (#:string) = #)))))) = (app cdr 'nil)))))) (app cdr 'nil))) (app cdr (and #5# (app car _) (app cdr 'nil))))))) (app cdr 'nil))))))) --=-=-=--