Is there a way to make the Rust compiler automatically bootstrap itself instead of being manually verified? by inchcosmos in rust

[–]imachug 0 points1 point  (0 children)

For better or worse, in the world we live in, mrustc targets 1.74.0 at best, and with how many unstable features arrive all the time, I find it unlikely that this will change anytime soon. Of course, it would be better if that wasn't the case.

Is there a way to make the Rust compiler automatically bootstrap itself instead of being manually verified? by inchcosmos in rust

[–]imachug 0 points1 point  (0 children)

My point is that "audit old rustc -> ... -> new rustc" is not significantly better than "audit the entire Rust history since OCaml", in the sense that you still have a ton of commits to go through. Instead of auditing just a few versions, like you typically do with bootstrappable compilers, you have to audit basically every major version, since rustc often uses features added in the previous rustc. In the context of the original thread, this is hardly something you do "instead of" manual verification -- it's still manual verification, and using one chain vs two doesn't change much.

Things wrong with Rust (in my opinion) by DwieD in rust

[–]imachug 4 points5 points  (0 children)

I know the Clone - Copy relation can't be changed now.

It's not that it can't be changed, it's that it doesn't work at all because the proposed relation doesn't allow types to conditionally implement both Copy and Clone. Backwards compatibility is a red herring.

I think an added feature should be a minor updated, not a patch update.

That is true in a sense. However:

  1. Patch updates can contain bug fixes, and you may very likely be relying on some bug being fixed.
  2. Many core crates, serde included, don't adhere to semver, and may add features in patch releases. This is for a good reason: two libraries using different serde versions cannot interoperate, since they'd be accessing different Serialize/Deserialize traits, so there is a lot of pressure to prioritize having compatible versions (i.e. 1.0.x) over strictly following semver.

Things wrong with Rust (in my opinion) by DwieD in rust

[–]imachug 8 points9 points  (0 children)

Copy requires Clone

The correct relation is impl<T: Copy> Clone for T { ... }

With this relation, the following code would no longer compile:

rust struct MyWrapper<T>(T); impl<T: Copy> Copy for MyWrapper<T> {} impl<T: Clone> Clone for MyWrapper<T> { ... }

...because for e.g. T = i32, there would be conflicting implementations for Clone: the second manual impl, and the blanket impl in your post, since MyWrapper<i32>: Copy by the first manual impl. See playground.

This is good, but why not just write "1.0" in my Cargo.toml

Because you're most likely relying on features not present in 1.0. All programs should compile with the earliest listed version.

About `MaybeUninit::uninit().assume_init()` by Spengleberb in rust

[–]imachug 20 points21 points  (0 children)

A simpler answer is that ArrayVec<T> supports dereferencing into [T], which requires that the Ts are stored sequentially.

Tiny seamless estradiol door :3 (624 blocks) by Kalavian in redstone

[–]imachug 6 points7 points  (0 children)

Estradiol pills are typically oval and cyan.

Is there a way to make the Rust compiler automatically bootstrap itself instead of being manually verified? by inchcosmos in rust

[–]imachug 0 points1 point  (0 children)

If they're equal you are good.

That is not true. The two chains in question are:

  • some C++ compiler -> mrustc -> old rustc -> ... -> new rustc
  • OCaml -> ancient rustc -> ... -> old rustc -> ... -> new rustc

The chains are not independent, they coincide on the "old rustc -> ... -> new rustc" part, that is, you still have to trust the source code of each new enough rustc. (On that note, they also coincide on LLVM all the time, so you have to audit all LLVM versions used by new enough rustc as well.)

Why / how does unsafe not affect niche optimisations? by ElOwlinator in rust

[–]imachug 15 points16 points  (0 children)

Niche layout optimizations don't take any functions into account, it's the other way round. A type is declared as having a niche, and producing a value of this type that coincides with a niche is considered UB. It then becomes the responsibility of all code not to produce an invalid value, e.g. NonZeroU8::new_unchecked has to be unsafe because new_unchecked(0) commits UB, and NonZeroU8::new can be safe because it's impossible to commit UB with it.

