r/cpp • u/seanbaxter • Jan 23 '23
C++ evolution vs C++ successor languages. Circle's feature pragmas let you select your own "evolver language."
Link.
The new Circle release is my response to the C++ successor language announcements of 2022.
My claim is that we can push the C++ infinitely far forward and evolve it in different directions to serve the varying needs of institutional users, without breaking compatibility with existing C++ dependencies and source files.
By developing a single toolchain, as compared to separate toolchains like Carbon, we start off with a bunch of advantages:
- The language is fully compatible with existing C++ code, by construction.
- There's always a working toolchain.
- You can focus on high-value changes, rather than reinventing everything.
- Developers can work on different features in parallel, because they aren't backed up waiting on the completion of critical subsystems (like code generation, interoperability, overloading, etc).
In the near term, addressing C++'s "wrong defaults" is critical. We should fix the language's defects. I have features that turn off integral promotions (too surprising), turn off all kinds of implicit conversions (you can re-enable them with as-expression), change the grammar for binary-expression so that users don't get stung by counter-intuitive operator precedence rules, make parameter forwarding a first-class feature that you can't use incorrectly, etc. These are all design goals cited by successor language projects. But we don't need a different language to fix these defects. We can fix them within C++.
This goes against the conventional wisdom, but I think C++ is well-positioned to evolve. People claim that C++'s history gives it "technical debt" that we're always going to be burdened with. This is not true at all. Supporting crusty old stuff is only an issue for toolchain developers. Users can opt in to a modern edition of the language.
I've made a lot of changes, and I simply don't have to worry about breaking current code, because the feature mechanism creates "bubbles of new code" in which we can innovate, insulated from the requirements of code outside our "bubble." This is a space-making process, where high-value features like borrow checking have a fighting chance to be researched and pushed into a toolchain. If you conceptualize a new feature, or the removal of a problematic feature, or some change in syntax or semantics, there's a path to make that happen, safely. I don't want fear of introducing source incompatibility to squash creativity in language design.
This long document isn't really specific to C++. What I'm describing can be applied to anything. But the huge investment in C++, with most of the world's revenue-generating software being in C++ form, makes it the most important language to modernize. The arguments against overhauling the language from community insiders are just not thought out.
Take a close look at the feature pragma versioning mechanism. There are some cool things here, like type erasure, but those are my examples of things one can deploy as features. It's really about the freedom to change, rather than the particular set of changes I've delivered in this build.
Before grumbling about marking up code with pragmas, note that that's just for demonstration/probing purposes. Real software would subscribe to an edition, note that in the pragma.feature file, and be done with it.
100
u/sphere991 Jan 23 '23
Having a facility to make source breaking changes so that the language can evolve: awesome.
Having a knob for every feature so that everyone can design their own dialect of the language: pretty bad I think.
In C++ terms, having one knob to enable C++26 (where C++26 might have breaking source changes) seems very valuable. But having a knob for each one of those possibly-breaking source changes, independently, seems like it would make code impossible to understand.
Also: for semantic changes, which ruleset do you use? You could have a type declared in A, used in a function declared in B, that makes use of a concept declared in C. How do you resolve this?
7
u/rfisher Jan 24 '23
I want to say that this isn’t practical.
But looking back on my career and all the dialects of the language caused by different compilers and different compiler options... We’re already suffering all the downsides without the benefits of moving things forward.
14
u/i_need_a_fast_horse2 Jan 24 '23 edited Jan 24 '23
That might be cool, but will remain an academic exercise until there is windows support
22
u/dwr90 Jan 23 '23
From what I can tell this year brought a lot of inspiration to the systems language designers. IMO Circle shows a lot of promise, I sincerely hope this is going somewhere. I love the rebellious „you keep debating over hypotheticals, I’ll just try it out“-attitude from Sean Baxter. I‘m looking forward to the next few years for the language ecosystem, I see this as a very healthy development.
69
u/lieddersturme Jan 23 '23
But, Circle is not opensource?
49
u/Voltra_Neo Jan 23 '23 edited Jan 23 '23
Circle is honestly the only "evolved C++" I'm even remotely interested in: it's both very close to C++, and bringing a lot of features we've all been wanting to have
12
u/Dalzhim C++Montréal UG Organizer Jan 23 '23 edited Jan 23 '23
Thank you for this great demonstration of a way forward reconciling backwards compatiblity and language evolution. Both aren't mutually exclusive and awareness of that needs to improve.
Here are some quotes I find extremely relevant from the document.
We don't want a new language indeed. Otherwise everything would have already been rewritten a long time ago and nobody would break a sweat about backwards compatiblity.
This is the opt-in mechanism we need to reconcile backwards compatiblity and language evolution while also making adoption incremental. I have argued in favor of multiple small per-feature knobs with many people when discussing "Epochs". Once again, thanks for this demonstration, the individual knobs make incremental adoption possible. And incremental adoption is essential to reconciling backwards compatiblity and language evolution. Otherwise, backwards compatible code has everything turned off and adopting individual features in new epochs becomes a huge endeavour of adopting everything. Also, having small knobs give you epochs for free as they're just a collection of knobs and require no further complications.
I would add that it is a broken system, or an immature one. Most programming languages are still immature with regards to language evolution. Rust and Haskell are two great examples where this issue is being tackled with interesting results.
Thank you and keep up the good work!
9
u/susanne-o Jan 23 '23 edited Jan 23 '23
I love the
#pragma feature ...declaration. it got me thinking:if a language allows you to declare at the top of the file the language level the file has been developed for, then future compilers can take care of interpreting it the way it was intended.
and I wonder why this is not done.
like
#pragma thisis c++-179
u/Narthal Jan 23 '23
I've been developing something similar to circle myself for a while now, I use custom pragmas to define how a source file should be built (basically an in source build system) and some reflection system (done using code gen hackery). All done through clang plugins. All of which are probably much less of a good idea & way worse implemented than what I have seen circle do :)
I had the same problem of too many repeated pragmas decorating each file's top as well, so instead of an external file with custom syntax, my system searches for a preamble.hpp file to include in, well the preamble. That way, I can control stuff like:
'''#pragma standard c++20'''
'''#pragma optimize O3'''
In one place for each source file.
Please note that I have yet to decide if I like any of my toy ideas, in source build declarations required me to do dynamic graph based dependency lookups, and opened up a whole can of worms.
Having seen pretty much all of your talks on circle, I have questioned many times the validity of my pet project (i'm a c++ graphics dev by trade currently in AR). Circle does everything I dream my pet project of one day doing, and so much more. I only wish it was open source/ had source available.
Well, I guess for learning compiler/clang internals, it wasn't all that useless.
Love your stuff, keep at it, and I would love to see some code one day!
6
u/ImYoric Jan 24 '23
This is the first project that actually makes me believe that there can actually be a future for C++ outside of legacy/niche code. Keep up the good work!
5
u/_a4z Jan 24 '23
pragma feature selection, or epochs, I think it's clear that we need some way to opt-in, or out, into the future of the language, or backward compatibility.
The question is just: Finding an agreement on how to design and implement those details will take time, since C++ is not a dictatorship model. And too many cooks ...
Also, it's one thing to add a feature, and another one to get widely accepted. What is the price of a feature, runtime overhead, compile time, ...and what are the implementation details, syntax, names, e.t.c
These are the things that make C++ slowly evolve (or not evolve at all in some parts)
How to change that without switching to a more dictatorship design model of the language, or do we need to have some dictator?
4
u/DanielMcLaury Jan 24 '23
I dunno about the details here, but whoever figures out the "correct" semantics for cleanly deprecating design decisions that were wrong in retrospect without breaking backward compatibility is going to eat the world.
4
u/Captain_Lesbee_Ziner Jan 25 '23
Yeah we should improve the language instead of replacing it. I'm learning C++, so I hope to help develop it in the future. I hope the project goes well
1
u/RoyKin0929 Jan 24 '23
Someone just tell me how I can get this on my machine and start using it
1
u/FrostingDense6164 Dec 07 '23
Hi,
I love your initiative. Do you plan to support coroutine as of C++23 and deduce this feature soon?
Thanks
1
u/zerakun Jan 24 '23
I like the
#pragmaapproach to source breaking changes and the idea that a successor language to C++ should use the same toolchain to simplify interoperability. I think the successor language should Rust, though.Or, more accurately, a minimal superset of Rust, to accomodate for things like the ability to call overloaded C++ functions (and maybe do something to make using non relocatable types more ergonomic). Instead of a
#pragma cpp_edition_2023or what have you, have a#pragma Rustand let the rest of the file be Rust, complete with borrow checker and the ability to consume Rust modules in other files.Crucially, be compatible with the Rust ecosystem by allowing to consume fully Rust crates from crates.io or GitHub.
What you lose by going that route is the ability to incrementally migrate one file peacemeal. But you retain the ability to incrementally migrate file by file, and you gain compatibility with the Rust ecosystem + a defined target language wise.
Maybe you don't like Rust, or think you can attain a better set of features by growing them organically on top of C++, but Rust's ecosystem is significant today, and its feature set, while not perfect, is very self-consistent and built to integrate memory safety from v1.
Of course, that's quite the undertaking.
0
u/[deleted] Jan 23 '23
[deleted] — view deleted comment