You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[RFC] split rustpython_stdlib from rustpython_vm #3102
Doesn't vm require minimal support from the stdlib? sys seems like it defines things that are also used in vm/, importlib should be around for importing things and io and encodings also are required if I recall correctly.
I can see how a subset of the stdlib could be separated but not really seeing how all could be yanked and placed in a new crate with could be a nostdlib feature, a limited-stdlib maybe. This is just a quick though on it, though, what's your idea on this?
I think modules defined in sys.builtin_module_names must be included in vm. Other modules will be splited.
I also think the name vm::stdlib doesn't fit anymore.
Maybe vm::module include builtin modules (since it is defined in sys.builtin_module_names),
and they will be re-exported through rustpython_stdlib again
Something I've been thinking about - oh which it seems also @DimitrisJim brought up - some things should be core to the interpreter, right? Like _signal, or _weakref, or _codecs - imo, anything that's required to start up rustpython (and to be honest, I thought it was a given that sys/builtins would stay in the vm). CPython makes this distinction via "built-in" modules vs dlls. _io is <module 'io' (built-in)>, but zlib is <module 'zlib' from '/usr/lib/python3.9/lib-dynload/zlib.cpython-39-x86_64-linux-gnu.so'>. Obviously we don't have extension modules, but I think it's more productive/useful to put those ancillary modules in a separate crate while keeping the actually core ones in rustpython-vm.
Oh, right - like sys.builtin_module_names. These all seem preeetty core to the interpreter, except for things like functools/itertools but those are still very heavily used in all kinds of python code, they aren't like zlib which is domain-specific.
Maybe the distinction we could have, if we kept these in rustpython-vm, is corelib instead of stdlib? Obviously a different set of priorities than Rust's core vs std, but a similar concept imo.
@coolreader18 In the sense of contrasting stdlib_module_names in builtin_module_names in python api, I think corelib sounds more like original concept. How do you think about it?
As an interested (very) minor contributor I really like the idea of defining a corelib for minimal RustPython–only what's needed for the language itself. What is considered the CPython stdlib could be a feature, or even split into multiple feature flags. Particularly esoteric libraries would be good candidates to be moved out into external packages.
The list from sys.builtin_module_names seems like a good core, with the caveat that xxsubtype is CPython-specific module (not tested, see #3250). Similarly marshal is deliberately undocumented, and is only used for CPython internal stuff like byte-code.
So RustPython might needs its own versions of those modules but trying to port them doesn't seem useful and they shouldn't block a corelib PR.
Activity
DimitrisJim commentedon Sep 25, 2021
Question on this since #3132 got me thinking.
Doesn't vm require minimal support from the stdlib?
sysseems like it defines things that are also used in vm/,importlibshould be around for importing things andioandencodingsalso are required if I recall correctly.I can see how a subset of the stdlib could be separated but not really seeing how all could be yanked and placed in a new crate with could be a
nostdlibfeature, alimited-stdlibmaybe. This is just a quick though on it, though, what's your idea on this?youknowone commentedon Sep 25, 2021
I think modules defined in
sys.builtin_module_namesmust be included in vm. Other modules will be splited.I also think the name
vm::stdlibdoesn't fit anymore.Maybe
vm::moduleinclude builtin modules (since it is defined insys.builtin_module_names),and they will be re-exported through rustpython_stdlib again
coolreader18 commentedon Sep 27, 2021
Something I've been thinking about - oh which it seems also @DimitrisJim brought up - some things should be core to the interpreter, right? Like
_signal, or_weakref, or_codecs- imo, anything that's required to start uprustpython(and to be honest, I thought it was a given thatsys/builtinswould stay in the vm). CPython makes this distinction via "built-in" modules vs dlls._iois<module 'io' (built-in)>, butzlibis<module 'zlib' from '/usr/lib/python3.9/lib-dynload/zlib.cpython-39-x86_64-linux-gnu.so'>. Obviously we don't have extension modules, but I think it's more productive/useful to put those ancillary modules in a separate crate while keeping the actually core ones inrustpython-vm.coolreader18 commentedon Sep 27, 2021
Oh, right - like
sys.builtin_module_names. These all seem preeetty core to the interpreter, except for things like functools/itertools but those are still very heavily used in all kinds of python code, they aren't likezlibwhich is domain-specific.coolreader18 commentedon Sep 27, 2021
Maybe the distinction we could have, if we kept these in
rustpython-vm, iscorelibinstead ofstdlib? Obviously a different set of priorities than Rust's core vs std, but a similar concept imo.youknowone commentedon Sep 27, 2021
#3129 is now working version. it solves native modules, but not pylib
youknowone commentedon Sep 28, 2021
I have another public stdlib api suggestion in #3165youknowone commentedon Oct 1, 2021
I don't remember which PR it was, but Jim commented about sys.stdlib_module_names.
@coolreader18 In the sense of contrasting
stdlib_module_namesinbuiltin_module_namesin python api, I thinkcorelibsounds more like original concept. How do you think about it?jamestwebber commentedon Oct 8, 2021
As an interested (very) minor contributor I really like the idea of defining a
corelibfor minimal RustPython–only what's needed for the language itself. What is considered the CPythonstdlibcould be a feature, or even split into multiple feature flags. Particularly esoteric libraries would be good candidates to be moved out into external packages.The list from
sys.builtin_module_namesseems like a good core, with the caveat thatxxsubtypeis CPython-specific module (not tested, see #3250). Similarlymarshalis deliberately undocumented, and is only used for CPython internal stuff like byte-code.So RustPython might needs its own versions of those modules but trying to port them doesn't seem useful and they shouldn't block a
corelibPR.DimitrisJim commentedon Oct 8, 2021
Running Python (3.8) with increased verbosity (
-vv) does give a list of imports during start-up. For normal file invocations, this is:Launching the REPL does entail some additional imports:
readline, atexit, rlcompleteryouknowone commentedon Apr 17, 2022
This is finished by #3620