From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9D03C77B60 for ; Thu, 30 Mar 2023 20:28:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229799AbjC3U2c (ORCPT ); Thu, 30 Mar 2023 16:28:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbjC3U2b (ORCPT ); Thu, 30 Mar 2023 16:28:31 -0400 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46FF7C9; Thu, 30 Mar 2023 13:28:30 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 1907D3200959; Thu, 30 Mar 2023 16:28:29 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 30 Mar 2023 16:28:29 -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= 1680208108; x=1680294508; bh=vQs4ynDb5KaPKtPAzLl0Rc9EXZoECrk6bMr SAt43TCw=; b=DV2BCGAEYE89/0qB9BCxZL65j8OujS0AqVHYgP6geTlizxxKs+a n+h1/Rq0qDKGEvXlhQ3O/WNsnR1iUWY5opFs1bthRv66hQkp2mSUsBFhJ365fqrc uWVQjDkLbzhI9GwllS5MMma21dc+SJjKS91l+tC9sSGHCPWo+8H6n/Vxj9+whEwL q/U2I1Cy3UsFHQyuS8n8rolINuuX/p0H5US0IQtqQh4QJRA3IUX6RgaOWaYVkxQA nda80+Px8RfxpltFBmJn98UEWFHA8DLkegrG7PBbgVMF/vH9fzzreLw3H6EASD79 z3Mf3fHhdb1gpToC6TpqWN2+xHZPmk8jrwg== 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= 1680208108; x=1680294508; bh=vQs4ynDb5KaPKtPAzLl0Rc9EXZoECrk6bMr SAt43TCw=; b=bRz94HWqUtIeSEAzn9WBi4BZ43hv/ArbNIhDIIKZl6nL1zBd+Mp Ny0EEMvuLcADVBfXvTvp4W4uT+lwMvjIz0CqAGyLB2j0hItCZIGMgUPK+6v8lzim bNwZV/CR4DhR+pQDW08TC71bTSu//+oOs6BcbDH5gN248SatJxg/YxaDUB28s38Z Z+4sG4kLIFAajLDA1HQEuat345FU4SBVXUdnmubK0VvGgAYTmLdAeBtCBtPS1xYE ss5nvUNvlxpc+q6yCElrDpKQhZNFkw3y/cn8PbyvXVD0yrvzYHKR38Cy+ucnLDj3 iHzRN/qeEno8Zs8jHNmGDCCAkqGJS02kfCA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehledgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpeetlhhi tggvucfthihhlhcuoegrlhhitggvsehrhihhlhdrihhoqeenucggtffrrghtthgvrhhnpe ehudduvdetkedvkedtudeludfgfffhudegjeeguedvvedtteevjeehheeiffefgeenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhitggvse hrhihhlhdrihho X-ME-Proxy: Feedback-ID: i56684263:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 30 Mar 2023 16:28:26 -0400 (EDT) Message-ID: Date: Thu, 30 Mar 2023 22:28:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH v3 08/13] rust: init: add `stack_pin_init!` macro Content-Language: en-US-large To: Benno Lossin Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , =?UTF-8?Q?Bj=c3=b6rn_Roy_Baron?= , Gary Guo References: <20230329223239.138757-1-y86-dev@protonmail.com> <20230329223239.138757-9-y86-dev@protonmail.com> <4b048bfc-e4fe-8c2f-ebfe-9b6a410cd8b8@protonmail.com> From: Alice Ryhl In-Reply-To: <4b048bfc-e4fe-8c2f-ebfe-9b6a410cd8b8@protonmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/30/23 17:19, Benno Lossin wrote: > On 30.03.23 17:00, Alice Ryhl wrote: >> On 3/30/23 00:33, y86-dev@protonmail.com wrote: >>> From: Benno Lossin >>> >>> The `stack_pin_init!` macro allows pin-initializing a value on the >>> stack. It accepts a `impl PinInit` to initialize a `T`. It allows >>> propagating any errors via `?` or handling it normally via `match`. >>> >>> Signed-off-by: Benno Lossin >> >> Reviewed-by: Alice Ryhl >> >>> --- >>> +#[macro_export] >>> +macro_rules! stack_pin_init { >>> + (let $var:ident $(: $t:ty)? = $val:expr) => { >>> + let mut $var = $crate::init::__internal::StackInit$(::<$t>)?::uninit(); >>> + let mut $var = { >>> + let val = $val; >>> + unsafe { $crate::init::__internal::StackInit::init(&mut $var, val) } >>> + }; >>> + }; >>> + (let $var:ident $(: $t:ty)? =? $val:expr) => { >>> + let mut $var = $crate::init::__internal::StackInit$(::<$t>)?::uninit(); >>> + let mut $var = { >>> + let val = $val; >>> + unsafe { $crate::init::__internal::StackInit::init(&mut $var, val)? } >>> + }; >>> + }; >>> +} >> >> This will be inconvenient to use if the initializer is infallible and is >> used inside an infallible function. However, I'm not sure what a better >> alternative would be. Perhaps we should have three variants? > > That could be an option, any ideas for the syntax though? Or should it > be a different macro like `stack_pin_init!` and `try_stack_pin_init!`? You've also split up the other macros into a fallible and infallible version, so I think the same would be fine here. Perhaps use `stack_pin_try_init!` as the name? >> Also, maybe a `<-` rather than `=` would be more consistent? > > That is sadly not possible, since `<-` is not allowed after `ty` fragments. > >> Anyway, I don't think this should block the PR. We can revisit it later >> if it becomes a problem. > > Sure. > > -- > Cheers, > Benno > >