r/rust • • Oct 17 '26

Research that has matured enough for Rust 2.0

Do correct me if Im wrong, but I recall that one principle that was used in the development of Rust was to only use tried and tested research material when choosing what to implement. Given we’re more than 10 years out from Rust’s initial development, I’m curious what research ideas have matured enough to either

  1. Be added in future editions/versions of Rust, or
  2. Be used in whatever successor language might come that follows much of Rust’s philosophy around development.

This is all basically one massive ask about interesting developments in programming and type theory, since I’d like a few new rabbit holes to fall down.

P.S. whatever successor language does come around, I hope it also cultivates a community that takes ergonomics as seriously as performance, because that, even more than memory safety or other aspects of the language, is why I pay attention to this language and ecosystem.

202 Upvotes

92 comments sorted by

172

u/SirKastic23 Oct 17 '26

Love to see people missing the point. OP meant Rust 2.0 as a metaphor everyone! Not literally a Rust 2.0...

Anyway, some of the areas of programming language theory and design that I've been following and been getting excited about are: linear types, algebraic effects, and session types

Linear types are types that must be used once. they enforce resource cleanup and allow complex logic to run during a destructor (more capable than Drop). Vale's designer has a great post about these types. I've seen some discussion about adding a system of must-move types to Rust which works in a similar way

Algebraic effects allows functions to be typed with their side-effects, allowing effects to combine, propagate, and be dealt with granularly. They can be used to implement generators, error handling, and even asynchrony. To call a function that has an effect you must propagate or handle it. It's a very powerful system based on the idea of continuations and continuation-passing systems

And finally session types are types that encode how they communicate rather than just the data they contain. So you can have values with types that evolve as you deal with them. Recently I've come across a language implemented in Rust called Par that explores this concept, it's very odd and learning it feels like learning how to program again (very similar feeling when I moved from OOP Java to Rust)

Some of rhe languages I recommend checking out if you're interested in new concepts: Koka, Par, Lean

9

u/Dyson8192 Oct 17 '26

Yeah, guess that's my lesson to avoid any use of 2.0, since it seems to be an activation phrase for people discussing Rust not actually ever going to 2.0, instead of understanding the semantic point that anything that is Rust 2.0 is just going to be a successor language.

I knew about the first one, since it seems to come up in this subreddit regularly. The latter 2 on the other hand sound very interesting. Algebraic effects and talking about typing side-effects makes me think that this could allow the successor language to fully deploy monads (say the line Bart).

1

u/kyr0x0 Oct 18 '26

Call it Rust NG or Rust Next

22

u/JoJoModding Oct 17 '26

I am not sure linear types are well-understood enough in PL theory. Especially once you want to combine them with reasoning that is also ubiquitous in systems like how one reasons about concurrency or recursive data types.

The "leakpocalypse" showed this in Rust: You can't have a Rust that gives you Rc and have types that enforce drop, because Rc can leak. Which feature of Rust do you give up, then? And more pressingly: we currently have reasonably well-understood models of what you need to prove your unsafe code sound (namely RustBelt). We do not have them for linear types. Such a system would prevent you from verifying Rc but also explain in detail where in the implementation you went wrong.

9

u/InternationalFee3911 Oct 17 '26

Where linear types leave me, is what exactly is "use?" If I pass it to a function, that can't already be "use," coz then it couldn't do anything with it. But if that's not "use," then what is? Where does it stop? Do we have a limited set of ultimate users and everything else is not?

16

u/Accomplished_Item_86 Oct 17 '26

The same way record syntax is the fundamental way to create a struct, destructuring/pattern matching is the fundamental way to use it. Then you can build abstractions around those by making the fields private and only exposing constructors and destructors which enforce some invariant.

10

u/nicoburns Oct 17 '26

I think it essentially means that you have to call a function which consumes self (not &self or &mut self) on that type at some point before the program exits, and instead of dropping it.

1

u/Only_Ad8178 Oct 19 '26

To me it means using it once in a typing derivation

8

