Subject: [2.0.6] CSE bug

From: [email-masked] (Ludovic Courtès)
Date: Wed, 14 Nov 2012 16:26:41 +0100

Hello,

This piece of code triggers a CSE bug:

--8<---------------cut here---------------start------------->8---
(use-modules (ice-9 match))

(define (snix-derivation->guix-package derivation)
  (match derivation
    (((_ _ _))
     #t)))
--8<---------------cut here---------------end--------------->8---

Or just:

--8<---------------cut here---------------start------------->8---
(define (snix-derivation->guix-package v)
  (let ((failure
         (lambda ()
           (error 'match "no matching pattern"))))
    (if (and (pair? v)
             (null? (cdr v)))
        (let ((w foo)
              (x (cdr w)))
          (if (and (pair? x)
                   (null? (cdr x)))
              #t
              (failure)))
        (failure))))
--8<---------------cut here---------------end--------------->8---

Details:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user) [1]> ,bt
In geiser/evaluation.scm:
    59:13 26 (call-with-result #<procedure ev ()>)
In unknown file:
          25 (call-with-output-string #<procedure 33727c0 at ice-9/r4rs.scm:236:3 (p)>)
In ice-9/r4rs.scm:
    176:4 24 (with-output-to-port #<variable 3374bb0 value: #<output: file /dev/pts/3>> #<procedure 4725360 at geiser/evaluation…>)
In geiser/evaluation.scm:
    63:19 23 (#<procedure 4725360 at geiser/evaluation.scm:60:15 ()>)
In ice-9/r4rs.scm:
    180:4 22 (with-error-to-port #<variable 33748f0 value: #<output: file /dev/pts/3>> #<procedure 4725300 at geiser/evaluation.…>)
In geiser/evaluation.scm:
    64:45 21 (#<procedure 4725300 at geiser/evaluation.scm:64:21 ()>)
    75:21 20 (ev)
In system/base/compile.scm:
    231:6 19 (compile (define (snix-derivation->guix-package v) (let ((failure (lambda () (error (quote match) "no …")))) (…))) # …)
   177:32 18 (lp (#<procedure compile-glil (x e opts)> #<procedure compile-asm (x e opts)> #<procedure compile-bytecode (ass…> …) …)
In language/tree-il/compile-glil.scm:
     65:2 17 (compile-glil #<tree-il (define snix-derivation->guix-package (lambda ((name . snix-derivation->guix-package)) (la…> …)
In language/tree-il/optimize.scm:
     44:6 16 (optimize! #<tree-il (lambda () (lambda-case ((() #f #f #f () ()) (define snix-derivation->guix-package (lambda ((…> …)
In language/tree-il/cse.scm:
   537:31 15 (visit #<tree-il (lambda () (lambda-case ((() #f #f #f () ()) (define snix-derivation->guix-package (lambda ((name…> …)
   543:33 14 (visit #<tree-il (lambda-case ((() #f #f #f () ()) (define snix-derivation->guix-package (lambda ((name . snix-der…> …)
   483:32 13 (visit #<tree-il (define snix-derivation->guix-package (lambda ((name . snix-derivation->guix-package)) (lambda-ca…> …)
   537:31 12 (visit #<tree-il (lambda ((name . snix-derivation->guix-package)) (lambda-case (((v) #f #f #f () (v-66965)) (let (…> …)
   543:33 11 (visit #<tree-il (lambda-case (((v) #f #f #f () (v-66965)) (let (failure) (failure-66977) ((lambda () (lambda-case…> …)
   430:34 10 (visit #<tree-il (let (failure) (failure-66977) ((lambda () (lambda-case ((() #f #f #f () ()) (apply (primitive er…> …)
   496:31  9 (visit #<tree-il (if (apply (primitive pair?) (lexical v v-66965)) (if (apply (primitive null?) (apply (primitive …> …)
   496:31  8 (visit #<tree-il (if (apply (primitive null?) (apply (primitive cdr) (lexical v v-66965))) (let (x) (x-66968) ((ap…> …)
   430:34  7 (visit #<tree-il (let (x) (x-66968) ((apply (primitive cdr) (toplevel w))) (begin (toplevel foo) (let (failure) (f…> …)
   553:39  6 (lp (#<tree-il (let (failure) (failure-66973) ((lambda () (lambda-case ((() #f #f #f () ()) (apply (primitive err…>) …)
   429:33  5 (visit #<tree-il (let (failure) (failure-66973) ((lambda () (lambda-case ((() #f #f #f () ()) (apply (primitive er…> …)
   370:41  4 (lp (#<tree-il (lambda () (lambda-case ((() #f #f #f () ()) (apply (primitive error) (const match) (const "no mat…>) …)
   403:15  3 (return #<tree-il (lambda () (lambda-case ((() #f #f #f () ()) (apply (primitive error) (const match) (const "no m…> …)
   333:28  2 (find-dominating-lexical #<tree-il (lambda () (lambda-case ((() #f #f #f () ()) (apply (primitive error) (const ma…> …)
   315:10  1 (unroll #<vhash 2c63040 8 pairs> 8 1)
In ice-9/vlist.scm:
    303:8  0 (vlist-ref #<vhash 2c63040 8 pairs> 8)
scheme@(guile-user) [1]> ,locals
  Local variables:
  $11 = vlist = #<vhash 2c63040 8 pairs>
  $12 = index = 8
  $13 = index = 0
  $14 = base = #(#() #f 0 0 0)
  $15 = offset = 0
  $16 = content = #()
  $17 = offset = 0
scheme@(guile-user) [1]> ,error
ice-9/vlist.scm:303:8: In procedure vlist-ref:
ice-9/vlist.scm:303:8: Value out of range: 0
--8<---------------cut here---------------end--------------->8---

Ludo’.