围绕编程语言的内存安全实现方式,技术社区正在进行讨论。争议的焦点涉及Rust语言的安全性评价,以及Fil-C、Zig等替代方案提出的不同技术路线。
根据实践数据,Rust在内存安全方面的表现明显优于传统语言。Android平台中约500万行Rust代码仅发现1个潜在内存安全漏洞,漏洞密度为0.2/百万行[1],而C和C++的历史数据显示内存安全漏洞密度接近1000/百万行[1],这意味着Rust相比C/C++的内存安全漏洞风险降低超过1000倍[1]。然而,Fil-C的作者在社交媒体上声称Rust是内存不安全的语言[1],Zig作者Andrew Kelley也提议引入"真正内存安全"的编译模式[1]。
不同的技术方案各有权衡。Fil-C虽然提供了更严格的内存安全保证,但存在ABI不兼容问题,可能导致性能下降数倍,并引入了垃圾回收机制[1]。这表明在追求内存安全保证与实际工程需求之间,技术社区对最优方案仍存在分歧。
A heated debate has emerged within the programming community regarding the most effective approaches to memory safety, centered on contrasting technical philosophies between Rust and alternative languages.[1]
Rust has demonstrated substantially better memory safety outcomes compared to traditional languages in real-world deployments.[1] Android's codebase contains approximately 5 million lines of Rust code with only one identified potential memory safety vulnerability, yielding a vulnerability density of 0.2 per million lines.[1] This represents a dramatic improvement over historical data from C and C++, which show memory safety vulnerability densities approaching 1,000 per million lines.[1] Consequently, Rust exhibits a memory safety risk reduction exceeding 1,000 times compared to C and C++.[1]
However, critics have challenged Rust's safety credentials. The author of Fil-C has claimed on Twitter that Rust is an unsafe language,[1] while Zig's creator Andrew Kelley has proposed introducing a "truly memory safe" compilation mode, implicitly suggesting that Rust falls short of absolute safety guarantees.[1] Fil-C offers stricter memory safety assurances than Rust by design, though this approach involves significant trade-offs.[1] Compatibility between Fil-C and non-Fil-C compiled programs is not maintained at the binary level, potential performance degradation of multiple times may occur, and the approach introduces garbage collection mechanisms.[1] These constraints reflect the broader tension between maximizing safety guarantees and maintaining practical considerations such as performance and interoperability.