unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Maxime Devos <maximedevos@telenet.be>
To: "Ludovic Courtès" <ludo@gnu.org>, guile-devel@gnu.org
Subject: Re: [PATCH] Print backtraces for syntax errors too.
Date: Sat, 25 Feb 2023 00:38:50 +0100	[thread overview]
Message-ID: <308e0731-1532-b39a-d169-eace8fe30019@telenet.be> (raw)
In-Reply-To: <871qmf2hfb.fsf@gnu.org>


[-- Attachment #1.1.1: Type: text/plain, Size: 3244 bytes --]



On 24-02-2023 16:48, Ludovic Courtès wrote:
> Maxime Devos <maximedevos@telenet.be> skribis:
> 
>> ;; Before:
>> ;;  unknown file:#f:#f: syntax-stuff-twice: bad in subform
>>      #<syntax:reproducer.scm:15:27 "imagine this syntax is very hard to
>>      follow"> of #<syntax:reproducer.scm:15:27 "imagine this syntax is
>>      very hard to follow">
>> ;; After:
>> ;;  [the same thing]
>> ;;
>> ;; Looks like another patch is needed ...
> 
> What backtrace are you trying to get?
> 
> Getting a backtrace showing which macros are being expanded (similar to
> what GCC does) would be great, but it’s much more work; changing this
> one line in libguile won’t achieve that.

Just a regular backtrace like Guile already makes for exceptions 
unrelated to syntax, not some kind of expansion backtrace that tracks 
macro expansion.

For example, let's say you have a macro that during expansion throws an 
exception in some cases.  For non-'syntax-error' exception types, a 
backtrace is printed:

;; a.scm
(define-module (a) #:export (whatever))
(define (syntax-negate s)
   (syntax-case s ()
     (#false #true)
     (#true #false)
     (_ (error "bogus!")))) ; <--- line 6!
(define (syntax-identity s) ; identity
   (syntax-case s ()
     (#false #'#false)
     (#true #'#true)
     (_ (error "bogus!"))))
(define-syntax whatever
   (lambda (s)
     (syntax-case s ()
       ((_ x) #`(#,(syntax-negate #'x) #,(syntax-identity #'x))))))
;; b.scm
(use-modules (a))
(whatever 0)
;; Shell commands
guild compile a.scm
guild compile -L . b.scm
;; Output: a backtrace that mentions on which line of a.scm things went 
wrong:
Backtrace:
[Lots of lines]
In ice-9/psyntax.scm:
[More lines]
In a.scm:
       6:7  1 (_ _)
In ice-9/boot-9.scm:
   1685:16  0 (raise-exception _ #:continuable? _)

ice-9/boot-9.scm:1685:16: In procedure raise-exception:
bogus!

However, suppose I removed the (_ (error "bogus!")) lines and hence the 
code produces syntax-error exceptions:

;; c.scm
(define-module (c) #:export (whatever))
(define (syntax-negate s)
   (syntax-case s () ; L3
     (#false #true)
     (#true #false)))
(define (syntax-identity s) ; identity
   (syntax-case s () ; L7
     (#false #'#false)
     (#true #'#true)))
(define-syntax whatever
   (lambda (s)
     (syntax-case s ()
       ((_ x) #`(#,(syntax-negate #'x) #,(syntax-identity #'x))))))
;; d.scm
(use-modules (c))
(whatever 0)
;; Shell commands
guild compile c.scm
guild compile -L . d.scm
;; Output: no backtrace at all!
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Syntax error:
d.scm:2:10: source expression failed to match any pattern in form 0
;; In case of complicated macros, it would be nice if it said _which_
;; pattern matcher failed: L3, or L7, like with a.scm+b.scm.

Summarised, I want the relatively nice backtrace that happens for 
non-'syntax-error' exceptions from a.scm+b.scm (*) (it's verbose, has 
lots of irrelevant stuff, but ultimately it provides an useful piece of 
information: the line number on which a pattern matcher failed).

(*) Ideally you would have both the backtrace _and_ the line number in 
b.scm/d.scm.

Greetings,
Maxime.

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

      reply	other threads:[~2023-02-24 23:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-08 15:59 [PATCH] Print backtraces for syntax errors too Maxime Devos
2023-02-23 11:38 ` Ludovic Courtès
2023-02-23 19:04   ` Maxime Devos
2023-02-23 19:10   ` Maxime Devos
2023-02-23 19:27   ` Maxime Devos
2023-02-24 15:48     ` Ludovic Courtès
2023-02-24 23:38       ` Maxime Devos [this message]

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=308e0731-1532-b39a-d169-eace8fe30019@telenet.be \
    --to=maximedevos@telenet.be \
    --cc=guile-devel@gnu.org \
    --cc=ludo@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).