unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Noah Lavine <noah.b.lavine@gmail.com>
To: Mark H Weaver <mhw@netris.org>
Cc: Andy Wingo <wingo@pobox.com>, guile-devel@gnu.org
Subject: Re: GNU Guile branch, wip-peval-predicates, created. v2.0.5-100-g59c5570
Date: Fri, 13 Apr 2012 11:18:36 -0400	[thread overview]
Message-ID: <CA+U71=OuQ_ikmNckEDqNoZXN7wy7zWUDiung04874UgzGG0yXw@mail.gmail.com> (raw)
In-Reply-To: <87zkaf4sov.fsf@netris.org>

At first I thought you were right. But then I realized there's an even
deeper problem here. Imagine implementing a record mutator like this:

(define (set-foo-a! foo new-value)
  (if (is-foo? foo)
     (%unsafe-set-foo-a! foo new-value)
     (error)))

That code is incorrect, by the same logic you used: something could
change the class of foo in between the is-foo? call and the
%unsafe-set-foo-a! call. You need some atomic check-and-set operation
in order to do this safely.

Unfortunately, I don't see a correct way short of some sort of mutex.
A mutex for each record would be a lot of overhead, but what about a
mutex per class, that has to be acquired to change any instance of the
class to or from a different class? Changing a class is a rare enough
operation that we should not optimize for it, I think. Also, if we had
such a mutex, we could use it to eliminate redundant struct-vtable
checks correctly, by acquiring it at the beginning of a function and
releasing it at the end.

I'm somewhat afraid, however, that the real solution is changing how
we deal with parallelism, and that is a much bigger problem.

Noah

On Fri, Apr 13, 2012 at 10:22 AM, Mark H Weaver <mhw@netris.org> wrote:
> Hi Andy,
>
>> commit 59c557056cff1ce6146b4d689eeee922300b6278
>> Author: Andy Wingo <wingo-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org>
>> Date:   Tue Apr 10 15:56:23 2012 -0700
>>
>>     peval: elide redundant predicates; eliminate some common subexpressions
>>
>>     * module/language/tree-il/peval.scm (fold-constants): Returns #f instead
>>       of the expression, as all continuations handle #f themselves.
>>       (negate, bailout?, extract-facts, infer, infer-defined?)
>>       (infer-struct-vtable): New helpers.
>
> I haven't looked at the code, but it sounds like you are trying to
> eliminate redundant 'struct-vtable' checks.  Unfortunately, it seems to
> me that this cannot be done safely.  In practice, the checks look like:
>
>  (eq? (struct-vtable s) <foo>)
>
> Both of the values being compared here are fetched from mutable
> locations.  The 'struct-vtable' field is mutable, and <foo> is usually a
> top-level variable that is also mutable.  Furthermore, both of these
> things are mutated in practice when a GOOPS class is redefined, IIUC.
>
> Am I missing something?
>
>    Thanks,
>      Mark
>



  reply	other threads:[~2012-04-13 15:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <E1SHjzo-0005oe-8t@vcs.savannah.gnu.org>
2012-04-13 14:22 ` GNU Guile branch, wip-peval-predicates, created. v2.0.5-100-g59c5570 Mark H Weaver
2012-04-13 15:18   ` Noah Lavine [this message]
2012-04-13 19:59     ` Ludovic Courtès
2012-04-13 20:36       ` Noah Lavine
2012-04-13 16:28   ` Andy Wingo
2012-04-13 17:07     ` Mark H Weaver
2012-04-15  0:28       ` Andy Wingo
2012-04-15  7:53         ` David Kastrup
2012-04-15 21:26         ` Ludovic Courtès
2012-04-16  6:36           ` David Kastrup

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='CA+U71=OuQ_ikmNckEDqNoZXN7wy7zWUDiung04874UgzGG0yXw@mail.gmail.com' \
    --to=noah.b.lavine@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=mhw@netris.org \
    --cc=wingo@pobox.com \
    /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).