From patchwork Fri Feb 24 09:11:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asahi Lina X-Patchwork-Id: 61198 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:7b8e:b0:9f:8c76:fea4 with SMTP id j14csp1210898dyk; Fri, 24 Feb 2023 01:13:22 -0800 (PST) X-Google-Smtp-Source: AK7set8OrKgpz8aEoLCxgaPfxY69J1/LrdmiKbbGSNRLBiY1SbVhxJe/QvH2u5E1gGh5yGFgDPrg X-Received: by 2002:aa7:9843:0:b0:5e3:ba14:8566 with SMTP id n3-20020aa79843000000b005e3ba148566mr1056065pfq.28.1677230001832; Fri, 24 Feb 2023 01:13:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677230001; cv=none; d=google.com; s=arc-20160816; b=JaqpFcoaxjPeOIg18gYVvXMe1DbttYpfmfi7NWBrlt6iV8KYKUVqTqClp/n4tYaAxY XtoM6q0x+Ot5wegEb/IvWfFsOPXHAELN70hmrGt2AgtdUV1a5BNRATC0dOm58kcWUem2 pxp7HZQEvP5zGCCoOLxucczoSAXnQxnbD0g7gAqvYgVpiTiirdQLpQFMkkI6GMq5860O x8EAzY7v4FXkCsDW8ufVrdRB4mgPXZGOW9CuciQ78t7bhA2/dBNdhzugz0gLrCYMnW0q TPqNF8Zq5u3ykPImdJdjwkei1UQl9ZLNGeKYkf2jw4M4LJYbLiLhcWupsKVd+D1cEoxw cW3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=cd6K2qDv3NcFRgrExt/mrZ/0ut6ug9ZVYdKznyaYmiE=; b=Gi3XbtZA5qOoq/KJzpxSi66YT2udwfEnZzUrCtUh9bUVW0RfaHH3mMabmDEq7fikS4 z25GcjOEwd94kukaSllZPXSUQo+ShZXZfg7Wm2XRdrzi95tvU6owbxA76aTQGUzyyEkU oy/dxq5yq5OKY2KvV+Xfk8MLV59WKWjHuR2O7mXFP9MGEJ+jtU5rN/GJziE/nuo1BLtF dTLP8s0T4hol8uQASqbmDau69mpEnsM4tpVnCBp31tBhA/Z3H6ZmvubgmEuLlwDLfvW6 w0LTPCZvhCZ9elBLMCav/ZhUjYIOXDQ/BQDjwCmbS3niFVGQmsNBN2/+hQ+NuLMVliyb 1+Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@asahilina.net header.s=default header.b=sSC0VSiw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=asahilina.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cn15-20020a056a00340f00b005a911b0a4e0si13454052pfb.240.2023.02.24.01.13.09; Fri, 24 Feb 2023 01:13:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@asahilina.net header.s=default header.b=sSC0VSiw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=asahilina.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229685AbjBXJMI (ORCPT + 99 others); Fri, 24 Feb 2023 04:12:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229635AbjBXJMF (ORCPT ); Fri, 24 Feb 2023 04:12:05 -0500 Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBAA05D460; Fri, 24 Feb 2023 01:12:04 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: linasend@asahilina.net) by mail.marcansoft.com (Postfix) with ESMTPSA id C82703FB17; Fri, 24 Feb 2023 09:12:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=asahilina.net; s=default; t=1677229923; bh=wkplfyZ81CMYGIVsW/sksaSI2sUSjgdmqyg/orT1EzU=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=sSC0VSiw/DFJcOw0MluWtnpjsgxnaq5CRtv7bT0CgvUiR3KLVKidiViSTDTIrv9Y4 A7SYMnJsBK19GyYUUOxTtR1+UEwroRWOqFfiWQ19NETTJEJSGos1xZwqygD7mF0j8C jyLEuKh4WJMXMQh6IPFGkChcOoF+PTmb9cVE5vqvqj9rtaDLnPS3UbiHHntG0q9Vpr oPJWSuhzluFMHv0Wz4+3R4lYTYv/dTifwgoxPPukgEYRwziQqn0aUgGO+KwGtUWFT1 up4AmdxFwYePNonwk1gUiSUGcjRfPrKH89FZermEbHlCFIcaJifuvnam0UQFY5jj9f QivRoXWGRXZ3A== From: Asahi Lina Date: Fri, 24 Feb 2023 18:11:47 +0900 Subject: [PATCH 1/4] rust: Import upstream `alloc::vec::set_len_on_drop` module MIME-Version: 1.0 Message-Id: <20230224-rust-vec-v1-1-733b5b5a57c5@asahilina.net> References: <20230224-rust-vec-v1-0-733b5b5a57c5@asahilina.net> In-Reply-To: <20230224-rust-vec-v1-0-733b5b5a57c5@asahilina.net> To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, asahi@lists.linux.dev, Asahi Lina X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1677229917; l=1615; i=lina@asahilina.net; s=20230221; h=from:subject:message-id; bh=wkplfyZ81CMYGIVsW/sksaSI2sUSjgdmqyg/orT1EzU=; b=dpihB9SPTYWGtGlJDBu1TR+XXTZHd3dUY5XNgEcfL9XzxZo4G8htddwW/e3Rk+nV1QD7x8SyI 47RrcxWK6GnBI/z/4z6xeqIM19pQDYRDiG1WxZRMFh7rPO8plJONNEB X-Developer-Key: i=lina@asahilina.net; a=ed25519; pk=Qn8jZuOtR1m5GaiDfTrAoQ4NE1XoYVZ/wmt5YtXWFC4= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758703126757915868?= X-GMAIL-MSGID: =?utf-8?q?1758703126757915868?= This is a subset of the Rust standard library `alloc` crate, version 1.66.0, licensed under "Apache-2.0 OR MIT", from: https://github.com/rust-lang/rust/tree/1.66.0/library/alloc/src The file is copied as-is, with no modifications whatsoever (not even adding the SPDX identifiers). For copyright details, please see: https://github.com/rust-lang/rust/blob/1.66.0/COPYRIGHT Signed-off-by: Asahi Lina --- rust/alloc/vec/set_len_on_drop.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/rust/alloc/vec/set_len_on_drop.rs b/rust/alloc/vec/set_len_on_drop.rs new file mode 100644 index 000000000000..8b66bc812129 --- /dev/null +++ b/rust/alloc/vec/set_len_on_drop.rs @@ -0,0 +1,28 @@ +// Set the length of the vec when the `SetLenOnDrop` value goes out of scope. +// +// The idea is: The length field in SetLenOnDrop is a local variable +// that the optimizer will see does not alias with any stores through the Vec's data +// pointer. This is a workaround for alias analysis issue #32155 +pub(super) struct SetLenOnDrop<'a> { + len: &'a mut usize, + local_len: usize, +} + +impl<'a> SetLenOnDrop<'a> { + #[inline] + pub(super) fn new(len: &'a mut usize) -> Self { + SetLenOnDrop { local_len: *len, len } + } + + #[inline] + pub(super) fn increment_len(&mut self, increment: usize) { + self.local_len += increment; + } +} + +impl Drop for SetLenOnDrop<'_> { + #[inline] + fn drop(&mut self) { + *self.len = self.local_len; + } +}