guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[BUG] Eval sets incorrect runtime metainformation


From: Andrew Tropin
Subject: [BUG] Eval sets incorrect runtime metainformation
Date: Tue, 25 Jun 2024 19:07:22 +0400

TLDR: primitive-eval ignores information provided by reader.

There are two identical snippets of code, which differ only in keyword
argument `compile?` value.  When compile? is set to #t, metainformation
for procedure is correct, but when it is set to #f resulting data is
different :)

--8<---------------cut here---------------start------------->8---
(define-module (2024-06-25-eval-string-metadata))

(use-modules (system vm program)
             (ice-9 eval-string))

(eval-string "(define (test-fn) 'hey)"
             #:module (current-module)
             #:file "hello.scm"
             #:line 1
             #:column 1
             #:compile? #f)

(format #t "~a\n" (program-sources test-fn))
;; ((0 ice-9/eval.scm 329 . 13) (12 ice-9/eval.scm 330 . 21) (44 ice-9/eval.scm 
330 . 15))

(eval-string "(define (test-fn) 'hey)"
             #:module (current-module)
             #:file "hello.scm"
             #:line 1
             #:column 1
             #:compile? #t)

(format #t "~a\n" (program-sources test-fn))
;; ((0 hello.scm 1 . 1) (12 hello.scm 1 . 19))

(exit 0)
--8<---------------cut here---------------end--------------->8---


To track down the issue, I simplified the code a bit and removed
unecessary wrappers, the resulting snippet looks like this:

--8<---------------cut here---------------start------------->8---
(use-modules (system base language)
             (system vm program))

(call-with-input-string
 "(define (hello) 'hey)"
 (lambda (port)
   (set-port-filename! port "test.scm")
   (set-port-line! port 100)
   (set-port-column! port 0)

   (let ((reader (language-reader (lookup-language (current-language))))
         (eval (language-evaluator (lookup-language (current-language)))))
     (eval (pk (reader port (current-module))) (current-module)))))

(format #t "~a\n" (program-sources hello))
;;; (#<syntax:test.scm:101:0 (#<syntax:test.scm:101:1 define> 
#<syntax:test.scm:101:8 (#<syntax:test.scm:101:9 hello>)> 
#<syntax:test.scm:101:16 (quote #<syntax:test.scm:101:17 hey>)>)>)
;; ((0 ice-9/eval.scm 329 . 13) (12 ice-9/eval.scm 330 . 21) (44 ice-9/eval.scm 
330 . 15))
--8<---------------cut here---------------end--------------->8---

The reader keeps all metainformation obtained from port, so the issue is
in the eval phase.

The problem is in language-evaluator (primitive-eval in our case), which
just ignores all the info from reader.

--8<---------------cut here---------------start------------->8---
(use-modules (system vm program))
(primitive-eval '(define (hello) 'hey))
(format #t "~a\n" (program-sources hello))
;; ((0 ice-9/eval.scm 329 . 13) (12 ice-9/eval.scm 330 . 21) (44 ice-9/eval.scm 
330 . 15))
--8<---------------cut here---------------end--------------->8---

It leads to several shortcomings: the inability to utilize the built-in
eval for implementing interactive development tooling (IDEs with proper
eval and goto definition functionality, interactive test runners and
debuggers) and do other programmatic interactions with the running Guile
process.  I want to bring more attention to this issue, because it can
have serious negative impact on the guile ecosystem.

The another related problem is that the metainformation is stored in
prodecures properties, but not in variables, which makes it impossible
to implement a proper goto definition in general case.

Would be glad to cooperate on improving all of those points 👆 and would
be twice as glad to get some guidance or hear a word of encouragement.

-- 
Best regards,
Andrew Tropin

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]