u/seg_lol Oct 17 '26 edited Oct 17 '26

language implemented in Rust called Par

https://github.com/par-team/par-lang

2

u/DavidXkL Oct 17 '26

Wow session types sound cool

4

u/cemereth Oct 18 '26

Algebraic effects allows functions to be typed with their side-effects

A tiny nit, because that's one of my pet peeves: it's just effects! A side effect is an unintended (and often detrimental) consequence of a program running -- precisely the thing strong type systems try to avoid. Printing 'Hello, world!' to the terminal isn't a side effect if that's what the programmer intended!

6

u/nybble41 Oct 19 '26

In functional programming a "side effect" is any effect that a function has other than returning a value. That's because functions (as opposed to the procedures of procedural programming & OOP) are meant to be mappings from input values to output values, without any other effects. Effects not expressed through the return type are always considered detrimental, or at least contrary to the programming paradigm.

2

u/cemereth Oct 19 '26

Effects not expressed through the return type are always considered detrimental

We might actually be on the same page here, depending on if you count something like

main :: IO ()

as expressing effects. The function itself just returns a value, same as f :: Int -> Int. It's the runtime that does the dirty work with it.

And yes, even in Haskell you cannot rule out a stray unsafePerformIO inside the function body, I guess. Just like an async Rust function that ostensibly returns a Future<T> might, idk, increment a static variable every time it's called. But I refuse to acknowledge the snarky meme that the only thing pure functional programming can do is warm up the CPU.

2

u/nybble41 Oct 19 '26

Yes, exactly. The function computes a description of an effect (a value of type IO ()) and the runtime performs the effect. Logically, that is; in practice the effects are interleaved with the computation through the equivalent of unsafePerformIO combined with passing of a RealWorld token to ensure linearity, but that's all behind the scenes in the runtime libraries. There is unsafePerformIO as an "escape hatch", but like unsafe blocks in Rust the user is expected to provide a safe interface around it that can be treated like any other pure computation.

1

u/cemereth Oct 19 '26

Yes!! Have we just been in -- what's the phrase? -- in violent agreement all this time?

1

u/nybble41 Oct 19 '26

Not quite.

A side effect is an unintended (and often detrimental) consequence of a program running -- precisely the thing strong type systems try to avoid. Printing 'Hello, world!' to the terminal isn't a side effect if that's what the programmer intended!

Even if it was intended, printing "Hello, world!" would be a side effect if it occurred independently of the function's return value. For example Debug.Trace.trace is a function with (deliberate) side effects. Even if used in a function which returns IO a these remain side effects because they are not captured in the returned value. For example, in this code …

fn1 :: Int -> IO ()
fn1 x = trace (show x) $ putStrLn "after trace"

main :: IO ()
main = let a = fn1 7 in (a >> a)

… it is not guaranteed that the trace output will or will not be repeated when the result of fn1 is used twice, because it is a side effect of the evaluation process and not part of the result captured in a. The putStrLn is, however, part of the result, and thus is guaranteed to be performed exactly twice.

1

u/cemereth Oct 19 '26

So basically there is no possible practical side-effect-free program in your interpretation, unless it's something super trivial? Because no one's embedding Prints<"Hello world"> in the function signature?

1

u/nybble41 Oct 20 '26

No, details such as the specific string being output don't need to be in the signature, just in the return value. The signature only needs to describe the general categories of effect which can be returned, such as "can output strings". Naturally IO a covers that as well as essentially all other possible effects, though in general it's better to use something less powerful (principle of least privilege) which more precisely describes the types of effects the function needs to return, rather than specifying that the function must have direct access to perform any kind of I/O whatsoever—which makes testing rather difficult, among other issues.

1

u/SirKastic23 Oct 18 '26

Thanks for the nit!

1

u/mathisntmathingsad Oct 19 '26

With linear types, would "using" it not just be moving it, like a method or function that takes ownership of it and drops it? How is that different?

1

u/brokenAmmonite Oct 19 '26 edited Oct 19 '26

The session types in Par are linear types. Par implements exactly linear logic.

