From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ian Price Newsgroups: gmane.lisp.guile.bugs Subject: bug#15533: optimizing away noticeable effects Date: Wed, 23 Oct 2013 11:16:31 +0100 Message-ID: <87li1kxpfk.fsf@Kagami.home> References: <87bo33cybo.fsf@Kagami.home> <87ioxba2el.fsf@netris.org> <87eh7za1ko.fsf@netris.org> <871u3yaoor.fsf@netris.org> <87siwe97gy.fsf@netris.org> <877gdpc96f.fsf@Kagami.home> <8738obd6u6.fsf@Kagami.home> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1382523434 11559 80.91.229.3 (23 Oct 2013 10:17:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 23 Oct 2013 10:17:14 +0000 (UTC) Cc: 15533@debbugs.gnu.org To: Mark H Weaver Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Wed Oct 23 12:17:19 2013 Return-path: Envelope-to: guile-bugs@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 1VYvV8-0006tv-NE for guile-bugs@m.gmane.org; Wed, 23 Oct 2013 12:17:18 +0200 Original-Received: from localhost ([::1]:48556 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VYvV6-0000fP-3F for guile-bugs@m.gmane.org; Wed, 23 Oct 2013 06:17:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VYvUx-0000f9-Qd for bug-guile@gnu.org; Wed, 23 Oct 2013 06:17:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VYvUt-0005Ul-CB for bug-guile@gnu.org; Wed, 23 Oct 2013 06:17:07 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:51303) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VYvUt-0005Uf-6n for bug-guile@gnu.org; Wed, 23 Oct 2013 06:17:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1VYvUs-0000Z1-F3 for bug-guile@gnu.org; Wed, 23 Oct 2013 06:17:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ian Price Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 23 Oct 2013 10:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 15533 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 15533-submit@debbugs.gnu.org id=B15533.13825234072139 (code B ref 15533); Wed, 23 Oct 2013 10:17:02 +0000 Original-Received: (at 15533) by debbugs.gnu.org; 23 Oct 2013 10:16:47 +0000 Original-Received: from localhost ([127.0.0.1]:37089 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VYvUc-0000YL-RC for submit@debbugs.gnu.org; Wed, 23 Oct 2013 06:16:47 -0400 Original-Received: from mail-wi0-f175.google.com ([209.85.212.175]:46947) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VYvUa-0000Y5-5D for 15533@debbugs.gnu.org; Wed, 23 Oct 2013 06:16:45 -0400 Original-Received: by mail-wi0-f175.google.com with SMTP id hm4so7065315wib.14 for <15533@debbugs.gnu.org>; Wed, 23 Oct 2013 03:16:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=TbwUEbQfMjPH1fE0p16vzoMaqtso1CEg0fV88+uSV58=; b=nkpv0BMpMppukUzAys+5gRSiYCSGOWheH5M75g3qgko6y4CqFogTxgFExiKizxhLj8 iBoQx/dzxrvsWVZLuC58DWQgFSPYbgqmrS1slZR19gyKEQ9tL1uygAf5/oXEepa6cW48 FS9Kpk0yykiF1BLkq4uMBGZXS7xyY6bGfCUhDTB45Pjbla3WRm+ortviSGftepYKcaO+ NiTwUTweGYOzfygo5cf7ofsNn/DipdnXVU5JRNwGlppb7EQO0l1Cx4vcYlskKZRNBT0Z Md5+cxj7UpdnpcG+ZXabiLfiv5uzNJgwKxn358vs/4uBPoX+UEICsFR6rDKzKoKETruB zsgw== X-Received: by 10.194.173.163 with SMTP id bl3mr958672wjc.10.1382523398150; Wed, 23 Oct 2013 03:16:38 -0700 (PDT) Original-Received: from Kagami.home (host86-132-92-201.range86-132.btcentralplus.com. [86.132.92.201]) by mx.google.com with ESMTPSA id b13sm15318773wic.9.2013.10.23.03.16.35 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 23 Oct 2013 03:16:37 -0700 (PDT) In-Reply-To: <8738obd6u6.fsf@Kagami.home> (Ian Price's message of "Tue, 08 Oct 2013 18:13:05 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:7317 Archived-At: --=-=-= Content-Type: text/plain Ian Price writes: > If Andy is happy with this change, I'll add a test, and push a commit, > but I'm going leave it to his discretion. Andy OKed it on IRC, so I've attached the patch. -- Ian Price -- shift-reset.com "Programming is like pinball. The reward for doing it well is the opportunity to do it again" - from "The Wizardy Compiled" --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Fix-inlining-of-tail-list-to-apply.patch Content-Description: peval fix >From ee6b0bb09dbf48e83c6e0ac7b7f1699bae34108a Mon Sep 17 00:00:00 2001 From: Ian Price Date: Wed, 23 Oct 2013 11:14:26 +0100 Subject: [PATCH] Fix inlining of tail list to apply. Fixes . * module/language/tree-il/peval.scm (peval): Final list argument to `apply' should not be inlined if it is mutable. * test-suite/tests/peval.test ("partial evaluation"): Add test. --- module/language/tree-il/peval.scm | 38 ++++++++++++++++++++------------------ test-suite/tests/peval.test | 16 +++++++++++++++- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/module/language/tree-il/peval.scm b/module/language/tree-il/peval.scm index a6e4076..bd92edc 100644 --- a/module/language/tree-il/peval.scm +++ b/module/language/tree-il/peval.scm @@ -716,24 +716,26 @@ top-level bindings from ENV and return the resulting expression." (cond ((lookup (lexical-ref-gensym x)) => (lambda (op) - (let ((y (or (operand-residual-value op) - (visit-operand op counter 'value 10 10) - (operand-source op)))) - (cond - ((and (lexical-ref? y) - (= (lexical-refcount (lexical-ref-gensym x)) 1)) - ;; X is a simple alias for Y. Recurse, regardless of - ;; the number of aliases we were expecting. - (find-definition y n-aliases)) - ((= (lexical-refcount (lexical-ref-gensym x)) n-aliases) - ;; We found a definition that is aliased the right - ;; number of times. We still recurse in case it is a - ;; lexical. - (values (find-definition y 1) - op)) - (else - ;; We can't account for our aliases. - (values #f #f)))))) + (if (var-set? (operand-var op)) + (values #f #f) + (let ((y (or (operand-residual-value op) + (visit-operand op counter 'value 10 10) + (operand-source op)))) + (cond + ((and (lexical-ref? y) + (= (lexical-refcount (lexical-ref-gensym x)) 1)) + ;; X is a simple alias for Y. Recurse, regardless of + ;; the number of aliases we were expecting. + (find-definition y n-aliases)) + ((= (lexical-refcount (lexical-ref-gensym x)) n-aliases) + ;; We found a definition that is aliased the right + ;; number of times. We still recurse in case it is a + ;; lexical. + (values (find-definition y 1) + op)) + (else + ;; We can't account for our aliases. + (values #f #f))))))) (else ;; A formal parameter. Can't say anything about that. (values #f #f)))) diff --git a/test-suite/tests/peval.test b/test-suite/tests/peval.test index 923b0d1..5b003d2 100644 --- a/test-suite/tests/peval.test +++ b/test-suite/tests/peval.test @@ -1223,4 +1223,18 @@ (call-with-prompt t (lambda () (abort-to-prompt t 1 2 3)) (lambda (k x y z) (list x y z)))) - (apply (primitive 'list) (const 1) (const 2) (const 3)))) + (apply (primitive 'list) (const 1) (const 2) (const 3))) + + (pass-if-peval resolve-primitives + ;; Should not inline tail list to apply if it is mutable. + ;; + (let ((l '())) + (if (pair? arg) + (set! l arg)) + (apply f l)) + (let (l) (_) ((const ())) + (begin + (if (apply (primitive pair?) (toplevel arg)) + (set! (lexical l _) (toplevel arg)) + (void)) + (apply (primitive @apply) (toplevel f) (lexical l _)))))) -- 1.7.11.7 --=-=-=--