Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp659105pxb; Fri, 16 Apr 2021 15:05:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhpEEk/AeHW5xZB5BmLm2ms/7N+dz5yr2lH0HZcwCouowMq2Gh5SbqY7Sp6MBo1QSmIqjn X-Received: by 2002:a17:90a:a00e:: with SMTP id q14mr12373369pjp.70.1618610758714; Fri, 16 Apr 2021 15:05:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618610758; cv=none; d=google.com; s=arc-20160816; b=hPPONMqHrAK5VVyJvwGQIpXsiBRdWVr4oSyuzHFXKYRhzPbPptsUoCPyHlUeOhLGbD 8bYszavBqeFn11a2vWSbXcP2GCstHx+Ck0RegzZu3zxkNocAFyLILBwHIfojUHOn/Upl /7qUMFFuCrxlZ15cAhs5IuR2yRxXVavV7y87gr2thViJMbZz2Dph4TFEn5ibsoZxAmDl luIo+t5t7TQkQgITf7HZ6sv+Ni0p6UphpnaEyacACLiLbPOVBj6cA39s5nDhkhbPkNtg xVQu8ACLaCVIFT+beTRXXlPXRo5E+dsoQN5jPtGka/+NGJck9DaKOPJYpdXRCtyXathO WfbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=zsf64UJcU1VOsEKM/lt6z7MFcW3XbEoMSvsX601STN0=; b=jkkH0kbO/9szM9t/hTiWQNzTRaUJ/Bo5lKo3NlcQVqqjZshOwaE8ja9XrnFDx9byIp Ryo5s77DmXCROuoij2q3FSP0L8EiDWHolHlWms79WUHVE0Y9Z3v8JFwi4+W6+mjUdwAu cqszUpNM2Lfq+gAH4xmSibdwFBFNZ/KX04DLdTSiw5b6uyjFMmoz6JQATh3TO7S5bL7e 4GtwZ06KQsDAVzJvUfwZl0W5S+qXz1ZUyykooAuro0qbyPRF+ARNRhWne0/WuI4uwxzZ cv1P4Vfam6xlUmpwKlbTXG/+eZNhbGG0nevDMLRoSoYDiyQ89zMEAdf1MAyD81Lr8o9q RDWQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t10si8325957plr.42.2021.04.16.15.05.46; Fri, 16 Apr 2021 15:05:58 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236592AbhDPU7H (ORCPT + 99 others); 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: linux-kernel@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