Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp662671pxb; Fri, 16 Apr 2021 15:11:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyC9/ta+9KSNJApggDtGnlaOb2REeN7bzNrIEO8ZOXYoSAaFOTL8drZUFL8fhR3IIGpUHe7 X-Received: by 2002:a17:902:d2ce:b029:eb:364:a2a0 with SMTP id n14-20020a170902d2ceb02900eb0364a2a0mr11639058plc.0.1618611096888; Fri, 16 Apr 2021 15:11:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618611096; cv=none; d=google.com; s=arc-20160816; b=J8I9RVLzwt6EdVYbKziEwdZP/Xq4W7jGm+JDm+7slO2zAP1yROVyw0/y+ws21k6EqU qhoHA1xeqlzAbQhnNdNNyUmQY2hbvj48oXGBWXeTPV5A+8kZw7znmK90RIUOZLOX3KUP 75/Pamm1O/s4dEnIUwIK5zzYXmk6LViBmnfFZZ4sv6qcdxCMUHwuRnFsQ9+ghsHotpzD Qt8frUpUByGZJftjuz6PaoJKOn4jsnvPbSxXsiP1uxlPtTYI6N2/JnMu++MzDrQ3QNcG K4rmMsUZYuADVc8z1kJr1AwczAXtEUKHq/u0amVzCm6W7+1T1pSAAmqtWZxkTHbmQyiZ NCuA== 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:message-id:subject:cc:to:from:date; bh=F6+s+mS7JZnaHthm0avc31cONY0Sx+euL6FJBHdIpqI=; b=ETyYA7LNUOJvE36E+jO4Qrw9QywlXeLvLx8lZAsp87+bOAnC4RVykMu2e9WEWwQo8S oSutfOZo3e7pQ0IgPL9xWpz5lSrGOa2PlkfjxSpyiX6hQjravJytwF5+d3ZzkOBVeLQP sJWhmDXFPm8AcMnYbmfZdvxHIdqu0B/PVTYKnXZ3xfw28SB+69+xb4DAg/je5sdzQv82 N4cgrEB3K59W3Brdc7NSuOJIuA0aXrVOA3E0wL3iJFVYaNN3IuyMhJHUJSX0LcIS2gEG NMGn3CLM0le20JHeol4tTT4mYoz1Co17Au4BjTHjYjOISO5Nq6oqobR10DTIuNdHpmeq zrYg== 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 a2si7871533pgd.578.2021.04.16.15.11.25; Fri, 16 Apr 2021 15:11:36 -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 S235957AbhDPWFJ (ORCPT + 99 others); Fri, 16 Apr 2021 18:05:09 -0400 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:51766 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234898AbhDPWFJ (ORCPT ); Fri, 16 Apr 2021 18:05:09 -0400 Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 13GM4GQh011937; Sat, 17 Apr 2021 00:04:16 +0200 Date: Sat, 17 Apr 2021 00:04:16 +0200 From: Willy Tarreau To: Miguel Ojeda Cc: Connor Kuehl , 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: <20210416220416.GA11872@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 11:39:00PM +0200, Miguel Ojeda wrote: > On Fri, Apr 16, 2021 at 10:58 PM Willy Tarreau wrote: > > > > 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 > > Yes, but that is the implementation -- conceptually you only have one > or the other, and Rust won't allow you to use the wrong one. OK so for unions you always pass two values along the whole chain, a selector and the value itself. But my point remains that the point of extreme care is at the interface with the rest of the kernel because there is a change of semantics there. > > 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: > > That is the optimizer being fancy since the error can be put > unconditionally in `rdx`. Yes that's what I understood as well. I just didn't know that it had to be seen as a union. On Fri, Apr 16, 2021 at 11:19:18PM +0200, Miguel Ojeda wrote: > On Fri, Apr 16, 2021 at 10:22 PM Willy Tarreau wrote: > > > > So it simply does the equivalent of: > > > > struct result { > > int status; > > int error; > > }; > > Not exactly, it is more like a tagged union, as Connor mentioned. > > However, and this is the critical bit: it is a compile-time error to > access the inactive variants (in safe code). In C, it is on you to > keep track which one is the current one. Sure but as I said most often (due to API or ABI inheritance), both are already exclusive and stored as ranges. Returning 1..4095 for errno or a pointer including NULL for a success doesn't shock me at all. Along thes lines I hardly see how you'd tag pointers by manipulating their lower unused bits. That's something important both for memory usage and performance (supports atomic opts). > > kill_foo(); // only for rust, C doesn't need it > > Please note that `kill_foo()` is not needed in Rust -- it was an > example of possible cleanup (since Al mentioned resources/cleanup) > using RAII. Yep but I kept it just to have comparable output code since in C you'd simply use "goto leave" and not have this function call to do the cleanup. Willy