unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: BT Templeton <bpt@hcoop.net>
To: guile-devel@gnu.org
Subject: Re: [PATCH] primitive resolution for public refs
Date: Mon, 12 Mar 2012 14:03:06 -0400	[thread overview]
Message-ID: <87aa3l3det.fsf@olor.terpri.org> (raw)
In-Reply-To: CA+U71=Mdaf-xn=gHk-xsWOdySHbg8PQ=ELFuXAQB2DCC-ws=8Q@mail.gmail.com

Noah Lavine <noah.b.lavine@gmail.com> writes:

> Hello,
>
> Are you sure this is correct? What if someone calls the module-set!
> function on that module between the definition and use of whatever
> function you're compiling?
>
> I agree very strongly that we need to be able to do this sort of
> optimization, but I think we might need some sort of caching mechanism
> to do it right, where the cache of compiled function bodies is
> invalidated by module-set!.

I don't think I've changed the correctness wrt `module-set!' and the
like -- the current, private-refs-only optimization already exhibits the
problem you describe:

| scheme@(guile-user)> (define old-car car)
| scheme@(guile-user)> (module-set! (current-module)
|                                   'car
|                                   (lambda (x) (format #t "car ~A~%" x) (old-car x)))
| scheme@(guile-user)> ,x (lambda (x) ((@@ (guile) car) x))
| [...]
| Disassembly of #<procedure 1d23ae0 at <current input>:4:0 (x)>:
|   
|   0    (assert-nargs-ee/locals 1)      ;; 1 arg, 0 locals
|   2    (local-ref 0)                   ;; `x'
|   4    (car)
|   5    (return)

I'm not certain it's otherwise correct; I just added a workaround for
the specific issue mentioned in the comment.

> On Mon, Mar 12, 2012 at 12:42 PM, BT Templeton <bpt@hcoop.net> wrote:
>> * module/language/tree-il/primitives.scm (resolve-primitives!): Resolve
>>  public module-refs to primitives.
>> ---
>>  module/language/tree-il/primitives.scm |   16 +++++++++-------
>>  1 files changed, 9 insertions(+), 7 deletions(-)
>>
>> diff --git a/module/language/tree-il/primitives.scm b/module/language/tree-il/primitives.scm
>> index 3c6769d..1dcab20 100644
>> --- a/module/language/tree-il/primitives.scm
>> +++ b/module/language/tree-il/primitives.scm
>> @@ -265,13 +265,15 @@
>>                                (module-variable mod name)))
>>                (lambda (name) (make-primitive-ref src name))))
>>        ((<module-ref> src mod name public?)
>> -        ;; for the moment, we're disabling primitive resolution for
>> -        ;; public refs because resolve-interface can raise errors.
>> -        (let ((m (and (not public?) (resolve-module mod))))
>> -          (and m
>> -               (and=> (hashq-ref *interesting-primitive-vars*
>> -                                 (module-variable m name))
>> -                      (lambda (name) (make-primitive-ref src name))))))
>> +        (and=> (and=> (resolve-module mod)
>> +                      (if public?
>> +                          module-public-interface
>> +                          identity))
>> +               (lambda (m)
>> +                 (and=> (hashq-ref *interesting-primitive-vars*
>> +                                   (module-variable m name))
>> +                        (lambda (name)
>> +                          (make-primitive-ref src name))))))
>>        ((<call> src proc args)
>>         (and (primitive-ref? proc)
>>              (make-primcall src (primitive-ref-name proc) args)))
>> --
>> 1.7.9.1

-- 
Inteligenta persono lernas la lingvon Esperanton rapide kaj facile.
Esperanto estas moderna, kultura lingvo por la mondo. Simpla, fleksebla,
belsona, Esperanto estas la praktika solvo de la problemo de universala
interkompreno. Lernu la interlingvon Esperanton!




  reply	other threads:[~2012-03-12 18:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-12 16:42 [PATCH] primitive resolution for public refs BT Templeton
2012-03-12 17:17 ` Noah Lavine
2012-03-12 18:03   ` BT Templeton [this message]
2012-03-12 19:42     ` Noah Lavine
2012-03-12 21:05       ` BT Templeton
2012-03-16 11:22 ` Ludovic Courtès
2012-03-16 19:38   ` BT Templeton
2012-03-21 21:58     ` Ludovic Courtès
2012-04-09 21:16       ` BT Templeton

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=87aa3l3det.fsf@olor.terpri.org \
    --to=bpt@hcoop.net \
    --cc=guile-devel@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).