#Pointer type with unchecked shared mutability?

1 messages · Page 1 of 1 (latest)

hallow star
#

I'd like to ignore the shared xor mutability rules that Rust uses to stay memory safe
you are aware that you can't "just" ignore the rules, right?

#

whether your language is garbage collected is irrelevant

severe moth
#

@hallow star Why can't I? Memory safety is enforced for all those types via the language's GC

#

There are a ton of types in Rust's stdlib that "just" ignore the rules-- that's the whole point of half the containers in the stdlib.

hallow star
severe moth
#

isn't that the whole point of GC?

#

managed languages

#

managed memory

#

etc

hallow star
#

what scripting language are you using, anyway

severe moth
#

it's my own

hallow star
#

all garbage collection does is cleaning up objects when they're not used anymore

#

you will have to ensure memory safety some other way

severe moth
#

how am i going to access invalid memory if there's no new/free because the GC handles it for me?

hallow star
#

you could move a type

severe moth
#

what?

#

it's GC'd, all types are refs

hallow star
#

memory safety is much more than just not double freeing or use after free

severe moth
#

like what?

#

buffer overflows, dangling pointers? not an issue

hallow star
#

data races, for example

severe moth
#

ok can you please just go away no offense but you aren't answering my question and you're adding a lot of noise

#

you're also trying to peg me on semantics which i don't appreciate 🙂

#

thanks! if anyone else knows please answer

hallow star
#

You're not going to get any useful advice from anyone without actually giving any information

severe moth
#

i asked a very specific question and you're out in left field

#

go away

#

thanks!

hallow star
#

but raw pointers and ussafecell are meant for exactly that thing

severe moth
#

👍

#

that exact thing i can't "just" do

#

wild

hallow star
#

What you can't do is use raw pointers and unsafecell and then just ignoring the rules. It is up to you to enforce these rules yourself, that is what unsafe means

#

given that you have to ask this question there is zero chance you will be able to do this correctly, that is why I asked questions

#

and more to the point, you can often just avoid unsafe altogether and use types like cell/refcell/mutex etc

hallow star
#

if you use unsafe, it's up to you to enforce them

severe moth
#

lmao

tacit cape
# severe moth There are a ton of types in Rust's stdlib that "just" ignore the rules-- that's ...

they absolutely do not "ignore" the rules
they just use the rules in special ways to get new behavior
"the rules" are more complicated than just "shared xor mutable"
so shared mutability can work
if you're single-threaded then something like Cell (which never hands out references to the inner content) or RefCell (which checks it at runtime) can work
in a multithreaded context you want locks or atomics
you just have to make sure that data races do not happen and that you dont violate the aliasing rules (for example by mutating through a & except through a {ref,unsafe,}cell or to not have two overlapping &mut T used in overlapping ways)

upbeat estuary
#

Even in a single threaded context, violating the shared XOR mutable rules can be a terrible idea. Optimizers assume those rules are respected, and this is without getting into how, uh, Rust-style enums are fundamentally unsound if you ignore those rules.