Skip to content

Conversation

@isidentical
Copy link
Member

@isidentical isidentical commented May 21, 2020

When there are 2 negative lookaheads in a same rule, let's say
!"(" blabla "," !")", there will the 2 FunctionCall's where
assigned value is None. Currently when the add_var is called
the first one will be ignored (since it will be returned as same
from dedupe because there aren't any None named variables in
locals, but when the second lookahead's var is sent to dedupe it
will be returned as None_1 and this wont be ignored by the
declaration generator in the visit_Alt. This patch adds an explicit
check to add_var to distinguish whether if there is a variable or not.

https://bugs.python.org/issue40334

When there are 2 negative lookaheads in a same rule, let's say
`!"(" blabla "," !")"`, there will the 2 `FunctionCall`'s where
assigned value is None. Currently when the `add_var` is called
the first one will be ignored (since it will be returned as same
from dedupe because there aren't any `None` named variables in
locals, but when the second lookahead's var is sent to dedupe it
will be returned as `None_1` and this wont be ignored by the
declaration generator in the `visit_Alt`. This patch adds an explicit
check to `add_var` to distinguish whether if there is a variable or not.
@pablogsal
Copy link
Member

Could you add a test?

@isidentical
Copy link
Member Author

I couldnt find the suitable place to add test, would you give me a hint about it?

@pablogsal
Copy link
Member

@pablogsal
Copy link
Member

pablogsal commented May 21, 2020

or alternatively https://github.com/python/cpython/blob/master/Lib/test/test_peg_generator/test_c_parser.py if you cannot reproduce it in the Python version.

@isidentical
Copy link
Member Author

I dont know if this test is suitable, but I couldn't find a better way to test this.

@pablogsal
Copy link
Member

pablogsal commented May 21, 2020

Also, why mypy has not catched this? dedupe does not allow None

grammar = parse_string(grammar_source, GrammarParser)
parser_source = generate_c_parser_source(grammar)

self.assertNotIn("int None_1", parser_source)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hummmm. I don't like this test because is checking the implementation. What goes wrong exactly now when there are two negative lookaheads?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What goes wrong exactly now when there are two negative lookaheads?

gcc -pthread -c -Wno-unused-result -Wsign-compare -g -Og -Wall    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE -o Parser/pegen/parse.o Parser/pegen/parse.c
Parser/pegen/parse.c: In function ‘invalid_import_from_targets_rule’:
Parser/pegen/parse.c:12249:13: warning: unused variable ‘None_1’ [-Wunused-variable]
12249 |         int None_1;
      |             ^~~~~~

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hummmm. I don't like this test because is checking the implementation.

I agree with you but this is an implementation problem so I dont know exactly how to write a better test for this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you but this is an implementation problem so I dont know exactly how to write a better test for this

Yeah, let's remove the test and let's focus on why mypy has not found this.

Copy link
Member Author

@isidentical isidentical May 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because of CCallMakerVisitor's return value is Any, mypy kind a ignores it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦

Ok, will prepare a PR to fix mypy, I found a couple of other stuff.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #20297 to fix mypy issues

This reverts commit 5440280.
@isidentical isidentical requested a review from pablogsal May 21, 2020 19:40
@pablogsal pablogsal merged commit f50516e into python:master May 21, 2020
arturoescaip pushed a commit to arturoescaip/cpython that referenced this pull request May 24, 2020
…honGH-20296)

When there are 2 negative lookaheads in the same rule, let's say `!"(" blabla "," !")"`, there will the 2 `FunctionCall`'s where assigned value is None. Currently when the `add_var` is called
the first one will be ignored but when the second lookahead's var is sent to dedupe it
will be returned as `None_1` and this won't be ignored by the declaration generator in the `visit_Alt`. This patch adds an explicit check to `add_var` to distinguish whether if there is a variable or not.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants