Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2309893rwl; Thu, 30 Mar 2023 08:38:17 -0700 (PDT) X-Google-Smtp-Source: AKy350YmMJMQvD5JpnF+3fkE9u223CeQqm4zcc2Fb9i07VRS/al/a3LAVObyCYj9mza3akhZbg2B X-Received: by 2002:a05:6402:2803:b0:502:e50:3358 with SMTP id h3-20020a056402280300b005020e503358mr3158365ede.3.1680190697464; Thu, 30 Mar 2023 08:38:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680190697; cv=none; d=google.com; s=arc-20160816; b=nKOC8qUM6s4c9b9SlAQs3MHGslqVbpL8Q71MpeBRwgcXzNETqwLAsnSKG8U9NplKD7 lx+rM2Ai1t8g6ydRsGykyudVlroG+JhCAgvILfCGDuaJ7w/0wwm5CD6Y/Ljdh9oV2mWI /yddaQIySUnqw5Hsm3bf8OKq7ueilgAg1+Zr9YA1D9GpQ8LoIHOy+GVyjFgNAXE/CyMh bMA2DAAzaDmpaMG6u/jCIhfSL7u6ffXEEyNs1JRydhGc13GODGfyedEe4jgmy3Yv7Pb3 TG9RUVyicF8GzHyYLJJ8AZIG1lxfcO5BBlhcozgpB95FKYoBcZhJ81qKLGfCoEGkNF3R 3CNA== 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 :dkim-signature:date; bh=BFhSFq3J8IyHD8N/GJl+CpIhHOZfQHYWPId2eeLRAZk=; b=XjIhGKfg81nO/Rr5tjHvpV/axMd8WL0jAPJgH2sVLiNea+gbNT55Rh1DrYvJIvOtp/ JLv8puA4vMHrz7iayyb6unrLU3tOyI/KomAsI5cBesLKpB47PCeKw6v/WSIKsTEsChza pCyEek2Hue1UfSoxbg8v3/2UhlCrSz7jvb9TVe770mH3CHgDL2t7ml9Ik1MlCRlxk0Ea FhG1D7Z+iv/CHqfqAdtT6k/xcn8vQ+YnFDMogIeVYUsFhxmQOYYhXlAPEHXkhrAjfcWh cTwcRa14nU+fw6EAlebPZAfrjoJsS9ZmJ0FqIqOT46oBdf1vehkYY3TDVRMKePwmLWbC Z7+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b="snCcK7u/"; 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=protonmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i9-20020a50fc09000000b004fe96201050si71932edr.261.2023.03.30.08.37.51; Thu, 30 Mar 2023 08:38:17 -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=@protonmail.com header.s=protonmail3 header.b="snCcK7u/"; 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=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233146AbjC3PhK (ORCPT + 99 others); Thu, 30 Mar 2023 11:37:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233132AbjC3PhI (ORCPT ); Thu, 30 Mar 2023 11:37:08 -0400 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF83CD517 for ; Thu, 30 Mar 2023 08:36:36 -0700 (PDT) Date: Thu, 30 Mar 2023 15:36:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680190593; x=1680449793; bh=BFhSFq3J8IyHD8N/GJl+CpIhHOZfQHYWPId2eeLRAZk=; 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=snCcK7u/bNBcYmywMJ1/hoYfNPUpab5DYWsPfsI3mGFS8NicIrzagfnFvjI9ZyRpq VR6j0ZFWmed3XNnGh+0jSJHV/dedOil8FAdU5FA0qybzAyfiwhE3/pMP5dYevTZcb7 zrmtfZDxkOl9XROZZB3ElybjbhMzgNr6aMmfAnlUd78xRyGs2Dyj8YXAsKj9T9qOMg C1BrnOmTGriTcz2dPtOvJc6cGOrXN/GmGoiOzFA9uQ58kZmnybTyArmkuq0/9euS+P ARJcLS4trYz/hIMZtVBS7RRoieU4VLFuav2RsWqIPpSkqi0Xw/+Wn3fosq+qgvH+OS hcGhA9prSYwng== To: Alice Ryhl From: 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 , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= Subject: Re: [PATCH v3 04/13] rust: add pin-init API core Message-ID: <9c2d4516-f0d7-73ca-d64b-df60e9bd6df1@protonmail.com> In-Reply-To: References: <20230329223239.138757-1-y86-dev@protonmail.com> <20230329223239.138757-5-y86-dev@protonmail.com> Feedback-ID: 40624463:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS 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 On 30.03.23 15:33, Alice Ryhl wrote: > On 3/30/23 00:33, y86-dev@protonmail.com wrote: >> From: Benno Lossin >> >> This API is used to facilitate safe pinned initialization of structs. It >> replaces cumbersome `unsafe` manual initialization with elegant safe mac= ro >> invocations. >> >> Due to the size of this change it has been split into six commits: >> 1. This commit introducing the basic public interface: traits and >> functions to represent and create initializers. >> 2. Adds the `#[pin_data]`, `pin_init!`, `try_pin_init!`, `init!` and >> `try_init!` macros along with their internal types. >> 3. Adds the `InPlaceInit` trait that allows using an initializer to crea= te >> an object inside of a `Box` and other smart pointers. >> 4. Adds the `PinnedDrop` trait and adds macro support for it in >> the `#[pin_data]` macro. >> 5. Adds the `stack_pin_init!` macro allowing to pin-initialize a struct = on >> the stack. >> 6. Adds the `Zeroable` trait and `init::zeroed` function to initialize >> types that have `0x00` in all bytes as a valid bit pattern. >> >> Co-developed-by: Gary Guo >> Signed-off-by: Gary Guo >> Signed-off-by: Benno Lossin > > Reviewed-by: Alice Ryhl > >> +//! Aside from pinned initialization, this API also supports in-place c= onstruction without pinning, >> +//! the marcos/types/functions are generally named like the pinned vari= ants without the `pin` >> +//! prefix. > > Typo: Should be "macros". > >> +type Invariant =3D PhantomData *mut T>; > > I think it would make sense to include a link to the nomicon on the > documentation for the Invariant type. > > E.g. this link: https://doc.rust-lang.org/nomicon/subtyping.html Sure that is a good idea. >> +// This is the module-internal type implementing `PinInit` and `Init`. = It is unsafe to create this >> +// type, since the closure needs to fulfill the same safety requirement= as the >> +// `__pinned_init`/`__init` functions. >> +struct InitClosure(F, Invariant<(E, T)>); > > Documentation for a type should use /// rather than //. > > I think it would help to call out explicitly in the documentation on > this type that it is an implementation detail of the > pin_init_from_closure and init_from_closure methods. Yeah, I will also move this into `__internal.rs` and add the comment. -- Cheers, Benno