Evan Ovadia在Hacker News上介绍了Valen编程语言的创新借用检查设计1。这一方案基于Nick Smith的群组借用提案,旨在改进内存安全检查机制1。
与Rust的借用检查器相比,Valen的新型检查器在保证内存安全的同时提供了更大的灵活性1。该检查器放松了Rust所坚持的「共享异或可变」限制,转而聚焦于消除「使用后释放」错误1。核心区别在于,Valen允许多个可读写引用同时指向同一对象,这些引用都可以通过任意一个对该对象进行修改1。
检查器的运作基础是为每个对象赋予唯一的「路径」描述,如world.entities,编译器通过追踪这些对象路径在编译时检测潜在的内存安全问题1。这种设计相比Rust提供了更简洁的API,开发者无需重复获取引用,而是可以直接使用func step(world &World, entity in world.entities[] mut)这样的函数签名1。
Valen还支持通过通配符后代路径(如in self.gem...)与Rust代码实现互操作1。后续文章将讨论引用计数与生成式引用的融合方案1。
Evan Ovadia has introduced a novel flexible borrow checker for the Valen programming language, designed based on Nick Smith's group borrowing proposal 1. This new approach aims to address memory safety while offering greater flexibility than Rust's traditional borrow checking model 1.
The group borrowing model relaxes the "shared XOR mutable" constraint that characterizes Rust, instead focusing specifically on preventing use-after-free errors 1. Unlike Rust's strict rules, Valen's borrow checker permits multiple read-write references to point to the same object simultaneously, with any of these references able to modify the object 1. The compiler enforces safety by tracking object paths—unique descriptors such as world.entities—to detect memory safety violations at compile time 1. This approach eliminates the need for repeated reference acquisition that Rust often requires, enabling cleaner APIs; for example, Valen allows functions like func step(world &World, entity in world.entities[] mut) without the boilerplate common in Rust 1.
Valen further supports interoperability with Rust code through wildcard descendant paths, such as in self.gem... 1. Ovadia has indicated plans to explore the integration of reference counting and generational references in future discussions 1.
评论
还没有评论,欢迎留下第一条。