(评论)
(comments)
原始链接: https://news.ycombinator.com/item?id=40375341
您正确地观察到,在“Mutex”内使用“RefCell”没有多大意义,因为“Mutex”已经为锁定区域提供了互斥性。 当需要对共享和借用进行更细粒度的控制时,通常使用“RefCell”,并且在该粒度级别上没有强烈的同步必要性。 相反,“互斥体”可以被视为管理跨多个线程的资源共享的粗粒度方法。
然而,重要的是要记住,您提供的数字代表您个人使用统计数据的快照,它不一定反映 Rust 生态系统甚至您的特定项目内的更广泛趋势。 这些数字受到您分析的特定代码库的影响,并且它们并没有描绘出 Rust 开发人员如何选择使用这些功能的整体情况。 此外,值得注意的是,这些构造的相对频率并不自动意味着它们对使用 Rust 构建的软件的错误率或整体质量的影响。 此外,重要的是要认识到不安全代码的存在或“RefCell”的使用并不意味着该软件是错误的或必然会引入错误; 它仅表明如果不小心处理可能存在的风险。
最后,观察您提到的两个功能(“不安全”代码和“RefCell”)之间的频率差异很有趣。 尽管“RefCell”实例数量较少,但它往往会带来更大的感知风险,这可能是由于其更细致的行为和谨慎处理的要求。 尽管如此,这两个功能都不应该绝对避免或忽视,因为它们在 Rust 生态系统中都有有价值的用途,并且可以满足不同的编码场景。
Having worked on program verification in the past, Rust looks like the most useful modern language to which formal methods can be applied. Rust's rules eliminate so many of the cases that are hard to formalize.
Big remaining problems involve deadlock analysis, both in the thread sense and in the Rc/borrow sense. Those are somewhat equivalent. I'd like to have static deadlock analysis in Rust. If you had that, I think you could get safe back-pointers, too. If you can prove that all borrow and upgrade calls can't fail, you can eliminate most reference counts. That gives you free interior mutability when that's possible.
The author's comment on provers is interesting. The big problem with theorem provers is that they're developed by people who like to prove theorems. They're in love with the formalism. This leads to a UI disconnect with programmers.
You can knock off most things you have to prove with a SAT solver. But you'll need something heavier for the hard problems. Coq is too manual. The author thinks ACL2 is too functional. Not sure what to do there, but I've been out of this for decades.
Machine learning may help in guiding theorem provers. Most programs aren't that original in terms of control flow and data usage. So inferring a proof plan from other code may work. ML systems can't be trusted to do the proof, but may take over guiding the process.