From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@chbouib.org (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: slowness in guile 1.8 Date: Sat, 26 May 2007 16:45:17 +0200 Message-ID: <87k5uviqyq.fsf@chbouib.org> References: <1180110804.4388.16.camel@localhost.localdomain> <87tzu0pybk.fsf@chbouib.org> <1180176594.4388.29.camel@localhost.localdomain> <87sl9jn2tl.fsf@chbouib.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1180190771 5547 80.91.229.12 (26 May 2007 14:46:11 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 26 May 2007 14:46:11 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat May 26 16:46:09 2007 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HrxWy-0000cM-00 for guile-devel@m.gmane.org; Sat, 26 May 2007 16:46:08 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HrxWx-0002m9-7k for guile-devel@m.gmane.org; Sat, 26 May 2007 10:46:07 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HrxWt-0002kx-9N for guile-devel@gnu.org; Sat, 26 May 2007 10:46:03 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HrxWs-0002ja-Dg for guile-devel@gnu.org; Sat, 26 May 2007 10:46:02 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HrxWs-0002jA-1s for guile-devel@gnu.org; Sat, 26 May 2007 10:46:02 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1HrxWr-0003sy-8s for guile-devel@gnu.org; Sat, 26 May 2007 10:46:01 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1HrxWc-0002Vk-O2 for guile-devel@gnu.org; Sat, 26 May 2007 16:45:46 +0200 Original-Received: from adh419.fdn.fr ([80.67.176.9]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 26 May 2007 16:45:46 +0200 Original-Received: from ludo by adh419.fdn.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 26 May 2007 16:45:46 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 160 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: adh419.fdn.fr X-URL: http://www.laas.fr/~lcourtes/ X-PGP-Key-ID: 0xEB1F5364 X-PGP-Key: http://www.laas.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 821D 815D 902A 7EAB 5CEE D120 7FBA 3D4F EB1F 5364 X-OS: i486-pc-linux-gnu User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:1OwS9xa2KhOMteIyzOuHK1Oxj1M= X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:6620 Archived-At: --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Hi, ludo@chbouib.org (Ludovic Courtès) writes: > Actually, no: the test does a `define' _within_ the body of `begin', so > I *think* this qualifies as an internal define, and internal defines are > equivalent to `letrec' (Section 5.2.2). I was wrong: `define' within `begin' does not qualify as an "internal define", so the test "binding is created before expression is evaluated" was incorrect (or over-specified compared to R5RS[*]). After further discussion with Andy, I committed the patch below to HEAD. It inverts the order of expression evaluation and `scm_sym2var' in `scm_m_define ()' (which is concerned only with top-level defines), thereby fixing the `(define round round)' case. At the same time, it breaks the aforementioned test from `syntax.test', but there's nothing wrong with that. For 1.8, I'm pretty much inclined to commit a similar patch, i.e., where `module-make-local-var!' and `scm_m_define' are copied from HEAD. This would break code that does things like: (define foo (begin (set! foo 1) (+ foo 1))) but I think it's reasonable to break such code (which relies on non-R5RS-compliant behavior anyway), especially given the performance gain we get in return. What do you think? Thanks, Ludovic. [*] FWIW, the wording for `define' in the newly-released R5.93RS (Section 9.3.1) is the same as that of R5RS (Section 5.2.1). --=-=-= Content-Type: text/x-patch; charset=iso-8859-1 Content-Disposition: inline; filename*=us-ascii''%2c%2cdefine-round-round.diff Content-Transfer-Encoding: 8bit Content-Description: The fix for `(define round round)' in HEAD --- orig/libguile/ChangeLog +++ mod/libguile/ChangeLog @@ -1,3 +1,9 @@ +2007-05-26 Ludovic Courtès + + * eval.c (scm_m_define): Updated comment. Changed order for value + evaluation and `scm_sym2var ()' call, which is perfectly valid per + R5RS. This reverts the change dated 2004-04-22 by Dirk Herrmann. + 2007-05-05 Ludovic Courtès Implemented lazy duplicate binding handling. --- orig/libguile/eval.c +++ mod/libguile/eval.c @@ -1209,10 +1209,11 @@ return expr; } -/* According to section 5.2.1 of R5RS we first have to make sure that the - * variable is bound, and then perform the (set! variable expression) - * operation. This means, that within the expression we may already assign - * values to variable: (define foo (begin (set! foo 1) (+ foo 1))) */ +/* According to Section 5.2.1 of R5RS we first have to make sure that the + variable is bound, and then perform the `(set! variable expression)' + operation. However, EXPRESSION _can_ be evaluated before VARIABLE is + bound. This means that EXPRESSION won't necessarily be able to assign + values to VARIABLE as in `(define foo (begin (set! foo 1) (+ foo 1)))'. */ SCM scm_m_define (SCM expr, SCM env) { @@ -1222,9 +1223,9 @@ const SCM canonical_definition = canonicalize_define (expr); const SCM cdr_canonical_definition = SCM_CDR (canonical_definition); const SCM variable = SCM_CAR (cdr_canonical_definition); + const SCM value = scm_eval_car (SCM_CDR (cdr_canonical_definition), env); const SCM location = scm_sym2var (variable, scm_env_top_level (env), SCM_BOOL_T); - const SCM value = scm_eval_car (SCM_CDR (cdr_canonical_definition), env); if (SCM_REC_PROCNAMES_P) { --- orig/test-suite/ChangeLog +++ mod/test-suite/ChangeLog @@ -1,3 +1,11 @@ +2007-05-26 Ludovic Courtès + + * tests/syntax.test (top-level define)[binding is created before + expression is evaluated]: Moved to "internal define", using `let' + instead of `begin'. The test was not necessarily valid for + top-level defines, according to Section 5.2.1 or R5RS. + [redefinition]: New. + 2007-05-09 Ludovic Courtès * tests/srfi-19.test ((current-time time-tai) works): Use `time?'. --- orig/test-suite/tests/syntax.test +++ mod/test-suite/tests/syntax.test @@ -725,15 +725,16 @@ (with-test-prefix "top-level define" - (pass-if "binding is created before expression is evaluated" - (= (eval '(begin - (define foo - (begin - (set! foo 1) - (+ foo 1))) - foo) - (interaction-environment)) - 2)) + (pass-if "redefinition" + (let ((m (make-module))) + (beautify-user-module! m) + + ;; The previous value of `round' must still be visible at the time the + ;; new `round' is defined. According to R5RS (Section 5.2.1), `define' + ;; should behave like `set!' in this case (except that in the case of + ;; Guile, we respect module boundaries). + (eval '(define round round) m) + (eq? (module-ref m 'round) round))) (with-test-prefix "currying" @@ -780,6 +781,17 @@ (eq? 'c (a 2) (a 5)))) (interaction-environment))) + (pass-if "binding is created before expression is evaluated" + ;; Internal defines are equivalent to `letrec' (R5RS, Section 5.2.2). + (= (eval '(let () + (define foo + (begin + (set! foo 1) + (+ foo 1))) + foo) + (interaction-environment)) + 2)) + (pass-if "internal defines with begin" (false-if-exception (eval '(let ((a identity) (b identity) (c identity)) --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel --=-=-=--