Skip to content

Commit

Permalink
pythonGH-111485: Delete the old generator code. (pythonGH-113321)
Browse files Browse the repository at this point in the history
  • Loading branch information
markshannon authored and ryan-duve committed Dec 26, 2023
1 parent 8c989c8 commit cf884d8
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 3,723 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ Programs/test_frozenmain.h generated
Python/Python-ast.c generated
Python/executor_cases.c.h generated
Python/generated_cases.c.h generated
Python/abstract_interp_cases.c.h generated
Python/opcode_targets.h generated
Python/stdlib_module_names.h generated
Tools/peg_generator/pegen/grammar_parser.py generated
Expand Down
46 changes: 23 additions & 23 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 31 additions & 46 deletions Lib/test/test_generated_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ def skip_if_different_mount_drives():
root_drive = os.path.splitroot(ROOT)[0]
cwd_drive = os.path.splitroot(os.getcwd())[0]
if root_drive != cwd_drive:
# generate_cases.py uses relpath() which raises ValueError if ROOT
# and the current working different have different mount drives
# (on Windows).
# May raise ValueError if ROOT and the current working
# different have different mount drives (on Windows).
raise unittest.SkipTest(
f"the current working directory and the Python source code "
f"directory have different mount drives "
Expand All @@ -28,10 +27,9 @@ def skip_if_different_mount_drives():

test_tools.skip_if_missing('cases_generator')
with test_tools.imports_under_tool('cases_generator'):
import generate_cases
import analysis
import formatting
from parsing import StackEffect
from analyzer import StackItem
import parser
from stack import Stack
import tier1_generator


Expand All @@ -43,37 +41,24 @@ def handle_stderr():

class TestEffects(unittest.TestCase):
def test_effect_sizes(self):
input_effects = [
x := StackEffect("x", "", "", ""),
y := StackEffect("y", "", "", "oparg"),
z := StackEffect("z", "", "", "oparg*2"),
stack = Stack()
inputs = [
x:= StackItem("x", None, "", "1"),
y:= StackItem("y", None, "", "oparg"),
z:= StackItem("z", None, "", "oparg*2"),
]
output_effects = [
StackEffect("a", "", "", ""),
StackEffect("b", "", "", "oparg*4"),
StackEffect("c", "", "", ""),
outputs = [
StackItem("x", None, "", "1"),
StackItem("b", None, "", "oparg*4"),
StackItem("c", None, "", "1"),
]
other_effects = [
StackEffect("p", "", "", "oparg<<1"),
StackEffect("q", "", "", ""),
StackEffect("r", "", "", ""),
]
self.assertEqual(formatting.effect_size(x), (1, ""))
self.assertEqual(formatting.effect_size(y), (0, "oparg"))
self.assertEqual(formatting.effect_size(z), (0, "oparg*2"))

self.assertEqual(
formatting.list_effect_size(input_effects),
(1, "oparg + oparg*2"),
)
self.assertEqual(
formatting.list_effect_size(output_effects),
(2, "oparg*4"),
)
self.assertEqual(
formatting.list_effect_size(other_effects),
(2, "(oparg<<1)"),
)
stack.pop(z)
stack.pop(y)
stack.pop(x)
for out in outputs:
stack.push(out)
self.assertEqual(stack.base_offset.to_c(), "-1 - oparg*2 - oparg")
self.assertEqual(stack.top_offset.to_c(), "1 - oparg*2 - oparg + oparg*4")


class TestGeneratedCases(unittest.TestCase):
Expand Down Expand Up @@ -104,9 +89,9 @@ def tearDown(self) -> None:

def run_cases_test(self, input: str, expected: str):
with open(self.temp_input_filename, "w+") as temp_input:
temp_input.write(analysis.BEGIN_MARKER)
temp_input.write(parser.BEGIN_MARKER)
temp_input.write(input)
temp_input.write(analysis.END_MARKER)
temp_input.write(parser.END_MARKER)
temp_input.flush()

with handle_stderr():
Expand Down Expand Up @@ -636,13 +621,13 @@ def test_cond_effect(self):
PyObject *output = NULL;
PyObject *zz;
cc = stack_pointer[-1];
if ((oparg & 1) == 1) { input = stack_pointer[-1 - ((((oparg & 1) == 1) ? 1 : 0))]; }
aa = stack_pointer[-2 - ((((oparg & 1) == 1) ? 1 : 0))];
if ((oparg & 1) == 1) { input = stack_pointer[-1 - (((oparg & 1) == 1) ? 1 : 0)]; }
aa = stack_pointer[-2 - (((oparg & 1) == 1) ? 1 : 0)];
output = spam(oparg, input);
stack_pointer[-2 - ((((oparg & 1) == 1) ? 1 : 0))] = xx;
if (oparg & 2) stack_pointer[-1 - ((((oparg & 1) == 1) ? 1 : 0))] = output;
stack_pointer[-1 - ((((oparg & 1) == 1) ? 1 : 0)) + (((oparg & 2) ? 1 : 0))] = zz;
stack_pointer += -((((oparg & 1) == 1) ? 1 : 0)) + (((oparg & 2) ? 1 : 0));
stack_pointer[-2 - (((oparg & 1) == 1) ? 1 : 0)] = xx;
if (oparg & 2) stack_pointer[-1 - (((oparg & 1) == 1) ? 1 : 0)] = output;
stack_pointer[-1 - (((oparg & 1) == 1) ? 1 : 0) + ((oparg & 2) ? 1 : 0)] = zz;
stack_pointer += -(((oparg & 1) == 1) ? 1 : 0) + ((oparg & 2) ? 1 : 0);
DISPATCH();
}
"""
Expand Down Expand Up @@ -682,8 +667,8 @@ def test_macro_cond_effect(self):
}
stack_pointer[-3] = deep;
if (oparg) stack_pointer[-2] = extra;
stack_pointer[-2 + (((oparg) ? 1 : 0))] = res;
stack_pointer += -1 + (((oparg) ? 1 : 0));
stack_pointer[-2 + ((oparg) ? 1 : 0)] = res;
stack_pointer += -1 + ((oparg) ? 1 : 0);
DISPATCH();
}
"""
Expand Down
8 changes: 1 addition & 7 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -1585,12 +1585,6 @@ Objects/mimalloc/page.o: $(srcdir)/Objects/mimalloc/page-queue.c
regen-cases:
# Regenerate various files from Python/bytecodes.c
# Pass CASESFLAG=-l to insert #line directives in the output
PYTHONPATH=$(srcdir)/Tools/cases_generator \
$(PYTHON_FOR_REGEN) \
$(srcdir)/Tools/cases_generator/generate_cases.py \
$(CASESFLAG) \
-a $(srcdir)/Python/abstract_interp_cases.c.h.new \
$(srcdir)/Python/bytecodes.c
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/cases_generator/opcode_id_generator.py \
-o $(srcdir)/Include/opcode_ids.h.new $(srcdir)/Python/bytecodes.c
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/cases_generator/target_generator.py \
Expand All @@ -1614,7 +1608,6 @@ regen-cases:
$(UPDATE_FILE) $(srcdir)/Include/internal/pycore_opcode_metadata.h $(srcdir)/Include/internal/pycore_opcode_metadata.h.new
$(UPDATE_FILE) $(srcdir)/Include/internal/pycore_uop_metadata.h $(srcdir)/Include/internal/pycore_uop_metadata.h.new
$(UPDATE_FILE) $(srcdir)/Python/executor_cases.c.h $(srcdir)/Python/executor_cases.c.h.new
$(UPDATE_FILE) $(srcdir)/Python/abstract_interp_cases.c.h $(srcdir)/Python/abstract_interp_cases.c.h.new
$(UPDATE_FILE) $(srcdir)/Lib/_opcode_metadata.py $(srcdir)/Lib/_opcode_metadata.py.new

Python/compile.o: $(srcdir)/Include/internal/pycore_opcode_metadata.h
Expand Down Expand Up @@ -1896,6 +1889,7 @@ PYTHON_HEADERS= \
$(srcdir)/Include/internal/pycore_unicodeobject.h \
$(srcdir)/Include/internal/pycore_unicodeobject_generated.h \
$(srcdir)/Include/internal/pycore_uops.h \
$(srcdir)/Include/internal/pycore_uop_metadata.h \
$(srcdir)/Include/internal/pycore_warnings.h \
$(srcdir)/Include/internal/pycore_weakref.h \
$(DTRACE_HEADERS) \
Expand Down
Loading

0 comments on commit cf884d8

Please sign in to comment.