From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 17 07:32:17 2023 Received: (at submit) by debbugs.gnu.org; 17 Jun 2023 11:32:17 +0000 Received: from localhost ([127.0.0.1]:50964 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAUAC-0008Cf-Nm for submit@debbugs.gnu.org; Sat, 17 Jun 2023 07:32:17 -0400 Received: from lists.gnu.org ([209.51.188.17]:53874) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAUA7-0008CU-NF for submit@debbugs.gnu.org; Sat, 17 Jun 2023 07:32:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qAUA7-0002dT-8S for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2023 07:32:11 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qAUA3-0007DF-Vw for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2023 07:32:10 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3f8f3786f20so15476905e9.2 for ; Sat, 17 Jun 2023 04:32:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd.ie; s=google21; t=1687001524; x=1689593524; h=mime-version:message-id:date:subject:to:from:from:to:cc:subject :date:message-id:reply-to; bh=+gQcGOFiD3oFWIiffcgLvTknKw9NaRBYxD9Y7LcUADs=; b=DTkmyXa3iXYomtbUdeAt3vZoQADhQNA07/GVh9iaEpeKhvG28rvcaROSkRWFdJelL1 3s0rwk6GAB/iAV6CURDI4SsgY7sF/psYzzQQv/gP1EJvvY7trV8WdCnnAvTldSjNKFwp g4k7MqoEc8dq5JqiUi0TZtj96f04VWq6WLaI9gNoAxtYa+MMG8Mixo6fsnfcsvJx67df XJBeEjGgZR9xCOQHJ+aIR42bPPIqrBjubLix9pnlcgiP1cvT85yXPg8Lf/R3S0CMqYxB t8BWQehO1XR1TXKIj7IZMB7xAc3BhdC/RvamB99vl7M8mibSPm+hcWQgttz+NTv2txt/ wQPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687001524; x=1689593524; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=+gQcGOFiD3oFWIiffcgLvTknKw9NaRBYxD9Y7LcUADs=; b=e63yaLmErQU6JVTV6+Hry8JZ1H6xCGBjvbskMMo2LVDjuf7ORG0DZQVEfbmRli5XV0 0r5dwNoBHgrzfAVdDkNesa6YjKmNY+RQfRgLHxlwHal4OchgeN/ObIJIgahaBwJbcJV6 IJf2AfjSwrBAJeQAW7umbRgBS04yMHmOoEFTWJNx0NjN7TuWP9fatzFnFjk5kG6Nric8 chUeRwxBlgqg/UHMQi/8gLohHW31vQSEjvEgsiBgiYUImqIFsY4bFoOl3SuYuOJnfSUv 6M3pXupugIePFi26Lkr6PO0k/fsg4WEeBu1ac1AvxxHDj+NkotpAc7eh8HW7h4VCzQJw xJyA== X-Gm-Message-State: AC+VfDwgMYNEX0BpGoPfYaNU2RyRdj8ff0cvVv7yi2NzEAii+RIjtSJ6 4SLG1fq2VxARzXUVixn7oRDEurgvc0T6DuPhQ0I= X-Google-Smtp-Source: ACHHUZ7YmmeGXjSO+0EEWU/cXuWe4R3pAwPYK5z9Z2E5LYfWfQgeWYm8lHvf/mIsDliuscccL0vpXg== X-Received: by 2002:a05:600c:2291:b0:3f7:f8d7:cc72 with SMTP id 17-20020a05600c229100b003f7f8d7cc72mr4396007wmf.27.1687001524305; Sat, 17 Jun 2023 04:32:04 -0700 (PDT) Received: from localhost ([109.78.105.162]) by smtp.gmail.com with ESMTPSA id f18-20020a1cc912000000b003f5ffba9ae1sm4780661wmb.24.2023.06.17.04.32.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jun 2023 04:32:03 -0700 (PDT) From: Basil Contovounesios To: bug-gnu-emacs@gnu.org Subject: 30.0.50; mutate-constant warning with pure function X-Debbugs-Cc: Mattias =?utf-8?Q?Engdeg=C3=A5rd?= Date: Sat, 17 Jun 2023 12:32:02 +0100 Message-ID: <87ttv6b9zh.fsf@epfl.ch> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=contovob@tcd.ie; helo=mail-wm1-x32a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) --=-=-= Content-Type: text/plain Given a file foo.el that defines a pure function foo: --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=foo.el Content-Transfer-Encoding: quoted-printable ;;; foo.el -*- lexical-binding: t -*- (defun foo (x) (declare (pure t)) (list x)) (provide 'foo) ;;; foo.el ends here --=-=-= Content-Type: text/plain and another file bar.el that mutates the result of foo: --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=bar.el Content-Transfer-Encoding: quoted-printable ;;; bar.el -*- lexical-binding: t -*- (require 'foo) (setcar (foo nil) t) ;;; bar.el ends here --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable byte-compiling bar.el emits a mutate-constant warning, even though the result of foo is a fresh list: $ for f in foo bar; do emacs -Q -batch -L . -f batch-byte-compile $f.el; do= ne In toplevel form: bar.el:3:2: Warning: =E2=80=98setcar=E2=80=99 on constant list (arg 1) Am I missing something? Thanks, --=20 Basil In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw3d scroll bars) of 2023-06-17 built on blc Repository revision: c279369a7a9e373bb4b88feff0a05f56f3c0fa3b Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12101004 System Description: Ubuntu 22.04.2 LTS Configured using: 'configure CC=3Dgcc-12 'CFLAGS=3D-Og -ggdb3' --prefix=3D/home/bic/.local --with-file-notification=3Dyes --with-x --with-x-toolkit=3Dlucid' Configured features: ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XAW3D XDBE XIM XINPUT2 XPM LUCID ZLIB Important settings: value of $LC_MONETARY: en_IE.UTF-8 value of $LC_NUMERIC: en_IE.UTF-8 value of $LC_TIME: en_IE.UTF-8 value of $LANG: en_GB.UTF-8 value of $XMODIFIERS: @im=3Dibus locale-coding-system: utf-8-unix Major mode: Lisp Interaction Minor modes in effect: tooltip-mode: t global-eldoc-mode: t eldoc-mode: t show-paren-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t line-number-mode: t indent-tabs-mode: t transient-mark-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message mailcap yank-media puny dired dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068 epg-config gnus-util text-property-search time-date subr-x mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils rmc iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic indonesian philippine cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese composite emoji-zwj charscript charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp files window text-properties overlay sha1 md5 base64 format env code-pages mule custom widget keymap hashtable-print-readable backquote threads dbusbind inotify lcms2 dynamic-setting system-font-setting font-render-setting cairo x-toolkit xinput2 x multi-tty make-network-process emacs) Memory information: ((conses 16 36748 9460) (symbols 48 5178 0) (strings 32 13894 1203) (string-bytes 1 379737) (vectors 16 9300) (vector-slots 8 148644 10010) (floats 8 23 25) (intervals 56 244 0) (buffers 984 10)) --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 17 07:58:20 2023 Received: (at 64127) by debbugs.gnu.org; 17 Jun 2023 11:58:20 +0000 Received: from localhost ([127.0.0.1]:50971 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAUZQ-0000Ui-Bo for submit@debbugs.gnu.org; Sat, 17 Jun 2023 07:58:20 -0400 Received: from mail-lf1-f45.google.com ([209.85.167.45]:42381) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAUZM-0000UO-6q for 64127@debbugs.gnu.org; Sat, 17 Jun 2023 07:58:18 -0400 Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-4f762b3227dso2118355e87.1 for <64127@debbugs.gnu.org>; Sat, 17 Jun 2023 04:58:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687003090; x=1689595090; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:from:to:cc:subject :date:message-id:reply-to; bh=PzSQYxacgWgAUuvziJM9ak8MCYmkFMiUC++6LnWHTXE=; b=TtBBHRqRAMt8D9l8gg1+CVPWfLPU2LYI67usJes5rdahTdnHa7C0/wq066/rL6vbJB cKc5kz4J4dfHjmtjvnXxWkYkXBGNhvW1QnfJnWei/qVs1+WFPS5rDQwF3wwvj98A09qr RlOpY96AzNrC+i9WqQIkPOkmw8+bn6/sH1+n3/QUXAkDWNxCMGzu3ZPZJDBpjb+QsFgq lKLUJt3gu2AS3FtfZnj1QX3TIj6M+SouMPkybzl6QAsQVN1JjaiJoeBDH+rzZFpY7uCn q3Glxw17R9dUocXFhbAHrogldCujnqXoPdLyLqWPMA3FuL5sx4Xo2yLj/xVNVQ6Vv8bT 8e0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687003090; x=1689595090; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=PzSQYxacgWgAUuvziJM9ak8MCYmkFMiUC++6LnWHTXE=; b=Jic5XkfINtWTvNFIcpcj2f5vfDl7fLYoxc1TA7wRPz7xf+Ld1W8CEkHVKw4MZoPs23 M0WapqqCs4eOT7KYXpjDcQznvQDg/jbARn9C+5IgwW6Nc7bQlMXarCDO+juIItWEJylz us6xO2/CosRJSE9DKRWVNHIUu748IYjKg03UdA7tFs4TAWt4NeZj3pQs1sRbXYddwerT ko3n3UlUuC4pIUBqOR8YwT9bPsLFTPgzDRRFArCjKuBwZujWksq4twd28YOKv8Al6vkp OURq3BsQa54cQFnCr2jDTfxq8YiJUIwWyipMUwFxoxdOeWlN/1nutxgeGcEa/Qwyy7Pc wkxQ== X-Gm-Message-State: AC+VfDy7dyCjfv+tjhXjdgwn6oyxzjmKItle9eot5p26vwZ+FVX6xgE0 t+Un4ihIcBVRo15OIbEPiXc= X-Google-Smtp-Source: ACHHUZ7DRH67H57fEjcjRi8BlmlYJLQHCRk8bLahzEFggFZuuVX+AdQWr6aT3L47Cpv5xw2g+C+QXw== X-Received: by 2002:a05:6512:e96:b0:4f8:586a:d6ca with SMTP id bi22-20020a0565120e9600b004f8586ad6camr1217622lfb.9.1687003089685; Sat, 17 Jun 2023 04:58:09 -0700 (PDT) Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id n18-20020a2e86d2000000b002ada919a09asm4112870ljj.73.2023.06.17.04.58.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Jun 2023 04:58:09 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Subject: Re: bug#64127: 30.0.50; mutate-constant warning with pure function From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= In-Reply-To: <87ttv6b9zh.fsf@epfl.ch> Date: Sat, 17 Jun 2023 13:58:08 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <42E68F81-EDE7-45E4-AF08-BF420EE53F4B@gmail.com> References: <87ttv6b9zh.fsf@epfl.ch> To: Basil Contovounesios X-Mailer: Apple Mail (2.3654.120.0.1.15) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 64127 Cc: 64127@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) 17 juni 2023 kl. 13.32 skrev Basil Contovounesios : > Given a file foo.el that defines a pure function foo: > (defun foo (x) (declare (pure t)) (list x)) > and another file bar.el that mutates the result of foo: > (setcar (foo nil) t) > byte-compiling bar.el emits a mutate-constant warning, even though the > result of foo is a fresh list: No, the `pure` declaration means that the function can be evaluated at = compile time which the compiler happily does, yielding a constant list, = which your code then attempts to modify. This is why the function `list` itself is not declared `pure` -- while = it does look like a pure function when speaking informally, users relies = on it returning a freshly allocated list that can be modified and that = makes it non-pure. (If lists were immutable, then `list` would naturally = be pure.) Only the mutate-constant warning is new here; previously, the compiler = would have let you make this mistake undisturbed. Thus either you remove the pure-declaration from your function, or you = don't mutate what it returns. From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 17 12:28:15 2023 Received: (at 64127) by debbugs.gnu.org; 17 Jun 2023 16:28:15 +0000 Received: from localhost ([127.0.0.1]:52516 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAYmc-0001QC-RS for submit@debbugs.gnu.org; Sat, 17 Jun 2023 12:28:15 -0400 Received: from mail-lf1-f48.google.com ([209.85.167.48]:51525) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAYmX-0001Pk-3Z for 64127@debbugs.gnu.org; Sat, 17 Jun 2023 12:28:13 -0400 Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-4f865f0e16cso487886e87.3 for <64127@debbugs.gnu.org>; Sat, 17 Jun 2023 09:28:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd.ie; s=google21; t=1687019283; x=1689611283; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=42EF4PHXNbwDVPowfFpv+SE6V56E7q0g7lz1Ao0Nq2o=; b=JHFp2N7smPGnydQkAgw31z5RDze+gfFo4mQ1pOB9hanZEN8+GuRPPCVb1+fuHsfm99 lud4Yv5zlPpP1bhwVhvuPTl0tzOKVQKyGJx9IvYSPOW60C7y6gv9tdBLnWroyj1pnTdY HkzML1V+M12EsarZHtsdsY/IDCInoMPrzjH7qUxKoOy1HZzyUaeT+tmzOptU0URYArl+ vG3aCpBam/Ljb1QYhlcjrxi/6dXOhuUy8lZ6ilKsVLCkIf4Sr9TxqavwLQtd+nPhcDyP msFl8hCDoC171tPHlimybX3XEVYLB1R+CcFSqn5cvtw3dK5Q72l9R5R8MMNTdptHxNQF /ACA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687019283; x=1689611283; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=42EF4PHXNbwDVPowfFpv+SE6V56E7q0g7lz1Ao0Nq2o=; b=gqP5muitOuiiQvyFHio0nseY1lbxDS49kmmyI3ZgSX+IE6oCdoWRdXvwPKZb3f8Dnv +CAOfRhBMjLK1e7CJtOZwIulmeqkUjCxtDJukjmBNKnt9bT+dwzLUkcyk5hZ7LtVU7NR uvl5FtLCxISSh8rRYuAmReyfPuXNU90l+HylJ5qwk4Pzwu92WgQZ5nviO/u+Sv/FFoIE vEd1n4HYaPSP/n3Hvn03q6Bt4EFfQ1MB35QLIjjgDxTrZNok09HVXYg1dNtXSHJba9Kl 7tL3/MPYeUGrqgzdeUFYstIPHJq25n9BVegePbcHVvdP64AoVrJAxkpYT+RrTk0tyjXm FpSw== X-Gm-Message-State: AC+VfDxZaWfluR8jBpn9SD+/zBR7EiXLMf351KgWcIJP4ha8p2r1Bkoo ycHrRomPTALSZ1cjb6PQJ10pqg== X-Google-Smtp-Source: ACHHUZ5Qblq+WBw8clqwH973a3JB6PnR7/FuLO4Q9ZxfhG/3YtPVhj5T52LuhKayaqYItVPoCMgxiw== X-Received: by 2002:a19:380f:0:b0:4f8:43b8:c722 with SMTP id f15-20020a19380f000000b004f843b8c722mr2843861lfa.67.1687019282910; Sat, 17 Jun 2023 09:28:02 -0700 (PDT) Received: from localhost ([109.78.105.162]) by smtp.gmail.com with ESMTPSA id u16-20020a7bc050000000b003f080b2f9f4sm5438734wmc.27.2023.06.17.09.28.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jun 2023 09:28:02 -0700 (PDT) From: Basil Contovounesios To: Mattias =?utf-8?Q?Engdeg=C3=A5rd?= Subject: Re: bug#64127: 30.0.50; mutate-constant warning with pure function In-Reply-To: <42E68F81-EDE7-45E4-AF08-BF420EE53F4B@gmail.com> ("Mattias =?utf-8?Q?Engdeg=C3=A5rd=22's?= message of "Sat, 17 Jun 2023 13:58:08 +0200") References: <87ttv6b9zh.fsf@epfl.ch> <42E68F81-EDE7-45E4-AF08-BF420EE53F4B@gmail.com> Date: Sat, 17 Jun 2023 17:28:01 +0100 Message-ID: <87jzw29hpq.fsf@epfl.ch> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 64127 Cc: 64127@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Mattias Engdeg=C3=A5rd [2023-06-17 13:58 +0200] wrote: > 17 juni 2023 kl. 13.32 skrev Basil Contovounesios : > >> Given a file foo.el that defines a pure function foo: > >> (defun foo (x) (declare (pure t)) (list x)) > >> and another file bar.el that mutates the result of foo: > >> (setcar (foo nil) t) > >> byte-compiling bar.el emits a mutate-constant warning, even though the >> result of foo is a fresh list: > > No, the `pure` declaration means that the function can be evaluated at > compile time which the compiler happily does, yielding a constant > list, which your code then attempts to modify. > > This is why the function `list` itself is not declared `pure` -- while it= does > look like a pure function when speaking informally, users relies on it re= turning > a freshly allocated list that can be modified and that makes it non-pure.= (If > lists were immutable, then `list` would naturally be pure.) > > Only the mutate-constant warning is new here; previously, the compiler > would have let you make this mistake undisturbed. > > Thus either you remove the pure-declaration from your function, or you > don't mutate what it returns. Right. Which approach do you think the dash.el library in GNU ELPA should follow? It generally defines nondestructive operations over lists, some of which even claim in their docstring that they return a partial or complete copy of their arguments (modulo the parts changed by the operation). Is it okay for a pure function to say it returns a copy in its docstring, with the onus lying on the caller to realise that a pure function call may be byte-compiled to a runtime constant? Or should all such functions be impurified? Thanks, --=20 Basil From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 17 13:03:33 2023 Received: (at 64127) by debbugs.gnu.org; 17 Jun 2023 17:03:33 +0000 Received: from localhost ([127.0.0.1]:52554 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAZKm-0002Tw-Jr for submit@debbugs.gnu.org; Sat, 17 Jun 2023 13:03:32 -0400 Received: from mail-lf1-f53.google.com ([209.85.167.53]:42285) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAZKk-0002Tc-7S for 64127@debbugs.gnu.org; Sat, 17 Jun 2023 13:03:31 -0400 Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-4f762b3227dso2339689e87.1 for <64127@debbugs.gnu.org>; Sat, 17 Jun 2023 10:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687021404; x=1689613404; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:from:to:cc:subject :date:message-id:reply-to; bh=guBTkr5JKsPLk+dXLVSbNqTRkg7nrYp5xEPWwuFOEyk=; b=aikLxljIaxigwzoBGFs295rvpbNEXplVfGEuxfahME6aLFeJJaHx2NYd8O3zbHeZNS 55UdAfrZGAGGJcs0hbFarOeipg+0N7q5bWC1ka/TxyjeTycZG3M/6Dp14fqVhdnfnNB/ DZBPmP3QHi6VEJFlPsmz10iX3yMcz5pMdKntCM25T+9zdFJkZt82vySmOjsesdiTQ3u4 TiJuAn0xIEZUWK9wMHYiKWF8rbzOvcIqu/WG7Q6/JHCGxYaaL3/M+737/dtgpefTQBNf 2NfTDpgj4CpQM5XNkSjHfRMuMI6rcE8PAmFB2HrhgNTf0KVsyz1KOsySpmGKuQw9h/N7 ei8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687021404; x=1689613404; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=guBTkr5JKsPLk+dXLVSbNqTRkg7nrYp5xEPWwuFOEyk=; b=KYEH9yMAwtMKXmARpHANvGPMeK7uKST4nz1zfo6B/R3B5T4Ks50Rz3AgtU9bg1gxkR g16X21TzYSdo7CG2S5Vd+ZLLpi+M4wjabac8PnS8b4eeFsrQQqY1R1vgltt381jzKBCJ q62OvPfNlVvasNoa1D+X4Qyyju1GsbaDzK6WaJ4/FuMN2nxmUFOMxtqqqagaNqjcqK4k 8O2K9N7vceypN68a09xEOYpRuT1bPUNC6fQvd+VrYhoHqdVjyyaQ4Bswgw3XQfMrQrtm +JR/x0c/1ThISaDs+agxiRAYheLMr33HQmbnqF/i6KDGJuBFEtpXVnXeX6WJcWpevw2H uyhQ== X-Gm-Message-State: AC+VfDxPBMIOiBp0u4OR/mK8nlPhgGQqKgiMQg01Ze8zjxuRtqD68g98 dmeQTJMGnYotbpqYfiP1Slc= X-Google-Smtp-Source: ACHHUZ5V0HpTJCuRb2ervWkx/Ha0w44u/lLTPRVUdhugzHKW5Ll1nu4e0fV6f7F0S+6XE2gVcEfZWg== X-Received: by 2002:a19:640e:0:b0:4f8:5510:c897 with SMTP id y14-20020a19640e000000b004f85510c897mr1841243lfb.18.1687021403919; Sat, 17 Jun 2023 10:03:23 -0700 (PDT) Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id r24-20020ac24d18000000b004eed8de597csm3495731lfi.32.2023.06.17.10.03.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Jun 2023 10:03:23 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Subject: Re: bug#64127: 30.0.50; mutate-constant warning with pure function From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= In-Reply-To: <87jzw29hpq.fsf@epfl.ch> Date: Sat, 17 Jun 2023 19:03:23 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <22FA3A9A-A113-437C-A338-15A2BA7ADA59@gmail.com> References: <87ttv6b9zh.fsf@epfl.ch> <42E68F81-EDE7-45E4-AF08-BF420EE53F4B@gmail.com> <87jzw29hpq.fsf@epfl.ch> To: Basil Contovounesios X-Mailer: Apple Mail (2.3654.120.0.1.15) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 64127 Cc: 64127@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) 17 juni 2023 kl. 18.28 skrev Basil Contovounesios : > Which approach do you think the dash.el library in GNU ELPA should > follow? It generally defines nondestructive operations over lists, = some > of which even claim in their docstring that they return a partial or > complete copy of their arguments (modulo the parts changed by the > operation). Its doc strings seem to talk a lot about how the functions returns a new = this or a copy of that. Maybe that provides the licence to return a = constant when those words are absent, or perhaps the users will just = assume mutability in absence of stern warnings. I don't know how dash.el = is used in practice, so perhaps it's prudent to stay off the `pure` = declarations. > Is it okay for a pure function to say it returns a copy in its > docstring, with the onus lying on the caller to realise that a pure > function call may be byte-compiled to a runtime constant? Or should = all > such functions be impurified? A pure function cannot in general be guaranteed to return an eq-unique = value. By definition it will, if all its arguments are constants, be = called at compile-time to generate a constant used in the program. There is nothing wrong with returning a newly created object from a = `pure`-declared function, as long as reasonable steps are taken to = prevent the returned value from being mutated. Depending on the context = this can be as simple as not saying that it returns a new object. From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 17 16:56:41 2023 Received: (at control) by debbugs.gnu.org; 17 Jun 2023 20:56:41 +0000 Received: from localhost ([127.0.0.1]:52729 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAcyP-0000Hu-Eb for submit@debbugs.gnu.org; Sat, 17 Jun 2023 16:56:41 -0400 Received: from mail-wm1-f52.google.com ([209.85.128.52]:57436) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAcyL-0000HX-R1 for control@debbugs.gnu.org; Sat, 17 Jun 2023 16:56:40 -0400 Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-3f90b8ace97so335195e9.2 for ; Sat, 17 Jun 2023 13:56:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd.ie; s=google21; t=1687035392; x=1689627392; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kUoRQy08AKYJa7CXAQ3cTAEVimVuGqyErdzWu/72HJA=; b=DnIPvePw4cbX7uJNHBmxs3geORXRZmLkl+gdPWy4hz6XAi8cVKkbEBH4Qsy3qPY6Q2 Ox1YW1yT1UnT2atmOaSPJBcm92wmARRwufXHD0RZoAlUM+BZUwfsMUuodgZ7T8Bry1Br SolHUDfts5R1w8+pLXPE5mn8SPQJQs3eTXTQHOsv3/6UoLTVEqiqMy519wncKDcLYR6N 9ecLiObNoj2AgbVMrXK5JDEqzFfgAWPYrIkgBSywa8P8HgoCrAI4p7rXOaY3sa67Xe4Y QnVjWDPPQ08vgzC5kfCttUj1Azqe2GGr9VVtKsBB4+AWzmR9Sr59PHmDLgrNRspWIxjR rOsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687035392; x=1689627392; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=kUoRQy08AKYJa7CXAQ3cTAEVimVuGqyErdzWu/72HJA=; b=Xbp1Md6w+MGTUZs+Z6lo5C3EyQDm93WBwxdJxoSyOIsGThS5brOXt7NlqiwKKH5t+g YAZ194MCMfgugvJ0H7Jb0h2gC3ao04/NX5Ep9z/VAYTv1KVoyxVd1r0KMIflxK3pnrqE kfNGeGJkQMyvv88EA3ELBmqqnm6e0cA3QH0O0HDmICDbZXRcQI946dghFosnt2KVAZ84 qBWB0dJ59UxXw7zi0va7izzcSjXOzpeGnYcnrIRWNjLwzCVeavPtC6b2QDMTp/5FWFaI lUDDPevvgbzBzlE32dsIIhyfL4boJwNCU2TpM8J2IqJWRWeLn+h0zyCCDKjM8KQ9OMDy BuoQ== X-Gm-Message-State: AC+VfDwzuV0aR59uqKIPdyt/5T/lqHElGmXdFjbVA1KfULo8VfjSlpQY IXt8DwU5kic7UKQLTdLBblEs3Rt68YlRH5O4JiyWnw== X-Google-Smtp-Source: ACHHUZ5t3hvQlTEOv9G4gbdlZEDCBXKgTKWogG9NaTD0Tzk9kSQdsVLpdOZZxYYhIoV2qTU4gUc7gg== X-Received: by 2002:a1c:e909:0:b0:3f6:a65:6ff3 with SMTP id q9-20020a1ce909000000b003f60a656ff3mr4626656wmc.32.1687035391965; Sat, 17 Jun 2023 13:56:31 -0700 (PDT) Received: from localhost ([109.78.105.162]) by smtp.gmail.com with ESMTPSA id b1-20020a5d5501000000b0030ae69920c9sm27197443wrv.53.2023.06.17.13.56.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jun 2023 13:56:31 -0700 (PDT) From: Basil Contovounesios To: Mattias =?utf-8?Q?Engdeg=C3=A5rd?= Subject: Re: bug#64127: 30.0.50; mutate-constant warning with pure function In-Reply-To: <22FA3A9A-A113-437C-A338-15A2BA7ADA59@gmail.com> ("Mattias =?utf-8?Q?Engdeg=C3=A5rd=22's?= message of "Sat, 17 Jun 2023 19:03:23 +0200") References: <87ttv6b9zh.fsf@epfl.ch> <42E68F81-EDE7-45E4-AF08-BF420EE53F4B@gmail.com> <87jzw29hpq.fsf@epfl.ch> <22FA3A9A-A113-437C-A338-15A2BA7ADA59@gmail.com> Date: Sat, 17 Jun 2023 21:56:30 +0100 Message-ID: <87edm97qpt.fsf@epfl.ch> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: control Cc: 64127-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) tags 64127 notabug wontfix close 64127 quit Mattias Engdeg=C3=A5rd [2023-06-17 19:03 +0200] wrote: > 17 juni 2023 kl. 18.28 skrev Basil Contovounesios : > >> Which approach do you think the dash.el library in GNU ELPA should >> follow? It generally defines nondestructive operations over lists, some >> of which even claim in their docstring that they return a partial or >> complete copy of their arguments (modulo the parts changed by the >> operation). > > Its doc strings seem to talk a lot about how the functions returns a new = this or > a copy of that. Maybe that provides the licence to return a constant when= those > words are absent, or perhaps the users will just assume mutability in abs= ence of > stern warnings. I don't know how dash.el is used in practice, so perhaps = it's > prudent to stay off the `pure` declarations. Done for some of the likelier candidates in https://github.com/magnars/dash.el/commit/d5182da04c. >> Is it okay for a pure function to say it returns a copy in its >> docstring, with the onus lying on the caller to realise that a pure >> function call may be byte-compiled to a runtime constant? Or should all >> such functions be impurified? > > A pure function cannot in general be guaranteed to return an eq-unique > value. By definition it will, if all its arguments are constants, be > called at compile-time to generate a constant used in the program. > > There is nothing wrong with returning a newly created object from a > `pure`-declared function, as long as reasonable steps are taken to preven= t the > returned value from being mutated. Depending on the context this can be as > simple as not saying that it returns a new object. Makes sense, thanks for elaborating. --=20 Basil From unknown Sun Jun 22 22:48:20 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 16 Jul 2023 11:24:06 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator