bug#62053: Guile compiler is unable to compile tiny program

"Dr. Arne Babenhauserheide" <[email protected]>
Newsgroups gmane.lisp.guile.bugs
Message-ID <[email protected]>
<[email protected]> 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, 1.1 KB)
-----BEGIN PGP SIGNATURE-----

iQJEBAEBCAAuFiEE801qEjXQSQPNItXAE++NRSQDw+sFAmQIyWgQHGFybmVfYmFi
QHdlYi5kZQAKCRAT741FJAPD66EZEADTj4uEOxB+H75X9GlwHg7eAVZ8mLl29tTl
+7BZwCH920mgxU9hD52vjMojBE9DkLFOAbNe4w/xvmBdmR4/Tthri77l0HlcRpfI
ymeP6Fc55Dz8dNK9BIeF/JXCtrnYNl4giVQ16isF9UPqD95rbvLZDkqQBlNrm7OF
snJXvBVa+WSQGdoUVLN4/71GOg4I0JI4W24OD3SAB/uYfSC1yCs+6lPSyPsQO/kV
t0eFEyAzsLsDJMwYLW2/66fjog0NjqMu/TpDL+MEVGOprcKCf2EWwRhG/ox/6RM0
l2RM/pXyqslrHcKZrmNHD9rndGBa037GF1NewBHzu4ljzWVNKIKgbVEH2c4JlA8f
ZKtmAJSliFAqXoNFGrgP5LdJ/nGpvdRqBUrnNuqo2YPMhJz9+Wf3QBbLZdWJHW9C
HeJ5J83yaslXb+aoUO9bBE/qRaI9lhvsR5L2MwH01l2dVkPQqRkbpsmINLMEN/5y
GKiu43Tk/90S+o3IhUW5Yui7SohT+dlchEz/vAO0fUe9RAJXvlzPai0NHkhfMdhn
F+JXiPTUDCEeO7nuseZzEZ7TTiw30gQ98HjUQuRs/P0CsOnHPNRRNYVIjnUvbJ3+
PUZPxhEyLyBFha9VM9JPlCI0ESPOeN+v3ihR5IympQItferyMikMt3ueEPREG5fL
+NbLRK77IojEBAEBCAAuFiEE3Si95tmHXKvOSosd3M8NswvBBUgFAmQIyWgQHGFy
bmVfYmFiQHdlYi5kZQAKCRDczw2zC8EFSNp4A/4pdyJsEdXeuYLCWk7wFXhwghGf
x51OBeiVsdBJkcuP3zCfJuOIiOa+I4lCsQGyfs7qqA11Bd/Ms9yO8B/qQQq2NMyY
oavBvDhqIujhKElIzf7RL0smIJt553VPjZC25Sw0Wt5EhjDa74HlY5xPGRWi/UYB
/atZaeIC9Etbi8HSHg==
=i1Le
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.