* Enable truncation of exception output
@ 2017-02-03 13:40 Daniel Llorens
2017-03-10 8:47 ` Andy Wingo
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Llorens @ 2017-02-03 13:40 UTC (permalink / raw)
To: guile-devel
(I've messed up with git send-email, the patch with this email is
at http://lists.gnu.org/archive/html/guile-devel/2017-02/msg00008.html).
Some objects have large printed representations and trying to print
them can kill the terminal. This is a serious problem when handling
e.g. big arrays.
For repl values there's (repl-default-option-set! 'print (lambda (val)
...)) which lets you override the default printing routine. But for
exceptions there's no equivalent. The default exception printers are
in (ice-9 boot-9) and are difficult to override. Besides, the format
of the exception output is often chosen by arguments to scm-error and
not by those printers.
The patch to master (ice-9 boot-9) lets you override the (format) used
internally by the exception printers. Then I rewrite the format string
in user code, see below. It's a bit hacky, maybe someone has a better
solution.
See also the other patch I've posted to the list to support arrays in
(truncated-print). The patches are independent, but they make each
other useful so to speak.
Regards
Daniel
(In the code below for .guile, replace [AT] by the at symbol).
; Truncate output on exceptions. Requires exception-format in ice-9/boot.scm.
; FIXME doesn't handle e.g. "x~~~s" -> "x~~~[AT]y"
(define (rewrite-fmt fmt)
(let loop ((f "") (b 0))
(let ((next (string-contains-ci fmt "~s" b)))
(if next
(loop
(if (or (zero? next) (not (char=? #\~ (string-ref fmt (- next 1)))))
(string-append f (substring fmt 0 next) "~[AT]y")
fmt)
(+ b next 2))
(string-append f (substring fmt b))))))
(when (defined? 'exception-format)
(set! exception-format
(lambda (port fmt . args)
(apply format port (rewrite-fmt fmt) args))))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Enable truncation of exception output
2017-02-03 13:40 Enable truncation of exception output Daniel Llorens
@ 2017-03-10 8:47 ` Andy Wingo
2017-03-10 9:07 ` Ludovic Courtès
2017-03-10 9:12 ` Daniel Llorens
0 siblings, 2 replies; 5+ messages in thread
From: Andy Wingo @ 2017-03-10 8:47 UTC (permalink / raw)
To: Daniel Llorens; +Cc: guile-devel
On Fri 03 Feb 2017 14:40, Daniel Llorens <daniel.llorens@bluewin.ch> writes:
> The patch to master (ice-9 boot-9) lets you override the (format) used
> internally by the exception printers. Then I rewrite the format string
> in user code, see below. It's a bit hacky, maybe someone has a better
> solution.
>
> See also the other patch I've posted to the list to support arrays in
> (truncated-print). The patches are independent, but they make each
> other useful so to speak.
I have a crazy idea :) What about, we just let (ice-9 format) be
"format" ? Right now loading (ice-9 format) does a set! to format, as
you know, overriding the core binding. This is unnecessary and
complicated. I see that using (ice-9 format) only adds 50 KB to the
2828-KB baseline of private dirty memory. Then we can use :@y
directly in the format strings and we can avoid all the monkeypatching.
There are only a couple instances of calls to scm_simple_format in
libguile and they can be replaced, so we don't have C bootstrapping
concerns. Guile users calling scm_simple_format would do a pthread_once
load to the "format" binding in the root module. In boot-9, we start
with a simple boot definition (for boot-time errors) then replace it
with (module-ref (resolve-interface '(ice-9 format) 'format)) at the
end.
Maybe Ludovic has a thought here :)
Andy
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Enable truncation of exception output
2017-03-10 8:47 ` Andy Wingo
@ 2017-03-10 9:07 ` Ludovic Courtès
2017-03-10 9:17 ` Andy Wingo
2017-03-10 9:12 ` Daniel Llorens
1 sibling, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2017-03-10 9:07 UTC (permalink / raw)
To: guile-devel
Hello!
Andy Wingo <wingo@pobox.com> skribis:
> On Fri 03 Feb 2017 14:40, Daniel Llorens <daniel.llorens@bluewin.ch> writes:
>
>> The patch to master (ice-9 boot-9) lets you override the (format) used
>> internally by the exception printers. Then I rewrite the format string
>> in user code, see below. It's a bit hacky, maybe someone has a better
>> solution.
>>
>> See also the other patch I've posted to the list to support arrays in
>> (truncated-print). The patches are independent, but they make each
>> other useful so to speak.
>
> I have a crazy idea :) What about, we just let (ice-9 format) be
> "format" ? Right now loading (ice-9 format) does a set! to format, as
> you know, overriding the core binding. This is unnecessary and
> complicated. I see that using (ice-9 format) only adds 50 KB to the
> 2828-KB baseline of private dirty memory. Then we can use :@y
> directly in the format strings and we can avoid all the monkeypatching.
>
> There are only a couple instances of calls to scm_simple_format in
> libguile and they can be replaced, so we don't have C bootstrapping
> concerns. Guile users calling scm_simple_format would do a pthread_once
> load to the "format" binding in the root module. In boot-9, we start
> with a simple boot definition (for boot-time errors) then replace it
> with (module-ref (resolve-interface '(ice-9 format) 'format)) at the
> end.
>
> Maybe Ludovic has a thought here :)
I’d be in favor of something more conservative, notably because
‘simple-format’ remains faster than ‘format’:
1. Remove ‘set!’ in (ice-9 format), which has always been a bad idea.
-Wformat behaves as if this ‘set!’ wasn’t in place (that is, it
warns you if you’re using “extended” functionality but haven’t
explicitly imported (ice-9 format)), so I suspect little code will
break.
Then (ice-9 format) can #:replace (format) instead of #:export.
2. For exception printers, use some autoload magic, just like we do
for the debugger.
How does that sound? I believe this should work no?
Ludo’.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Enable truncation of exception output
2017-03-10 8:47 ` Andy Wingo
2017-03-10 9:07 ` Ludovic Courtès
@ 2017-03-10 9:12 ` Daniel Llorens
1 sibling, 0 replies; 5+ messages in thread
From: Daniel Llorens @ 2017-03-10 9:12 UTC (permalink / raw)
To: Andy Wingo; +Cc: guile-devel
On 10 Mar 2017, at 09:47, Andy Wingo <wingo@pobox.com> wrote:
> I have a crazy idea :) What about, we just let (ice-9 format) be
> "format" ? Right now loading (ice-9 format) does a set! to format, as
> you know, overriding the core binding. This is unnecessary and
> complicated. I see that using (ice-9 format) only adds 50 KB to the
> 2828-KB baseline of private dirty memory. Then we can use :@y
> directly in the format strings and we can avoid all the monkeypatching.
This change would make things simpler, but it wouldn't solve the problem we had. Sometimes you want the full error printed out and sometimes you do not. It's a decision that should be made in ~/.guile or at the REPL or at the call site, not when you code the scm_error call.
Daniel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Enable truncation of exception output
2017-03-10 9:07 ` Ludovic Courtès
@ 2017-03-10 9:17 ` Andy Wingo
0 siblings, 0 replies; 5+ messages in thread
From: Andy Wingo @ 2017-03-10 9:17 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guile-devel
Hi :)
On Fri 10 Mar 2017 10:07, ludo@gnu.org (Ludovic Courtès) writes:
> I’d be in favor of something more conservative, notably because
> ‘simple-format’ remains faster than ‘format’:
Ah indeed. simple-format does appear to be much faster.
Tested using:
(define-syntax-rule (do-times count exp) (let lp ((n 0)) (when (< n count) exp (lp (1+ n)))))
,time (string-length (call-with-output-string (lambda (p) (do-times #e1e4 (format p "foo")))))
and for simple-format too, and when adding a ~a.
Clearly the answer here is to work on improving the performance of
"format" :)
> 1. Remove ‘set!’ in (ice-9 format), which has always been a bad idea.
This is *not* conservative. We would certainly break users' code with
this. I know there's -Wformat but still :)
> 2. For exception printers, use some autoload magic, just like we do
> for the debugger.
This is hard for boot reasons -- you might get an exception before you
are able to load modules. Of course this doesn't happen in the normal
case but it would make Guile hacking a bit harder. Still, perhaps it is
possible.
Andy
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-03-10 9:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-03 13:40 Enable truncation of exception output Daniel Llorens
2017-03-10 8:47 ` Andy Wingo
2017-03-10 9:07 ` Ludovic Courtès
2017-03-10 9:17 ` Andy Wingo
2017-03-10 9:12 ` Daniel Llorens
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).