Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp39686lqp; Thu, 4 Apr 2024 06:40:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUGjJYvpJPfBggXA3AraXekWMJ3WxcFYrif/Y5h65HZ00rrj8NynP6ugGB5tXcYJOqw1sKNKA+H7A1bJHtQMIa9G0fyECopNAIVcdh1iQ== X-Google-Smtp-Source: AGHT+IEYN6Wa+lYPPDlwUy0CDbSiZe9CdHCwuCDGnB1tTU8d9emvP7jdLcmVt69AyCRTw7RdHsNa X-Received: by 2002:a05:6808:d48:b0:3c5:db51:367a with SMTP id w8-20020a0568080d4800b003c5db51367amr42099oik.38.1712238058511; Thu, 04 Apr 2024 06:40:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712238058; cv=pass; d=google.com; s=arc-20160816; b=jcqvk6UNHrOn+/CvZdporTXYdQU0PZRAI4Vja+nfDvCiWMrJCBG7opxBNoAsQD96GN LcbPI65WNAmDKVfO2oR0UPfmXvwtvrXXh/xjiwSSPWG6ar8zAK/4eN+u05Ayvu0dV30E 09/tOpIT2fdH6MdBNxDu8a1qJRvTth9un9VSr/iDhYpDufkNMshycDKCqYDAi60XF4n9 V/01+pN9KaMTMIhtyqDFMAL7ZTrDTmj3nk7aoY9SQJxIHkgTEtWHF18RVFtt+ttV6whg H5j95dVon4AKvl1OIDr/MXJDuW2RyGe5tlXsJBcmiqP2QL0k6J8lBBzq//tWnaOI4lcI hSYQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=aOS6jB5q96k7GK5LtcB2yIdNav1TsSAYvbOvkVp9ZNE=; fh=71L1VDCPZNMC6lTykFKEsJzPsrKmJ72OrplAQ9IOVmU=; b=QagjXeO2TumIr+h86ft4gU3PbORQ+KRLHNOy3zcuC7tLAohC5RzmLgVZo++l3zsYfe DsiaKLCZcv62/408iduqU3DD+bF1hsR37oyRDqTDGBGXs73L+83mp1ZftCEzneaNyeNg aAIrn9nYyiYtclvk/R/o0jVmoDje11NGHF84GrqXKjj6K1iRWhJ3oL00Prtkm1TpIHyi e7ZjoJcmuSNdYX58dftXMkzfaE5gHckfynTVlqaWy+JNQvFljWALjgq2FozuVQ52Voyh VAC9pcOpbVqLzFizNTL/4SKzpwWsE1JFWp3qQvDKAOzZc/a4nd1gyz8QHTTP9J0Az+2+ +mRA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="PgH0YwT/"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-131519-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131519-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id dt7-20020a05620a478700b00789e9180877si16303807qkb.721.2024.04.04.06.40.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 06:40:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131519-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="PgH0YwT/"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-131519-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131519-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2042B1C24F7D for ; Thu, 4 Apr 2024 13:40:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A95F412837F; Thu, 4 Apr 2024 13:40:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PgH0YwT/" Received: from mail-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D1B92E401 for ; Thu, 4 Apr 2024 13:40:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712238051; cv=none; b=iCx0MmZg8wxq5UkkRHBFDm065EI67PpDu6DykQJUzebMO9N+mBtrBVy566Api+CjcMfN8c2XLgOnSDt+uIcQNpUSXl9CzBll2xja04Ij95/su0xSJZiTKpC3iO9AAE6lCR6vpvEaCXfkbGSql9BbyhqJVeUsRNsuPsxCLGD2Zrw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712238051; c=relaxed/simple; bh=z89MX8HYRU8eftunJgLf/N/hvA+22G0MlIRdKBYcBOQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=jzSCXniAtQQTrW8GcvCMy3KVFCdzLgZKAsECOK+AR5tW6szhSyXf++BNEEhkNpn6xI3ylOyYpBf72y1H/bzKy7Si/v4Reuwq/VhkQT/fHEPzdJsmMFNWaQurAB/hs0yBkmMZBjzqxRMiEKQvKVjgCgXpBuO8mT+S7PaajtoIpyQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=PgH0YwT/; arc=none smtp.client-ip=209.85.222.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ua1-f41.google.com with SMTP id a1e0cc1a2514c-7e3d93697f7so332497241.1 for ; Thu, 04 Apr 2024 06:40:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712238049; x=1712842849; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=aOS6jB5q96k7GK5LtcB2yIdNav1TsSAYvbOvkVp9ZNE=; b=PgH0YwT/maUKinOEMoJeJk4WnIxwiZTejcEeGmI/DPQLzkTNGgss4D9gmgLTe1l37p 6daai5ETDqoMwVDYmAyXjk8nLsPA12joiLU9WEvcYRA27ICOl4KipMdTFiS1IdRJb8LD ZOwUy4nyc8vwwUIqeZ79nUayH7EduYwkxzGVA8YzUxrS38dQIIqLwNEBuBZXHexkrH/0 hLDKtDUDRp+ui+9lL0yLgCasVBSYz+e/swMLNP5RgFHTRPnPiNFpz0IuswuxfAnfYixy Lf1z/9aGI6Uy64pPIfJyQFW6v4ErYNSLZmG9HqJ/F5fM0wJPuOy120CRPoM/LkCWVVzR g0Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712238049; x=1712842849; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aOS6jB5q96k7GK5LtcB2yIdNav1TsSAYvbOvkVp9ZNE=; b=kjLq6LA3Dy+bl7KfUeK1b/kO6T/mtaB96j4vRObXRgE8AfUIEx527Z+cZjrmjq11r4 Ed0Xr9Nl88Wrka956N9R7WKP3p5p2sSukp4p26b5C6aBpsayLJQ9yTBjE8zXpSvQre+/ qUChn/A4KtLpfBBRdiB0atgwAWqrm6qRG2UN0UifDTvsSGcX8MNzyFhJ7rYHzMBAAFVW WCrD5SqV6E0mdKz/7X9HKNQH01/Faa3iBIvwl6eEbrYrin1URQMqMmisardUfMPfApv4 o1gFroeWjeKBrcmPYGUL1u5kmZbGKJMXaZBK3JgBbjOqQmetnyGQ8KPFRJxfNbBfnMw5 54YA== X-Forwarded-Encrypted: i=1; AJvYcCXPrFeLcsE/t08BwNxf1vwqwtMARxhmg1Uc+E2xU6yZI7R3jeSUcmc4+5PjISJe5V2lywHIdMuNd0kN2WP24UyUEpUG9YICM0f+4aMF X-Gm-Message-State: AOJu0YxwgxaDr6DDMCYTYKW0IYXylfG7AjlXSBrBKURqgxKdnk5nE1KJ gNXzQXhuBxjO4W3b68SriPFeKC8LxHeHJHPBp1Q8vAkGjRo8mblQ0paVyoq2R093ZrG4Xi5wlJR xH+eL5sv5SDyrMC0lJufAo6gPJPCdhLJt+GwH X-Received: by 2002:a05:6102:f0a:b0:479:c181:a659 with SMTP id v10-20020a0561020f0a00b00479c181a659mr3220344vss.14.1712238048672; Thu, 04 Apr 2024 06:40:48 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240402-linked-list-v1-0-b1c59ba7ae3b@google.com> <20240402-linked-list-v1-7-b1c59ba7ae3b@google.com> <4aaf7fd7-49ed-4b3e-b691-0d8d7d426d3a@proton.me> In-Reply-To: From: Alice Ryhl Date: Thu, 4 Apr 2024 15:40:37 +0200 Message-ID: Subject: Re: [PATCH 7/9] rust: list: add cursor To: Benno Lossin Cc: Miguel Ojeda , Andrew Morton , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Marco Elver , Kees Cook , Coly Li , Paolo Abeni , Pierre Gondois , Ingo Molnar , Jakub Kicinski , Wei Yang , Matthew Wilcox , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 4, 2024 at 3:28=E2=80=AFPM Benno Lossin wrote: > > On 03.04.24 14:49, Alice Ryhl wrote: > > On Wed, Apr 3, 2024 at 2:19=E2=80=AFPM Benno Lossin wrote: > >> On 02.04.24 14:17, Alice Ryhl wrote: > >>> +impl<'a, T: ?Sized + ListItem, const ID: u64> Cursor<'a, T, ID> = { > >>> + /// Access the current element of this cursor. > >>> + pub fn current(&self) -> ArcBorrow<'_, T> { > >>> + // SAFETY: The `current` pointer points a value in the list. > >>> + let me =3D unsafe { T::view_value(ListLinks::from_fields(sel= f.current)) }; > >>> + // SAFETY: > >>> + // * All values in a list are stored in an `Arc`. > >>> + // * The value cannot be removed from the list for the durat= ion of the lifetime annotated > >>> + // on the returned `ArcBorrow`, because removing it from t= he list would require mutable > >>> + // access to the cursor or the list. However, the `ArcBorr= ow` holds an immutable borrow > >>> + // on the cursor, which in turn holds an immutable borrow = on the list, so any such > >> > >> The cursor has a mutable borrow on the list. > >> > >> > >>> + // mutable access requires first releasing the immutable b= orrow on the cursor. > >>> + // * Values in a list never have a `UniqueArc` reference. > >> > >> Is there some type invariant guaranteeing this? > > > > The List owns a ListArc reference to the value. It would be unsound > > for there to also be a UniqueArc reference to it. > > I think it would be good to add the existence of the `ListArc` as an > explanation. Will do. I'll do the other suggestions as well. Alice