Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CFP] Implement the _sre module in Rust #2258

Open
coolreader18 opened this issue Oct 1, 2020 · 1 comment
Open

[CFP] Implement the _sre module in Rust #2258

coolreader18 opened this issue Oct 1, 2020 · 1 comment
Labels

Comments

@coolreader18
Copy link
Member

@coolreader18 coolreader18 commented Oct 1, 2020

At the moment, _sre is a modified version of _sre.py from an old version of PyPy: https://github.com/nikhaldi/_sre.py.

This is s l o w. If you ctrl-C rustpython while it's running a decently complex script, there's a good chance that the traceback from the KeyboardInterrupt will have originated somewhere in _sre.py. While it's definitely feasible to implement _sre in Rust -- I was able to modify the constant-generation script to output Rust instead of C code -- both the C and Python versions of _sre don't really lend well to translation to Rust. The C version (_sre.c/sre_lib.h) uses lots of pointer arithmetic and a kind of "as long as we own an active reference to the str object, we can send pointers anywhere we want" approach that doesn't jive well with Rust's memory-safety rules. The Python version (Lib/_sre.py in the RustPython source tree) uses enough nested references (context.x_stack[n].context is context), generator functions, and dynamic typing that it's also tricky to translate to Rust.

If anyone wants to take a stab at this, I've left a scaffold of the implementation in the _sre-wip branch, that has the SRE constants available to Rust, and some of my sketches for how it might work, but no real functionality. Be warned, either route you go to emulate is tricky, so feel free to try whichever approach you think would be easier.

@coolreader18 coolreader18 added the feat label Oct 1, 2020
@darleybarreto
Copy link

@darleybarreto darleybarreto commented Oct 1, 2020

pyre2 and Jython's _sre [1,2] might help on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.