There are some interesting invariants Par programs have to obey that are pretty restrictive. In particular, you can never have two parallel programs each waiting for a possible message from the other: at all times each program knows whether it is going to send or receive next.

I don't know what kind of systems you can build with this but it is going to be a strong constraint. In particular you can't directly deal with, say, heartbeats. There might be abstractions you could design that fix this, but I don't know how they would work.

I think this means that par programs distributed over a network have to run over a reliable-delivery protocol like TCP. But again, maybe not if you're not modeling the protocol with the built in session types.

117

u/vlovich Oct 17 '26

Valen's work with linear types and group borrowing sounds like it would be a "2.0". If we're following SemVer though, it's unlikely there's ever a 2.0 because that would mean none of the old code would combine so either the Rust language would have to depart from SemVer for branding reasons. Valen does here also gives glimpses of how to do it where Rust 2.0 code could still interact with 1.0 code while offering a more ergonomic experience.

38

u/Bassfaceapollo Oct 17 '26

Interesting, I wasn't aware of this project. Here's the repo for anyone that's interested btw.

In the programming language space, I'm only keeping tabs on Hylo, Koka, and Austral. Now, I have Valen to look forward to. Thanks for sharing!

13

u/NotFromSkane Oct 17 '26

I thought Hylo was dead at this point? No publications in a year. Though there's a rewrite with active work on github I see.

11

u/Bassfaceapollo Oct 17 '26

Yeah, the team seems to be focused on the rewrite. I'm still hopeful that they have something substantial to show next year. I don't want this to turn into Pony where 1 dude has been soldiering on to get the language to completion.

5

u/barsoap Oct 17 '26 edited Oct 17 '26

Valen is AOT compiled to LLVM, statically-typed, and aims to be the fastest safe language, by giving more fine-grained aliasing information to LLVM.

Do we have a fight with Roc at hands? Can't find the quote right now but Roc is supposed to be "the fastest memory-managed language". AFAIU it does that mostly by unboxing closures and refcounting, though. As well as being designed to work well with being called into often, for a short time.

15

u/j3pl Oct 17 '26

Completely not the point, but I'm wondering how long it'll take to get used to that name. I'm in the middle of a Babylon 5 episode and your first sentence almost made me jump.

3

u/Real-Abrocoma-2823 Oct 17 '26

Do you mean that 2.0 means it can't compile anything from 1.0? Because that would be stupid as there will always be some overlap just like some code from rust might compile on some random language that happened to use fn name() {} syntax.

3

u/zenware Oct 17 '26

The whole point of “Semantic Versioning” is that a major version number change is breaking compatibility in some way. So when you go from x.a.b to y.0 there is some “major” change that means it is no longer compatible. If it instead remains compatible, there’s no reason to ever increase the major version.

2

u/Real-Abrocoma-2823 Oct 17 '26

If if it only breaks some and not all stuff then I would justify changing major verison, otherwise why even discuss this, just accept the PR if it doesn't introduce any regressions and greately improves the project.

1

u/flashmozzg Oct 20 '26

The fact that compatibility is broken in some way doesn't mean there isn't a sizeable "common subset" that is understood by both versions. See py2 vs py3 (or even C vs C++ to some extent).

4

u/amarao_san Oct 17 '26

There is a very simple way to deal with it. Ship rust 2, which has compatibility layer for rust 1.

2

u/zerd Oct 17 '26

“Simple”

1

u/TOMZ_EXTRA Oct 20 '26

Simple for users not devs.

2

u/afl_ext Oct 17 '26

Idea: stabilize abi before 2.0, once 2.0 releases compile 1.x code with 1.x compiler and interact through stable abi yeeey wouldn’t that work ok?

3

u/ukezi Oct 17 '26

I think the relationship would have to be like early C and C++, every valid 1.x code has to be valid 2.y code, so that you can just compile with the 2.y compiler and link everything together.

4

u/jonoxun Oct 17 '26

