"MiniRust is the cornerstone of my vision for a normative specification of Rust semantics. It is an idealized MIR-like language with the purpose of serving as a "core language" of Rust. This is part of a larger story whose goal is to precisely specify the operational behavior of Rust, i.e., the possible behaviors that a Rust program might have when being executed: the behavior of a Rust program is defined by first translating it to MiniRust (which is outside the scope of this repository), and then considering the possible behaviors of the MiniRust program as specified in this document. That translation does a lot of work; for example, traits and pattern matching are basically gone on the level of MiniRust. On the other hand, MiniRust is concerned a lot with details such as the exact evaluation order, data representations, and precisely what is and is not Undefined Behavior."
It is yet another step on the path to having a Rust specification, especially with respect to precisely specifying the capabilities and requirements of `unsafe` code.
Zig is also very compiler dependent, but at least the language has direct enough translation as a goal, that it's straightforward to learn the semantics from trial and error alone.
It wasn't standardized until 1989 - 17 years later!
I think Rust will do just fine, and the compiler error message is (IMO) the best of any language, making adhoc exploration possible.
Can you imagine trying to explore C from ad-hoc alone based on its compiler errors?!
It’s in many ways similar to the way the early web was developed, different browsers tried out many different additions, copied the better ones and improved them. The standardisation process we now have didn’t exist back then, and has been through a number of iterations itself since (the “xml every thing” process that ended with xhtml had a questionable outcome at best).
Some may argue that a formal standardisation process should have started earlier, before IE became too dominant. But I’m not too sure, IE was incredibly innovative and introduced some important technologies and apis, before stagnating.
In fact the “modern” html/css/js standardisation process is specifically lead by individual browsers implementing and trying out new additions, with formal acceptance dependent on other browsers also implementing it. It’s inherently a implementation lead standardisation process, not necessarily committee led.
Realistically, I think the most likely outcome if there's a formal standard is similar to C: You end up with one compiler that adds extensions to the standard language that are too useful to ignore, and then ~everyone copies them anyway. The most useful extensions are then standardized in the next version of said standard.
Meanwhile, some poor suckers will be working in We Must Follow The Standards hellscapes and will have to stick to the ISO version, and they'll be completely left behind by the community.
Rust has the goal of putting as much smartness between what you type and what the compiler produces, which is a perfectly fine goal, but without a specification for the input semantics it's a pretty wobbly thing, especially for a systems programming language. A lot of bit packing code is simply not writable in rust today without immediately invoking UB, that works for now but might break with every bugfix release.
I don't know about Zig, but as for C, this take is not just wrong, but dangerously wrong. The behavior of C code isn't defined by the underlying assembly, but by an abstract machine model that may or may not match your real machine (narrator: It doesn't). As a result, the compiler can and will ignore the intention of your code when it can prove that your code would invoke UB. Good example: signed integer arithmetic and overflow tests. It is very difficult to write overflow tests for signed integer operations without accidentally invoking UB, and modern compilers will simply remove your overflow tests instead of translating them 1:1 to assembly instructions.
If your compiler merely translates a source line into a series of assembly mnemonics, function calls, or interpreter gotos, then the interface is the implementation. You can rely on the underlying target language to provide your program with meaning and the only people who have to care are people reimplementing your compiler for compatibility.
The moment you start talking about optimization, then this no longer works. You no longer have a correspondence between source and compiled forms of one program. You have a many-to-many relationship where one source form can be compiled into hundreds of binaries depending on how the compiler is configured, and many source forms may actually optimize to the exact same compiled form. This requires you to provide your own semantics, else compiled programs have no meaning and -O3 becomes shorthand for "make demons fly out my nose".
In the case of C they came up with a series of rules for what-not-to-do that both did not match existing language semantics and also were dangerously incomplete. There are still C programmers who insist that you can free() memory but still touch it for a "little while"[0], or access memory "off the end" of an allocation[1], for example. And ISO C still made the mistake of retaining pointers, which are a confusing mix of value and reference type. They aren't references because you are allowed to cast them to and from integers; and they can't be values because you can use them to modify other values. Because of this tension, we keep discovering new combinations of valid transformations on valid programs that cause miscompiles, and then we have to invent things like pointer provenance to fix them.
As far as I'm concerned, the only difference between Rust and C is that Rust is honest about it's cleverness. C has to pretend to be simple while also out-clevering Rust (or at least, the safe subset of Rust).
[0] Usually in an attempt to emulate automatic memory management. Manual memory management does not work when passing complex structures across an API boundary, and the only options are to either expose custom deallocators (which means no optimizations even when they are sound), tell callers how to deallocate the data (which means no changing the data), or hack the allocator to do what you really want.
[1] It works for malware developers, it should work for me, right?
No it doesn't. "smartness" is a means, not an end or a goal.
At about the time K&R1 was published, the Ritchie's original C compiler was being replaced by pcc, and `lint` was another early (diagnostics-only) implementation. The K&R1 reference manual includes a few mentions of features that were deprecated by pcc, or new in pcc.
So I think C was more mature than "the compiler is the specification" by the end of the 1970s.
K&R is remarkable for fitting all that into one slim book, and Rust's documentation rightly doesn't try.
Rust's documentation also has some considerable advantages from its modernity. That library documentation gets to link to the actual source code which can answer tricky questions you'd never cover in a book, yet in many cases that source is very readable, its examples are something you can try for yourself with one click, instead of one of the very best human compiled indices of any book it has text search and hyperlinks.
> It wasn't standardized until 1989 - 17 years later!
> I think Rust will do just fine,
Not based on the example you gave - using the behaviour of a single C compiler as a specification for the language implemented by that fairly easy due to how small C is. Rust is very much larger than C.
> and the compiler error message is (IMO) the best of any language, making adhoc exploration possible.
> Can you imagine trying to explore C from ad-hoc alone based on its compiler errors?!
Not much different from Rust: Gcc and clang C compiler errors are exceptionally good, and I miss them terribly when programming in some other language (like C++, or Javascript).
I wish i still had my late 80s copy.
Not mainstream language 'fine', but fine.
But what is interesting I think is that if miniRust is successful (or even if it isn't) zig can learn lessons on how to do borrow checking on zir: even if it isn't part of the official language release it could be a useful tool for ci/linting/touchup, especially if it becomes an "anointed" tool
Is there any way to have Zig output a flat binary? I am looking for a higher level FlatAssembler. [0]
It's not "useful" in the sense of being something that you'd actually run.
This is a start on the lowest layer of the description, describing the "abstract machine" that runs Rust programs; it assumes that all borrow-checking and type-checking has already been done, generics have been expanded, and so on.
The other two big pieces that will need doing are properly describing the type system, and properly describing how the high-level features that aren't strictly necessary can be "lowered" into simpler forms.
In the last year there's been some real work on the first of those under the name "A MIR Formality": https://nikomatsakis.github.io/a-mir-formality/docs/intro
Maybe the existing Rust Reference will turn into the second.
What if we could actually run it (stay with me for a second) with a well known interpreter such as python3 or v8?
That is the direction py2many has taken. Trying to define a small subset of python + missing rust features (pattern matching as an expression), interfacing with formal verification methods such as z3 and then finally building a transpiler to transpile this language to rust.
- Testing the spec itself - Ensuring that a more production-grade interpreter like Miri has the same semantics as the spec it claims to implement
It's not intended that unsafe Rust authors would ever run the MiniRust interpreter; if they want something like that, they should run Miri instead. They might still read the MiniRust interpreter sources to figure out what the heck Miri is doing.
If you are writing a Rust compiler or a Rust verification tool, then a spec like MiniRust is a key part of telling you whether you got it right.
If you are not doing either of these things then you probably don't have a use-case for MiniRust. :)
lol, I didn't even realize the wrong associations I would create here. Glad you liked it anyway. :)
I guess my choice of name was not great. I also considered pseudo-MIR but that didn't really capture it, either. And "formally specified fragment of Rust" isn't very catchy.^^ "CoreRust", maybe it should have been "CoreRust"...
I'd personally pretty much always expect "mini" or "r" (as in "rperl", a restricted subset of Perl with C++ connections) versions of a language to be restricted subsets for some purpose (rperl's is to give away flexibility for performance while maintaining a good portion of the original language).
I've seen an "e" or "emb" prefix or a "small", "tiny", "micro" or "µ" (or "u") prefix to mean a small toolchain version several places, like SmallC or uclibc or Mikroe's mikroC (https://www.mikroe.com/mikroc). It wouldn't surprise me to see a "nano" version of a language tool either. Sometimes these are subsets as well, but to fit the size constraints of the target rather than for constraining the input for its own sake.
Programming in NQP is troublesome, but it is fast and it is self-hosting.
The two projects are related, but have different objectives (mir-formality includes traits and borrow checking, while MiniRust focuses on operational semantics).
Not only that the spec will be clearer but you can get more contributors on the core part of Rust.
Cool bear has breached containment.
I do have to admit I love the recent-ish trend of including dialogues in blog posts. Plato would be proud.
My only worry regarding Cool Bear is the licensing of the two pieces of artwork: I bought them a while ago on some stock image website but the terms weren't super clear, so I might need to revisit that. Since then I've commissioned drawings of bear and myself (5 variants each) but I haven't had a chance to use those yet — they're not monochrome, which makes dark mode awkward.
[1]: Living with the Rust trademark [LWN.net] https://lwn.net/Articles/901816/