From: "Ludovic Courtès" <ludo@gnu.org>
To: 58217@debbugs.gnu.org
Subject: bug#58217: tree-il->bytecode compilation of (not (list …)) fails
Date: Sat, 01 Oct 2022 12:27:30 +0200 [thread overview]
Message-ID: <87sfk7g7ot.fsf@inria.fr> (raw)
Hi,
I stumbled upon this bug of the baseline compiler:
--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (compile '(not (list 1 2)) #:optimization-level 2)
$3 = #f
scheme@(guile-user)> (compile '(not (list 1 2)) #:optimization-level 1)
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
In procedure struct-vtable: Wrong type argument in position 1 (expecting struct): #f
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> ,bt
In system/base/compile.scm:
352:28 5 (compile _ #:from _ #:to _ #:env _ #:optimization-level _ #:warning-level _ #:opts _)
265:44 4 (_ _ _)
261:27 3 (_ _ _)
In language/tree-il/compile-bytecode.scm:
1386:14 2 (compile-bytecode #<tree-il (primcall not (primcall list (const 1) (const 2)))> #<module (#{ g446}#) …> …)
412:30 1 (_ _)
In ice-9/boot-9.scm:
1685:16 0 (raise-exception _ #:continuable? _)
scheme@(guile-user) [1]> (version)
$4 = "3.0.8"
--8<---------------cut here---------------end--------------->8---
The exception is raised in the ‘predicate?’ call below, where
(lookup-primitive 'list) returns #f:
(define (finish-conditional exp)
(define (true? x) (match x (($ <const> _ val) val) (_ #f)))
(define (false? x) (match x (($ <const> _ val) (not val)) (_ #f)))
(define (predicate? name) (primitive-predicate? (lookup-primitive name)))
(match exp
(($ <conditional> src ($ <conditional> _ test (? true?) (? false?))
consequent alternate)
(finish-conditional (make-conditional src test consequent alternate)))
(($ <conditional> src ($ <conditional> _ test (? false?) (? true?))
consequent alternate)
(finish-conditional (make-conditional src test alternate consequent)))
(($ <conditional> src ($ <primcall> _ (? predicate?)))
exp)
(($ <conditional> src test consequent alternate)
(make-conditional src (make-primcall src 'false? (list test))
alternate consequent))))
I believe this is fixed by changing ‘predicate?’ to:
(define (predicate? name)
(and=> (lookup-primitive name) primitive-predicate?))
Thoughts?
Ludo’.
next reply other threads:[~2022-10-01 10:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-01 10:27 Ludovic Courtès [this message]
2022-10-01 14:02 ` bug#58217: tree-il->bytecode compilation of (not (list …)) fails Ludovic Courtès
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=87sfk7g7ot.fsf@inria.fr \
--to=ludo@gnu.org \
--cc=58217@debbugs.gnu.org \
/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).