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的cppyy,该反射库基于Cling和Clang-Repl提供了互操作原语。