Skip to content

Commit 8d18db7

Browse files
Docs: Init README.md (#8)
Co-authored-by: Ken Jin <[email protected]>
1 parent 511c5f0 commit 8d18db7

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# pyLBBVAndPatch
2+
3+
A Lazy Basic Block Versioning + Copy and Patch JIT Interpreter for CPython.
4+
5+
Python is a widely-used programming language. CPython is its reference implementation. Due to Python’s dynamic type semantics, CPython is generally unable to execute Python programs as fast as it potentially could with static type semantics.
6+
7+
Last semester, while taking CS4215, we made progress on implementing a technique for removing type checks and other overheads associated with dynamic languages known as [Lazy Basic Block Versioning (LBBV)](https://arxiv.org/abs/1411.0352) in CPython. This work will be referred to as pyLBBV. More details can be found in our [technical report](https://github.com/pylbbv/pylbbv/blob/pylbbv/report/CPython_Tier_2_LBBV_Report_For_Repo.pdf). For an introduction to pyLBBV, refer to our [presentation](https://docs.google.com/presentation/d/e/2PACX-1vQ9eUaAdAgU0uFbEkyBbptcLZ4dpdRP-Smg1V499eogiwlWa61EMYVZfNEXg0xNaQvlmdNIn_07HItn/pub?start=false&loop=false&delayms=60000).
8+
9+
This Orbital, we intend to refine pyLBBV. These include but are not limited to:
10+
- General refactoring
11+
- Bug fixing
12+
- Better unboxing + support unboxing of other types
13+
- More type specialised code
14+
15+
Furthermore, we intend to further pyLBBV by integrating a [Copy and Patch JIT](https://arxiv.org/abs/2011.13127) (using code written externally by Brandt Bucher) on top of the type specialisation PyLBBV provides. The culmination of these efforts will allow further optimisations to be implemented. We hope that this effort can allow Python to be as fast as a statically typed language. Our work here will be made publically available so that it will benefit CPython and its users, and we plan to collaborate closely with the developers of CPython in the course of this project.
16+
17+
Due to Python being a huge language, pyLBBVAndPatch intends to support and optimise a subset of Python. Specifically pyLBBVAndPatch focuses on integer and float arithmetic. We believe this scope is sufficient as an exploration of the LBBV + Copy and Patch JIT approach for CPython.
18+
19+
# Project Plan
20+
21+
- Fix bugs and refactor hot-patches in pyLBBV
22+
- Implement interprocedural type propagation
23+
- Implement typed object versioning
24+
- Implement unboxing of integers, floats and other primitive types
25+
- Implement Copy and Patch JIT (Just In Time) Compilation
26+
27+
## Immediate Goals
28+
29+
Refer to [the issues page](https://github.com/pylbbv/pylbbv/issues).
30+
31+
# Changelog over CS4215
32+
33+
* Refactor: Typeprop codegen by @JuliaPoo in https://github.com/pylbbv/pylbbv/pull/1
34+
* Refactored type propagation codegen to more explicitly align with the formalism in our [technical report (Appendix)](https://github.com/pylbbv/pylbbv/blob/pylbbv/report/CPython_Tier_2_LBBV_Report_For_Repo.pdf) and remove duplicated logic
35+
* Fixed bug with possible reference cycle in the type propagation `TYPE_SET` operation
36+
* feat: granular type checks by @Fidget-Spinner in https://github.com/pylbbv/pylbbv/pull/2
37+
* Split `BINARY_CHECK_X` into simply `CHECK_X` and short-circuit failure paths. This allows us to follow more closely to the LBBV paper. It also means we can supported cases where one operand is known but the other unknown.
38+
* Perf: Improved typeprop by switching overwrite -> set by @JuliaPoo in https://github.com/pylbbv/pylbbv/pull/6
39+
* Stricter type propagation reduces type information loss
40+
41+
# Build instructions
42+
43+
You should follow the official CPython build instructions for your platform.
44+
https://devguide.python.org/getting-started/setup-building/
45+
46+
We have one major difference - you must have a pre-existing Python installation.
47+
Preferrably Python 3.9 or higher. On MacOS/Unix systems, that Python installation
48+
*must* be located at `python3`.
49+
50+
The main reason for this limitation is that Python is used to bootstrap the compilation
51+
of Python. However, since our interpreter is unable to run a large part of the Python
52+
language, our interpreter cannot be used as a bootstrap Python.
53+
54+
During the build process, errors may be printed, and the build process may error. However,
55+
the final Python executable should still be generated.
56+
57+
# Where are files located? Where is documentation?
58+
59+
The majority of the changes and functionality are in `Python/tier2.c` where Doxygen documentation
60+
is written alongside the code, and in `Tools/cases_generator/` which contains the DSL implementation.
61+
62+
# Running tests
63+
64+
We've written simple tests of the main functionalities.
65+
Unfortunately we did not have time to write comprehensive tests, and it doesn't seem worth it eitherways given the experimental nature of this project.
66+
67+
After building, run `python tier2_test.py` or `python.bat tier2_test.py` (on Windows) in the repository's root folder.
68+
69+
# Debugging output
70+
71+
In `tier2.c`, two flags can be set to print debug messages:
72+
```c
73+
// Prints codegen debug messages
74+
#define BB_DEBUG 0
75+
76+
// Prints typeprop debug messages
77+
#define TYPEPROP_DEBUG 0
78+
```

0 commit comments

Comments
 (0)