r/ProgrammingLanguages • u/Lauel • 11h ago
Discussion I am working on a C-targeted systems programming language, with prover and checker at the heart
Note: English isn't my native language. Please pardon mistakes.
I love C, Rust, Zig and Go, and I love what they bring to the table. But majority of languages give you a choice: eat the cake or have it. I started thinking from a new end, what if we can eat the cake and have it too?
I will be sharing some ideas with some code from my language.
First, post conditions exist without introducing a separate spec language:
In such cases compiler throws an error: 'broken' breaks its promised return/exit rule.
Second, range rules can work along with types:
type Percent = int in 0..=100
..=hi
With this compiler gets the ability to optimize even further.
Third, there are no lifetimes and graphs can't leak because the compiler statically rejects strong ref cycles, so you break them with weak:
// Example code only
Fourth, you can keep the allocator local to a block where YOU care about it. Many code issues can be avoided this way, since compiler stops dangling pointers automatically. Anything allocated inside the with Alloc(arena) block can't escape it, so the compiler explicitly rejects returning or assigning directly to an outer variable, unless you explicitly copy:
use std.mem
Fifth, inferred error for private functions, explicitness and transparency for public functions. ? does the heavy job of lifting and wraps automatically:
Adding to this are a heavy prover which is a Z3 searching for proofs and a tiny checker which verifies them before any runtime check gets removed, which are still being fleshed out. To my realization they are the toughest, and the most important piece of work here.
Please share your opinion on the work so far, and what questions or criticisms do you have in this regard?
5
u/alphaglosined 10h ago
Putting pre and post conditions inside the body indeed doesn't matter vs at the signature during that functions analysis. Of course there is no way to know what is a pre and post condition if you do this (which can be fine).
But that isn't the only scenario where you must analyze it, consider what happens to functions without bodies or when you're looking at the documentation.
2
u/srednaby 7h ago
Reminds me of the Monad language, which I am working on. Sigma types and propositions are the way these kind of proofs and properties are named / encoded usually in languages like Lean, Agda, Idris or Monad.
1
u/Lauel 11h ago edited 10h ago
I am sorry I forgot to share dependency permissions and the idea of manifests. There are no build scripts, and third party dependencies only get the OS access you explicitly allow in `package.toml`, checked at compile time. Please note this is my idea, I have not yet fleshed even this too. I placed my dreams, visions and desires before even seeing whether something like this can be built, because even if it doesn't an attempt was just as beautiful to me.
Cherry picking aside, the language has a lot of issues to tackle, which are to some extent much harder than I expected:
1
u/Diffidente 9h ago
Do you have a Github link ?
1
u/gremolata 8h ago
Can you reformat code samples using 4-space indent? Triple backticks don't render correctly on old.reddit.com.