Concrete proposal: Reusable API Glue code
Let's take a couple of example files and see what it would take to make them reusable and move them into the HPy repository for ANY interpreter host to build upon.
https://foss.heptapod.net/pypy/pypy/-/blob/branch/hpy/pypy/module/_hpy_unive...
According to my IDE, most of the imports in e.g. interp_list.py are not used.
Imagine that we replaced all of them with:
from interpreter_context.apiset import API, handles, pytypes
W_ListObject would be imported from pytypes.
As an interpreter host vendor, I'd just implement space, API, handles, pytypes and I could reuse interp_list as-is. The PyPy implementation of the "interpreter" package would just rename the modules from pypy.module. _hpy_universal
According to my IDE, these SAME imports would make interp_number and interp_tuple "just work" as well.
To implement interp_long, I need to inject a new dependency, called "typesystem" which is a generalization of rffi and lltype.
interp_builder and interp_tracker need only a "Root" object injected.
A couple of the files need Unicode stuff injected.
There is an implicit dependency on cparser which would need to be dealt with one way or another...using a C Parser seems a bit like overkill given a) Python has type annotations and b) all of the declarations are machine-generated anyhow. But if CParser is a hard requirement then I guess it would become a dependency of the HPyHostAPI package.
My last thought is that perhaps the CPython Universal implementation could be written in Python instead of C. Of course it would run slower, but development of it would tend to maintain feature parity with PyPy "automatically".
Or you could do it in Python for the next year or two and then go back and optimize it back to C once HPy is finalized.
- Paul
On Tue, Dec 29, 2020 at 5:06 PM Paul Prescod <paul@prescod.net> wrote:
Let's take a couple of example files and see what it would take to make them reusable and move them into the HPy repository for ANY interpreter host to build upon.
https://foss.heptapod.net/pypy/pypy/-/blob/branch/hpy/pypy/module/_hpy_unive...
see my other email for why it's a bad idea.
There is an implicit dependency on cparser which would need to be dealt
with one way or another...using a C Parser seems a bit like overkill given a) Python has type annotations and b) all of the declarations are machine-generated anyhow. But if CParser is a hard requirement then I guess it would become a dependency of the HPyHostAPI package.
cparser is an RPython feature, it has nothing to do with HPy. You see it because you are reading RPython code.
My last thought is that perhaps the CPython Universal implementation could be written in Python instead of C. Of course it would run slower, but development of it would tend to maintain feature parity with PyPy "automatically".
Or you could do it in Python for the next year or two and then go back and optimize it back to C once HPy is finalized.
and nobody would adopt it in the meantime because it's too slow :). The "rule zero" of HPy is to have zero overhead on CPython.
participants (2)
-
Antonio Cuni
-
Paul Prescod