Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp677291pxb; Fri, 16 Apr 2021 15:38:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLLZdJk+CiTAlqgDKp3fDSrJhZ5Cs7Bq23gjCR47PHGZYoQUiKCLF564uEnDG96qe2TUn0 X-Received: by 2002:a05:6402:138f:: with SMTP id b15mr12707810edv.121.1618612682313; Fri, 16 Apr 2021 15:38:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618612682; cv=none; d=google.com; s=arc-20160816; b=nuGdup8dEaoWgDXKJXDjpB+1JIDUp08efob9ynaGdcRUXUHi1GVCWFQu/qHx3WeU/Z 75y13wVBpm++QT3j/p1CxjlW6dj3lFBlxZGutSob6lczzXt3EP1M6ratZyiFivl+Ri6v NiLg2WpPXTwaQWv+g7G39wnj955c4fVWqqhM3D84umRBfjlOFzZkOw28BpH1m56mrHx0 VJgpG2719219JcBVToNMZZDyXnDEM8pRLes49ZSOheKPHJhM3iQcX3F/5tbK+u4XwMiC WzugsuhpzEieNB5HNU45nHp08BvykdxNeXyggB+qCWJrpEzn1vfhX0Z+E/WuNscqXJjy 7XVg== 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=IuXR4s76KW2g16KgmTJ3s1NR8NxaS0rBglhD+4wC2bA=; b=eD1CG8EWTfuQTY5mrKITJSClrjfqxGky06kgABHqmX/V04mamdEXgIJCLc7HUHfQwp JtpjYnv24EdL2Fcg1pFrKk2Sv39XFJcu4oqVBXc2pbOt0b9RbN+FDnxEPFoYPfugN8f/ rVc9BppMDcf+gT95CC3F02XPRH+E8WWWDe13Tm1PkbgT3CIqQkKjOj1Bl0TH3HXQ6zcH Fm+KtpQYFrxKqpjbfvljHbu5fou7yycuCqm1OnfYSyTRWNz6c07uPlTPElJnCoZzeDNc 6qaEfdycUxWdY5MkVBhj/cDYghXAqZZ43lAbzKWSN9jBtSdZUa4MyrJZOJ/yFluTAbS/ pwiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=t6Eh6V9O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v17si5819575ejj.22.2021.04.16.15.37.36; Fri, 16 Apr 2021 15:38:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=t6Eh6V9O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S239501AbhDPS5o (ORCPT + 99 others); Fri, 16 Apr 2021 14:57:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235957AbhDPS5o (ORCPT ); Fri, 16 Apr 2021 14:57:44 -0400 Received: from mail-yb1-xb2f.google.com (mail-yb1-xb2f.google.com [IPv6:2607:f8b0:4864:20::b2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16BA6C061574; Fri, 16 Apr 2021 11:57:19 -0700 (PDT) Received: by mail-yb1-xb2f.google.com with SMTP id c195so31207566ybf.9; Fri, 16 Apr 2021 11:57:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IuXR4s76KW2g16KgmTJ3s1NR8NxaS0rBglhD+4wC2bA=; b=t6Eh6V9OMwi659Ak0KE8pRM5p87Dz7/7Ty3eBJkJHR3jxgYIRk0vixc1KxYDXStbk3 0xvaAqI02zC6EBd3wRdbUwS3/Z/BenDWtD6tLgUY2gwjWBt+8SHdws8AwkQZcTMCn7kl Sp3dnKOM/qyPCfBCJ40L2kHBWxeAhGPHPN4AjRdjoXVllD5DZC/L4Wl2n0WmZDCEsFkM J6Qc9+HPOeE5f+JvWQTM/3gHA99pYJs2U5IS1IiXXhX8jaOCQOY7X19eZOG14hIgMPWg O1+7MnPo2thZERtolLuOH8vVpWQgb18ZVviCi3wdpOcMF7nxQ4o2D5qfJ4G5oRDOrgUh 2p3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IuXR4s76KW2g16KgmTJ3s1NR8NxaS0rBglhD+4wC2bA=; b=NYIjMm4lEkPwIcMaUDyDT5xaKKD2U+yilwnWNNlNTT0yL5dBBkzR58BLM+F2F0f0Vz Hfwc/exKTRDJYkiGFLxg+82FDOcAwaiaCELMW8jWjk41YDH6sH65lOl0JtYbmz2dYgH9 ATzlSpZAxMB48F1b0yanH60GxDQxyETKwFg0k+f7yntuKSHVKp24aZnXQW15ArCgdOrf aXjQYPPClvmE3QTzZpQOQohHrb5+V35NE1UMXkCQZte4Gpy1i8XN+WyKSfTgIN5dukRd quksGae5h3qn8rw/ZRZXODe2a8VT+nh8jhdoEsN6DCYbCdEdqLPOSd6em8rgm0XulNz0 ac2w== X-Gm-Message-State: AOAM530n34tK4h6tsiWP/rwK4NU7jOQpH1dbWd0jTCXehiLmdTS6k46f 3Yy3t6/Rpk7MS3DTX4T++U795QSCYyqTaoFZcFA= X-Received: by 2002:a25:7909:: with SMTP id u9mr796140ybc.22.1618599438460; Fri, 16 Apr 2021 11:57:18 -0700 (PDT) MIME-Version: 1.0 References: <20210414184604.23473-1-ojeda@kernel.org> <20210414184604.23473-5-ojeda@kernel.org> In-Reply-To: From: Miguel Ojeda Date: Fri, 16 Apr 2021 20:57:07 +0200 Message-ID: Subject: Re: [PATCH 04/13] Kbuild: Rust support To: Al Viro Cc: Linus Torvalds , Peter Zijlstra , Miguel Ojeda , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, Linux Kbuild mailing list , "open list:DOCUMENTATION" , Linux Kernel Mailing List , Alex Gaynor , Geoffrey Thomas , Finn Behrens , Adam Bratschi-Kaye , Wedson Almeida Filho , Michael Ellerman Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 16, 2021 at 8:10 PM Al Viro wrote: > > How well would ? operator fit that pattern? _If_ it's just a syntax sugar > along the lines of "if argument matches Err(_), return Err(_)", the types > shouldn't be an issue, but that might need some fun with releasing resources, > etc. If it's something more elaborate... details, please. Yes, it is just syntax sugar -- it doesn't introduce any power to the language. It was introduced because it is a very common pattern when using the `Result` and `Option` enums. In fact, before it existed, it was just a simple macro that you could also implement yourself. For instance, given `Foo` and `Bar` types that need RAII cleanup of some kind (let's say `kill_foo()` and `kill_bar()`): fn foo() -> KernelResult { if black_box() { return Err(EINVAL); } // something that gets you a `Foo` let foo = ...; Ok(foo) } fn bar() -> KernelResult { let p = foo()?; // something that gets you a `Bar`, possibly using the `p` let bar = ...; Ok(bar) } This reduces to (full example at https://godbolt.org/z/hjTxd3oP1): bar: push rbx mov ebx, 1 call qword ptr [rip + black_box@GOTPCREL] test al, al jne .LBB2_2 call qword ptr [rip + kill_foo@GOTPCREL] xor ebx, ebx .LBB2_2: mov eax, ebx mov edx, -1234 pop rbx ret You can see `bar()` calls `black_box()`. If it failed, it returns the EINVAL. Otherwise, it cleans up the `foo` automatically and returns the successful `bar`. Cheers, Miguel