From nobody Fri Sep 06 07:13:34 2024 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4X0SBf4xdLz5WBqL for ; Fri, 06 Sep 2024 07:13:46 +0000 (UTC) (envelope-from theraven@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X0SBf38HDz4JdS; Fri, 6 Sep 2024 07:13:46 +0000 (UTC) (envelope-from theraven@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725606826; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GnlbFm2JwOQ8tZNzYPmrmpf8OXzU5v7YNFmwtC/Rda4=; b=U1bR40sLIuiV7i8fqEzHOt7O00KBVQS6Muzmdsg5MQaVZysdisS8qxwFoxTCPJ1i2HKfNk 4BPVAr5poVTAk1Qz4DhwA7Aqqu6BzR32RGdO4R/7B0Q3yZh9WjG/yYc8WW/7VGsOp+dY2R sclPK2vLM+xhevEtUlGUmYt2GdPSfWbFgfefjdrDXmLNZkhIqQF8v6fV65dVCdDI1n+6Ww i8hT7ld2KWy3dnIvCcDvTBLxx8aw/4eDg2QieDTCRl0mTEX20J0Y6qZaUrjAE4AdUHR0fX KoExHhXSAPI57uuwBLBI7o8hYvXlN9dK4zlz10UOWmh6Zv6JyWze8M6xQRpo0A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725606826; a=rsa-sha256; cv=none; b=JEErFhVrqenW9sNiHQ6oaBW3Vzp/Zy5MLGPHHxzx4Jk9jW4oRSnKVhuXxGKmSY7Gzqh0Vu ZUazkTToACCc+LQsNhx2kSaZECm/qNs33Mo2YrvFwc4KykIkj2ZUrD8DjBEiQ8WQu/4LSJ v+PAKphTrjU6V3z2MBNe6FVGd2fYLoSVYr82X4iUYicDFJbmUJ4o9kXiNq3CIJf1edtW3k sC6e/8gzhMpWowXtsGeq0oH0d9RVhUJWgdnZv7K7Lz8bgauEA0ZfWAUYNJolm3MKCat9la FDLLP2vfJWToIXaDoRQIjuOm4iX3fNYfMvZhIL6h6vu4QbuBgnxP1CFeQ0ivmA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725606826; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GnlbFm2JwOQ8tZNzYPmrmpf8OXzU5v7YNFmwtC/Rda4=; b=jrYR3nESFmY8eD1qru746congVZAsxgGtuCtCRd94T0q0edLOU9KpBUdyViH3oKp7Ydixp C9UgbfxZUWYFYwNUqTdRetKn/CQaqcR7oRxG/x29Hk6Yiim6//yBhBTCY9mmOIr3Z/GZKH nqUuydfS04EoCklYEzvHyaDpzVApV+AH/90/8/f22gFtdZea2DVS5YJxYFuxXC0l8SGFFB mdwqNIh+P7NajIgCWRDg5RhW6bw72xHwFSPrWDGhNyUHy9/38LTdQbtX6iPYVwktMblQ2n gXHA9h4SeHM03mvQ1rRnmT2HPcglMvy7JrqWgK7o3T7tJym3JkEcJyeuA3Z24A== Received: from smtp.theravensnest.org (smtp.theravensnest.org [45.77.103.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: theraven) by smtp.freebsd.org (Postfix) with ESMTPSA id 4X0SBf2bvxzHdx; Fri, 6 Sep 2024 07:13:46 +0000 (UTC) (envelope-from theraven@freebsd.org) Received: from smtpclient.apple (host109-155-136-107.range109-155.btcentralplus.com [109.155.136.107]) by smtp.theravensnest.org (Postfix) with ESMTPSA id BACA464F9; Fri, 06 Sep 2024 08:13:45 +0100 (BST) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: David Chisnall List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@FreeBSD.org Mime-Version: 1.0 (1.0) Subject: Re: The Case for Rust (in any system) Date: Fri, 6 Sep 2024 08:13:34 +0100 Message-Id: References: Cc: Karl Denninger , freebsd-hackers@freebsd.org In-Reply-To: To: Alan Somers X-Mailer: iPad Mail (21G93) On 5 Sep 2024, at 20:50, Alan Somers wrote: >=20 > I think you are misinformed about the runtime costs involved. In > fact, Rust's overhead is quite low. It=E2=80=99s very hard to get good apples to apples comparisons here but the= main thing to remember is that C and Rust compile down to the same instruct= ion sets. For spatial safety, you have basically two cases: - Things where the size is statically known and so all accesses are in boun= ds if their offsets are known. - Things where the size needs to be carried around with the object. There is nothing magic in C here. You either have fixed-sized things and a c= ompiler will be able to statically bounds check (though will typically only w= arn for invalid ones) or you carry the length around and check it. The diffe= rence is that Rust or C++ can express both of these in the type system and s= o will always insert bounds checks for any access where they cannot be prove= n to be redundant. The cases where you will see a difference are the ones where the safety depe= nds on some extrinsic property that the programmer knows but which cannot be= expressed in the type system. In C, you will do an unchecked access. In Rus= t, you *can* do unsafe things with raw pointers, but usually you won=E2=80=99= t, and so you=E2=80=99ll get bounds checks that are redundant. Assuming, of c= ourse, that the assumption that the programmer made is correct and remains c= orrect as the code is refactored. Which it often isn=E2=80=99t, and then you= get security vulnerabilities. David