Circle C++: C++ superset to add Memory Safety based on Rust's borrow checking (www.circle-lang.org)
from armchair_progamer@programming.dev to programming_languages@programming.dev on 03 Jun 2024 06:00
https://programming.dev/post/15005390

From the page:

My aim is to produce a superset of C++ that has a rigorously safe subset. Start a new project, or take an existing one, and write safe code in C++. Code written in the safety context exhibits the same strong safety guarantees as safe code programmed in Rust. Indeed, lifetime safety is enforced statically with borrow checking, the signature safety technology first introduced in Rust

What properties characterize Safe C++?

  • A superset of C++ with a safe subset. Undefined behavior is prohibited from originating in the safe subset.
  • The safe and unsafe parts of the language are clearly delineated, and users must explicitly leave the safe context to use unsafe operations.
  • The safe subset must remain useful. If we get rid of a crucial unsafe technology, like unions or pointers, we should supply a safe alternative, like choice types or borrows. A perfectly safe language is not useful if it’s so inexpressive you can’t get your work done.
  • The new system can’t break existing code. If you point a Safe C++ compiler at existing C++ code, that code must compile normally. Users opt into the new safety mechanisms. Safe C++ is an extension of C++. It’s not a new language.
#feature on safety
#include "std2.h"

int main() safe {
  std2::vector<int> vec { 11, 15, 20 };

  for(int x : vec) {
    // Ill-formed. mutate of vec invalidates iterator in ranged-for.
    if(x % 2)
      vec^.push_back(x);

    unsafe printf("%d\n", x);
  }
}
$ circle iter3.cxx
safety: iter3.cxx:10:10
      vec^.push_back(x);
         ^
mutable borrow of vec between its shared borrow and its use
loan created at iter3.cxx:7:15
  for(int x : vec) {
              ^

A couple other languages aiming to create a “C++ successor” which is fully interoperable with C++ (analogous to TypeScript and JavaScript):

Compared to the other languages, Circle remains closest to C++. The other languages try to fix other C++ “problems”; Circle’s only goal is to fix memory unsafety, and otherwise keep syntax and semantics the same for maximum interoperability.

#programming_languages

threaded - newest

Alexstarfire@lemmy.world on 03 Jun 2024 06:51 next collapse

<img alt="" src="https://lemmy.world/pictrs/image/a06a03fb-3282-4880-bd75-16c809bc3c6a.png">

Gotta start somewhere though.

FizzyOrange@programming.dev on 03 Jun 2024 07:43 collapse

I feel like this is one of those XKCDs that automatically opts you out of sensible debate if you post it.

anton@lemmy.blahaj.zone on 03 Jun 2024 10:15 collapse

That’s why I keep this image in my back pocket:

<img alt="" src="https://i.kym-cdn.com/photos/images/original/002/705/714/520.png">

It may not directly create sensible debate, but it conters the thought terminating effect of the xkcd.

Edit: new link to the image

ananas@sopuli.xyz on 03 Jun 2024 11:41 next collapse

I’m going to steal this.

b_van_b@programming.dev on 03 Jun 2024 23:20 collapse

What’s the image? I just get an error message.

icesentry@programming.dev on 04 Jun 2024 00:54 next collapse

Now I’m just curious if that was intentional.

anton@lemmy.blahaj.zone on 04 Jun 2024 08:01 collapse

No, my instance was down.

anton@lemmy.blahaj.zone on 04 Jun 2024 07:58 collapse

It’s the “We Should Improve Society Somewhat” meme with society replaced with technology and the answer replaced with the xkcd.

knowyourmeme.com/…/2705714-we-should-improve-soci…

ananas@sopuli.xyz on 03 Jun 2024 09:04 next collapse

Circle is a bit weird, since instead of being a new language, it’s (or at least was when I last checked it out) technically a conforming C+±compiler, just with a lot of extensions. If we had interest, a lot of the stuff there could be standardised.

suy@programming.dev on 03 Jun 2024 21:46 collapse

FWIW, cppfront would be the same, IMHO. It allows C++ syntax, and it just passes it through verbatim. Only transforms “syntax 2” into today’s C++. And Herb Sutter very much says that what it does is based on the papers that he’s presented for standardization, and that he’d like this approach (new syntax) land into today’s C++ compilers and the standard.

cppfront is the only one that I thought had a chance till recently. The presentations from Sean Baxter seem to finally make the community see it on a positive light (I’ve seen posts on Reddit being removed on the premise of not being C++, which I think it’s a bit unfair), so that’s good.

ananas@sopuli.xyz on 04 Jun 2024 05:03 collapse

I do not really agree with cppfront being the same, given that it basically needs a full transpiler in front. A lot of the stuff there though is something that could be standardised though (and some of it absolutely shouldn’t, I’m looking at you UFCS), but I don’t think there’s much support for changing any of the core syntax.

I kinda understand the r/cpp stance, because it’s a bit difficult to draw the line there, but yeah, it feels a bit unfair. I think the first step of getting circle-like stuff into the language would be to standardise the #feature somehow.

QuadriLiteral@programming.dev on 04 Jun 2024 10:28 collapse

Note that the scope of “New Circle” is much bigger than “just” memory safety: choice types, pattern matching, …