The simplicity of Python and the power of C++ force stark choices on a scientific software stack. There have been multiple developments to mitigate language boundaries by implementing language bindings, but the impedance mismatch between the static nature of C++ and the dynamic one of Python hinders their implementation; examples include the use of user-defined Python types with templated C++ and advanced memory management. The development of the C++ interpreter Cling has changed the way we can think of language bindings as it provides an incremental compilation infrastructure available at runtime. That is, Python can interrogate C++ on demand, and bindings can be lazily constructed at runtime. This automatic binding provision requires no direct support from library authors and offers better performance than alternative solutions, such as PyBind11. ROOT pioneered this approach with PyROOT, which was later enhanced with its successor, cppyy. However, until now, cppyy relied on the reflection layer of ROOT, which is limited in terms of provided features and performance. This paper presents the next step for language interoperability with cppyy, enabling research into uniform cross-language execution environments and boosting optimization opportunities across language boundaries. We illustrate the use of advanced C++ in Numba-accelerated Python through cppyy. We outline a path forward for re-engineering parts of cppyy to use upstream LLVM components to improve performance and sustainability. We demonstrate cppyy purely based on a C++ reflection library, InterOp, which offers interoperability primitives based on Cling and Clang-Repl.
翻译:Python的简洁性与C++的强大能力迫使科学软件栈做出明确选择。为缓解语言界限,已有多种实现语言绑定的开发方案,但C++的静态特性与Python的动态特性之间的阻抗不匹配阻碍了其实施——例如在模板化C++中使用用户自定义Python类型以及高级内存管理。C++解释器Cling的发展改变了我们对语言绑定的思考方式,因为它提供了运行时可用的增量编译基础设施。这意味着Python可以按需查询C++,绑定可在运行时惰性构建。这种自动绑定机制无需库作者直接支持,且比PyBind11等替代方案具有更优性能。ROOT率先采用此方法实现PyROOT,后续由cppyy强化。然而,此前cppyy依赖ROOT的反射层,该层在功能特性和性能方面存在局限。本文提出cppyy语言互操作的下一步发展方向,支持统一跨语言执行环境研究并提升跨语言边界优化机会。我们演示了通过cppyy在Numba加速Python中使用高级C++的方法,勾勒了重构cppyy部分模块以利用上游LLVM组件提升性能与可持续性的路线图。最终展示了完全基于C++反射库InterOp(提供基于Cling和Clang-Repl的互操作原语)的cppyy实现。