From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrea Corallo via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#42147: 28.0.50; pure vs side-effect-free, missing optimizations? Date: Wed, 08 Jul 2020 22:19:32 +0000 Message-ID: References: <3A9CC2A3-8307-47B2-8D80-795C0AF020E1@acm.org> <5F2B4684-34D1-4474-8909-9F435369FE54@acm.org> <705260433.2731607.1593698199171@mail.yahoo.com> <6CF8EE58-9A49-40E7-AA86-48AB39BF94BA@acm.org> <28B19D86-343C-4126-B95F-1F38735F73F2@acm.org> <1288c6a5-545b-f68c-ff6b-7683db3e54c1@cs.ucla.edu> <1690361185.4397117.1593879228865@mail.yahoo.com> <374F2E9C-E8C2-4362-8BEF-E6AA5EEE5C79@acm.org> <68F4CFD4-17BF-4ADA-B2EF-55281ACD2373@acm.org> <926674413.6042347.1594070583586@mail.yahoo.com> <475381031.6812910.1594139070322@mail.yahoo.com> <459BE59A-76CE-46A3-BE5E-B65AED0B85F5@acm.org> Reply-To: Andrea Corallo Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4100"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cc: 42147-done@debbugs.gnu.org, Paul Eggert , Stefan Monnier , Andrea Corallo To: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 09 00:39:13 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jtIie-0000wf-Pg for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 09 Jul 2020 00:39:12 +0200 Original-Received: from localhost ([::1]:56198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtIid-0005E6-Jh for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 08 Jul 2020 18:39:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48062) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jtIQ8-0007dJ-6N for bug-gnu-emacs@gnu.org; Wed, 08 Jul 2020 18:20:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56049) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jtIQ7-0000kn-T0 for bug-gnu-emacs@gnu.org; Wed, 08 Jul 2020 18:20:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jtIQ6-0004IJ-PZ for bug-gnu-emacs@gnu.org; Wed, 08 Jul 2020 18:20:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andrea Corallo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 08 Jul 2020 22:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42147 X-GNU-PR-Package: emacs Original-Received: via spool by 42147-done@debbugs.gnu.org id=D42147.159424678316462 (code D ref 42147); Wed, 08 Jul 2020 22:20:02 +0000 Original-Received: (at 42147-done) by debbugs.gnu.org; 8 Jul 2020 22:19:43 +0000 Original-Received: from localhost ([127.0.0.1]:39361 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jtIPn-0004HS-7f for submit@debbugs.gnu.org; Wed, 08 Jul 2020 18:19:43 -0400 Original-Received: from mx.sdf.org ([205.166.94.24]:54708) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jtIPl-0004HJ-FC for 42147-done@debbugs.gnu.org; Wed, 08 Jul 2020 18:19:42 -0400 Original-Received: from mab (ma.sdf.org [205.166.94.33]) by mx.sdf.org (8.15.2/8.14.5) with ESMTP id 068MJWch024242; Wed, 8 Jul 2020 22:19:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sdf.org; s=default; t=1594246775; bh=uBCcp8drLWLyYLoZqNZYanROzlAKcilKDVR9y+3H1e0=; h=From:To:Cc:Subject:References:Date:In-Reply-To; b=UlsSmSuI/pomek7jwib6OJsNX0vOUNV9giRj2m9h/dEKmKZNcpUkc2bgk8CpPouD1 kP4hHZcZra4rJ2ZY3aZU+hd8HXLNLisGj9ELIx9gxmg3J8uTZa/FcZcgRlnzmyihIC 6T94zAI5tUFAmYzXTaumQ95yNjK+BFuVx5cnRmS0= In-Reply-To: <459BE59A-76CE-46A3-BE5E-B65AED0B85F5@acm.org> ("Mattias \=\?utf-8\?Q\?Engdeg\=C3\=A5rd\=22's\?\= message of "Wed, 8 Jul 2020 23:25:58 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:182854 Archived-At: Mattias Engdeg=C3=A5rd writes: > Hello Andrea, > >> In my version I assumed (after a look to the manual) to have strings to >> be immutable only at speed 3. Is it safe to assume this always instead? > > Ultimately it depends on the transformations you do, but yes: this > patch substitutes let-bound names for their values, and since the > behaviour of mutating string literals is undefined, it's > safe. Consider: > > (let ((s "abc")) > (f s) > s) > > It doesn't matter what 'f' does; since it isn't permitted to mutate its a= rgument string, the transformation to > > (progn (f "abc") "abc") > > is safe (assuming lexical binding, since f could otherwise set s to somet= hing else). Understand, in your code this predicate is used for substitution therefore is just correct to substitute with the original object. In mine is governating the objects we can materialize with const folding so I had it a little stricter. But this raise to me another doubt on the topic that is: why don't we have the same in the byte-compiler? That is: (defun foo (x) (concat "bar" "foo")) is byte compiled optimizing on `concat' because pure. But doing that the resulting string "barfoo" becomes immutable. I'd expect "barfoo" to be mutable because without optimizations the allocation would be done in the run-time. In general how I imagined the thing is that we can optimize only pure functions returning immutable objects to avoid the risk of unexpectedly creating objects that should not be changed. Or is it maybe that the only way to certainly have a mutable string is with `copy-sequence' or `make-string'? >> Also I wanted ask why symbols are not included but only keywords, is >> this to respect the side effect of interning them or something else? > > Symbols are included, but since this is (normalised) Lisp source, > plain symbols are variables; constants of symbol type are represented > as (quote SYM), matched by the and-expression. Keywords are just > symbols whose name begin with a colon, like :chocolate, and need no > quoting. Understand It's a little late hope I'm not talking stupid, thanks for your patience. Andrea --=20 akrl@sdf.org