From 0413d5287b0664fb4b575d04f9a5a44703866fea Mon Sep 17 00:00:00 2001 From: Kaustubh Date: Thu, 23 Nov 2023 16:25:53 +0530 Subject: [PATCH 1/6] Simulator test fixes for Python 3.12 version upgrade --- numba_rvsdg/tests/simulator.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/numba_rvsdg/tests/simulator.py b/numba_rvsdg/tests/simulator.py index 16e9e77..0210263 100644 --- a/numba_rvsdg/tests/simulator.py +++ b/numba_rvsdg/tests/simulator.py @@ -10,6 +10,9 @@ ) import builtins +import sys + +PYVERSION = sys.version_info[:2] class Simulator: @@ -327,8 +330,11 @@ def op_FOR_ITER(self, inst): try: ind = next(tos) except StopIteration: - self.stack.pop() self.branch = True + if PYVERSION <= (3, 11): + self.stack.pop() + else: + self.stack.append(None) else: self.branch = False self.stack.append(ind) @@ -427,3 +433,11 @@ def op_POP_JUMP_FORWARD_IF_NONE(self, inst): def op_POP_JUMP_BACKWARD_IF_NONE(self, inst): self.branch = self.stack[-1] is None self.stack.pop() + + def op_END_FOR(self, inst): + self.stack.pop() + self.stack.pop() + + def op_COPY(self, inst): + assert inst.argval > 0 + self.stack.append(self.stack[-inst.argval]) From 159bb2d47dbf09d7ab327970388fadc114dba692 Mon Sep 17 00:00:00 2001 From: Kaustubh Date: Fri, 24 Nov 2023 16:52:45 +0530 Subject: [PATCH 2/6] Refactored conditional statements --- numba_rvsdg/tests/simulator.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/numba_rvsdg/tests/simulator.py b/numba_rvsdg/tests/simulator.py index 0210263..e893f4c 100644 --- a/numba_rvsdg/tests/simulator.py +++ b/numba_rvsdg/tests/simulator.py @@ -331,10 +331,12 @@ def op_FOR_ITER(self, inst): ind = next(tos) except StopIteration: self.branch = True - if PYVERSION <= (3, 11): + if PYVERSION in ((3, 11),): self.stack.pop() - else: + elif PYVERSION in ((3, 12),): self.stack.append(None) + else: + raise NotImplementedError(PYVERSION) else: self.branch = False self.stack.append(ind) From 40481aa40e1f6976d9f8507ba4439eebeaa27a35 Mon Sep 17 00:00:00 2001 From: Kaustubh Date: Thu, 7 Dec 2023 22:11:31 +0530 Subject: [PATCH 3/6] Made END_FOR declaration conditional on Python versioning --- numba_rvsdg/tests/simulator.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/numba_rvsdg/tests/simulator.py b/numba_rvsdg/tests/simulator.py index e893f4c..95f7fe3 100644 --- a/numba_rvsdg/tests/simulator.py +++ b/numba_rvsdg/tests/simulator.py @@ -436,9 +436,10 @@ def op_POP_JUMP_BACKWARD_IF_NONE(self, inst): self.branch = self.stack[-1] is None self.stack.pop() - def op_END_FOR(self, inst): - self.stack.pop() - self.stack.pop() + if PYVERSION in ((3, 12),): + def op_END_FOR(self, inst): + self.stack.pop() + self.stack.pop() def op_COPY(self, inst): assert inst.argval > 0 From 635bfd4539816e2406776b9ce41e1e38ce3be97f Mon Sep 17 00:00:00 2001 From: Kaustubh Date: Thu, 7 Dec 2023 22:13:56 +0530 Subject: [PATCH 4/6] Made PYVERSION declaration part of core utilities. --- numba_rvsdg/core/utils.py | 2 ++ numba_rvsdg/tests/simulator.py | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/numba_rvsdg/core/utils.py b/numba_rvsdg/core/utils.py index 08940db..0c2cc50 100644 --- a/numba_rvsdg/core/utils.py +++ b/numba_rvsdg/core/utils.py @@ -1,7 +1,9 @@ import logging +import sys _logger = logging.getLogger(__name__) +PYVERSION = sys.version_info[:2] class _LogWrap: def __init__(self, fn): # type: ignore diff --git a/numba_rvsdg/tests/simulator.py b/numba_rvsdg/tests/simulator.py index 95f7fe3..c900aa2 100644 --- a/numba_rvsdg/tests/simulator.py +++ b/numba_rvsdg/tests/simulator.py @@ -8,12 +8,9 @@ RegionBlock, SyntheticBlock, ) +from numba_rvsdg.core.utils import PYVERSION import builtins -import sys - -PYVERSION = sys.version_info[:2] - class Simulator: """SCFG simulator. From d3c611847108ead46c515dedd2b6a0838b7bd4db Mon Sep 17 00:00:00 2001 From: Kaustubh Date: Thu, 7 Dec 2023 22:15:46 +0530 Subject: [PATCH 5/6] Added pre-commit requested changes --- numba_rvsdg/core/utils.py | 1 + numba_rvsdg/tests/simulator.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/numba_rvsdg/core/utils.py b/numba_rvsdg/core/utils.py index 0c2cc50..3dbf6ba 100644 --- a/numba_rvsdg/core/utils.py +++ b/numba_rvsdg/core/utils.py @@ -5,6 +5,7 @@ PYVERSION = sys.version_info[:2] + class _LogWrap: def __init__(self, fn): # type: ignore self._fn = fn diff --git a/numba_rvsdg/tests/simulator.py b/numba_rvsdg/tests/simulator.py index c900aa2..b0924c0 100644 --- a/numba_rvsdg/tests/simulator.py +++ b/numba_rvsdg/tests/simulator.py @@ -12,6 +12,7 @@ import builtins + class Simulator: """SCFG simulator. @@ -434,6 +435,7 @@ def op_POP_JUMP_BACKWARD_IF_NONE(self, inst): self.stack.pop() if PYVERSION in ((3, 12),): + def op_END_FOR(self, inst): self.stack.pop() self.stack.pop() From 61c14d04fa2aa9e01f0d39f794bd45de791a05a8 Mon Sep 17 00:00:00 2001 From: Kaustubh Date: Mon, 11 Dec 2023 14:44:28 +0530 Subject: [PATCH 6/6] Added else clause for END_FOR declaration conditional statement --- numba_rvsdg/tests/simulator.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/numba_rvsdg/tests/simulator.py b/numba_rvsdg/tests/simulator.py index b0924c0..7e0ff3d 100644 --- a/numba_rvsdg/tests/simulator.py +++ b/numba_rvsdg/tests/simulator.py @@ -440,6 +440,11 @@ def op_END_FOR(self, inst): self.stack.pop() self.stack.pop() + else: + + def op_END_FOR(self, inst): + raise NotImplementedError(PYVERSION) + def op_COPY(self, inst): assert inst.argval > 0 self.stack.append(self.stack[-inst.argval])