基于推导彩色Petri网的安全Rust代码合成方法
A Synthesis Method of Safe Rust Code Based on Pushdown Colored Petri Nets
AI总结:
本文提出基于推导彩色Petri网的Rust代码合成方法,通过直接建模编译约束生成有效的调用序列,确保内存安全性和类型正确性。
摘要:
Safe Rust通过严格的编译时约束保证内存安全:所有权可转移,借用可临时保证共享只读或独占写入访问,所有权和借用由生命周期限定。自动合成正确且安全的Rust代码具有挑战性,因为生成的代码必须满足所有权、借用和生命周期约束,同时在编译时满足类型和接口要求。本文提出一种基于我们新定义的推导彩色Petri网(PCPN)的合成方法,从公共API签名直接建模这些编译约束以生成有效的调用序列。令牌颜色编码动态资源状态并结合指示借用有效生命周期区域的范围级别。推导栈通过推送和弹出令牌跟踪生命周期参数的进入或离开。只有在类型匹配和接口义务都满足且所需资源状态可用时,转换才被启用。基于双模拟理论,我们证明了PCPN的启用和触发规则与这三个约束的编译时检查一致。我们开发了基于PCPN的自动合成工具,实验结果表明生成的代码均正确。
英文摘要:
Safe Rust guarantees memory safety through strict compile-time constraints: ownership can be transferred, borrowing can temporarily guarantee either shared read-only or exclusive write access, and ownership and borrowing are scoped by lifetime. Automatically synthesizing correct and safe Rust code is challenging, as the generated code must not only satisfy ownership, borrowing, and lifetime constraints, but also meet type and interface requirements at compile time. This work proposes a synthesis method based on our newly defined Pushdown Colored Petri Net (PCPN) that models these compilation constraints directly from public API signatures to synthesize valid call sequences. Token colors encode dynamic resource states together with a scope level indicating the lifetime region in which a borrow is valid. The pushdown stack tracks the entering or leaving of lifetime parameter via pushing and popping tokens. A transition is enabled only when type matching and interface obligations both hold and the required resource states are available. Based on the bisimulation theory, we prove that the enabling and firing rules of PCPN are consistent with the compile-time check of these three constraints. We develop an automatic synthesis tool based on PCPN and the experimental results show that the synthesized codes are all correct.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。