JavaScript 正则表达式语义的 Coq 机械化
A Coq Mechanization of JavaScript Regular Expression Semantics
AI总结:
本文提出首个在交互式定理证明器中忠实机械化的 JavaScript 正则表达式语义的 Coq 实现,证明了其终止性与安全性,并验证了优化与边界情况,最终生成通过官方 Test262 测试套件的可执行引擎。
摘要:
我们提出了一种可执行、经过安全性验证、忠实且面向未来的 JavaScript 正则表达式(regex)匹配的 Coq 机械化实现,其规范遵循最新发布的 ECMA-262 第 22.2 节。据我们所知,这是首次在交互式定理证明器中对工业级正则表达式语言进行忠实机械化。我们强调了在此过程中出现的有趣挑战(包括编码问题、边界情况和可执行性问题),并记录了我们为确保结果易于审计,以及我们对规范的理解与现有实现保持一致所采取的步骤。我们通过广泛的分析、案例研究和实验展示了该机械化实现的可用性和多功能性:我们证明了 JavaScript 正则表达式匹配总是终止且是安全的(无断言失败);我们识别出导致先前出版物出现错误的微妙边界情况;我们验证了从最先进的正则表达式引擎中提取的优化;我们表明自动机教科书中描述并用于基于导数的匹配器中的某些经典属性在 JavaScript 正则表达式中不成立;我们证明更新该机械化实现以适应原始规范变更的成本相当低。我们的机械化实现可提取至 OCaml 和 JavaScript,并与 Unicode 库链接以生成可执行的正则表达式引擎,该引擎通过了官方 Test262 一致性测试套件的相关部分。
英文摘要:
We present an executable, proven-safe, faithful, and future-proof Coq mechanization of JavaScript regular expression (regex) matching, as specified by the latest published edition of ECMA-262 section 22.2. This is, to our knowledge, the first time that an industrial-strength regex language has been faithfully mechanized in an interactive theorem prover. We highlight interesting challenges that arose in the process (including issues of encoding, corner cases, and executability), and we document the steps that we took to ensure that the result is straightforwardly auditable and that our understanding of the specification aligns with existing implementations. We demonstrate the usability and versatility of the mechanization through a broad collection of analyses, case studies, and experiments: we prove that JavaScript regex matching always terminates and is safe (no assertion failures); we identify subtle corner cases that led to mistakes in previous publications; we verify an optimization extracted from a state-of-the-art regex engine; we show that some classic properties described in automata textbooks and used in derivatives-based matchers do not hold in JavaScript regexes; and we demonstrate that the cost of updating the mechanization to account for changes in the original specification is reasonably low. Our mechanization can be extracted to OCaml and JavaScript and linked with Unicode libraries to produce an executable regex engine that passes the relevant parts of the official Test262 conformance test suite.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。