From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: BT Templeton Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] primitive resolution for public refs Date: Mon, 12 Mar 2012 14:03:06 -0400 Message-ID: <87aa3l3det.fsf@olor.terpri.org> References: <87haxt3h53.fsf@olor.terpri.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1331575440 30778 80.91.229.3 (12 Mar 2012 18:04:00 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 12 Mar 2012 18:04:00 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Mar 12 19:04:00 2012 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1S79b9-0003Pw-Sp for guile-devel@m.gmane.org; Mon, 12 Mar 2012 19:03:56 +0100 Original-Received: from localhost ([::1]:36692 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S79b9-0007la-7o for guile-devel@m.gmane.org; Mon, 12 Mar 2012 14:03:55 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:52609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S79ai-0007jd-O5 for guile-devel@gnu.org; Mon, 12 Mar 2012 14:03:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S79ac-0005PU-5b for guile-devel@gnu.org; Mon, 12 Mar 2012 14:03:28 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:38879) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S79ab-0005P9-Rt for guile-devel@gnu.org; Mon, 12 Mar 2012 14:03:22 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1S79aa-00034z-0O for guile-devel@gnu.org; Mon, 12 Mar 2012 19:03:20 +0100 Original-Received: from cpe-071-070-253-241.nc.res.rr.com ([71.70.253.241]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 12 Mar 2012 19:03:20 +0100 Original-Received: from bpt by cpe-071-070-253-241.nc.res.rr.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 12 Mar 2012 19:03:20 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 75 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: cpe-071-070-253-241.nc.res.rr.com User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.94 (gnu/linux) Cancel-Lock: sha1:vt8caqf5/ucv9apjjJ9P1rrCWQQ= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:14088 Archived-At: Noah Lavine 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 #: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 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)))) >>        (( 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)))))) >>        (( 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!