Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1026643rdh; Fri, 27 Oct 2023 02:33:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzx6XL55TN40HoQxzV6W9nYJmg7XCh9LjTfSmd3ZLSKmCWqYX6JOqGev2ERXE9cQBkj2RM X-Received: by 2002:a67:c19d:0:b0:45b:ece:21f7 with SMTP id h29-20020a67c19d000000b0045b0ece21f7mr2394952vsj.14.1698399186969; Fri, 27 Oct 2023 02:33:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698399186; cv=none; d=google.com; s=arc-20160816; b=x+vF6L8JwBhA6Bdrn4Dem4odh0dry+/mSyguUvlOBMXhIZnYO5BWmyUPDyxTbUuoyP h6SG6BrSqDsVtZgDm0qxHC8U/LmRpjOnXkCysWZZtur6qCZblve0MTj6fVOg84suUWXT kkJUdJ9YufwOJn6IHxlpcDzye2+HLre5xVuh6YIF9B6dpvQPaX9UoEco9/bKOJGa1GOt OIgumAxpn7ixluQl9uVBBiXwIdCHI68OFpkyr1mYySx8w7iUejALypTo9tdA7Q5patVW uPNKw7d+D9tRz6mPna7e+llokrgeBOPGtSo/qE9eDFy9184JMbeETdUiYp+HSGyr+UBp imag== 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=qX0sYQ68NldqQzH0zn7TigorKLiFCKmIhJbiP6fSiqI=; fh=OI3we8m2ORxlKzCmCeLUFP8mo7YvYqGokS17eFXHOPU=; b=a5LDMrdxaxtfcLQEtpyOIZT3kD7DWNBdUNZ7Kve1I9IA9JznHmyBNnLtNiXVlQqASP JNd+8eeSvU5haaEKYzPYBN2+NW/WYxTn5Aa1sJ2hT9suksr4UwHGx+D/18uIpmB9pYJd 8gK2MzTbOazr+gyDwBisnFfMo1GqcW7kj4BHWCA6ksy5YkOn0WD9HUdEjbewwSYhfCJ5 VadY6p93hsM+7tCRBl0+PN+tvkMIvwnsc4lBdhBSWB2gysU26tYY7pccxBmnDuS6IzlI OialcgiU3ZD4YHt4f+Oi6JhI9RxbWJbwuS3aQaMoGG3bbPM5OAwdHCSDJbLsSckOCRPR nIEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=IL+7giNU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id 10-20020a25060a000000b00d867bccdd42si1705924ybg.10.2023.10.27.02.33.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 02:33:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=IL+7giNU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 191B283ACB64; Fri, 27 Oct 2023 02:32:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345581AbjJ0Jcd (ORCPT + 99 others); Fri, 27 Oct 2023 05:32:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231386AbjJ0Jcb (ORCPT ); Fri, 27 Oct 2023 05:32:31 -0400 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC65CAF for ; Fri, 27 Oct 2023 02:32:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1698399144; x=1698658344; bh=qX0sYQ68NldqQzH0zn7TigorKLiFCKmIhJbiP6fSiqI=; 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=IL+7giNUcJyqpQUi2c2jyzZTSiUh18R83I751zNBpFaBvZK0UOYMQdvjSCEbbvCq8 iWNtNmjTTHPAot/8NL1ZmWZRHW9p22nfl9Zz5HM60Unzs0GFMhkvt/cRGHyiqLeM9E 0d+ySgq8T1PdZ3cch52qpUJsq6o4S181eOIIkMYO29hFaOdM/Zqir5Pnpull9Ca5QK Dzt99S1ewo+UVrgOl0neWh+f4zN6tmRsOpZ06gudneKIU+JbV3fSAz+aWKa6ucKBpg rswgWAhIh6zls1CcROfLWWE0t1m8SkuZZKa86Lge/raK1tNSX5l8/XjGbphSLXBWvB 2i8PJymaG8aWg== Date: Fri, 27 Oct 2023 09:32:19 +0000 To: "Ariel Miculas (amiculas)" From: Benno Lossin Cc: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Martin Rodriguez Reboredo , Asahi Lina , Sven Van Asbroeck , Viktor Garske , Finn Behrens , "rust-for-linux@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v3] rust: macros: improve `#[vtable]` documentation Message-ID: In-Reply-To: References: <20231026201855.1497680-1-benno.lossin@proton.me> 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=-0.8 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 fry.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 (fry.vger.email [0.0.0.0]); Fri, 27 Oct 2023 02:32:44 -0700 (PDT) On 10/26/23 23:12, Ariel Miculas (amiculas) wrote: > On 23/10/26 08:19PM, Benno Lossin wrote: >> Traits marked with `#[vtable]` need to provide default implementations >> for optional functions. The C side represents these with `NULL` in the >> vtable, so the default functions are never actually called. We do not >> want to replicate the default behavior from C in Rust, because that is >> not maintainable. Therefore we should use `build_error` in those default >> implementations. The error message for that is provided at >> `kernel::error::VTABLE_DEFAULT_ERROR`. >> >> Signed-off-by: Benno Lossin >> --- >> v2 -> v3: >> - don't hide the import of the constant in the example >> - fixed "function" typo >> - improve paragraph about optional functions >> - do not remove the `Send + Sync + Sized` bounds on the example >> >> v1 -> v2: >> - removed imperative mode in the paragraph describing optional >> functions. >> >> rust/kernel/error.rs | 4 ++++ >> rust/macros/lib.rs | 37 ++++++++++++++++++++++++++++++------- >> 2 files changed, 34 insertions(+), 7 deletions(-) >> >> diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs >> index 05fcab6abfe6..1373cde025ef 100644 >> --- a/rust/kernel/error.rs >> +++ b/rust/kernel/error.rs >> @@ -335,3 +335,7 @@ pub(crate) fn from_result(f: F) -> T >> Err(e) =3D> T::from(e.to_errno() as i16), >> } >> } >> + >> +/// Error message for calling a default function of a [`#[vtable]`](mac= ros::vtable) trait. >> +pub const VTABLE_DEFAULT_ERROR: &str =3D >> + "This function must not be called, see the #[vtable] documentation.= "; >> diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs >> index c42105c2ff96..917a51183c23 100644 >> --- a/rust/macros/lib.rs >> +++ b/rust/macros/lib.rs >> @@ -87,27 +87,48 @@ pub fn module(ts: TokenStream) -> TokenStream { >> /// implementation could just return `Error::EINVAL`); Linux typically = use C >> /// `NULL` pointers to represent these functions. >> /// >> -/// This attribute is intended to close the gap. Traits can be declared= and >> -/// implemented with the `#[vtable]` attribute, and a `HAS_*` associate= d constant >> -/// will be generated for each method in the trait, indicating if the i= mplementor >> -/// has overridden a method. >> +/// This attribute closes that gap. A trait can be annotated with the `= #[vtable]` attribute. >> +/// Implementers of the trait will then also have to annotate the trait= with `#[vtable]`. This >> +/// attribute generates a `HAS_*` associated constant bool for each met= hod in the trait that is set >> +/// to true if the implementer has overridden the associated method. >=20 > The above paragraph seems to be wrapped at 100 characters while the > paragraph below seems to be wrapped at 80 characters. Oh I forgot about that. Miguel, would it be reasonable for you to fix this when picking the patch? --=20 Cheers, Benno