-
-
Notifications
You must be signed in to change notification settings - Fork 103
WIP: Crossversion Testing #181
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
base: master
Are you sure you want to change the base?
Conversation
|
Seems like a reasonable thing. I'll try to look at this when I get a chance. Thanks for the PR. I am too often finding stuff in this code base that is in great need of improvement, and this may be one of those areas. (One of the other areas is making sure the marshal and unmarshal routines round trip properly. Or getting opcode classification correct.) |
|
I just had a chance to look at and try. It's okay to put in so that the code doesn't become stale as things change in the code base. As you note, it can't be used automatically as is without more work. Some of the fragility is indeed baked into the nature of what xdis is doing. Let me explain.... Ideally, Python's dis output would be the same as pydisasm's when First, dis output has changed over time — presumably, the later dis output is more helpful. But for this to work in an automated fashion, either this means more work in xdis's formatting routines (for version x we format this way, but for version y we change that because Python's But I am seeing it gets worse than that. Recently, I've added RustPython disassembly. RustPython decided that it wanted more "friendly" opcode names. So This adds the dilemma of whether we want to match the RustPython names, which are generally less familiar to folks who know Python bytecode (CPython, PyPy, or Graal), or whether we want the For automated testing here, RustPython names are better (except you'd still need to figure out the dance to get RustPython to use RustPython's builtin But if what you are doing is analysis, using common names like Of course, the RustPython convention can be used only when The tendency is to do that. But this is more work. |
|
@rocky - thanks for this info, these are some important things to consider. Initially I had started developing crossversion testing when we ran into issues when working on pylingual where "native" disassembly would be different than "non-native" (say xdis on 3.12 disassembling a bytecode of version 3.13, compared to python version 3.13 disassembling a bytecode of version 3.12). As I made it, and from my understanding, this test should be "format agnostic", as it separately "serializes" the instructions and code object attrs. In terms of RustPython, I really am not too familiar. If maintaining some translation between the "friendly names" and CPython opnames is the best approach, I think that makes sense to me. I think either way, implementing this in this tester wont be too hard considering the serialization process already does some "massaging" of the bytecode. I could see integrating with tox/pyenv/uv being a challenge though. |
There can be differences, although probably not the kind that will bother the LLM too much. In marshalling, dictionaries and sets that have the same content might appear in different orders. The semantics of course are the same, but when printed, the order can be different. Oddly, this can happen in the same version of Python, and Python considers the fact that sets and dictionaries may appear in arbitrary order depending on whim and the time of day, to be a feature, not a bug. Since it is useful for marshal/unmarshal to round-trip to get the same results, recently I've added extra fields to capture the specific order in which such kinds of objects appear.
I just wanted to point out that what the "right" thing to do depends on what you are trying to accomplish. If you are someone who is familiar with Python bytecode, the "user-friendly" CamelCase names get in the way. Yes, we have that |
|
Happy Holidays Rocky :)
That's good to know, I was not aware. I knew sets were ordered randomly, but looking into it, I see that the arbitrary order is decided literally randomly at compile time. I'm surprised I hadn't seen this before. python/cpython#73894. The way I am "serializing" would definitely miss this, so that might be something to consider. I could pull this in and then investigate further and make a new PR if that is good to you.
My personal opinion is I wouldn't expect xdis to have the capability to keep a translation like this. I think it could definitely be useful for certain people as you say though. |
Happy Holidays!
The work you and others do is always appreciated. Also note that there is some work here done in |
I improved cross version testing, and think it may be ready for development use. It is currently quite strict, so finds very small discrepancies between dis and xdis. I think with a little more work it could be used to automatically find changes and differences when adding new versions of python to xdis; and make sure they still work with older versions of python.
Here is an example output of a test run. This automatically finds a couple minor difference in xdis and dis.
0while dis's argval is<.0while dis's argval is(None, False)@rocky @jdw170000 thoughts?