Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1581729rdh; Mon, 25 Sep 2023 18:25:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFcEWPJ2PRw6+xRPzz/01fPMpQhcaLY6acR5t4SyimUfpvEdCNcSQtTuDWyK6XqqWj4dmBo X-Received: by 2002:a05:6a21:a584:b0:15e:556:bc26 with SMTP id gd4-20020a056a21a58400b0015e0556bc26mr8301791pzc.62.1695691518375; Mon, 25 Sep 2023 18:25:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695691518; cv=none; d=google.com; s=arc-20160816; b=GM1iujiJgKbPcdbK4ikGqxeWGoUXKGbt7STHiW/RFl+gS+WXxx1uDQfA+fmPG7yNbb 6AKX1JZDPZSMkSUo/V5tKNXJH61mZGNuujI28BfUXY+8I9mESasUZfWu61qgbNPmVl8B 3JAkySkmt3e8nKU8cwtDSDk8Ev0PKSjzX/axKYCRExirw+DFhEQpBh/XHi6PWDCpcwsQ 77Qw+N6xnkoR/ivkKkqkX1NEUyY+l52+2n2nxCa+VilezDowPsyg9cn/+E/McwYFj3zU H/3C9b9nk2ys5Lm4smtPxiPx728tVQmfCrsoLP27tKPxvrxvgYNyzl/sDrTOUH9fKgsB sCmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature; bh=cp05RJcC1kdlonhGXdkkByIHpEVtVJUJziov6gnH670=; fh=yxfkMbnF1C72usPyZiZOCZnNOFoa7VSQ1prJ+J2c1p4=; b=0s5H2xmKwln5w3ThbCuhHW8JqdiyEeK4RkalGuhX2NeRuwP45L0sfxK6+hIgXBGUJb Q5cgdoRpag47NwLTKyQo5oLLtKca2vVfY5wxDE0xSgWotCxHDvnkZ6wNWzaBZj0RuqTu 5oEuLsfdilKRiD4byz6zW6aMr8hyEmm1n4uTzTCtUTSfv5EsxTGZKqndlhMgmF6w/kX5 FHRoSHev9RAN5ZCrToSxjpBiI4ZBv8PoNX0caWyg7klfg3N0LUGLLjvGuvCbKkTO9hAJ sFlXGlqknlweV1RqEUbgotySUO16ugRDoJfjuMAo/4nU9V5H2IKiO3co/uRSmMBZVmYf Jq2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZFVqU31W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id s1-20020a170903200100b001c62139b16esi2531017pla.4.2023.09.25.18.25.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 18:25:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZFVqU31W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 5C347807452A; Mon, 25 Sep 2023 08:17:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230076AbjIYPSC (ORCPT + 99 others); Mon, 25 Sep 2023 11:18:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbjIYPSB (ORCPT ); Mon, 25 Sep 2023 11:18:01 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87A509C; Mon, 25 Sep 2023 08:17:54 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-99c93638322so1517828366b.1; Mon, 25 Sep 2023 08:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695655073; x=1696259873; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=cp05RJcC1kdlonhGXdkkByIHpEVtVJUJziov6gnH670=; b=ZFVqU31W2m8GZQlgRKzGzniC2VYw+yfFaqsIsn0Q7VzHrk9gxtsY89C/Zm2R+rPD8R W5es7notYtwI/Nj4o10WnuCgaTaSpMMhsXyiAnwsGmQka2bMRnZtFDTQKBpWPe3jSXaN NHXpuOHzah/sTxd2GfkZlBCUv5Tf4RauYzRHWreamswERK5Z9ezqE54i5jRv4rkU5jfO GzV/UBoWCmYr58fbWHLSN/EvmXRbHj2O1eJMg/SqTOXBdGYwebPow7+HdSwCF0kt+mtY DX+zz80/amZ7pyIq4XUdWoz4dAViqcD9b4vZcmG+N9SdRaEoGzohRCdcfniUYxUVB5wF fnjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695655073; x=1696259873; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cp05RJcC1kdlonhGXdkkByIHpEVtVJUJziov6gnH670=; b=i/5Yjs+VGRsQMZaDsAmHS59Fey45NEjbCWqf4AqywIH5G6PsUSjnc9zvMKsZrdhPce N7jBVs8XG/7b2YANH+djZQRvSHFeJZiFws+3DTNWbn2lmKd/K1Q+b7ZYwvP2OiXlkt/I Is1cZoOETjfOdT//8lYs6v0O13Om5e4UcV/7YyOgItHbRfts3niHGLidGiZG+7XbpM6Z p7lHF1vlmw7k7PHqtf7I+z5/V3rI9L9dLY+BXCEvb5y8fxa8eBQ31KRh3LjRWhtRsyar BSdDolX32aWdeeCn1W6Yomt1NUcJHgAG1uU7w4CiMm22DGTob6RQSoYtrdZgsjHeFxtA 2DVg== X-Gm-Message-State: AOJu0Yz8VWFjBiD8uRfnW5U2cdxem3h2CXopHiuH2NJoteDGwoppcykm SeUXA2DJxcGBehvbVRA2LEI= X-Received: by 2002:a17:907:60cc:b0:9a1:8993:9532 with SMTP id hv12-20020a17090760cc00b009a189939532mr15927357ejc.30.1695655072767; Mon, 25 Sep 2023 08:17:52 -0700 (PDT) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id s16-20020a05640217d000b0053420e55616sm1166104edy.75.2023.09.25.08.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 08:17:52 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailauth.nyi.internal (Postfix) with ESMTP id 5254527C005C; Mon, 25 Sep 2023 11:17:50 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 25 Sep 2023 11:17:50 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudelgedgkeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeehudfgudffffetuedtvdehueevledvhfelleeivedtgeeuhfegueeviedu ffeivdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdei gedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfih igmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 25 Sep 2023 11:17:49 -0400 (EDT) Date: Mon, 25 Sep 2023 08:17:48 -0700 From: Boqun Feng To: Alice Ryhl Cc: a.hindborg@samsung.com, alex.gaynor@gmail.com, benno.lossin@proton.me, bjorn3_gh@protonmail.com, gary@garyguo.net, linux-kernel@vger.kernel.org, ojeda@kernel.org, rust-for-linux@vger.kernel.org, walmeida@microsoft.com, wedsonaf@gmail.com Subject: Re: [PATCH v2 2/2] rust: arc: remove `ArcBorrow` in favour of `WithRef` Message-ID: References: <20230925150047.1961646-1-aliceryhl@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230925150047.1961646-1-aliceryhl@google.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 25 Sep 2023 08:17:59 -0700 (PDT) On Mon, Sep 25, 2023 at 03:00:47PM +0000, Alice Ryhl wrote: > >>> I'm concerned about this change, because an `&WithRef` only has > >>> immutable permissions for the allocation. No pointer derived from it > >>> may be used to modify the value in the Arc, however, the drop > >>> implementation of Arc will do exactly that. > >> > >> That is indeed a problem. We could put the value in an `UnsafeCell`, but > >> that would lose us niche optimizations and probably also other optimizations. > >> > > > > Not sure I understand the problem here, why do we allow modifying the > > value in the Arc if you only have a shared ownership? > > Well, usually it's when you have exclusive access even though the value > is in an `Arc`. > > The main example of this is the destructor of the `Arc`. When the last > refcount drops to zero, this gives you exclusive access. This lets you > run the destructor. The destructor requires mutable access. > > Another example would be converting the `Arc` back into an `UniqueArc` > by checking that the refcount is 1. Once you have a `UniqueArc`, you can > use it to mutate the inner value. > > Finally, there are methods like `Arc::get_mut_unchecked`, where you > unsafely assert that nobody else is using the value while you are > modifying it. We don't have that in our version of `Arc` right now, but > we might want to add it later. > Hmm.. but the only way to get an `Arc` from `&WithRef` is impl From<&WithRef> for Arc { ... } , and we clone `Arc` in the that function (i.e. copying the raw pointer), so we are still good? Regards, Boqun > > Also I fail to see why `ArcBorrow` doesn't have the problem. Maybe I'm > > missing something subtle here? Could you provide an example? > > It's because `ArcBorrow` just has a raw pointer inside it. Immutable > references give up write permissions, but raw pointers don't even if > they are `*const T`. > > Alice