Subject: bug#74422: Wrong expected column number while backtracing?

From: Olivier Dion <[email-masked]>
Date: Mon, 18 Nov 2024 14:00:59 -0500

Hi,

Sometime, the printed backtrace from Guile gives wrong column numbers.
This seems to happen when referencing free variables.

Here is a dummy example that represents the problem:
--8<---------------cut here---------------start------------->8---
;; test.scm
(use-modules
 (foo))

(define (main _)
  (foo))

;; foo.scm
(define-module (foo)
  #:use-module (system vm debug)
  #:use-module (system vm frame)
  #:use-module (system vm program)
  #:export (foo))

(define (bar)
  (lambda () (throw 'bar)))

(define (foo)
  (catch #t
    (bar)
    (const #f)
    (lambda _
      (let ((stack (make-stack #t)))
        (let lp ((frame (stack-ref stack 0)))
          (when frame
            (let ((source (frame-source frame)))
              (pk
               (and=> source source:file)
               (and=> source source:line-for-user)
               (and=> source source:column)))
            (lp (frame-previous frame))))))))
--8<---------------cut here---------------end--------------->8---

Then `guile -L . -e main -s test.scm:

;;; note: source file ./foo.scm
;;;       newer than compiled /home/old/.cache/guile/ccache/3.0-LE-8-4.6/home/old/foo.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling ./foo.scm
;;; compiled /home/old/.cache/guile/ccache/3.0-LE-8-4.6/home/old/foo.scm.go

;;; (#f #f #f)

;;; ("foo.scm" 15 20)

;;; ("ice-9/boot-9.scm" 1780 13)

;;; ("ice-9/boot-9.scm" 1685 16)

;;; ("foo.scm" 8 13)

;;; ("ice-9/boot-9.scm" 1752 10)

;;; ("ice-9/boot-9.scm" 1747 15)

;;; ("ice-9/eval.scm" 619 8)

;;; ("ice-9/boot-9.scm" 724 2)

;;; (#f #f #f)

;;; ("ice-9/boot-9.scm" 1752 10)

See how the columns for foo.scm are weird:

foo.scm:15:20:
      (let ((stack (make-stack #t)))
                    ^

foo.scm:8:13:
  (lambda () (throw 'bar)))
             ^

When I would have expected the following:

foo.scm:15:20:
      (let ((stack (make-stack #t)))
                   ^

foo.scm:8:13:
  (lambda () (throw 'bar)))
        ^

Thanks,
Olivier
-- 
Olivier Dion
EfficiOS Inc.
https://www.efficios.com