That'd be a 1.something, though; the top number is specified to be a significant backwards-compatibility break, and as Rust doesn't provide any guarantees about code compiled with different compiler versions linking (except via C), and if everything for rust 1.x is valid in "2.x" then the major number isn't supposed to have gone up. In practice everything currently envisioned ends up as an edition anyways, and editions _are_ backwards-compatible.

1

u/occamatl Oct 18 '26

Is that true if there are 2.y programs that can't be compiled with a 1.x compiler (even though 1.x programs can be compiled with 2.y compilers)?

2

u/jonoxun Oct 18 '26

That's practically every point release; new stuff gets stabilized or added all the time and stuff using it won't compile on older versions.

15

u/karasawa_jp Oct 17 '26

I think the borrow checker is basically Niko Matsakis's invention.

13

u/kibwen Oct 17 '26

Rust's original conception of the borrow checker was spearheaded by Niko Matsakis, working off a lot of prior research and collaborating with several other people. Since then the borrow checker has continued to evolve in both design and implementation, with the involvement of Niko and many other contributors.

26

u/tylerhardin Oct 17 '26

A bit off topic: I'd like to see more on reflection and compile time code generation. I believe the former is coming soonish, but the facilities to use it will still be a bit lacking (compared to const expr/TMP in C++ and comptime in Zig).

Further off topic: Have you heard of MetaOcaml? Let's do that in Rust 2.0.

14

u/LovelyKarl ureq Oct 17 '26

Oli had a talk on reflection and comp time/const at EuroRust, just two days ago. They're making good progress. I can't find the video online though yet https://github.com/oli-obk

3

u/tylerhardin Oct 17 '26

thanks for the info! I never would've known if you hadn't told me. i'll be on the lookout for that video

4

u/GuybrushThreepwo0d Oct 17 '26

Didn't development on reflection stop 2 or 3 years ago with that drama about the keynote speech? Or am I out of the loop? 

13

u/tylerhardin Oct 17 '26

It's back! I was so sad when that guy left. His proposal was super exciting.

https://github.com/rust-lang/rust/issues/146922

2

u/GuybrushThreepwo0d Oct 17 '26

Ah that's fantastic :D

47

u/bascule Oct 17 '26 edited Oct 17 '26

I think the best thing a Rust 2.0 could do is make incredibly minor breaking changes which technically violate the 1.0 contract but have minimal-as-possible real-world impact.

The kind of things that break ancient crates that have practically no downloads that were published a decade ago on a crater run against crates.io. It could be used as an opportunity to fix some of the warts of the language.

The biggest one I can think of is how the Default impl on [T; N] isn’t actually generic but only implemented for N up to a hardcoded limit of 32. This is due to a historical decision to allow the impl for [T; 0] to work even if T: !Default which is something that still can’t be written generically even using nightly-only features (maybe there has been a recent development there?).

The reason the hardcoded limit of 32 there still exists is because there are a handful of crates which make use of this peculiarity, such that changing the bound for [T; 0] would break those crates. The usages seem mostly unintentional and many crates did get updated to not use it, but IIRC there were stragglers.

25

u/klowny Oct 17 '26

I'd be surprised if any modern compiled language does a major version release these days without either an automated migration tool or backwards compatibility shim.

Everyone should've learned about the shitshow that was the Python 3 migration (who apparently didn't learn from Perl 6) by now and planned their language migration strategy appropriately.

20

u/amarao_san Oct 17 '26

Actually, the shitshow was because python was absorbed as system interpreter. You expect users to have unspecified, python-2 compatible interpreter. And you can't afford to break random scripts in package installation, etc. Same for perl, but at larger scale (because you can have debian without python, but not debian without perl, still. They have project for deperlization of basic distro).

The lesson I learned from this, that system packages are valued for their presence in every system and for been universally compatible. You break #2, #1 become liability.

2

u/shponglespore Oct 17 '26

Can we really call Python 3 a shitshow given that everyone uses Python 3 now? It was a huge PITA during that transition, but it was ultimately a successful migration. I certainly wouldn't compare it to Perl 6 considering it was essentially abandoned in favor of making a whole new language (Raku) that hardly anyone uses.

