Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2312301rwl; Thu, 30 Mar 2023 08:40:17 -0700 (PDT) X-Google-Smtp-Source: AKy350Y/gVmamIKMAhU+GaOjPUnOETmCOh8mn0V8ueUJh8eyQtRK1zmjr84qaQprFmT90/0vv21k X-Received: by 2002:a05:6402:1e8e:b0:502:465:28e1 with SMTP id f14-20020a0564021e8e00b00502046528e1mr3118150edf.0.1680190817342; Thu, 30 Mar 2023 08:40:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680190817; cv=none; d=google.com; s=arc-20160816; b=eGTSAgK4pdjFtGx0iOP8EorcQemNgTa2rBg5M718bHuzDYG+DCIxnygQonS1T9KgKC G9cQ+L6pzCAZ8dHqe6SMzP+E6Q2f1HlHChEJ9KnYzJzSnRAMiU2xmZ/Ji2osCs21QdHu 0XhorzH7APp7Sa6Z3+VIMa789pSaCcgn1nzjxZpEeLGwAKFmal0YurZEbSKYPCnSEEVq 60rUKksSmqcvehed07SMU+WB6to5yGl74VuJt+MIUtTFucy/ilQvxLML9WtNdLbumFUH rGdA2lMvW5Yix6f7knR8sBhPsJ6YW9anci9mQzrmjSCxRAPEoEz67g/OQAA7MNRk/cUc jiKQ== 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=8Ckr3U3t4v65Ys60F1em+mj+qQLDAHD7DjiGBhJTkTs=; b=k9IA2ODZg+jU5+Aa3k4EBoZXp4JXNXgXchhc20gDq52nIdqD3YN52xn7TAlUw+qoyx FQ8g+tL+GCoVrC2njiH6gevszjDRv+DZY+uwVLklK7dM1Xkftiaa/nNNKEgRw9kxp4dh WXNUzzqZkkyC3JHcM7ya1qZvRwU8yHFW7R4DTAdTGaoJ1RM+pP2eK+uwCfW1SJyGL7zp CY2gyD/LsWRFV8DhLEWSAc2iPawmBr2uIeANf3IvUZDNlBPk7dV7Bqhg9T8mi/BMmPH9 F8wKEL0Ij63GAznOTfw7PFSvc3xbBDT8UR02Ue39ySMAH7T6P2PQKh6f62/ac5G+xL2l aWhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=ZgF7AqEP; 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 n17-20020aa7c691000000b004ad06322427si98802edq.9.2023.03.30.08.39.30; Thu, 30 Mar 2023 08:40: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=ZgF7AqEP; 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 S233232AbjC3Phv (ORCPT + 99 others); Thu, 30 Mar 2023 11:37:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233155AbjC3Phs (ORCPT ); Thu, 30 Mar 2023 11:37:48 -0400 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA2DD19C for ; Thu, 30 Mar 2023 08:37:29 -0700 (PDT) Date: Thu, 30 Mar 2023 15:37:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680190648; x=1680449848; bh=8Ckr3U3t4v65Ys60F1em+mj+qQLDAHD7DjiGBhJTkTs=; 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=ZgF7AqEPozgajYN4fveEAtHr/jgGXLuAhkOHhx0PeQrx6dqC634OWN7hDz2k2IXjN YpwGHan3Njm8+wDCzenB9xuo2rbdDI7C4hg3dWDBECSX+N8XG/jaX4xDBidcy8Dp6C muInA75JR2pwzyAQcbXzuNeXInVPmdw+IKxIrgP16ueTqZPEf7D4UCoVWZh2qTy2uZ zEDoKcECf8QzF2hzeI6OKiIGl2PWztwBdILLv7bRO+eDrkMumIpgxSFpUkWu3YW9pJ 5mB7CA8DTvoRHLdfIDi17VbfkPQmV/3UWZplnn4rZX6D0wgLPymWnK+jrpYG+lwM1L LFITn+/piG3sQ== To: Andreas Hindborg , 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: In-Reply-To: <878rfe493r.fsf@metaspace.dk> References: <20230329223239.138757-1-y86-dev@protonmail.com> <20230329223239.138757-5-y86-dev@protonmail.com> <878rfe493r.fsf@metaspace.dk> 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 16:16, Andreas Hindborg wrote: > > Alice Ryhl writes: > >> 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. I= t >>> replaces cumbersome `unsafe` manual initialization with elegant safe ma= cro >>> 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 cre= ate >>> 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 = construction without pinning, >>> +//! the marcos/types/functions are generally named like the pinned var= iants 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 > > That would be nice. I think this also applies: https://doc.rust-lang.org/= nomicon/phantom-data.html#table-of-phantomdata-patterns Yeah I very commonly use that one as well. > >> >>> +// 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 requiremen= t 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 thi= s type >> that it is an implementation detail of the pin_init_from_closure and >> init_from_closure methods. > -- Cheers, Benno