Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2203021rwl; Thu, 30 Mar 2023 07:21:07 -0700 (PDT) X-Google-Smtp-Source: AK7set8T0ocWUb1E8EGLYbjFQN0RqIDw1VxjGXkXJqux6nMbS94zws4N209mFEYj+aQNwiMQHkV8 X-Received: by 2002:a05:6a20:5499:b0:db:7789:237e with SMTP id i25-20020a056a20549900b000db7789237emr27141494pzk.4.1680186066731; Thu, 30 Mar 2023 07:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680186066; cv=none; d=google.com; s=arc-20160816; b=G9aRiDkq+uByYu5OHSaoc/SFAR+97SBWLkP5HuQWy9FWFKTpqELlKqErQ3aaqmPTck Qa7SxTdmxeDbFYPzSvmocgtlzuJnH5ifChMN5+6N04GhLyyzOnTPcdjbYDT1mnGxmnuf RBPqikpqZdhkGLLwCc6ExqhOqgEaVH08/wXnROp0TqicmfXnQ2R3aXexPi1DX55GRjrI L4iUYdwOUN9epX9IYGoZb7cE9IzyEwaAN3LXgQuWMHhgXz+FNsTDE/5m6rN50hxbFs0N 5g0sIidkPCOLPW4XSRqsfgq2wS5MoMhf0c9HuKT8Ewhyw6AjTPzt+EHO6RcmYnUGgtRK J8bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:dkim-signature; bh=V3w4/MoUcTVEnZSoDDuIRGwZ4uXMTJFYF6lNB23fCPk=; b=o2kfrM4Zn32YRRWxOmlvACga9K3/TCNQdwmcTAvMCK98uwG5nXzFWXfp5BJUHa+Ru4 MvZsW01pnLlp0ar5qVGivqiNjUo1y4eQQhT65jbSQ5fmEKn7h7OfdVJn7snB8B4BD4zj CqUK2LItdfEFrUA0jK4g/TxDt6xpgZekMWdJZI0O2eovMQJvwvdsvY11lMki3V/AjkFJ UPOLoj/wNSSlP7deHsHfNs5k6w9xG7xMbBc16Rxbo9twgnF8VGfm93CETMQVBRgm+f3O rDR0x2t1weEzoxJjC3K7/u6VbOOVtg4k4F8jPGAOSPBCDMk0re7GoNvEugpSluaJ7xgg w90Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20210112.gappssmtp.com header.s=20210112 header.b=jZto7yze; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s139-20020a632c91000000b0050f7f7865e6si26165652pgs.552.2023.03.30.07.20.52; Thu, 30 Mar 2023 07:21:06 -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=@metaspace-dk.20210112.gappssmtp.com header.s=20210112 header.b=jZto7yze; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232450AbjC3OSH (ORCPT + 99 others); Thu, 30 Mar 2023 10:18:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232316AbjC3ORw (ORCPT ); Thu, 30 Mar 2023 10:17:52 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C9A0CDFE for ; Thu, 30 Mar 2023 07:17:17 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id r19-20020a05600c459300b003eb3e2a5e7bso11887436wmo.0 for ; Thu, 30 Mar 2023 07:17:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20210112.gappssmtp.com; s=20210112; t=1680185834; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=V3w4/MoUcTVEnZSoDDuIRGwZ4uXMTJFYF6lNB23fCPk=; b=jZto7yzee4mHExZhJYL8EBHaZ6kim1/ImNBRIxf6WnHEB/vfwpDG8HHF19HwOgGoFk Unpwei39GNh2Cck7ne7iQyiMONqo2bhkqe7txxOMh38OBbcpgPs3nEBWiPrVZR4Uvpqq 1MUkJQQA/IjSoweErLKrTPAS6o9lBl0NVyP9QkjRYseuJiMakuYSwt0pf90ZZWu6N8oq HhfYUat9G5hFKKTQo2hxzAYW6IkZr37fG8DzCSCeuUxPxkd5Lzyd4PcpmOQ9HtYYvilE 8q5Hi/KSH14T1siemr7507LrIZgmOEfVz9aw80Pc5tmt8Sg3bbGMsM69cK5MGowQabF6 UCOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680185834; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=V3w4/MoUcTVEnZSoDDuIRGwZ4uXMTJFYF6lNB23fCPk=; b=QsmUx9fG1SlzWe4fRGrNwj9DxTVMgcDANuBcuYmdYES+MowrEEUuWjqHO2vOSzDPYF c0PVTqyYNyUhOpssGt9iJPepHY4bHVlXiOOTDsdjj03aWpr3XqQefmB98WeudO0Jd0Tp 6r/yXm8jI9MF48TpV/meBlbzU2R+ePrDZiZ5i4UNi77Bi/1YVl1Fm9vrPROwPx80YIkO N+kFRC9TqMatfrI3JTinOqWBjgaJjseF0dHXBF+ioD9auX2Uz6hDP8CS+Uf2jXh2V6z7 BtiDvyJcqY2jkIyuwp9E4z0KKg6uO8vcxIsmQTl/uAwkNTfbhdA4vQ6RnkPeFb4GeHwE IavQ== X-Gm-Message-State: AAQBX9fJnZK6sPCkcKyfmm0S7RvSBHSCZ+2ImuSmSu3h54o8P7jTF9tl 3/N2E96MlmhCLpC9o1PxEYjTFg== X-Received: by 2002:a05:600c:4591:b0:3f0:3070:f4ea with SMTP id r17-20020a05600c459100b003f03070f4eamr3689550wmo.11.1680185834017; Thu, 30 Mar 2023 07:17:14 -0700 (PDT) Received: from localhost ([147.161.155.82]) by smtp.gmail.com with ESMTPSA id o39-20020a05600c512700b003edddae1068sm6455975wms.9.2023.03.30.07.17.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 07:17:13 -0700 (PDT) References: <20230329223239.138757-1-y86-dev@protonmail.com> <20230329223239.138757-5-y86-dev@protonmail.com> User-agent: mu4e 1.9.18; emacs 28.2.50 From: Andreas Hindborg To: Alice Ryhl Cc: y86-dev@protonmail.com, 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 Date: Thu, 30 Mar 2023 16:16:31 +0200 In-reply-to: Message-ID: <878rfe493r.fsf@metaspace.dk> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=0.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE 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 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. It >> replaces cumbersome `unsafe` manual initialization with elegant safe macro >> 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 create >> 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 variants without the `pin` >> +//! prefix. > > Typo: Should be "macros". > >> +type Invariant = 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 > >> +// 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.