News for hackers. Stuff that matters.
Re:Show HN: Bolt: A research language with finer-grained con... by comex on Sunday May 10, 2020 @03:50AM (#23131002)
Well, I guess by "class fields" I actually mean two different things: class-typed fields and fields of classes :)

First of all, reference counting only happens for values of class type, plus closures and probably things I don't know about. Though, since copying a struct copies its fields, copying a struct containing a class-typed field will also produce reference counting; that includes String, Array, and Dictionary.

But also, shared mutability only exists for fields of classes (regardless of the field's type). When Swift decides to pass structs by pointer, those pointers are shared xor writable, similar to Rust; so if you have a pointer to a struct containing a string, the compiler can assume the string will stay untouched even if you run some arbitrary other code (as long as you don't mutate it yourself). Of course, unlike Rust, Swift doesn't let the programmer decide whether to pass structs by pointer or value (even with `inout`/`mutating` it's not guaranteed to use a pointer)...

Re:Show HN: Bolt: A research language with finer-grained con... by saagarjha on Sunday May 10, 2020 @04:16AM (#23131091)
Yup. The addition of restrictions on shared mutability were fairly recent (Swift 4 IIRC) and actually go further than just structs, which was slightly surprising to me when I read the proposal: apparently the Swift compiler is allowed to insert checks to dynamically ensure exclusive read/write access to a class’s properties as well.