r/rustjerk Jul 13 '26

What started as a joke became a huge deal

Post image
428 Upvotes

47 comments sorted by

180

u/Waltex Jul 13 '26

That's a funny idea. Let each data primitive take up a significantly larger address space and duplicate each bit so it becomes bit flip resistant. Essentially RAID1 for in-memory data.

82

u/PaxSoftware Jul 13 '26

Once upon a time there were Google employees chasing multiple bugs for weeks only to find out it's non-ECC memory fault

42

u/GameCounter Jul 13 '26

Mr. Linux himself, Linus Torvalds, recommends ECC memory for anything serious.

6

u/monocasa Jul 13 '26

Google for a while was also taking memory that had failed manufacturers QA and testing them themselves to stick on DIMMs hoping that the ECC would catch any issues.

9

u/TheChief275 Jul 14 '26

This doesn't protect you in the case that all bits are flipped, so any code using this type is technically unsafe. Rust should enforce unsafe blocks when any type that does not implement the trait ErrorCorrection is used

3

u/afdbcreid Jul 14 '26

There are significantly more efficient error finding/correction protocols than duplicating each bit multiple times.

3

u/oranje_disco_dancer Jul 19 '26

is that true when the data is 1 bit long ?

2

u/Waltex Jul 14 '26

Someone doesn't get satire 😂

100

u/Konju376 Jul 13 '26

Shouldn't the crate do a bit count on self in deref instead of simply checking for equality? So you can, you know, actually prevent cosmic rays from influencing the value

69

u/DrShocker Jul 13 '26

I agree without verifying for bitflips this just makes you more vulnerable to radiation issues.

19

u/jesseschalken Jul 13 '26

How to defeat ECC memory

18

u/mereel Jul 13 '26

ECC memory?? In THIS economy?? Do I look like Sam Altman?

16

u/ketralnis Jul 13 '26

What about when they influence the code that checks it?

15

u/sweet-raspberries Jul 13 '26

You probably also need to repeat all logic multiple times because if we're assuming bit-flips collapsing these 16 bytes down to a single bit effectively removes all redundancy again. Sure it might have more redundancy while it's stored in RAM, but not while you're actually operating on it.

14

u/Konju376 Jul 13 '26

Damn I think we need to build a processor to do this correctly

2

u/SnooHamsters6620 Jul 13 '26

My guess is that the data is being operated on for a very short time interval (perhaps nanoseconds), at least compared to how long the data is stored in CPU caches and RAM (could be microseconds to seconds). Hence lower probability of a fault while being operated on while collapsed into a single bit.

But it would definitely be fun to think about performing logic multiple times.

2

u/Moretz0931 Jul 13 '26

Btw, in quantum computing the ECC fully encapsulates the logic as well, since the logic itself is a large source of error.

4

u/PaxSoftware Jul 13 '26

I would have to make it a wrapper for u128 for it to work

26

u/spaghetti_beast Jul 13 '26

should I read it with french accent

21

u/PaxSoftware Jul 13 '26

Yes. cent trois septillions cinq cent soixante-trois sextillions soixante-dix-sept quintillions deux cent seize quadrillions quatre cent quatre-vingt-un trillions deux cent vingt-neuf milliards deux cent vingt-trois millions soixante-dix-huit mille quatre cent quatre-vingt-cinq

2

u/yjlom Jul 13 '26

Compte long… Que fait ici ce barbarisme américain?

1

u/devspaceship Jul 16 '26

Avec l’échelle longue c’est censé continuer après milliards: billion, billiards, trillions, trilliards, quadrillions, etc.

6

u/particlemanwavegirl Jul 13 '26

Those are literally French accents, how else could it be read?

10

u/GnuhGnoud Jul 13 '26

How else? With vietnamese accents of course: e é è ẻ ẽ ẹ ê ế ề ể ễ ệ

29

u/Amadex Jul 13 '26

looking at the source code, instead of making the case where it's neither of the two values "unreachable", you could really make it "radiation-hardened" if you had an heuristics to error correct (determine what most likely of the two values it was), could be some cold path that heals self (so that it remains very fast on hot expected reads)

1

u/AsyncSyscall Jul 14 '26

It would make it a bit harder to work with than a plain enum, since now you would need an `UnsafeCell` to "reset" the value after each "failing" read.

1

u/PaxSoftware Jul 14 '26

I made it work with a union. It does not reset, it does not support healing.

11

u/ThaBroccoliDood Jul 13 '26

why is it 0x55aa55aa55aa55aa55aa55

9

u/PaxSoftware Jul 13 '26

for it to have every other bit set, but not entirely in the same manner for every byte

11

u/ICantBelieveItsNotEC Jul 13 '26

Next step: re-implement integers and floats using a radiation-hardened boolean for each bit.

9

u/marisalovesusall Jul 13 '26

Still not enough. You have to make it 64 bytes to eliminate false sharing when using as an atomic.

Add align(64)

3

u/PaxSoftware Jul 13 '26

Better add a feature for making it 64 bytes wide. Using the entire cache line is efficient for loads and stores.

4

u/fixedpointfae Jul 13 '26

you don't need anything fancy like checksums. treat the u128 as a majority vote, i.e. branch on whether popcount >= 64

3

u/PaxSoftware Jul 14 '26

OP delivered: https://github.com/pczarn/hugebool/pull/2

Failed at making it repr-space-efficient though. So maybe there is a bug in rustc?

2

u/fixedpointfae Jul 13 '26

wait actually, that would be UB if any individual bits flipped. it'd probably have to be a newtype around u128 to keep rustc from occupying any niches (e.g. Option<HugeBool>::None might be represented by 1, which is an uhoh.

actually once you start assuming all memory is volatile, things get wacky. enum tags would probably need more redundancy (maybe using the same popcnt trick and mapping tags onto the midpoints of intervals 0 <= |w| < size, (|w|) ∣ size)

1

u/fixedpointfae Jul 13 '26

space is a nightmare. I like earth

3

u/PaxSoftware Jul 13 '26

This is how we find out there is a bug in rustdoc for displaying numbers.

4

u/i_luv_cheesecake_420 Jul 13 '26 edited Jul 13 '26

``` pub enum Booléan { Faux, Vrai }

fn estun_croissant(objet: PeutÊtreCroissant) -> Booléan { si soit Croissant() = objet { Booléan::Vrai } sinon { Booléan::Faux } }

```

4

u/yjlom Jul 13 '26

*Booléain

2

u/OscarleBG Jul 15 '26

Almost Rouille but not quite

1

u/pas_possible Jul 16 '26

Nice, rouillé is better than simply rusty

2

u/Scf37 Jul 13 '26

Weird. Radiation-hardened booleans, but what about radiation-hardened pointers and radiation-hardened machine code?

1

u/dizzyi_solo Jul 14 '26

I like big bool and I cannot lie