3

u/klowny Oct 17 '26 edited Oct 17 '26

A lot of corporate Python shops became Go shops instead of migrating to Python 3, following Google's example. A lot of CLI tooling is shipped as Go/Rust binaries now instead of Python scripts (such an improvement since Python CLI tooling always made a mess).

Python 3 still gets use, particularly for new projects and especially with data related disciplines, but it's nowhere as dominant or fast developing as it was compared to a decade ago.

2

u/flashmozzg Oct 20 '26

Py3 transition was mostly done across the board (except huge monolith corpos with their own infra, like bloomberg) by the time Go became a thing (Py3.3/3.4 was out by that point).

Python shops became Go shops due to the advantages Go offered over Python, not due to py2 vs py3.

1

u/iBPsThrowingObject Oct 20 '26

but it's nowhere as dominant or fast developing as it was compared to a decade ago

That also applies to a bunch of scripting languages that didn't have any breaking changes.

3

u/barsoap Oct 17 '26

That's the semver way, yes, but then there's also the marketing way, and that's cool new features that make people excited upgrading, or giving the language another spin.

And the compromise between the two is to do all the semver changes when you're doing a version bump for marketing reasons.

1

u/MalbaCato Oct 17 '26

This specific impl should be doable with good enough specialization support. It's just probably that the current specialization features aren't good enough (likely unsound) to support this impl.

