Live data from Hacker News

Ante: A new way to blend borrow checking and reference counting

verdagon.dev

11–20 of 31 posts

Re: Ante: A new way to blend borrow checking and reference counting

#11

I can see how multiple mutable references is fine in a single-threaded context, but surely this would cause UB in the multi-thread context?

Creator of Ante here, Ante inherits Rust's Send/Sync for thread-safety. `mut` refs and `Rc` which provides shared mutability don't implement either and thus can't be shared across threads. So shared mutability is only within a single thread.

Re: Ante: A new way to blend borrow checking and reference counting

#12

I can see how multiple mutable references is fine in a single-threaded context, but surely this would cause UB in the multi-thread context?

Given their "shape stability" design, not necessarily. The three ways that multithreaded access can cause UB are: * changing the type of the underlying memory (e.g. because it's part of an enum variant and you changed the tag, or because you changed the length of a vector) * data races (can be defined away by making [effectively] every access Relaxed, as Java does * use after free (resolved here by reference counting…

I was thinking of the data race case, and I was unaware of relaxed access used by other languages. Thanks for sharing!

Re: Ante: A new way to blend borrow checking and reference counting

#13

What is "stable shape"?

Creator of Ante here. It's just a term I made up for mutation which does not change the "shape" of data in a way that can invalidate any of that data. Mutating a struct or tuple field, even if nested, is stable for example, but mutating an optional string to None is not because you may be dropping a string which there may be a reference to somewhere.

Re: Ante: A new way to blend borrow checking and reference counting

#14
post #4

>"I have to admit, this is beautiful" Terse it is, beautiful it is not (well my version of beautiful that is - easy to read and understand). this is not to diminish the language.

What would your ideal version look like? I recommend reading the C++ or Rust equivalent code in the article. I like the example because it is copied 1:1 with example code from a textbook with only some keywords changed and a Copy constraint. Any other language without a GC and with unboxed types today represents it far more verbosely to the point where the meaning becomes obscured and a typo becomes more likely to survive code review.

Re: Ante: A new way to blend borrow checking and reference counting

#15
post #13

What is "stable shape"?

Creator of Ante here. It's just a term I made up for mutation which does not change the "shape" of data in a way that can invalidate any of that data. Mutating a struct or tuple field, even if nested, is stable for example, but mutating an optional string to None is not because you may be dropping a string which there may be a reference to somewhere.

I see, so would it would only be relevant to unions, or would adding a new node to a linked list or pushing another element in a dynamic array or setting a pointer to null also count?

Re: Ante: A new way to blend borrow checking and reference counting

#17

What about Vale? Is this a rename of it or something new?

Hi, article's author here (Verdagon, Vale's creator), and no, I'm just writing about someone else's language (Ante) that I thought was interesting. Ante is making some very intriguing steps forward in memory safety design and I thought others would find it interesting too.

Thank you for clarifying!

Re: Ante: A new way to blend borrow checking and reference counting

#19
> Because of this, Ante code can safely have multiple mutable borrow references to the same struct at the same time.

I doubt it can work in multithreaded code. Allowing sharing mutable references (even to simple structs) means race conditions, temporal inconsistency between different struct fields and even incorrect read results for basic integer types (if the target CPU can't atomically read/write values of types like u64).

Re: Ante: A new way to blend borrow checking and reference counting

#20
I am pretty skeptical about the whole idea about adding such exceptions to the single mutable reference rule. It may be safe to share references to simple structs in terms of raw bytes access, but as long as some non-trivial invariants are involved, it can be a source of nasty bugs.

In my programming language I generally don't allow having more than one mutable reference to a variable. The only exception is when two references point to different elements of structs/tuples. This gives some flexibility without sacrificing correctness.

Post reply on HN