Article View: comp.arch
Article #16Re: Optimization by programmers
From: Michael S
Date: Wed, 07 Oct 2026 20:25
Date: Wed, 07 Oct 2026 20:25
65 lines
3758 bytes
3758 bytes
On Wed, 7 Oct 2026 20:05:50 -0000 (UTC) cross@spitfire.i.gajendra.net (Dan Cross) wrote: > In article <20261007222539.000033d0@yahoo.com>, > Michael S <already5chosen@yahoo.com> wrote: > >On Mon, 5 Oct 2026 11:36:59 -0000 (UTC) > >cross@spitfire.i.gajendra.net (Dan Cross) wrote: > > > >> In article <86h5j5pky9.fsf@linuxsc.com>, > >> Tim Rentsch <tr.17687@z991.linuxsc.com> wrote: > >> >Terje Mathisen <terje.mathisen@tmsw.no> writes: > >> > > >> >> Tim Rentsch wrote: > >> >> > >> >>> Terje Mathisen <terje.mathisen@tmsw.no> writes: > >> >>> > >> >>>> Tim Rentsch wrote: > >> >[...] > >> >>>>> I favor a type equivalent to size_t for use as array index > >> >>>>> variables. > >> >>>> > >> >>>> In Rust, the only acceptable array index is of type "usize", > >> >>>> which is effectively the same as u64 on most platforms these > >> >>>> days, but does not need to be so: On a 32-bit target, it > >> >>>> would be the same as u32. > >> >>>> > >> >>>> So effectively very similar to size_t. > >> >>> > >> >>> Maybe that limitation works okay in Rust. In C sometimes it's > >> >>> important to allow a signed value for indexing. Probably 99% > >> >>> of the time size_t is good, but not always. > >> >> > >> >> The fact that array indices are unsigned is one of the more > >> >> crucial underpinnings of Rust safety. Even more importantly, > >> >> all such indices are verified against the actual array upper > >> >> boundary. [...] > >> > > >> >It's nice that array index values are checked against the array > >> >bounds. > >> > >> Terje was actually incorrect here; bounds checks are added in > >> debug mode, but are (usually) removed in optimized builds. > >> > > > >Are you sure? > >Methinks The Book states otherwise: > >https://doc.rust-lang.org/book/ch03-02-data-types.html?highlight=array#invalid-array-element-access > > > > If the array length and index are known ahead of time, or can be > statically proven to be valid, then yes, the checks are (likely) > removed in release mode as part of the ordinary optimization > passes. That is not different from any other bound-checked language that has optimizing compiler. > In the case where one has already asserted that > `p + n < arr.len()`, then I would expect any index `arr[p + k]` > to omit the bounds check, for k < n. > > - Dan C. >
Technical Details
Message-ID:
<20261007232531.000012dd@yahoo.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<1177fdi$26ea4$1@dont-email.me> <86h5j5pky9.fsf@linuxsc.com> <11a024r$f52$1@reader2.panix.com> <20261007222539.000033d0@yahoo.com> <11a68mu$m4l$1@reader2.panix.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Michael S <already5chosen@yahoo.com> Newsgroups: comp.arch Subject: Re: Optimization by programmers Date: Wed, 7 Oct 2026 23:25:31 +0300 Organization: A noiseless patient Spider Lines: 65 Message-ID: <20261007232531.000012dd@yahoo.com> References: <1177fdi$26ea4$1@dont-email.me> <86h5j5pky9.fsf@linuxsc.com> <11a024r$f52$1@reader2.panix.com> <20261007222539.000033d0@yahoo.com> <11a68mu$m4l$1@reader2.panix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Date: Wed, 07 Oct 2026 20:25:36 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2438720"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/VeMdJmRMGBU0y6Cl1XIxOlvNZlI+N3e0="; posting-host="ad05b586a96bfaffcf8a26253a6ce825" Cancel-Lock: sha1:80wiV1KPDjwH9en72zbUJ/m/YyU= sha256:JG7X2u95nSNYwPsURBcFX1ilaRUIVlRizG6ZEXogzFc= sha1:Glwsrr8S/M9JF0XP+9C5QLGMsOI= sha256:sCWwDE8GVUfjoPeIBX9kyNSVIiBg7C4jyRkRmOm7rL8= X-Newsreader: Claws Mail 4.1.1 (GTK 3.24.34; x86_64-w64-mingw32)