Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp1928431rdh; Sat, 25 Nov 2023 07:28:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVDjthzS447qRkh+Zj4XwIuKlIaHfwcgsgN6opnxHSirxzbdhAvu9D1YpDlsISLayKWBhI X-Received: by 2002:a05:6a20:3ca7:b0:18c:328b:61db with SMTP id b39-20020a056a203ca700b0018c328b61dbmr3024924pzj.1.1700926130272; Sat, 25 Nov 2023 07:28:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700926130; cv=none; d=google.com; s=arc-20160816; b=yHf3WmsfhKxeO6eQ/j0mk/OJqeWkIcksu9Dz4h2zgtH3hHIhR6pjKGDIKUbDTdja2I tLgJ10dWm0N2qDv0Kr4mp2jPgzXhEoV6VrPdu6CCzSaujlrj7R+z3u6CYS5ens1NOy1/ ZgEgiH93c5PUG9mohnZGjuQby04aJeEjX5Ev1Z8hXluNmBC+eTudbo3NtzK5z3HrF0+A VZGMgTLqRnEV8FGx1PbVKOmqIIOsAXZG1dNBjzhti+DRWnqbopo/DoYkKIlZ//d3Pl6M 6cF2B6MSsiEeW5wWEkKj8tSpahyuhnfM/GodhZsICnJ/kyXuLLpdoxB9YdE4Q7KY+4qH 1Ocw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :date:dkim-signature; bh=CresfKqNPceVr7nx//OsH0O83BJu9CLfB3p0kHEWEpw=; fh=tVmwkqAQQe3jPL8WZj+1sKT/wG7X2Wx9D2BJF6YcCKQ=; b=M3rZ/gIzPzYUHwzAoxYc/+QaealhpKp2By6g7jFq3HVOypNH5XLvq/6rRuyiSmGnNo KCA8YzsH1PUL8FzF717zo9or8As//EqAcPoKCrKFYRVh1/2bdlpufG6Zg1ruvE43Y+y1 osQJyu2uHzfCIhOnBZDVRJ075jNd1clGJBR9wEkhItwAaKzD+lpJWXCC8uE+gYM7ZorW RPj76JzqtQXF17i9jFrwwPJwJvTwEnXc2V8JLnixJXM/6YB93RshfE1ccqLq/T+31fcN Gse0sAkG99oMmXswrrqVI4kxk0qqYV6f7JJtVRNn8FJYushEU8+lUyTzib162LHqg33J sTdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=7bkobibq2ver7p3fnntwujk6hq.protonmail header.b=HJxukUSG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id o66-20020a634145000000b005b91a58721esi5980463pga.316.2023.11.25.07.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Nov 2023 07:28:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=7bkobibq2ver7p3fnntwujk6hq.protonmail header.b=HJxukUSG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A235A807280F; Sat, 25 Nov 2023 07:28:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232221AbjKYP0N (ORCPT + 99 others); Sat, 25 Nov 2023 10:26:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229906AbjKYP0M (ORCPT ); Sat, 25 Nov 2023 10:26:12 -0500 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D94E10A for ; Sat, 25 Nov 2023 07:26:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=7bkobibq2ver7p3fnntwujk6hq.protonmail; t=1700925975; x=1701185175; bh=CresfKqNPceVr7nx//OsH0O83BJu9CLfB3p0kHEWEpw=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=HJxukUSGz6pwgdGZAZshMCviglofAdNeRRGYwHBljRYO0JmiPM0SbgAmZshanU2UX tehxBjzjRiNC6jbCFUpbzFurOLoTWnyd+LrURy4s06lVzuiU1LqljlZxzJJRCyaxct 7iaar9hVGLBJ102GeL255iJ0ysVzezbu773PBc3JM6Qw1Sh2KKAa0oeCqvbwxJZrbo EtW8n47KPxFmXww/9IBwwcvBviT21t7jFQV40wSqom2ys2shcoKiUyn0xvqJ1ayWB3 jbicCUf3gJk8vx6jjo2Si2rQLaI+TIFzv5ZDCUgZdnSdsN8rda8pIXBDiW0m49RO1Q 47n/MDDEVUGXQ== Date: Sat, 25 Nov 2023 15:26:02 +0000 To: Greg KH From: Benno Lossin Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Martin Rodriguez Reboredo , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] rust: macros: allow generic parameter default values in `#[pin_data]` Message-ID: <5hsq7OfTOZ9Wi70n6p9nfFPr4IDJ9YECqWHEgsnMnzN3lcLeojK5ZlwR7nzDGdK5Wjrb95Jk60CGKszSiUhMsZQA2vlwSltMMypfk4HzgJM=@proton.me> In-Reply-To: <2023112514-laziness-valium-7a25@gregkh> References: <20231125125024.1235933-1-benno.lossin@proton.me> <20231125125024.1235933-2-benno.lossin@proton.me> <2023112525-impatient-untwist-ee3d@gregkh> <2023112514-laziness-valium-7a25@gregkh> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 (snail.vger.email [0.0.0.0]); Sat, 25 Nov 2023 07:28:48 -0800 (PST) On 25.11.23 16:10, Greg KH wrote: > On Sat, Nov 25, 2023 at 03:02:00PM +0000, Benno Lossin wrote: >> On 25.11.23 15:26, Greg KH wrote: >>> On Sat, Nov 25, 2023 at 12:51:09PM +0000, Benno Lossin wrote: >>>> This patch adds compatibilty for generic parameters defaults by using >>>> the newly introduced `decl_generics` instead of the `impl_generics`. >>> >>> This says _what_ is happening here, but not _why_ this is needed at all= . >>> >>> Try taking a look a the kernel documentation for how to write a good >>> changelog text to make this much better. It's often times the most >>> difficult portion of making a kernel patch, the code is easy, writing a >>> summary of why everyone else should agree that this code is acceptable >>> is hard. >> >> The reason is hidden in the third patch. >=20 > Please do not hide things, patches need to be stand-alone and > understandable that way, otherwise they will be rejected as no one can > understand why they would be needed. This was not my intention, I just realized this due to your question. I wanted to point you to the third patch (which for some reason sadly does not have the correct In-Reply-To header). Since that might help you understand some of the context. >> Without this, the `#[pin_data] >> macro would not allow specifying const generic parameter default values >> and instead emit a compile error. >=20 > That's nice, but it still doesn't tell me _why_ this is needed. Why > would I want any generic paramter default values at all? Who needs any > of this? What will it be used for? What does it actually do? `#[pin_data]` is a proc-macro that one can put on any struct to make the pin-init API available for use with that struct. Since e.g. mutexes are initialized using the pin-init API, you have to do this for anything that contains a mutex. This macro should be compatible with any struct definition even with ones that have const generic parameter defaults. This was an oversight in the original design, as it does not support that, since the proc macro parsing cannot handle the `=3D` character. The short answer for why one would want to have const generic parameter defaults is that the language supports it. And since there is nothing that prevents `#[pin_data]` to be implemented for such structs, we should it do it. Rust generally aims to make all features compatible with each other and we would like to do the same for our libraries/customized features. The longer answer is a concrete example of a usecase for const generic parameter defaults: the `Work` struct of the workqueue bindings. The `ID` parameter is used to identify multiple instances of `Work` within the same struct. But if you only intend to have a single `Work` struct embedded in your struct, then there is no need to distinguish it from something else (after all there is only one) and therefore we want people to just write `Work`. This is where the author of `Work` can write: struct Work { // ... } But the `=3D 0` syntax is currently not supported by `#[pin_data]`. --=20 Cheers, Benno