Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp909168rwb; Wed, 28 Sep 2022 10:32:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5luNp2trDrPikkOTgGw4lEN7ExVAnNaRrJ3/0jEhfcUkQIINhSvAoeoc0LbFMTULZuJlaz X-Received: by 2002:a17:902:ab52:b0:179:bb14:b3b5 with SMTP id ij18-20020a170902ab5200b00179bb14b3b5mr922452plb.10.1664386323560; Wed, 28 Sep 2022 10:32:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664386323; cv=none; d=google.com; s=arc-20160816; b=Zc7nkgEMBXpA9BEXxmZcu/p4UNGjPYrJoMPOLprm6oS0/zwsJ++/R6fovp/Hc0/+pS TMhg8gIrSJ44PgpSLE6OosB1tTHXWAoqm3nQjHvWFsWbtDK/FGl4RIpKqa8S+h6GqpI3 0G02IrjcANlShDTHO4Sy/6rE0E2z6nipivlNzsjc2QPZ3uFqZP2H2TL+SQbk+US2oy6x UNcwch1tSJqgSHeAG06le+cvApclUec51iKgmkJ0ujf13CD1SHv0p1QSiv4fgwVMl8rn PEFKfz+uK0Fs4+24OGbtxfsAaIzyp5S7d4UprGMpF+i9VeM45Gee5tVSAu/vhjghakuZ D57Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=TzxuSkFY1lkU+KFzHI4Ik/1IQbyTkGI/h/ZDb60baw0=; b=ZxokRu+RFBsWTfoUxjH9pHGONiCpDFnklG41cO0qdhU9UN0WeukBWC5kGS2bwHu6Rm c00std6JjiEq1Sr5Iw55FIHSNVcOvdpMQjbgP2a2g1Q0oz/Tco55j8r2PCNdwTtvtl5m lzwfaTc7T2czBtdmEwvKe1alkWlSF4jAPvSviv3UFIP7vat3Rv94t4a409MNbmkm/wBE G+1fzEN8wYHsruQ+qHnsuSjHkAdLc7isZ0nOeWjnXWNPMl7ExFg8uRuRZs8oytpM4okw TdS0V6jgyXxWYMuXC4RtgJYMARzoqVv/RQySrDdxg/CAC8fs47+H3yvPhAeNgoSw1rXC ujlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ghh0QCyw; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t18-20020a639552000000b0043970eddf93si6221308pgn.221.2022.09.28.10.31.51; Wed, 28 Sep 2022 10:32:03 -0700 (PDT) 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=@gmail.com header.s=20210112 header.b=ghh0QCyw; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229736AbiI1QgS (ORCPT + 99 others); Wed, 28 Sep 2022 12:36:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232380AbiI1QgQ (ORCPT ); Wed, 28 Sep 2022 12:36:16 -0400 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E22007A75C; Wed, 28 Sep 2022 09:36:15 -0700 (PDT) Received: by mail-io1-xd2f.google.com with SMTP id e205so10614579iof.1; Wed, 28 Sep 2022 09:36:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=TzxuSkFY1lkU+KFzHI4Ik/1IQbyTkGI/h/ZDb60baw0=; b=ghh0QCywbcq9KUctQSaKs+ZzF6e5x1tsi7CRIHXbI+VxyVjv28yERT2n9Bd2auhS3C L0JLhdZq3yI6hteiem5oShET5qpTbX6vU0KLg/xR96SkCedgU0H1pR0H5cUP4DoVX8FQ GAy+AQpq+uGZnnBfJoUmIPi2AIy+X7Sw1dqDjzFFt0IBxCOYbuE9InEdf5/v3vAv66t+ R/DEdTwIrqzbhpEjtT4nC5VEo8uyC24+gKTDYIbI7ws2j/rdgvg7bd/NZG0FUzSv/yhf xP4fiPZoTQtQXWJJXAJJ7GNC2JXKan8kug1kSWuQgT8x37t6IYa2G5ECC0a1u+0tnZmk 9KUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=TzxuSkFY1lkU+KFzHI4Ik/1IQbyTkGI/h/ZDb60baw0=; b=dyzM62BXObbUZqxl0ufv0zk98r4KgQjxbwe0yJemCXMGpo/MEBAZzqXAB/91L46V2c Fi37aAVJPXG9lzlhftYet1ptspEJujc9QQSX7T848lOvwbD8G3n05bHwcydRQluA3XRN Bw68FyZtghM/lX/gYa+CKyuXkfmDobCHQdnGjmTDdxWyky/0nQL8H2YmhlO18vYt5NOv xYr5MIbXLybip88JT9bw6dTE8wSKrOYG37kUXbnj/dioMBunnjme4/LILMrs9UCiwwso vpY6RLZrQt1JK+9iBtxRlK2jwLdPilwxy6Z0vvD+db0CJOoG8EXwQkvvz4lfzZMW2COE kDIA== X-Gm-Message-State: ACrzQf1vZ3Uf5iMXvm32LPOcF/uze4Z9QJnQO7Jc4qlp2ZAs7ehvDXVa nAPYTRqH5pi1U2rLlwl0dP18Fac79cicLIXUc+0= X-Received: by 2002:a05:6638:25cb:b0:35b:b1cd:c411 with SMTP id u11-20020a05663825cb00b0035bb1cdc411mr395294jat.308.1664382975350; Wed, 28 Sep 2022 09:36:15 -0700 (PDT) MIME-Version: 1.0 References: <20220927131518.30000-1-ojeda@kernel.org> <20220927131518.30000-11-ojeda@kernel.org> In-Reply-To: From: Miguel Ojeda Date: Wed, 28 Sep 2022 18:36:04 +0200 Message-ID: Subject: Re: [PATCH v10 10/27] rust: add `macros` crate To: Wei Liu Cc: Miguel Ojeda , Linus Torvalds , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, patches@lists.linux.dev, Jarkko Sakkinen , Alex Gaynor , Finn Behrens , Adam Bratschi-Kaye , Wedson Almeida Filho , Sumera Priyadarsini , Gary Guo , Matthew Bakhtiari , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Boqun Feng Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 On Wed, Sep 28, 2022 at 5:29 PM Wei Liu wrote: > > Just a general question: what is the house rule for adding new proc > macros? They are powerful tools. I can see their value in `module!` > because writing all that boilerplate by hand is just painful. Yet they > are not straightforward to understand. It is difficult, just by looking > at the macro, to fully grasp what the final code looks like (though the > rsi target will help). Is there a concern that proc macro gets abused? The rule is "use them as last resort". That is, they are not banned, but they need to be justified: if there is an alternative that is not too bad (e.g. in terms of ergonomics or implementation), then the alternative should be used instead. Nevertheless, sometimes they are very handy. Apart from `module!` here, we are currently using them in the full repo for vtables [1] and the Asahi M1 GPU driver is using them for versioning [2]. It is also possible to make proc macros easier to handle, for instance if we end up deciding to allow utilities like the `syn` crate. [1] https://github.com/Rust-for-Linux/linux/blob/fcad53ca9071c7bf6a412640a82e679bad6d1cd4/rust/macros/lib.rs#L99-L148 [2] https://github.com/AsahiLinux/linux/blob/3c8982e2c78c219bf96761445c8b73c2b3034fba/drivers/gpu/drm/asahi/fw/buffer.rs#L43-L56 Cheers, Miguel