6 ms·
> It is more "correct" because, while perhaps not providing some of the other benefits, those tools can prove more properties than the Rust type system can Suc
by lmm 10y ago
> It is more "correct" because, while perhaps not providing some of the other benefits, those tools can prove more properties than the Rust type system can
Such as? And in that case, why not lift them into a language type system?
When working on code where particular properties are verified, it's very useful if all the tools share a common understanding of those properties. If you write something in Rust, your IDE will understand the types (and make sure to preserve them when doing automated refactoring), your debugger will know which preconditions were supposed to be semantically impossible, and so on. Last time I looked at external verification tools for C-like languages you often ended up having to explain the same fact twice to two different verification tools with overlapping featuresets, yet alone getting any help from other tools. If we're going to reach critical mass on safety tooling, it will have to be via a commonly understood specification that's a de facto language definition.
So given we're creating a new safe language, what parts of C would we actually want to keep? The lengthy operator precedence table? The preprocessor, and the absence of any module system? The extensive array of language-level operators for doing a wide variety of arcane bit-twiddling operations? The signed/unsigned arithmetic promotion rules that even experts misread? The implicit conversions between arrays and pointers? The lack of any sum (tagged union) type? The for loop that makes arithmetic - or, indeed, arbitrary code - first class, and iterating over an array or other collection something you hand-code every time?
Even if it were as safe as Rust, C would still be harder to read, and harder to write as well. We can and should do better than C.
- pron 10y ago> And in that case, why not lift them into a language type system? Easier said than done. First, lifting a new verification property into a type system requires changing the language or creating a new one, so it doesn't solve the problem (another rewrite?). Second, and more fundamentally, some properties cannot always be proven one way or another, but only admit sound classification as yes/no/maybe. Type systems don't usually work well with such properties. There's also the problem of how much of the specification power you want to include in the programming language. More on that below. > it's very useful if all the tools share a common understanding of those properties. Sure, but see my response to fpoling. > it will have to be via a commonly understood specification that's a de facto language definition. Some such standard or nearly-standard specification languages exist, e.g. JML for Java, and ACSL[1] (inspired JML and supported by frama-C) for C. > So given we're creating a new safe language Your new programming language can be whatever you like -- like Rust. The specification language -- for your new or legacy code -- can be rather orthogonal. Even Rust would require a formal specification language for greater correctness, as the language itself cannot specify many interesting properties. Whether, in terms of language design, it's better to unify the specification language and the programming language (as, say, Idris aims to do) or keep them separate is subject to a heated debate (dating all the way back to Dijkstra and Milner). Obviously, if the specification could be unified with the language without it having any negative effect, then that's something desirable; the problem is that many people believe that no such language (or even an idea for one) has been conceived of just yet. > Even if it were as safe as Rust, C would still be harder to read, and harder to write as well. We can and should do better than C. Oh, absolutely! I'm all in favor of using Rust over C! But that doesn't mean that rewriting existing code in C is worthwhile in terms of cost-benefit, if your goal is to increase correctness. [1]: http://frama-c.com/acsl.html http://frama-c.com/acsl.html
- catnaroek 10y ago> First, lifting a new verification property into a type system requires changing the language or creating a new one, so it doesn't solve the problem (another rewrite?). Much of the value in using type systems is that, precisely because they're limited, they force you to write programs whose proofs of correctness would be simpler than if you didn't follow a type discipline. This is true even if you use an external logic for reasoning about your program. In a language like Rust, I can often arrange things so that the burden of verification is split between type checking and simple high-school algebra calculations. What do I get in C? Gigantic yet intricate state spaces, which need to be split into subsets either manually or mechanically using who knows what heuristics. These subsets are in turn described by formulas containing lots of nested quantification, which is a lot more difficult for humans to deal with than just algebra. > Second, and more fundamentally, some properties cannot always be proven one way or another, but only admit sound classification as yes/no/maybe. Type systems don't usually work well with such properties. Type systems err on the side of safety: if no typing derivation can be constructed for your program, your program is wrong, even if your evaluation rules are untyped and your program wouldn't get stuck under them. > Even Rust would require a formal specification language for greater correctness This means nothing. Correctness is a binary question: your program is either right or wrong... > as the language itself cannot specify many interesting properties. ... regardless of whether you've mechanically verified it or not. > Whether, in terms of language design, it's better to unify the specification language and the programming language (as, say, Idris aims to do) or keep them separate is subject to a heated debate (dating all the way back to Dijkstra and Milner). It's ultimately a matter of ergonomics, and there's a big continuum in between “prove everything internally” and “prove everything externally”. Rust sits very comfortably at some point in the middle.
- pron 10y agoMy response to Imm was about something a little different from my original point, which is this: Rust is absolutely amazing; I love it! It is leaps and bounds better than C! Yet none of that makes rewriting every line of C out there in Rust the most cost-effective way of improving software quality.