From: Andrew Tropin <andrew@trop.in>
To: guile-devel@gnu.org, Andy Wingo <wingo@igalia.com>
Subject: [BUG] Eval sets incorrect runtime metainformation
Date: Tue, 25 Jun 2024 19:07:22 +0400 [thread overview]
Message-ID: <87bk3pkqmt.fsf@trop.in> (raw)
[-- 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 --]
next reply other threads:[~2024-06-25 15:07 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-25 15:07 Andrew Tropin [this message]
2024-06-26 9:24 ` [BUG] Eval sets incorrect runtime metainformation 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bk3pkqmt.fsf@trop.in \
--to=andrew@trop.in \
--cc=guile-devel@gnu.org \
--cc=wingo@igalia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).