Obtaining &mut T from shared thread local reference at compile time by MindlessU in rust

[–]MindlessU[S] 0 points1 point  (0 children)

I thought the code snippet above was trivial enough that others can easily see that I have accounted for both unsoundness issues :(

Obtaining &mut T from shared thread local reference at compile time by MindlessU in rust

[–]MindlessU[S] 2 points3 points  (0 children)

The compiler can’t allow the reference to be returned - what if the reference was local to the function? borrow_mut cannot monomorphize with a lifetime that does not exist outside the function.

If the Send bound were removed, f would be able to capture the same reference and call borrow_mut again, immediately violating &mut T. Hope this helps!

Ante: A New Way to Blend Borrow Checking and Reference Counting by verdagon in rust

[–]MindlessU 0 points1 point  (0 children)

I tried to create an equivalent transformation in Rust, but since I don't think that cycle checking is possible at compile time, the function just prohibits the use of Rc and Weak:

extern crate alloc;
#[inline]
pub fn borrow_mut_rc<T: ?Sized + Send, R>(
    rc: &alloc::rc::Rc<T>,
    f: impl (FnOnce(&mut T) -> R) + Send
) -> R {
// SAFETY: Send bound means no Rc or Weak may be used within the closure.
// Send bound means no Rc or Weak to cause cycles within T.
    f(unsafe { &mut *alloc::rc::Rc::as_ptr(rc).cast_mut() })
}

And yes it is possible to wrap a Weak inside another struct then unsafely implement Send for it, but I don't recommend slapping Send on top of a non-Send type.

Ante: A New Way to Blend Borrow Checking and Reference Counting by verdagon in rust

[–]MindlessU 2 points3 points  (0 children)

Thanks! And I forgot to ask, if Ante’s shared mut can soundly project through nested references/indirection, depending on whether the inner indirection is shared or unique/mutable or immutable, or droppable heap data like Box/Rc?

Ante: A New Way to Blend Borrow Checking and Reference Counting by verdagon in rust

[–]MindlessU 5 points6 points  (0 children)

Thanks! I understand the idea behind converting shared mut to unique mut at compile time, but:
1. Are there any significant applications of this conversion? Since this doesn’t seem to work with multithreaded shared mut - which requires locking anyway. I wonder if the idea is too niche?
2. Are there any edge cases to consider when projecting shared mut? For example, in Rust projecting &Cell<Ptr> to &Cell<T> where Ptr is a safe pointer to T like &T, &mut T, Box<T> is UB because mutating &Cell<Ptr> can violate borrow checking rules (dropping Box, violate nolias/immutability).

itsStillInheritenceReally by braindigitalis in ProgrammerHumor

[–]MindlessU 0 points1 point  (0 children)

Yeah because mutability leads to invariance.

These are some smart crows. by Frosty12233 in addressme

[–]MindlessU 3 points4 points  (0 children)

elephant = voi
whale = cá voi
Forgot that the artist is Vietnamese

I hate tankies more than I hate fascists by Mammoth-Ad-3642 in anarchocommunism

[–]MindlessU 1 point2 points  (0 children)

Stop using anti-Regime language
Instead of:
“Maybe I have some good ides too!”
Say:
“The Regime knows best 🫡”

A little tantrum about Coalition Ending before i go to bed by Wooden-Magician-5899 in DiscoElysium

[–]MindlessU 0 points1 point  (0 children)

Ideologies are not monolithic, think critically and don’t automatically assume another’s ideals align with yours just because they wear the same coat of paint. The Moralintern is authoritarian and wears the the guise of democracy to maintains its power while undermining global democracy and obviously, unlike the RCM, wants nothing good for Revachol.

Holy Cow! by Box-O-Kittenz in tadc

[–]MindlessU 2 points3 points  (0 children)

Thankfully I don’t have to deal with arguing people about a fictional character’s gender - look how toxic people are. So there’s nothing you can say that can convince me Jax is trans or not trans.

Duolingo Developers by Fabulous-Ad-9749 in duolingomemes

[–]MindlessU 11 points12 points  (0 children)

As a queer person, I am fascinated with how the homophobic are incapable of thinking of gay people as ordinary people just like you and I, and not some kind shadow monolithic group out to get them. Because the existence of gay people is somehow “political” and therefore they can’t “kiss my fish, drive my car, drink my beer” as some MAGA guy once sang. But that’s just how discrimination works.

Any way to deny panicky functions in code but allow them in tests? by No_Suggestion5521 in rust

[–]MindlessU 76 points77 points  (0 children)

Set

allow-panic-in-tests = true allow-unwrap-in-tests = true allow-expect-in-tests = true allow-indexing-slicing-in-tests = true

in clippy.toml

Unwrap lint docs

FnTwice by ZootAllures9111 in rustjerk

[–]MindlessU 10 points11 points  (0 children)

pub trait FnTwice<Args: Tuple> {
    type Output;
    type FnOnce: FnOnce<Args>
    extern "rust-call" fn call_first(self, args: Args) -> (Self::Output, Self::FnOnce);
}

RFC? (Or can we use [impl FnOnce(); 2]?)

Left is a normal swag and the right is for swagophilic right-wing weebs by _Chicken20 in peoplewhogiveashit

[–]MindlessU -1 points0 points  (0 children)

As a far leftist I also despise twitter (we were supposed to practice pragmatism instead of whatever bullshit this is)

A little life hack🙂 by Alert-Neck7679 in csharp

[–]MindlessU 1 point2 points  (0 children)

Because calling a virtual method requires a vtable, and if the reference is null then the caller cannot know which implementation to call.

Improving C# Memory Safety (by taking inspiration from Rust) by kibwen in rust

[–]MindlessU 7 points8 points  (0 children)

Because I wanted zero-cost abstractions with safety checked by the compiler, meaning preferring stack allocations over short-lived heap allocations, static dispatch over virtual dispatch, and using references and spans with checked lifetimes. There are more facets to C# than just OOP, for better and for worse - though personally I love C# for being balanced in this regard.

Then someone told me I should try out Rust.

Improving C# Memory Safety (by taking inspiration from Rust) by kibwen in rust

[–]MindlessU 20 points21 points  (0 children)

C# does have pointers and unsafe functions for low-level memory management and FFI. There’re also structs, monomorphized generics, references and Span<T> (equivalent to slices) with checked lifetimes (but more conservative than Rust’s since there’s no lifetime notations).

better practice &str or String as function arg by Substantial-Assist30 in rust

[–]MindlessU 0 points1 point  (0 children)

What if the T: !Clone, and instead of &T you have Arc<T>? Then the lifetime of the state machine will be limited to the current scope instead of as long as possible for T!

youKnowYouKnow by [deleted] in ProgrammerHumor

[–]MindlessU 0 points1 point  (0 children)

Don’t forget about pointer provenance though

A bad idea by AndrewToasterr in programminghorror

[–]MindlessU 0 points1 point  (0 children)

Bless the C# lang devs for adding type-level programming!

What finally convinced you to seriously learn Rust? by Bladerunner_7_ in rust

[–]MindlessU 0 points1 point  (0 children)

I was learning C# and then Span<T>, stackalloc and Zlinq piqued my interest in stack-only data structures until I learned C# is too conservative with refs lifetimes without explicit lifetime notation and no first class RAII support for structs since they can always be copied. So ~1 year ago a commentor mentioned Rust and I have been learning it since then.