MCPcopy Index your code
hub / github.com/python/cpython / validate_uop

Function validate_uop

Tools/cases_generator/optimizer_generator.py:35–73  ·  view source on GitHub ↗

Check that the overridden uop (defined in 'optimizer_bytecodes.c') has the same stack effects as the original uop (defined in 'bytecodes.c'). Ensure that: - The number of inputs and outputs is the same. - The names of the inputs and outputs are the same (excep

(override: Uop, uop: Uop)

Source from the content-addressed store, hash-verified

33
34
35def validate_uop(override: Uop, uop: Uop) -> None:
36 """
37 Check that the overridden uop (defined in 'optimizer_bytecodes.c')
38 has the same stack effects as the original uop (defined in 'bytecodes.c').
39
40 Ensure that:
41 - The number of inputs and outputs is the same.
42 - The names of the inputs and outputs are the same
43 (except for 'unused' which is ignored).
44 - The sizes of the inputs and outputs are the same.
45 """
46 for stack_effect in ('inputs', 'outputs'):
47 orig_effects = getattr(uop.stack, stack_effect)
48 new_effects = getattr(override.stack, stack_effect)
49
50 if len(orig_effects) != len(new_effects):
51 msg = (
52 f"{uop.name}: Must have the same number of {stack_effect} "
53 "in bytecodes.c and optimizer_bytecodes.c "
54 f"({len(orig_effects)} != {len(new_effects)})"
55 )
56 raise analysis_error(msg, override.body.open)
57
58 for orig, new in zip(orig_effects, new_effects, strict=True):
59 if orig.name != new.name and orig.name != "unused" and new.name != "unused":
60 msg = (
61 f"{uop.name}: {stack_effect.capitalize()} must have "
62 "equal names in bytecodes.c and optimizer_bytecodes.c "
63 f"({orig.name} != {new.name})"
64 )
65 raise analysis_error(msg, override.body.open)
66
67 if orig.size != new.size:
68 msg = (
69 f"{uop.name}: {stack_effect.capitalize()} must have "
70 "equal sizes in bytecodes.c and optimizer_bytecodes.c "
71 f"({orig.size!r} != {new.size!r})"
72 )
73 raise analysis_error(msg, override.body.open)
74
75
76def type_name(var: StackItem) -> str:

Callers 1

Calls 2

analysis_errorFunction · 0.90
capitalizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…