unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: Neil Jerram <neil@ossau.uklinux.net>
Cc: bug-guile@gnu.org, Ian Price <ianprice90@googlemail.com>,
	guile-devel <guile-devel@gnu.org>
Subject: Re: exit & dynamic wind
Date: Wed, 30 Mar 2011 23:25:39 +0200	[thread overview]
Message-ID: <m3ei5o1ess.fsf@unquote.localdomain> (raw)
In-Reply-To: <87mxkcfojs.fsf@ossau.uklinux.net> (Neil Jerram's message of "Wed, 30 Mar 2011 19:31:19 +0100")

On Wed 30 Mar 2011 20:31, Neil Jerram <neil@ossau.uklinux.net> writes:

> Andy Wingo <wingo@pobox.com> writes:
>
>>>> |   GEN    guile-procedures.texi
>>>> | guile: uncaught throw to wrong-type-arg: (#f Wrong type (expecting ~A): ~S (exact integer (#t #<catch-closure 9916c10> #<catch-closure 9916be0>)) ((#t #<catch-closure 9916c10> #<catch-closure 9916be0>)))
>>
>> This, it turns out, was something more pernicious, fixed in
>> 572eef50c2d902d34427945dd504ba03af666e48.
>
> Thanks for the fix.  I'm afraid I struggled to understand the change,
> though - although I admit it may be largely my fault, as I'm not up to
> speed with VM or prompt internals.  Nevertheless, would it perhaps be
> worth a bit more commenting or a test, for future readers?

As for explanations... Catch and throw are implemented using fluids and
prompt and abort.  (A discussion of that is here:
http://wingolog.org/archives/2010/02/14/sidelong-glimpses .)  An abort
can pass arguments to the prompt's abort handler.  It does so by pushing
those values and a number-of-values marker onto the Scheme stack, after
the Scheme and dynamic stacks are unwound to the prompt.  The prompt
then needs to pop off those values and pass them to the handler.

It so happens that this values-then-number-of-values convention is the
same convention as is used for multiple-value returns -- so for compiled
code what happens is that the compiler inlines the handler, and the VM
just does a multiple-value bind on the values from the stack.  (See
truncate-values in the VM instruction docs.)

That's what happens when `prompt' is compiled, as it is in eval.scm.
But before eval.scm is compiled, we use eval.c, which also has to have
support for prompt and abort; but it's necessarily a different
mechanism.  This commit fixed a bug in that mechanism: that instead of
looking for the number-of-values marker (the exact integer that it was
expecting) from the VM's stack, as unwound by the abort, it was looking
for it at the VM's stack-pointer as seen when the prompt was created --
which necessarily is below any values returned to the prompt's abort
handler.

We didn't see this issue before because compiling eval.scm did not cause
a `throw'.  Interesting, no?  But since I changed the implementation of
ensure-writable-dir to one that probably throws, we see this error.

Any other error that caused a `throw' to a `catch' to occur before
eval.scm was compiled probably caused this error in the past.  I don't
know if we had any reports of it; I wouldn't be surprised.  In any case,
a tricky bug, and a good one to have fixed.

We do have prompt and abort tests for the VM implementation.  We don't
run them with the boot evaluator, because we can't, not after eval.scm
is compiled -- and anyway, now compilation causes throws at times, so
we'll pick up these issues from users if it comes back.

Hope that explains things :)

Andy
-- 
http://wingolog.org/



  reply	other threads:[~2011-03-30 21:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-22 13:26 exit & dynamic wind Ian Price
2011-03-24 19:23 ` Andy Wingo
2011-03-25  1:52   ` Neil Jerram
2011-03-25 16:45     ` Andy Wingo
2011-03-30 10:45       ` Andy Wingo
2011-03-30 18:31         ` Neil Jerram
2011-03-30 21:25           ` Andy Wingo [this message]
2011-03-30 21:43             ` Andy Wingo
2011-03-30 21:54             ` Neil Jerram
  -- strict thread matches above, loose matches on Subject: below --
2011-03-30 19:06 Mike Gran
2011-03-30 21:28 ` Andy Wingo

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=m3ei5o1ess.fsf@unquote.localdomain \
    --to=wingo@pobox.com \
    --cc=bug-guile@gnu.org \
    --cc=guile-devel@gnu.org \
    --cc=ianprice90@googlemail.com \
    --cc=neil@ossau.uklinux.net \
    /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).