GNU bug report logs - #62053
Guile compiler is unable to compile tiny program

Previous Next

Package: guile;

Reported by: Владимир ВНИИАЭС <var-vniiaes <at> mail.ru>

Date: Wed, 8 Mar 2023 15:39:02 UTC

Severity: normal

To reply to this bug, email your comments to 62053 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#62053; Package guile. (Wed, 08 Mar 2023 15:39:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Владимир ВНИИАЭС <var-vniiaes <at> mail.ru>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Wed, 08 Mar 2023 15:39:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Владимир ВНИИАЭС
 <var-vniiaes <at> mail.ru>
To: bug-guile <at> gnu.org
Subject: Guile compiler is unable to compile tiny program
Date: Wed, 08 Mar 2023 14:07:56 +0300
[Message part 1 (text/plain, inline)]
Guile compiler is unable to compile tiny program:
 
(define (fn l)
    (define (ok l)
       (or (and (pair? l) l)
           (error "list is empty")))
    (cons (reverse (car l)) (ok l)))
 
amaya <at> picasso:~/tmp/guile-3.0.9
$ ../prefix/bin/guile ~/tmp/guile-compiler-bug.scm
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /home/amaya/tmp/guile-compiler-bug.scm
;;; WARNING: compilation of /home/amaya/tmp/guile-compiler-bug.scm failed:
;;; not found 22
 
Compiler reports confusing message here: `not found 22’.   
[Message part 2 (text/html, inline)]

Information forwarded to bug-guile <at> gnu.org:
bug#62053; Package guile. (Wed, 08 Mar 2023 16:42:02 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: <tomas <at> tuxteam.de>
To: bug-guile <at> gnu.org
Subject: Re: bug#62053: Guile compiler is unable to compile tiny program
Date: Wed, 8 Mar 2023 17:41:19 +0100
[Message part 1 (text/plain, inline)]
On Wed, Mar 08, 2023 at 02:07:56PM +0300, var-vniiaes--- via Bug reports for GUILE, GNU's Ubiquitous Extension Language wrote:
> 
> Guile compiler is unable to compile tiny program:
>  
> (define (fn l)
>     (define (ok l)
>        (or (and (pair? l) l)
>            (error "list is empty")))
>     (cons (reverse (car l)) (ok l)))
>  
> amaya <at> picasso:~/tmp/guile-3.0.9
> $ ../prefix/bin/guile ~/tmp/guile-compiler-bug.scm
> ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
> ;;;       or pass the --no-auto-compile argument to disable.
> ;;; compiling /home/amaya/tmp/guile-compiler-bug.scm
> ;;; WARNING: compilation of /home/amaya/tmp/guile-compiler-bug.scm failed:
> ;;; not found 22
>  
> Compiler reports confusing message here: `not found 22’.   

Bizarre. Can confirm 

tomas <at> trotzki:~/foo$ vim buggy.scm
  tomas <at> trotzki:~/foo$ guile buggy.scm 
  ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
  ;;;       or pass the --no-auto-compile argument to disable.
  ;;; compiling /home/tomas/foo/buggy.scm
  ;;; /home/tomas/foo/buggy.scm:2:0: warning: possibly unbound variable `#{   }#'
  ;;; /home/tomas/foo/buggy.scm:3:0: warning: possibly unbound variable `#{      }#'
  ;;; /home/tomas/foo/buggy.scm:4:0: warning: possibly unbound variable `#{          }#'
  ;;; WARNING: compilation of /home/tomas/foo/buggy.scm failed:
  ;;; not found 25

  tomas <at> trotzki:~/foo$ guile --version
  guile (GNU Guile) 3.0.8.57-bc3b1
  Copyright (C) 2022 Free Software Foundation, Inc.

  License LGPLv3+: GNU LGPL 3 or later <http://gnu.org/licenses/lgpl.html>.
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.

(so in my case it's 25 instead of 22). Interestingly, my version also
produces warnings about possibly unbound variables). If I enter the
code line by line into a repl, I also get a "not found 22".

Interestingly, if I add a call to fn to the end of that snippet
(e.g. (fn '(a b))), the "not found" disappears. The unbound var
warnings stay.

Cheers
-- 
t


[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-guile <at> gnu.org:
bug#62053; Package guile. (Wed, 08 Mar 2023 17:45:02 GMT) Full text and rfc822 format available.

Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Dr. Arne Babenhauserheide" <arne_bab <at> web.de>
To: tomas <at> tuxteam.de
Cc: bug-guile <at> gnu.org, 62053 <at> debbugs.gnu.org
Subject: Re: bug#62053: Guile compiler is unable to compile tiny program
Date: Wed, 08 Mar 2023 18:38:10 +0100
[Message part 1 (text/plain, inline)]
<tomas <at> tuxteam.de> writes:

>> (define (fn l)
>>     (define (ok l)
>>        (or (and (pair? l) l)
>>            (error "list is empty")))
>>     (cons (reverse (car l)) (ok l)))
> (so in my case it's 25 instead of 22). Interestingly, my version also
> produces warnings about possibly unbound variables). If I enter the
> code line by line into a repl, I also get a "not found 22".
>
> Interestingly, if I add a call to fn to the end of that snippet
> (e.g. (fn '(a b))), the "not found" disappears. The unbound var
> warnings stay.

Also interesting: I can primitive-eval the code:
(define code '(define (fn l)
  (define (ok l)
    (or (and (pair? l) l)
      (error "list is empty")))
  (cons (reverse (car l)) (ok l))))

(primitive-eval code)

(fn '((1 2))) ;; => ((2 1) (1 2))

What might be happening here is control flow analysis discarding
impossible branches:

(car l) will throw an error when l is not a pair. Since arguments are
evaluated in order, (ok l) will always succeed. This means (ok l) can be
replaced by l.

To look into details:

(compile code) ;; => throws an error: not found 22
;; use ,bt to get:

,bt
In system/base/compile.scm:
   352:28 17 (compile _ #:from _ #:to _ #:env _ #:optimization-level _ #:warning-level _ #:opts _)
   265:44 16 (_ _ _)
   265:44 15 (_ _ _)
   261:33 14 (_ #<intmap 0-83> #<module (#{ g836}#) 7fcbf85dfbe0>)
In language/cps/optimize.scm:
   130:12 13 (_ _ _)
    102:3 12 (optimize-higher-order-cps _ _)
In language/cps/type-fold.scm:
   775:16 11 (type-fold _)
In language/cps/renumber.scm:
   170:36 10 (renumber #<intmap 0-4,6-21,52-53> _)
   166:30  9 (compute-renaming _ _)
    144:7  8 (visit-fun _ _ _)
   160:19  7 (visit-fun 12 #<transient-intmap 0-4,6-11> #<transient-intmap 0-3,5-6>)
In language/cps/utils.scm:
   245:39  6 (compute-predecessors #<intmap 0-4,6-21,52-53> _ #:labels _)
    107:3  5 (compute-function-body _ _)
   129:30  4 (visit-cont _ _)
   129:30  3 (visit-cont _ _)
    112:9  2 (visit-cont 22 _)
In language/cps/intmap.scm:
   397:51  1 (_ _)
In ice-9/boot-9.scm:
  1685:16  0 (raise-exception _ #:continuable? _)


I’ll leave further steps to folks who are more experienced with
optimize-higher-order-cps (or want to become more experienced with it).


Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein,
ohne es zu merken.
draketo.de
[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-guile <at> gnu.org:
bug#62053; Package guile. (Wed, 08 Mar 2023 17:45:02 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 264 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.