GNU bug report logs - #52112
Compilation of macro returning record type fails

Previous Next

Package: guile;

Reported by: Jean Abou Samra <jean <at> abou-samra.fr>

Date: Thu, 25 Nov 2021 17:52:01 UTC

Severity: normal

To reply to this bug, email your comments to 52112 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#52112; Package guile. (Thu, 25 Nov 2021 17:52:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jean Abou Samra <jean <at> abou-samra.fr>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Thu, 25 Nov 2021 17:52:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jean Abou Samra <jean <at> abou-samra.fr>
To: bug-guile <at> gnu.org
Subject: Compilation of macro returning record type fails
Date: Thu, 25 Nov 2021 18:45:49 +0100
Record types are self-evaluating:

scheme@(guile-user)> (eval (make-record-type 'my-record '()) 
(current-module))
$1 = #<record-type my-record>

Yet, when a macro returns a record type, Guile fails
to byte-compile the code, even though the execution
(via the evaluator) works fine. Here is a simple example:


(define-macro (my-macro)
  (make-record-type 'my-record-2 '()))

(display (my-macro))
(newline)


Execution log:


$ guile --no-auto-compile test.scm
#<record-type my-record-2>

$ guile test.scm
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /home/jean/test.scm
;;; WARNING: compilation of /home/jean/test.scm failed:
;;; unhandled constant #<record-type my-record-2>
#<record-type my-record-2>

This is with Guile version 3.0.5.130-5a1e7.




Information forwarded to bug-guile <at> gnu.org:
bug#52112; Package guile. (Fri, 26 Nov 2021 18:55:01 GMT) Full text and rfc822 format available.

Message #8 received at 52112 <at> debbugs.gnu.org (full text, mbox):

From: Taylan Kammer <taylan.kammer <at> gmail.com>
To: Jean Abou Samra <jean <at> abou-samra.fr>, 52112 <at> debbugs.gnu.org
Subject: Re: bug#52112: Compilation of macro returning record type fails
Date: Fri, 26 Nov 2021 19:54:36 +0100
On 25.11.2021 18:45, Jean Abou Samra wrote:
> Record types are self-evaluating:
> 
> scheme@(guile-user)> (eval (make-record-type 'my-record '()) (current-module))
> $1 = #<record-type my-record>
> 
> Yet, when a macro returns a record type, Guile fails
> to byte-compile the code, even though the execution
> (via the evaluator) works fine. Here is a simple example:
> 
> 
> (define-macro (my-macro)
>   (make-record-type 'my-record-2 '()))
> 
> (display (my-macro))
> (newline)
> 
> 
> Execution log:
> 
> 
> $ guile --no-auto-compile test.scm
> #<record-type my-record-2>
> 
> $ guile test.scm
> ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
> ;;;       or pass the --no-auto-compile argument to disable.
> ;;; compiling /home/jean/test.scm
> ;;; WARNING: compilation of /home/jean/test.scm failed:
> ;;; unhandled constant #<record-type my-record-2>
> #<record-type my-record-2>
> 
> This is with Guile version 3.0.5.130-5a1e7.

I don't think that's supposed to work.  I find it surprising that
record-type objects are self-evaluating, and in any case they can't
be turned into bytecode.

Your macro could return code that evaluates to a record definition.
Would that solve your use-case?

-- 
Taylan




Information forwarded to bug-guile <at> gnu.org:
bug#52112; Package guile. (Fri, 26 Nov 2021 19:03:02 GMT) Full text and rfc822 format available.

Message #11 received at 52112 <at> debbugs.gnu.org (full text, mbox):

From: Jean Abou Samra <jean <at> abou-samra.fr>
To: Taylan Kammer <taylan.kammer <at> gmail.com>, 52112 <at> debbugs.gnu.org
Subject: Re: bug#52112: Compilation of macro returning record type fails
Date: Fri, 26 Nov 2021 20:02:39 +0100
Thanks for your reply.

Le 26/11/2021 à 19:54, Taylan Kammer a écrit :
> I don't think that's supposed to work.  I find it surprising that
> record-type objects are self-evaluating, and in any case they can't
> be turned into bytecode.
>
> Your macro could return code that evaluates to a record definition.
> Would that solve your use-case?


Yes, that is how I solved it in LilyPond
(https://gitlab.com/lilypond/lilypond/-/merge_requests/1026).

I was also somewhat surprised to see that
record types are self-evaluating. I don't
know where to check in R6RS what the expected
behavior would be. At any rate, it seems that
there is an inconsistency between the interpreter
and the compiler that would warrant resolving
either way.




This bug report was last modified 2 years and 362 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.