Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1377296rdh; Mon, 25 Sep 2023 10:48:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF74LyR16k85oO29tLltB+7moKHsbgvVKDMNV63APMhDLvYsqT3akVgI+EbtuRuk2eDn+k0 X-Received: by 2002:a17:90a:b94a:b0:273:ec9c:a7e3 with SMTP id f10-20020a17090ab94a00b00273ec9ca7e3mr5530452pjw.17.1695664098866; Mon, 25 Sep 2023 10:48:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695664098; cv=none; d=google.com; s=arc-20160816; b=zML14/ZAixYQUKKW0ZIvgCMxcamEQ5JlYeLlpp+2wKoAC+Ptx/iZq9sdLkLQcbUTXs 2P+qSBpHtEybFuwGq7utKhoFcXz6m4UVgiojWexhqPRlDqMOslT+Y03pxIQUhMIe8D96 p+oAmIyvr2XwQX/bYZ2ULt9sYGD5f5uix2OSw1HkLMF8mDRAtJmXib7UjebaK1pGZqqt VC8/rZUQPNTGrvqLpKFL+bOhE6hxStxUXeGj5AdfhHHo71E1bdYQJJt0VU3jAXgBx1Wj Dj+BixbMrUx3W/iNCNI65UuoI80hEGajdoIfAlCe8ZmJ16kAS0PMKPKQYkJ82aaFGHAQ W+9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=STVyCq0Z9CufVRuINVHUuC/ypT8+q7NNtSadYInOtW4=; fh=9KEyjVkskG1skWKFC1Nw5gAMN4yEnzuPp4yO88wWFYg=; b=AmR6p9rhsR+HuW34BxSrWXPL6BSSMwduiYlpCMS4YlDzs5P9TxLI0nXBtxxetwIC7S 89zyA9X0f5kUormYZ7KoagOAIrMQgfad38L2b19eVSGLuhNyZE5F/4cks5jePz38njbP y3BcYye+9uEVqbL2oQ6eCoeh/ak8QZrwQld0PGzmUQXKk2kuxxmsVz3p1Ylf8vNQPSjn a/vanO8KrZWyUiPLmRK4gMQ7pi9LynOqmo2AAm4wNoD9erB1fKLv4uY+fjkb1q4b0JbW hG7alpDPv7XPUjHvuntFT2VThDG7yDGUa6K/7hSOUq+ElCCoJIE8HfbVsF1KEvH1fE3g +U4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="ctpBL/1M"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id lw16-20020a17090b181000b00263860e1f4csi4543199pjb.16.2023.09.25.10.48.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 10:48:18 -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=@google.com header.s=20230601 header.b="ctpBL/1M"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id DE87081BC484; Mon, 25 Sep 2023 08:04:37 -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 S231263AbjIYPEh (ORCPT + 99 others); Mon, 25 Sep 2023 11:04:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229647AbjIYPEg (ORCPT ); Mon, 25 Sep 2023 11:04:36 -0400 Received: from mail-ej1-x649.google.com (mail-ej1-x649.google.com [IPv6:2a00:1450:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1ED2103 for ; Mon, 25 Sep 2023 08:04:29 -0700 (PDT) Received: by mail-ej1-x649.google.com with SMTP id a640c23a62f3a-9a681c3470fso520551966b.1 for ; Mon, 25 Sep 2023 08:04:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695654268; x=1696259068; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=STVyCq0Z9CufVRuINVHUuC/ypT8+q7NNtSadYInOtW4=; b=ctpBL/1MdXZGWRF2Kk2lWUh5PkmjgwLrz6aoBCJo/aQtWjR3+5nHZmhLZnh/bppn/w W3TXczLgW1ZUXih+uN+0DsMjmYMKNg0TkU1hgmEzlFepKoixlVo37tDcsb4B0aJqcO6V bZVJLkIEbbvfCk4tnx75ycaa8pyYtFcwRc0N0wPkUgA5Qa8Oj1QH8Fzd/AgwfU/I2alD lqAPQlkISJzKqeJ5iZUsEw+Yf7D+pAt2VQT4b4Y+mINZgTZuOHMLqcUn4wcMxfySawBN ijD2de6eU4LWTJNjrRA7VaKM75JW15aayjSzRREUxEpi/rCU4Mdz8PXAXiGrEwMH/L/5 ts8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695654268; x=1696259068; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=STVyCq0Z9CufVRuINVHUuC/ypT8+q7NNtSadYInOtW4=; b=vM9ac1DQbULkI2svPqTsQGQntyCwtzG253YPUpFaolC/1BjHuXDzsD7IKTwnBIXLVB nngUPEbFpoPwe8MthTThUox+XnXmfN+6NwtayO6EwZl0ezsfqW170xa/+2H1KeukoHLG 56SAKC6l229zRf8kxwVxFsJjZjr6f+Z/XADWfcGs3Pf4suDyuqMjr49Xx/1WUZbNrE/R dog3nOERgPnlf22+gUL8XG+jHo/14RV/1xCS8sD87aKQjjj8/6YjeBLjprs8sT54Jjtk 2zBUBES8B7QPL6PxOtIkPEPFz6EIPS45qBRphTAlBhkXpPl9hQIIoaaWgfNCSj3he/80 +BzA== X-Gm-Message-State: AOJu0Yw9dY2iDkt8jQiKv0wr4zpoPTSWl4iqvyyDF2tq9aAJL0SEHdmG OPS03lr8+R17IG9kYTZdF9Bid4D+RwshQQc= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:6c8]) (user=aliceryhl job=sendgmr) by 2002:a17:907:3447:b0:9a9:dffb:4c6 with SMTP id ac7-20020a170907344700b009a9dffb04c6mr25326ejc.10.1695654268118; Mon, 25 Sep 2023 08:04:28 -0700 (PDT) Date: Mon, 25 Sep 2023 15:04:25 +0000 In-Reply-To: <969eab7f-ad40-0dfb-18b9-6002fc54e12b@proton.me> Mime-Version: 1.0 References: <969eab7f-ad40-0dfb-18b9-6002fc54e12b@proton.me> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230925150425.1963183-1-aliceryhl@google.com> Subject: Re: [PATCH v2 2/2] rust: arc: remove `ArcBorrow` in favour of `WithRef` From: Alice Ryhl To: benno.lossin@proton.me Cc: a.hindborg@samsung.com, alex.gaynor@gmail.com, aliceryhl@google.com, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, gary@garyguo.net, linux-kernel@vger.kernel.org, ojeda@kernel.org, rust-for-linux@vger.kernel.org, walmeida@microsoft.com, wedsonaf@gmail.com Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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:04:38 -0700 (PDT) >> 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. This is an option. Niche optimizations don't matter for `WithRef` since it's never directly wrapped with `Option`. > > It also means that we > > can't convert an Arc with refcount 1 into a UniqueArc. > > I think you still can, since to do that you would consume the `Arc` by > value, thus guaranteeing that no references (and thus no `&WithRef`) exist. > So I think this would still be fine. The problem is that if you have an `&WithRef` and use that to create an `Arc`, then the raw pointer in the `Arc` was created from an immutable reference, so the same restrictions apply to that `Arc`. And if you convert it into an `UniqueArc`, then the same restrictions also apply to the `UniqueArc` because it's raw pointer was derived from the immutable reference. Alice