From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CFD7567D; Wed, 5 Mar 2025 17:25:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741195505; cv=none; b=Pj/ksdWHrLOezOJBoTcWfRd2n3yxPV2QjmrksYCMla5AhZOZyXWlQe4D3EIoolOU0oN1pEuYiVkbJw++JtMeugKfenTqFPP1L8bxi3kd0Dbt6iX5d7/IzYAj0hwapjxdjGN0p8fJM3LbpLlxTTdczqt0YU2DojsqZZZzUzDyFxw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741195505; c=relaxed/simple; bh=U18Wfl4pQFaaYNIJzuQEGPdF/5EFkPOj+sQlvfXNzwI=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=rrNj1DXTFo5sveD268Yzf0L1GHoHOuA5T2KcOIE/2RbZ7ModdvErJ1QNXrBWX/iB8haHBiiToMHxM//9NEl9s1eYQQVuFRzIPIQuTFQJ7IB9tRV7Gmw2KoQW9b3Mu0kSGEOVoLEoPuieQkXj4YGjN3RMg0BvMwFHAshu2ul7oSo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=isfr5Yqk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="isfr5Yqk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B992C4CED1; Wed, 5 Mar 2025 17:25:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741195505; bh=U18Wfl4pQFaaYNIJzuQEGPdF/5EFkPOj+sQlvfXNzwI=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=isfr5YqkrSHxijEbW83wwx73H9aHLvHo8eU+AEzJN9GQOVvjVVjja2/+jVwCaz1T1 4gb8nfkVojSaUqQLS3m/Cz2JuurqyGBx16qNIFiRpqnW4uatm1NJS8gQPUSBKATPFv MixExuJEHlqWES55sGDYrGGmSTDGyBmQwP8gYaEzGF82riCx3dYrcK56bSFyxwJIwr PutuH+CccgN4/5yAfYL6nr4JzR3wf/+sbreFPieG/DLXLMxeeM+ejH5j8DvnY2uzuB 7WOT96PrF2aNL7euNM8lx9zCjHZL/H+Y0NDjFsjukUbLHOxnP3MNbtu8MvTVssRKIk Uoy/Ie5q7Odhg== From: Andreas Hindborg To: "Alice Ryhl" Cc: "Oliver Mangold" , "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?Q?Bj?= =?utf-8?Q?=C3=B6rn?= Roy Baron , "Benno Lossin" , "Trevor Gross" , , Subject: Re: [PATCH v4] rust: adding UniqueRefCounted and UniqueRef types In-Reply-To: (Alice Ryhl's message of "Wed, 05 Mar 2025 17:02:10 +0100") References: <20250305-unique-ref-v4-1-a8fdef7b1c2c@pm.me> <87ldtj8p2m.fsf@kernel.org> User-Agent: mu4e 1.12.7; emacs 29.4 Date: Wed, 05 Mar 2025 18:24:56 +0100 Message-ID: <875xkn8k5z.fsf@kernel.org> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable "Alice Ryhl" writes: > On Wed, Mar 5, 2025 at 4:39=E2=80=AFPM Andreas Hindborg wrote: >> >> "Alice Ryhl" writes: >> >> > On Wed, Mar 5, 2025 at 3:56=E2=80=AFPM Oliver Mangold wrote: >> >> >> >> Hi Alice, >> >> >> >> On 250305 1339, Alice Ryhl wrote: >> >> > On Wed, Mar 05, 2025 at 11:31:44AM +0000, Oliver Mangold wrote: >> >> > >> >> > > +impl Deref for UniqueRef { >> >> > > + type Target =3D T; >> >> > > + >> >> > > + fn deref(&self) -> &Self::Target { >> >> > > + // SAFETY: The type invariants guarantee that the object= is valid. >> >> > > + unsafe { self.ptr.as_ref() } >> >> > > + } >> >> > > +} >> >> > >> >> > What stops people from doing this? >> >> > >> >> > let my_unique: UniqueRef =3D ...; >> >> > let my_ref: &T =3D &*my_unique; >> >> > let my_shared: ARef =3D ARef::from(my_ref); >> >> > >> >> > Now it is no longer unique. >> >> > >> >> Oh, indeed. That's a serious problem. I see 2 options to deal with th= at: >> >> >> >> 1. remove ARef::From<&T> >> >> >> >> I checked the users of this, and it looks to me like there is rather >> >> a limited number and they are easy to fix by replacing the &T with AR= ef. >> >> But I assume that wouldn't be welcome as it is intrusive nonetheless >> >> and of course there is ergonomic value in having the function around. >> > >> > Definitely not an option. There are many users of this function that >> > are in the process of being upstreamed. The ability to go &T -> >> > ARef is pretty fundamental for ARef. >> >> Not having `impl From<&T> for UniqueArc` seems to work out fine. >> >> It would be unfortunate if `impl From<&T> for ARef` would prevent us >> from having a unique version of `ARef`. I would say that is a valid >> reason to consider removing that impl. > > I think the impl is really important. It's required to do things such as: > > let mm =3D ARef::from(&*current!().mm()); > > Without the impl (or something equivalent), it's not possible to > increment the refcount of the &Mm returned by `current!().mm()`. There > are many other examples of this. Right. Let's see what we can figure out of other solutions then. Best regards, Andreas Hindborg