unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [BUG] Eval sets incorrect runtime metainformation
@ 2024-06-25 15:07 Andrew Tropin
  2024-06-26  9:24 ` Andy Wingo
  0 siblings, 1 reply; 14+ messages in thread
From: Andrew Tropin @ 2024-06-25 15:07 UTC (permalink / raw)
  To: guile-devel, Andy Wingo

[-- Attachment #1: Type: text/plain, Size: 3605 bytes --]

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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-07-06 18:56 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-25 15:07 [BUG] Eval sets incorrect runtime metainformation Andrew Tropin
2024-06-26  9:24 ` Andy Wingo
2024-06-26  9:36   ` Maxime Devos
2024-06-26 11:41     ` Andrew Tropin
2024-06-26 22:06       ` Philip McGrath
2024-06-28 13:20         ` Andrew Tropin
2024-06-29 19:55           ` Philip McGrath
2024-06-29 23:05         ` Maxime Devos
2024-06-30 22:27           ` Philip McGrath
2024-07-01  9:06             ` Maxime Devos
2024-07-06 16:42             ` Rob Browning
2024-07-06 18:56             ` Matt Wette
2024-06-26 16:04     ` Andy Wingo
2024-06-28 13:27       ` Andrew Tropin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).