Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1495380rdh; Mon, 25 Sep 2023 14:51:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXHq8Ttkyb7kdD6zITs49JBRuBB+zHLRt5jgwDvglq4mlovEldOhzSb9OYw+13lyNPJtyy X-Received: by 2002:a05:6a00:1ace:b0:68b:a137:3739 with SMTP id f14-20020a056a001ace00b0068ba1373739mr7052905pfv.4.1695678677260; Mon, 25 Sep 2023 14:51:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695678677; cv=none; d=google.com; s=arc-20160816; b=MauLqz1T0UvJYxWOlQmTlq33wqCubVtU9w1RrmuLbWoJLS5+JgoL7z4FJaUNNw2AKu 2oSUz+//Wn5d1yj/uLOOnUhJoTiK0WErCMDmZYO+yyc5J3usUPYr9NE1QuWqeETm5wZz 4GBhItGg+mFYIkf1HYwQGs42876tvZKXjzZFu+SH8dh2bPBz3Thgdq9czqNzBmndObsC 9V8wAMb2izOI5B7XpSkUmCNKW11eiwtq42zPUIrq6BdATkyIR73qNzvGngW9IBirij0j 0Lek5zNAzFRgi2QyH3NMNElJVUa/xamgnOE5kUz5CWOqjh+dov0jQQDOo6BJkSS/G8En lAQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:feedback-id:dkim-signature:dkim-signature; bh=TgAuFtIu6cq6sGedGPSBpY1cujauqO84fvCBuUD8cl0=; fh=VPDWRaaDcyYl+vrcZnu2YIc7ggj2XWE0zvrVzo7DaoY=; b=zQlS8JAA61vn6JarRdr6ulYYVh4svGY05jJylQ9A948HlF61ekeGTyYku+jYYajYXJ yJYFiSI+vMr9JMvv46RV+RdomVUrwAKX8mqN4AZUjwSfMt7UDFakBUoSMbkLfNoyPcpG HRy33xdZMhdAoVUdAp2hKMaMM8RBvmK7jgHYDRLQmGEqbb3rA7XdbS1A/+jOV5+ocWjp tl3dcWGXapzoXIngyMxWIbZxXJy9QKbHEBgOlngCTDcDepiW8UISeOorivr77QLM62aO RJ3nEn+piDypWrXBJwWK983yN5bMP6y5p7mM5QIcQZ7B29Ya9RNch550HoYmR3cwc1o5 SywA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ryhl.io header.s=fm2 header.b=kXW43lac; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="eqa9Pe/i"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ryhl.io Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id g19-20020a631113000000b0057851fc2b4asi11012904pgl.55.2023.09.25.14.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 14:51:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@ryhl.io header.s=fm2 header.b=kXW43lac; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="eqa9Pe/i"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ryhl.io Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 74098806A612; Mon, 25 Sep 2023 08:30:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232807AbjIYPaS (ORCPT + 99 others); Mon, 25 Sep 2023 11:30:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231674AbjIYPaR (ORCPT ); Mon, 25 Sep 2023 11:30:17 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85B5D90; Mon, 25 Sep 2023 08:30:10 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id ACC555C26A7; Mon, 25 Sep 2023 11:30:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 25 Sep 2023 11:30:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ryhl.io; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1695655809; x=1695742209; bh=TgAuFtIu6cq6sGedGPSBpY1cujauqO84fvC BuUD8cl0=; b=kXW43laceJenWVuo6y4LI4rWzr2fzjlUy+wFE9mUe7lI6wtTuEQ O+GlgygxiI58JYlsOJo85VB+J1BsLHTOZ+rjkQKyKXqKG3FLxstDBbAYxr9vpU/c UahN5mq97X+z4diXwEmzkVUlY7k7Zv2L15WMhuTnDvoFdulaxON98KqhbG4033TI nUCNQPVJHCoN3ssCxRXNr3QAuRy2Z3EswSCS+dlFW+5zaIg1VklcmboeALwzRsxG mZVGIGMHONvQ72h8NOg8jQjNE3hnlzGj3xYSqrDHxxdHSzQXobSiBFpzrX+tVgEF xcNSyj9syr1aawFsgFebgrl+GmKq8x4Eo+A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1695655809; x=1695742209; bh=TgAuFtIu6cq6sGedGPSBpY1cujauqO84fvC BuUD8cl0=; b=eqa9Pe/iz9+IhSailMcc0FYrcWXTuJjj943pDey/aqsnZJ/ZIUH MvBuLeVNUsdP/yRnFSbNvu4qZnOmJ++pVLO0Rf3uUW1reEoFOd5/ReyAk038hxLL vpT0zk5D/xaWP3iz/J0YVu3EEwM9+8JR5qRFNULwAM+ooC9ok0mU68Qh2sp8LUhd pcK2TAqpXK9yS0eL0YAqErm+I2IfLcWr9NhsMzasw/ndwXr8rF5EUvaHjlq8wr6e s+thtAWKEY/f/VCCSKSAGGKnZ6T0WYAZ/jqYO4PJvxlNdKF/Ptcj8yanqQUUzDdk 2rtpUNgecMSDlR3yseCrGCgZsK2sRBzsF3w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudelgedgkeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdejnecuhfhrohhmpeetlhhi tggvucfthihhlhcuoegrlhhitggvsehrhihhlhdrihhoqeenucggtffrrghtthgvrhhnpe efgfeugfdtgefhueeiudffjefhveeuheeuheekvdetfefgheehtdffuddtgfdujeenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhitggvse hrhihhlhdrihho X-ME-Proxy: Feedback-ID: i56684263:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 25 Sep 2023 11:30:07 -0400 (EDT) Message-ID: <0b7fc71c-b3c7-4c29-92a9-587daa46ad59@ryhl.io> Date: Mon, 25 Sep 2023 17:30:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/2] rust: arc: remove `ArcBorrow` in favour of `WithRef` Content-Language: en-US-large To: Boqun Feng , 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 References: <20230925150047.1961646-1-aliceryhl@google.com> From: Alice Ryhl In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Mon, 25 Sep 2023 08:30:18 -0700 (PDT) On 9/25/23 17:17, Boqun Feng wrote: > 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? > No, the raw pointer in the Arc was created from the immutable reference, so the raw pointer has the same restrictions as the immutable reference did. Alice