From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BA96C433B4 for ; Fri, 16 Apr 2021 20:58:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E93A9613D9 for ; Fri, 16 Apr 2021 20:58:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244057AbhDPU7H (ORCPT ); Fri, 16 Apr 2021 16:59:07 -0400 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:51754 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236340AbhDPU7E (ORCPT ); Fri, 16 Apr 2021 16:59:04 -0400 Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 13GKwCKQ011673; Fri, 16 Apr 2021 22:58:12 +0200 Date: Fri, 16 Apr 2021 22:58:12 +0200 From: Willy Tarreau To: Connor Kuehl Cc: Miguel Ojeda , Al Viro , 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 Subject: Re: [PATCH 04/13] Kbuild: Rust support Message-ID: <20210416205812.GA11655@1wt.eu> References: <20210414184604.23473-1-ojeda@kernel.org> <20210414184604.23473-5-ojeda@kernel.org> <20210416202215.GA11236@1wt.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: rust-for-linux@vger.kernel.org On Fri, Apr 16, 2021 at 03:34:50PM -0500, Connor Kuehl wrote: > On 4/16/21 3:22 PM, Willy Tarreau wrote: > > So it simply does the equivalent of: > > > > #define EINVAL -1234 > > > > struct result { > > int status; > > int error; > > }; > > Result and Option types are more like a union with a tag that > describes which variant it is. > > struct foo_result { > /* if ok, then access foo_or_err.successful_foo > * else, access foo_or_err.error > */ > bool ok; > union { > struct foo successful_foo; > int error; > } foo_or_err; > }; OK. > > [..] > > > > So it simply returns a pair of values instead of a single one, which > > It will only return 1 value. No, two: - ok in %rax (seems like it's "!ok" technically speaking since it returns 1 on !ok and 0 on ok) - foo_or_err in %rdx However then I'm bothered because Miguel's example showed that regardless of OK, EINVAL was always returned in foo_or_err, so maybe it's just because his example was not well chosen but it wasn't very visible from the source: 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 Willy