TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Formally Verifying Rust's Opaque Types

133 点作者 BreakfastB0b将近 3 年前

15 条评论

stepchowfun将近 3 年前
It&#x27;s always a pleasant surprise to see people using Coq and other formal verification technology to build confidence in their ideas and algorithms. We need to stop producing buggy software! If this article gave you a thirst for interactive theorem proving and you want to learn it from the ground up, I&#x27;ve recently written a Coq tutorial [1] which covers topics like programming with dependent types, writing proofs as data, and extracting verified code. That repository also contains a handy tactic called `eMagic` [2] (a variant of another useful tactic called `magic`) which can automatically prove the theorem from the article.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;stepchowfun&#x2F;proofs&#x2F;tree&#x2F;main&#x2F;proofs&#x2F;Tutorial" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;stepchowfun&#x2F;proofs&#x2F;tree&#x2F;main&#x2F;proofs&#x2F;Tutor...</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;stepchowfun&#x2F;proofs&#x2F;blob&#x2F;56438c9752c414560cd55ed9b1e989947e99dcd6&#x2F;proofs&#x2F;Tactics.v#L81" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;stepchowfun&#x2F;proofs&#x2F;blob&#x2F;56438c9752c414560...</a>
评论 #32307864 未加载
homodeus将近 3 年前
A nice intro&#x2F;showcase to Coq, I suppose. But the triviality of this frankly makes it difficult for me to understand what value this has and what it teaches us - we&#x27;ve just proven that one kind of syntax is equivalent to another, because of an intuitionistic tautology. What I&#x27;d like to know is what it would mean for the rust type system if this <i>weren&#x27;t</i> true, and therefore, what is really the difference between rust opaque types and generics in function signatures other than syntactic, and their formulation?
yccs27将近 3 年前
As someone who&#x27;s used to functional programming but not familiar with any proof systems, I&#x27;ve sometimes applied Curry-Howard the other way and used Haskell as a primitive proof system by writing the corresponding function (being careful to avoid infinite recursion). GHC&#x27;s support for &quot;typed holes&quot; makes this pretty convenient - just write a part of the function and leave a hole (_) for the rest, GHC tells you what type is needed there.
agluszak将近 3 年前
The title is a bit misleading: you&#x27;re not formally verifying rust&#x27;s opaque types - you&#x27;re simply proving a intuitionistic logic proposition using Coq. There&#x27;s nothing Rust specific in that proof.
评论 #32306507 未加载
benreesman将近 3 年前
Fantastic article. For auditory learners like me, this is an iconic talk in the OG “Advanced Topics in Programming Languages” series that Google used to do: <a href="https:&#x2F;&#x2F;youtu.be&#x2F;h0OkptwfX4g" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;h0OkptwfX4g</a><p>It goes all the way from parametric polymorphism, up through Curry-Howard, and winds up at Girard-Reynolds. It was what got me passionate about type theory as a young lad.
yababa_y将近 3 年前
I love this walkthrough! It reproduces, in narrative form, the experience of interactive theorem proving. Great exploration of a niche detail.
评论 #32304702 未加载
PoignardAzur将近 3 年前
I&#x27;m having some trouble understanding the article&#x27;s formula; and honestly it&#x27;s a little weird to see people complain about how trivial the proof is.<p>Both this article and the article it quotes introduce the &quot;((∃ x. P(x)) → Q) ⇔ (∀ x. (P(x) → Q))&quot; formula with absolutely no additional explanation. I guess that&#x27;s fine if the article are <i>meant</i> for people with a mathematics background, but at someone who has always struggled with post-high-school-maths... what the hell?<p>I understand what ∃, ∀, ⇔, and → represent (&quot;there exists&quot;, &quot;for all&quot;, &quot;equivalent&quot; and &quot;implies&quot;, respectively), but I have no idea how to parse the entire formula. What are P and Q?<p>After multiple tries, I&#x27;m reading it as &quot;saying that &#x27;there exists a x such that P(x) is true&#x27; implies Q&quot; being equivalent to &quot;for all x, P(x) implies Q&quot;, with the idea that P and Q are arbitrary proposals or whatever the proper terms are... But still, just processing the logical reasoning in my head is tough.<p>On the other hand &quot;some types implement traits, and if a function expects a trait impl you can only pass it types that implement that trait&quot; feels absolutely clear to me. It might be that Rust is good at breaking down math concepts into the essentials you need for programming. Or it might be that formal Math notation is not for me.
评论 #32311039 未加载
评论 #32312211 未加载
评论 #32312647 未加载
评论 #32313946 未加载
mtlmtlmtlmtl将近 3 年前
I&#x27;ve been thinking for some time that one of the key advantages of Rust&#x27;s safe&#x2F;unsafe code will turn out to be that formal methods can be applied to the unsafe parts.<p>Safe Rust is truly safe if it only calls safe Rust or if all the unsafe code is correct.<p>And safe Rust is a little too inflexible to do certain things, so the unsafe word is a necessary evil. But turns out it&#x27;s not a bug, it&#x27;s a feature because now you can trivially identify which parts of the codebase require extra scrutiny to avoid memory corruption and data races.<p>With FM the main downside has always been the added cost and development time&#x2F;complexity, needing to use obscure academically oriented systems that most developers have no experience with, etc. But that complexity is probably okay for a project like the Rust standard library, which is already a highly complex project and will only be majorly worked on by a relatively small subset of Rust developers. So you could save some of that cost by only needing it in a (relatively) small part of the ecosystem.<p>Ofc I realise this wouldn&#x27;t give the same level of correctness as doing all code with FM. You could only verify whatever guarantees Rust provides for code with no unsafe codepaths. And proofs can have bugs too. But still I think it could increase safety a lot.
评论 #32312363 未加载
评论 #32314760 未加载
siraben将近 3 年前
The manual proof style was nice to see for pedagogical purposes, however it should be noted that the statement is just a intuitionistic tautology, so much so that the entire proof can be automated with the built-in firstorder tactic:<p><pre><code> Theorem impl_trait_transform: forall (Trait: Type -&gt; Prop) (Result: Prop), ((exists t, Trait(t)) -&gt; Result) &lt;-&gt; (forall t, (Trait(t) -&gt; Result)). Proof. firstorder. Qed.</code></pre>
Tainnor将近 3 年前
On a somewhat technical note, I think the author is being slightly imprecise, though in a way that will normally not trip up most people. The proof has to be understood either as a proof scheme in first order logic, in which case we <i>technically</i> need a separate proof for each possible choice of predicates P and Q, or we have to implicitly quantify over P and Q, i.e. &quot;for all P, for all Q&quot;, which leads us to second order logic, but in this case there is now a single proof (which is exactly what&#x27;s the case when we&#x27;re using Coq).<p>At least that&#x27;s the case in classical logic (which is enough to understand this article), I&#x27;m not knowledgeable enough about intuitionism to know whether it typically includes second-order quantification, but even in that it would probably be better to make the quantification explicit.
mirekrusin将近 3 年前
Michael Clarkson of &quot;OCaml Programming: Correct + Efficient + Beautiful&quot; [0] fame is currently publishing series of lectures &quot;Software Foundations in Coq&quot; [1] (new ones appearing once a week?) as a companion to [2] which looks as great as OCaml series.<p>[0] <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;playlist?list=PLre5AT9JnKShBOPeuiD9b-I4XROIJhkIU" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;playlist?list=PLre5AT9JnKShBOPeuiD9b...</a><p>[1] <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;playlist?list=PLre5AT9JnKShFK9l9HYzkZugkJSsXioFs" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;playlist?list=PLre5AT9JnKShFK9l9HYzk...</a><p>[2] <a href="https:&#x2F;&#x2F;clarksmr.github.io&#x2F;sf-lectures&#x2F;textbook&#x2F;lf&#x2F;Preface.html" rel="nofollow">https:&#x2F;&#x2F;clarksmr.github.io&#x2F;sf-lectures&#x2F;textbook&#x2F;lf&#x2F;Preface.h...</a>
Tainnor将近 3 年前
Just noting that the statement in question is not only a valid proposition in intuitionistic logic, but also in classical logic. That&#x27;s not really surprising, as classical logic can prove everything that intuitionism can prove, but it deserves to be called out, as it otherwise might seem more sophisticated than it is for people unfamiliar with the finer details of proof systems.
howling将近 3 年前
Personally, I find the title to be slightly misleading as the proof is essentially just (un)currying for dependently typed function.
评论 #32306537 未加载
kelnos将近 3 年前
Regardless of the verification bit (which I didn&#x27;t read, as it&#x27;s a bit over my head), this is probably the best explanation I&#x27;ve read about the difference between `imp Trait` and `dyn Trait`.
max_将近 3 年前
I have been contemplating on learning TLA+. Could someone experienced with formal verification let me know what I could be missing by not learning something like Coq?