-
Notifications
You must be signed in to change notification settings - Fork 0
Remove all unnecessary code from Tools/peg_generator; only keep the generator itself #23
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
Conversation
I am a bit uneasy removing the tests for the parser or the generator itself (not the ones for the ast of the grammar). If in the future we modify the generator once is merged in CPython, we certainly want the tests there, no? |
Agreed, I'd rather keep the tests, even if they are redundant. |
Those rely on a compiled extension though and for that we either need to have all the C code in Tools/peg_generator or we can refactor |
Edit: I was not aware of Lib/test/test_peg_parser.py |
Well, grammar tests can always go into Lib/test/test_peg_parser.py. There's still the problem with the generator tests though, which I agree is important. |
We should make sure also that those tests run with the compiled Python as now they are running with Python3.8. |
I have been struggling with this for a bit and then I remembered that it's not possible due to we-like-parsers/pegen_experiments#85. Any ideas on how to overcome this? |
We can include the private headers and link the compilation units for the functions that we use (like |
When I first created the peg_parser module as a directory I solved this -- you have to add a few extra |
b5df192
to
374198f
Compare
I started from scratch on this and I deleted only the unecessary duplicates, but kept everything else in place. Pegen Tests are failing, because Github Actions do not support 3.9 yet. But there is a problem with the generated extension module. If you build it and call In any case, I'm calling it a day. I'm going to further inspect this in the morning. Good night (evening in some timezones?) everybody! |
You need to use the compiled CPython for this. This is similar to how we test the rest of the code in
Good night from London :) |
Were there any changes in the return value of |
Not that I know of.
On Wed, Mar 25, 2020 at 12:09 Lysandros Nikolaou ***@***.***> wrote:
Were there any changes in the return value of PyAST_mod2obj in 3.9? For
some reason I keep getting TypeError: expected AST, got 'Module' when
calling ast.dump(..) with the return value of parse_string.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#23 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAWCWMTANOD3RNFTYKFQDOLRJJJF5ANCNFSM4LS5NTEA>
.
--
--Guido (mobile)
|
Everything is now ready apart from the AST bug! Since all of the tests are now in the stdlib, you can see the failures on Github Actions. Any pointer as to why this could be happening would really be helpful. |
Can you give an example of how it fail I just checked the PR and what I understood it should fail does not:
|
The CPython extension module under |
Oh, this is a tricky thing. The error is because there are two AST module classes that seem the same, so when you check for
The reason seems is because we have a copy of the symbols in the extension module:
Notice how both are "d", which means that they are in the data segment. I would need to investigate a bit more to confirm this theory, but this seems that is the reason. There is a reason my GitHub profile says "I hate symbols but I love linkers." 😛 |
Wow! I could never have found this by myself. The question now is, what do we do about this? If I understand correctly that means that we shouldn't compile |
I quick hack is doing this:
We need to also add the other module properties, but unless there isn't a bigger downside I would be ok with such hack + a comment explaining the problem. |
Well, this hack isn't enough though. We need to compare the full string produced by calling |
Does it complain about other than the top Module? For instance the
We can copy-paste the In general the problem is that once the python interpreter is compiled, there is no way to get access to the |
Nope, only for the top Module. But due to that complaint, |
Ohhhh, gotcha! |
…oving the isinstance checks
Note that most of the approx. 1440 lines of code added in this PR are in Lib/test/test_peg_generator.py with is just a copy paste of test_c_parser.py, test_first_sets.py and test_pegen.py(converted to unittest, of course). So even though this seems huge, it's not as bad as it looks. |
Would it be possible to have them in a folder into separate files? I would prefer not to mix them into a single gigantic file. We have already some other tests in this format (check the folders in
I would not mind much now that we have a comment given that we have more urgent things to care about. Maybe leave a todo for the future so we don't forget and open an issue if we all agree that we should do something better in the future. |
Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Great work and thanks for the perseverance :)
Thank you for the help! |
The tests ( |
What exactly are the compilation errors about, when you run |
Full output of
FWIW, there are also some warnings when running `./python.exe -m test test_peg_generator in the repo root:
|
The problem is that both These two copies are two different classes, so using |
This is our branch. Can't we just export that function? Or perhaps a wrapper with a name that makes it clear it's only for our own use? |
@gvanrossum Could it be that your version of python was built before python#9605 was merged? |
We could export it with an underscore may be like the other "private" functions (like |
Tools/peg_generator/Makefile
Outdated
@@ -1,4 +1,4 @@ | |||
PYTHON ?= python3.8 | |||
PYTHON ?= python3.9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be ../../python
? (Or python.exe
in mac)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be ../../python
indeed!
I'm now getting an ImportError: cannot import name 'parse' from 'peg_parser' (unknown location)
though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, it doesn't look like the ../../ solution works. :-(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is because is finding first the C extrension that we include in Modules
. We need to rename Tools/peg_generator/peg_parser
to something else. (Also make sure you always use the compiled python).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to rename Tools/peg_generator/peg_parser to something else.
Done.
Now that I think about this more, for us to not link against
|
But that's generated code isn't it? |
Yup, by |
So is it worse to export all those symbols or to duplicate all that code? Also, is this a permanent issue or is it temporary until we get to merge our branch? |
Notice that I may be missing a better solution here, but in case I am not this is my view:
Given that exporting the symbols may have some other consequences and this is only for testing the generator itself (not to make the extension for CPython or the itegration) I would prefer to duplicate the
This is a "permanent" issue, in the sense that this won't change on the integration. But to remark: this only happens for the tests and only happens if we insist in using the builtin |
That was it -- I built and installed from the upstream master and things are now better. So given the issues around sharing the AST definition maybe just land. |
I also added a TODO in the comment in I also think, we can land this as is for now and open an issue about fixing the AST symbols thing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go!
@@ -0,0 +1,60 @@ | |||
def ast_dump(node, annotate_fields=True, include_attributes=False, *, indent=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, if it's just this file that's duplicated, I don't mind. Sorry for making a fuss!
:party: |
Closes #14.