GNU bug report logs - #76017
31.0.50; Which args can cl-nintersection and cl-nset-difference mutate?

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: "Basil L. Contovounesios" <basil@HIDDEN>; dated Sun, 2 Feb 2025 17:49:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 2 Feb 2025 17:49:01 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 02 12:49:01 2025
Received: from localhost ([127.0.0.1]:36171 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tee5d-0002X7-6X
	for submit <at> debbugs.gnu.org; Sun, 02 Feb 2025 12:49:01 -0500
Received: from lists.gnu.org ([2001:470:142::17]:37302)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <basil@HIDDEN>)
 id 1tee5Z-0002Wk-Tx
 for submit <at> debbugs.gnu.org; Sun, 02 Feb 2025 12:48:58 -0500
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 <basil@HIDDEN>)
 id 1tee5T-00056g-AT
 for bug-gnu-emacs@HIDDEN; Sun, 02 Feb 2025 12:48:51 -0500
Received: from mta-10-4.privateemail.com ([198.54.122.149])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <basil@HIDDEN>)
 id 1tee5R-0005I5-AS
 for bug-gnu-emacs@HIDDEN; Sun, 02 Feb 2025 12:48:51 -0500
Received: from mta-10.privateemail.com (localhost [127.0.0.1])
 by mta-10.privateemail.com (Postfix) with ESMTP id 4YmHDZ3jbhz3hhTs
 for <bug-gnu-emacs@HIDDEN>; Sun,  2 Feb 2025 12:48:46 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=contovou.net;
 s=default; t=1738518526;
 bh=2IWkm+rwXWluDXemSbzrYsFcENUIuCX9ukfJoVZQrzw=;
 h=From:To:Subject:Date:From;
 b=sY1rgEbHzEinR47zMa1PvstENk1+tLJJA+2LeWuFe8EL3FV7rcMPrrFWt8Ik57wSE
 SQZ9m2j/a5SVE2wwKt3tFS6Sy5kM8tXdKr6tuuICHvN0eZLgsfyR2Smfy5ncUcfJuX
 NI+/9GxTZqGcXIADkHInOXI9OAYtf9/SOsnlfwyxhBZ+ttej7iKkz/nL4tsKThTN/i
 wlmMlRh+MDSIy1I8jBUJzGC8PE3xqlcYxL6/oCA7obvc2YKTwAJ/iUHx+Mhv0KBcyl
 Y75DeMdIxWg2q1FTL2Nbb26vktbOGNjAHOisuaJ+Vqgc5ldSj2AX0wdqYpuBauNWJj
 ubK34k7azH4YQ==
Received: from localhost (unknown [31.46.243.74])
 by mta-10.privateemail.com (Postfix) with ESMTPA
 for <bug-gnu-emacs@HIDDEN>; Sun,  2 Feb 2025 12:48:45 -0500 (EST)
From: "Basil L. Contovounesios" <basil@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 31.0.50; Which args can cl-nintersection and cl-nset-difference
 mutate?
X-Debbugs-Cc: Mattias =?utf-8?Q?Engdeg=C3=A5rd?=
 <mattias.engdegard@HIDDEN>, Stefan
 Monnier <monnier@HIDDEN>
Date: Sun, 02 Feb 2025 18:48:40 +0100
Message-ID: <87h65cgruv.fsf@HIDDEN>
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-Virus-Scanned: ClamAV using ClamSMTP
Received-SPF: pass client-ip=198.54.122.149; envelope-from=basil@HIDDEN;
 helo=MTA-10-4.privateemail.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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001,
 RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 1.0 (+)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

Since as far back as I can go in emacs.git history, the manual says:

 -- Function: cl-nintersection list1 list2 &key :test :test-not :key
     This is a destructive version of =E2=80=98cl-intersection=E2=80=99.  I=
t tries to
     reuse storage of LIST1 rather than copying.  It does _not_ reuse
     the storage of LIST2.

 -- Function: cl-nset-difference list1 list2 &key :test :test-not :key
     This is a destructive =E2=80=98cl-set-difference=E2=80=99, which will =
try to reuse
     LIST1 if possible.

whereas their docstrings say:

 (cl-nintersection LIST1 LIST2 [KEYWORD VALUE]...)
 Combine LIST1 and LIST2 using a set-intersection operation.
 The resulting list contains all items that appear in both LIST1 and LIST2.
 This is a destructive function; it reuses the storage of LIST1 and LIST2
 whenever possible.

 (cl-nset-difference LIST1 LIST2 [KEYWORD VALUE]...)
 Combine LIST1 and LIST2 using a set-difference operation.
 The resulting list contains all items that appear in LIST1 but not LIST2.
 This is a destructive function; it reuses the storage of LIST1 and LIST2
 whenever possible.

The mutates-arguments property added in

 Byte-compiler warning about mutation of constant values
 bfc07100d28 2023-05-13 11:53:25 +0200
 https://git.sv.gnu.org/cgit/emacs.git/commit/?id=3Dbfc07100d28

agrees with the docstrings, but CL docs I found online, and Jo=C3=A3o's pat=
ch
in https://lists.gnu.org/r/emacs-devel/2023-11/msg00595.html agree with
the manual.

My arguments in favour of the manual:
- Documented for decades in both Emacs and CL docs.
- It is the weaker of the two requirements, thus backward-compatible.
- Set difference implementations do not naturally benefit from modifying
  the second set (though I would love to see a counterexample).
- Callers of cl-nintersection having to ensure both arguments are safe
  to mutate (e.g. through excessive copying) could diminish any
  performance benefit it has over cl-intersection.

If there is agreement, I can follow up with a patch for our docs and
tests.

Thanks,
--=20
Basil

In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.18.2, Xaw3d scroll bars) of 2025-02-02 built on tais
Repository revision: c91c591f0f0cc774647c32bdcf05bb3a9551e340
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101015
System Description: Debian GNU/Linux trixie/sid




Acknowledgement sent to "Basil L. Contovounesios" <basil@HIDDEN>:
New bug report received and forwarded. Copy sent to mattias.engdegard@HIDDEN, monnier@HIDDEN, bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to mattias.engdegard@HIDDEN, monnier@HIDDEN, bug-gnu-emacs@HIDDEN:
bug#76017; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 2 Feb 2025 18:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.