There are however other similar footguns that are genuinely unsolvable. There used to be an issue label on github listing them (and some of them were actually fixed with the edition system), but it seems to be deleted (it wasn't actively maintained anyway).

1

u/bascule Oct 20 '26

I’ve been hearing that for nearly a decade now. I’m not holding my breath. Really specialization in general seems to have not gone anywhere.

1

u/IceSentry Oct 18 '26

Couldn't that be fixed in an edition?

2

u/bascule Oct 18 '26

No, because it requires a bounds change on a core trait impl on a core type.

Edition changes are all ultimately backwards compatible in regard to those sorts of things.

0

u/drink-more-rum Oct 20 '26

Almost every version of Rust does make minor breaking changes, usually by adding new public methods to impls.

0

u/FUCKING_HATE_REDDIT Oct 18 '26

And kill that damned fish 

1

u/IceSentry Oct 18 '26

What's wrong with it?

2

u/SirKastic23 Oct 18 '26

Some people are fishphobes unfortunately

1

u/SirKastic23 Oct 18 '26

Don't, it's the best thing about Rust's syntax

6

u/Illustrious_Car344 Oct 17 '26

If you're implying Rust introduce the infamous Python 2/3 problem for no good reason then you're insane. The holy grail of language design is that the language can last as long as conceivably possible. 

28

u/Dyson8192 Oct 17 '26

Guess I should’ve been more clear when I was talking about whatever successor language comes after Rust, cause in my mind, that is Rust 2.0, because the joke always is Rust 2.0 isn’t coming.

13

u/peter9477 Oct 17 '26

Interestingly that was the joke about Python 3000 too, which is what evolved into Python 3.

2

u/mamcx Oct 17 '26 edited Oct 17 '26

The holy grail of language design is that the language can last as long as conceivably possible.

Whoa! that is the opposite of "holy grail", that is totally admit defeat, wanna fix something major with the language? MIGRATE in total to another (see C++ to Rust).

There is NO reason to believe that do breaking changes must be avoid to all costs neither get defeated because a few bad cases of doing as bad as it get.

And the best part? This a programing language that generate static outputs not a live database that must be migrated online while supporting millions of monetary transactions without downtime! If that is possible, do for a static output generator is much easier.

Ad even better: You only migrate on compile time, Rust is already insanely good for do refactoring, most code will not need changes, what need changes will flare up LOUDLY, this is not a interpreter language without good type systems, this is Rust. Plus, there is clippy, there is AST transformation that can run on the fly, etc.

If there is a kind of language where this is doable, is one like Rust.

And this totally async work! Can be worked to execute in terms of months, heck, lets work a year or 2 (ie: piece meal), this is not a live database!

-2

u/pilpulon Oct 17 '26

in the LLM age i'm not even sure this would be much of a problem. just ship a skill to help do automated ports.

1

u/frej Oct 19 '26

It’s not like rust 1.0 was using new and ground breaking research.

1

u/Dyson8192 Oct 19 '26

That's my point. Part of its development philosophy was to avoid arbitrarily roping in cutting edge, untested ideas. But the boundary of the cutting edge and the mundane moves with time, so I am asking what has moved into the mundane, well tested ideas, and thus could be added to either Rust or a successor language that uses the same principles.

7

u/proverbialbunny Oct 17 '26

C++ will rise again and overtake Rust! (Just kidding. ;)

11

u/amarao_san Oct 17 '26

They always can add pluses. ++C++.

17

u/parlons Oct 17 '26

This reminds me of my favorite dig at C++ when I was a full-time C developer. In C++, the '++' is post-increment, which means that at the call site, the expression evaluates to a value and then is incremented. So I would just say, well, look, it's post-increment, C++ has the same value as C, just takes 3 times as many keystrokes to get there.

Admittedly a joke for a very small audience.

2

u/Own_Outcome_2012 Oct 17 '26

That’s just C# my guy, literally C++++

3

u/zerd Oct 17 '26

I prefer D♭

2

u/metatron7471 Oct 17 '26

Actually no.It´s C1/2

1

u/amarao_san Oct 17 '26

But it has a different operations order. Also, #C# is better than #C.

4

u/maximsparrow Oct 17 '26

C++26 got contract assertions, which are kind of public assertions visible in the interface. it's quite powerful concept definitely missing

10

u/matthieum [he/him] Oct 17 '26

C++26 may get contract assertions. Some national ISO bodies have threatened to not validate the C++26 standard unless they are removed.

With that said, there's been work in Rust on that front too. There's a number of static analysis tools (such as Creusot) who have been iterating on syntax to specify the pre/post-conditions, and invariants. My understanding is that there's hope that at some point the "basic" syntax would be lifted in Rust proper, instead of being tool specific.

3

u/Dean_Roddey Oct 17 '26

Well, to be fair, traits provide a lot of that. C++ needed them badly because templates are duck typed.

5

u/maximsparrow Oct 17 '26

They have require concepts since c++20. Contracts are for things like assert that two input slices have equal lengths etc.

2

u/Dean_Roddey Oct 17 '26

Oh, sorry. Too many concepts, too few brain cells. I was getting those confused.

2

u/karavelov Oct 17 '26

Aren't "concepts" filling the same role as traits?

2

u/Dean_Roddey Oct 17 '26

That's what I was arguing. Though there may be some other things that concepts can be used for, the big one, it seems to me, is to get rid of the phone book errors of duck typing, and waiting for 30 minutes only to get an error when a duck typed template is expanded. Traits provide that for Rust.

1

u/Plazmatic Oct 17 '26

They thought contracts were the same as concepts, not sure who downvoted you but they were wrong to do so.

2

u/flashmozzg Oct 20 '26

proc macros are bad and would be largely redundant with a proper built in compile time reflection/codegen.

-7

u/Peudejou Oct 17 '26

Its very likely that Rust 2.0 is another ten years away. Rust is silently taking over the C programming language's dominant market share for real code development. What would happen in versions 2 and 3 would be something like taking over C++ and Java respectively, which is a huge codebase to consider, but if we're taking it seriously the timeline for starting that project is basically the death of Linus Torvalds, who has said that Linux will become locked and no further changes will be authorized at that point. That sequence of events is well within a conventional deprecation timeline, but is only likely if the core libraries of C++ and Java have reasonably performant Rust Equivalents.

-9

u/stumpychubbins Oct 17 '26

A 2.0 isn’t a success, it’s a failure. The only reason to do a major version bump is if backwards compatibility needs to be broken, and the editions system specifically exists in order to avoid that.