Subject: Code causes guild compile to hang

From: Tommi Höynälänmaa <[email-masked]>
Date: Fri, 25 May 2018 18:32:24 +0300

The following code causes command "guild compile" to hang:
---cut here---
(define (select-nearest-methods binder
                index v-fixed-args v-rest-arg vb-included)
  (dwl4 "select-nearest-methods")
  (assert (is-binder? binder))
  (let ((n (vector-length vb-included)))
    (do ((i 0 (+ i 1))) ((>= i n))
      (if (vector-ref vb-included i)
      (let ((t1 (get-item-at-index
             (vector-ref v-fixed-args i)
             (vector-ref v-rest-arg i)
             index)))
        (do ((j 0 (+ j 1))) ((>= j n))
          (if (and (not (= i j))
               (vector-ref vb-included j))
          (let ((t2 (get-item-at-index
                 (vector-ref v-fixed-args j)
                 (vector-ref v-rest-arg j)
                 index)))
            (if (is-t-subtype? binder t1 t2)
            ;; t2 is excluded
            (vector-set! vb-included j #f))))))))))
---cut here---

However, the following code works fine:
---cut here---
(define (method-loop binder
             index v-fixed-args v-rest-arg vb-included t1 i n)
  (do ((j 0 (+ j 1))) ((>= j n))
    (if (and (not (= i j))
         (vector-ref vb-included j))
    (let ((t2 (get-item-at-index
           (vector-ref v-fixed-args j)
           (vector-ref v-rest-arg j)
           index)))
      (if (is-t-subtype? binder t1 t2)
          ;; t2 is excluded
          (vector-set! vb-included j #f))))))

(define (select-nearest-methods binder
                index v-fixed-args v-rest-arg vb-included)
  (dwl4 "select-nearest-methods")
  (assert (is-binder? binder))
  (let ((n (vector-length vb-included)))
    (do ((i 0 (+ i 1))) ((>= i n))
      (if (vector-ref vb-included i)
      (let ((t1 (get-item-at-index
             (vector-ref v-fixed-args i)
             (vector-ref v-rest-arg i)
             index)))
        (method-loop binder index v-fixed-args v-rest-arg vb-included
             t1 i n))))))
---cut here---

This problem occurs with guile 2.2.3.

     - Tommi Höynälänmaa