From e9fb1593666e827bce77a679931c54dca9ab4013 Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Sat, 11 Jan 2025 20:47:49 +0100 Subject: [PATCH 1/3] Remove comments from `find_assignment_target` result --- Tools/cases_generator/analyzer.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Tools/cases_generator/analyzer.py b/Tools/cases_generator/analyzer.py index 679beca3ec3a9d..e8aaee345ff453 100644 --- a/Tools/cases_generator/analyzer.py +++ b/Tools/cases_generator/analyzer.py @@ -388,7 +388,11 @@ def find_assignment_target(node: parser.InstDef, idx: int) -> list[lexer.Token]: offset = 0 for tkn in reversed(node.block.tokens[: idx]): if tkn.kind in {"SEMI", "LBRACE", "RBRACE"}: - return node.block.tokens[idx - offset : idx] + tokens = node.block.tokens[idx - offset : idx] + while tokens and tokens[0].kind == "COMMENT": + tokens = tokens[1:] + assert tokens + return tokens offset += 1 return [] @@ -405,9 +409,6 @@ def find_stores_outputs(node: parser.InstDef) -> list[lexer.Token]: if tkn.kind != "EQUALS": continue lhs = find_assignment_target(node, idx) - assert lhs - while lhs and lhs[0].kind == "COMMENT": - lhs = lhs[1:] if len(lhs) != 1 or lhs[0].kind != "IDENTIFIER": continue name = lhs[0] From 748e20899a162a70a5f149e7da60bcd6d66851e5 Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Sat, 11 Jan 2025 20:48:07 +0100 Subject: [PATCH 2/3] Add `test_PyStackRef_FromPyObjectNew_with_comment` to `test_generated_cases.py` --- Lib/test/test_generated_cases.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Lib/test/test_generated_cases.py b/Lib/test/test_generated_cases.py index 75cbd8dd94e9cb..5b78c32d641c1f 100644 --- a/Lib/test/test_generated_cases.py +++ b/Lib/test/test_generated_cases.py @@ -562,6 +562,30 @@ def test_error_if_plain_with_comment(self): """ self.run_cases_test(input, output) + def test_PyStackRef_FromPyObjectNew_with_comment(self): + input = """ + inst(OP, (-- value)) { + // Comment is ok + value = PyStackRef_FromPyObjectNew(GETITEM(FRAME_CO_CONSTS, oparg)); + } + """ + + output = """ + TARGET(OP) { + frame->instr_ptr = next_instr; + next_instr += 1; + INSTRUCTION_STATS(OP); + _PyStackRef value; + // Comment is ok + value = PyStackRef_FromPyObjectNew(GETITEM(FRAME_CO_CONSTS, oparg)); + stack_pointer[0] = value; + stack_pointer += 1; + assert(WITHIN_STACK_BOUNDS()); + DISPATCH(); + } + """ + self.run_cases_test(input, output) + def test_error_if_pop(self): input = """ inst(OP, (left, right -- res)) { From f801cefeb2dc6501d4f1247e512da451f0c63d56 Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Sun, 12 Jan 2025 09:36:48 +0100 Subject: [PATCH 3/3] bring assert back --- Tools/cases_generator/analyzer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/cases_generator/analyzer.py b/Tools/cases_generator/analyzer.py index e8aaee345ff453..18f782e6c741ab 100644 --- a/Tools/cases_generator/analyzer.py +++ b/Tools/cases_generator/analyzer.py @@ -391,7 +391,6 @@ def find_assignment_target(node: parser.InstDef, idx: int) -> list[lexer.Token]: tokens = node.block.tokens[idx - offset : idx] while tokens and tokens[0].kind == "COMMENT": tokens = tokens[1:] - assert tokens return tokens offset += 1 return [] @@ -409,6 +408,7 @@ def find_stores_outputs(node: parser.InstDef) -> list[lexer.Token]: if tkn.kind != "EQUALS": continue lhs = find_assignment_target(node, idx) + assert lhs if len(lhs) != 1 or lhs[0].kind != "IDENTIFIER": continue name = lhs[0]