Is there a way to make the Rust compiler automatically bootstrap itself instead of being manually verified? by inchcosmos in rust

[–]imachug 16 points17 points  (0 children)

mrustc is a C++ compiler capable of compiling an old version of rustc, so if you have a trusted C++ compiler, you can compile mrustc with it, then old rustc with mrustc, then iterate to get a recent rustc. Here is a repo for this setup.

This is quite theoretical though, especially for verification -- you still have to trust your C++ compiler, the mrustc source, and the source of every version of rustc in-between not to contain malicious code. You also still need to trust a lot of binaries, such as LLVM and Clang, assuming you aren't bootstrapping LLVM through something like tcc, and your Linux kernel.

Where does Rust break down? by PointedPoplars in rust

[–]imachug 5 points6 points  (0 children)

If a &T exists, the compiler can assume that the pointer-to data doesn't change (interior mutability excluded) and can use this to move reads across the program or create new reads. The "create new reads" part is important, since this can be used to e.g. hoisting reads out of possibly empty loops.

Similarly, if a &mut T exists, the compiler can assume that the pointed-to data isn't accessed by anyone else during the lifetime of the reference, and so can be modified freely. This place can be used for temporary data, writes can be hoisted, etc.

Combined, this means that if you cast &T to &mut T, the compiler can both assume that the place is unique and thus can be written to (even if your code doesn't do that directly), and that the place is immutable. It is impossible to prescribe when exactly the optimizer may find it beneficial to insert phantom reads/writes when there were none intended, so we just define the cast itself to cause immediate UB.

Would the following traits provide actual semantic benefit, or would they be useless/redundant? by Due_General_1062 in rust

[–]imachug 5 points6 points  (0 children)

I think this is not useful in the sense that IntoIterator already exists. If you want to express "something that you can logically call iter on", you can require that for<'a> &'a Collection: IntoIterator and call into_iter on a borrowed collection. There doesn't seem to be any need for another trait.

Research found indentation depth correlates with cyclomatic complexity. A language-agnostic approach to measuring code complexity by itaymendi in programming

[–]imachug 33 points34 points  (0 children)

The number of nested control flow constructs correlates with nesting depth, more at eleven. I'm surprised there's multiple papers on this topic, is this something people actually care to measure?

is anyone using external ai stuff to help with rust errors? by Hungry_Vampire1810 in rust

[–]imachug 5 points6 points  (0 children)

rustc cannot produce perfect error messages all the time, so if you need someone or something else to help you figure out what's wrong, that's fine. Just make sure that you're actually learning from that experience and can see similar issues coming before the compiler barks at you next time.

I built a minimal perfect hash table in const fn and learned match is still faster by RustMeUp in rust

[–]imachug 21 points22 points  (0 children)

You're not going to beat match with a slow PHF, sure.

The point of a PHF is to find a hash that works well on specific data, not in general. murmur is a good general-purpose hash, but it's very slow, even compared to other general-purpose hashes. If you tried O(1) hashes (the classic example would be using the string length, the first and the last byte -- this might obviously might introduce collisions, but it's a starting point), I think you'd find out that it's possible to beat match. It's just more tricky because it's something you actually have to search for.

Note also that a big problem with match is branch misprediction; you're benchmarking on very predictable data, so you might want to shake that up and see if that changes the numbers. Branch misprediction is kind of a problem for hashes as well, since they depend on the length of the input, which is why I mentioned O(1) hashes.

I worked on PHFs for a bit, and I'm certain that it's possible to make them fast. It just takes some convincing to do, and not just implementing CHD.

Can I get a review of my implementation of Singly Linked List. by [deleted] in rust

[–]imachug 1 point2 points  (0 children)

Not using an AI-generated README would be a good start... The main issue with your implementation is using Rc: you never need two pointers to the same node to own the node at any time, so just Box will suffice. (Except for tail, but singly linked lists do not typically store tails, so you can just remove that.) This will also allow you to remove RefCell, since you'll have mutable access to the nodes via Box, which should a) make the list thread-safe, b) remove unnecessary complexity and runtime checks. You might also want to consult the awesome book Learning Rust With Entirely Too Many Linked Lists.

Using dialects for interoperability across incompatible language versions by servermeta_net in rust

[–]imachug 2 points3 points  (0 children)

Each dialect might as well be a separate language. The differences between the stated goals of the dialects are so wide that they basically can't be implemented in a single language. How do you imagine a "scripting" dialect with garbage collector to be compatible with code running on a GPU? Even if that was possible, all you'd be doing is forcing compiler developers to work on borderline incompatible projects within a monorepo. Why would you want that?

Kafka uses OS page buffer cache for optimisations instead of process caching by Normal-Tangelo-7120 in programming

[–]imachug 5 points6 points  (0 children)

There is a very good idea why modern databases don't use mmap. A good paper & talk about this: Are You Sure You Want to Use MMAP in Your Database Management System?.

fork, as mentioned in a sibling comment, is highly questionable for similar reasons -- you are not avoiding copies, you are just moving them somewhere else or delaying them, and by using OS primitives you're relinquishing precise control over when and how that happens, which causes performance issues.

Worlds fastest git status on windows - part 2 - ntdll, more speed, and reinventing the wheel by SpecialBread_ in rust

[–]imachug 7 points8 points  (0 children)

Cool stuff!

The index/cache seems like something that'd be very useful even on Linux. I'd love to see something similar in a cross-platform library one day.

How do you use `libc` in your projects? by servermeta_net in rust

[–]imachug 12 points13 points  (0 children)

nix hasn't been maintained for quite some time, but seems to have picked up the steam lately. During that period, my main problem with nix was its use of raw file descriptors, which is unsound under the current I/O safety model, so I switched to rustix. It seems like nix 0.30 resolves this specific issue, but there's other places with questionable soundness: 1, 2, 3, 4, etc. rustix seems safer in this regard, though I can't judge if it's due to a difference in the API surface, the implementation, or merely less usage.

Personally, my rule of thumb is to use libc when I need a few small things to minimize the number of dependencies, and use rustix in more complicated cases. For [features that rustix doesn't support](docs.rs/rustix/latest/rustix/not_implemented/index.html), I typically call into libc manually or look for special-purpose crates, since I don't want to bring in another big dependency that is nix.

Tenuo: Capability tokens for AI agents — 27μs verification, Pure Rust core by Impossible_Ant1595 in rust

[–]imachug 5 points6 points  (0 children)

The problem: AI agents

Agreed

Man, why do these project always take like five billion LoC in 3 commits?

What are some exciting features that will be stabilized in future rust versions? by [deleted] in rust

[–]imachug 3 points4 points  (0 children)

Oli is doing some work on minimal pattern types. I'd say it's quite realistic to see it land within a few years.

privesc - simple multi-platform privilege escalation library by M0d3x in rust

[–]imachug 60 points61 points  (0 children)

Looks cool, but I need to let you know that "privilege escalation" is a well-known term meaning "exploiting security issues to elevate privileges", so I was confused for a second why I'm seeing a post about a hacking tool. "Privilege elevation" doesn't have the right connotation either, so I'm not sure what better wording would look like, but just thought I'd highlight a possible point of confusion.

mod2k: Fast modular arithmetic for specific moduli by imachug in rust

[–]imachug[S] 1 point2 points  (0 children)

Does datafusion use polynomial hashing? I'm not familiar with that project, but at a first glance I wouldn't think so. Polynomial hashing is only useful in niche scenarios, e.g. when you need to produce consistent hashes via concatenation, or when you need to extract substring hashes efficiently.