Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-107557: Setup abstract interpretation#107847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Fidget-Spinner merged 54 commits intopython:mainfromFidget-Spinner:partition_algo
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
54 commits
Select commitHold shift + click to select a range
d20fbb8
gh-107557: Tier 2 abstract interpreter barebones
Fidget-SpinnerAug 2, 2023
2aeea51
📜🤖 Added by blurb_it.
blurb-it[bot]Aug 2, 2023
1a728ab
Copy Guido's input and output code, and fix build
Fidget-SpinnerAug 2, 2023
17fccbc
fix separator
Fidget-SpinnerAug 2, 2023
a1da69d
credit Jules
Fidget-SpinnerAug 2, 2023
b458e17
add jules to co-authors
Fidget-SpinnerAug 2, 2023
f81f888
add pycore_optimizer.h to headers in makefile
Fidget-SpinnerAug 2, 2023
0020320
fix: remove whitespace
Fidget-SpinnerAug 2, 2023
1f93072
fix make smelly
Fidget-SpinnerAug 2, 2023
dac63e3
fix: build
Fidget-SpinnerAug 2, 2023
e62e015
fix wrong symbol
Fidget-SpinnerAug 2, 2023
a7f654c
ignore static globals check for abstract interpreter
Fidget-SpinnerAug 2, 2023
f4040b8
Merge remote-tracking branch 'upstream/main' into abstract_interpreter
Fidget-SpinnerAug 4, 2023
ec58145
merge Guido's changes
Fidget-SpinnerAug 4, 2023
4292767
remove unused stuff
Fidget-SpinnerAug 4, 2023
fdcca90
Turn on the abstract interpreter
Fidget-SpinnerAug 4, 2023
5110fb9
Merge remote-tracking branch 'upstream/main' into abstract_interpreter
Fidget-SpinnerAug 5, 2023
9f443a2
Merge remote-tracking branch 'origin/abstract_interpreter' into parti…
Fidget-SpinnerAug 5, 2023
7632ed1
(leaky) data structures for constant propagation
Fidget-SpinnerAug 5, 2023
0d0c4c4
(with cycles) try to fix the type prop
Fidget-SpinnerAug 6, 2023
4c8953e
fix: cycles
Fidget-SpinnerAug 6, 2023
3bd36fa
cleanup
Fidget-SpinnerAug 6, 2023
229097f
Fix+Refactor: Handling of root nodes in special-cased type prop (#40)
JuliaPooAug 7, 2023
ca0fab7
partially partially evaluate
Fidget-SpinnerAug 8, 2023
68c684f
rename vars
Fidget-SpinnerAug 8, 2023
46c5777
fixx off by one
Fidget-SpinnerAug 8, 2023
b839ee4
partial eval working for real this time
Fidget-SpinnerAug 9, 2023
6ecf3d2
Fix: Inconsistent `AbstractInterpContext` used in `PARTITIONNODE_OVER…
JuliaPooAug 9, 2023
b6eeb25
fix test, refactor, bugfix
Fidget-SpinnerAug 9, 2023
d5cceb9
re-compute jump offsets and targets
Fidget-SpinnerAug 10, 2023
8c0d65f
Fix+Refactor: Extra EXIT_TRACE emitted (#42)
JuliaPooAug 10, 2023
95db909
fix: overallocate buffer and virtual/real stack offset calculation
Fidget-SpinnerAug 10, 2023
1e05ef8
more bugfix
Fidget-SpinnerAug 10, 2023
d7d8b52
Merge remote-tracking branch 'upstream/main' into partition_algo
Fidget-SpinnerAug 10, 2023
4d7abc7
Perf+Cleanup: Removed temporary allocation in `remove_duplicate_save_…
JuliaPooAug 11, 2023
3d76f9a
clean up code
Fidget-SpinnerAug 11, 2023
e81def2
Merge branch 'partition_algo' of https://github.com/Fidget-Spinner/cp…
Fidget-SpinnerAug 11, 2023
9a5a3f7
make static
Fidget-SpinnerAug 11, 2023
df490d0
make types static
Fidget-SpinnerAug 11, 2023
1e4fc94
make const and ignore in c analyzer
Fidget-SpinnerAug 11, 2023
6de77a7
fix c-analyzer ignored list
Fidget-SpinnerAug 11, 2023
a11fc80
more cleanup
Fidget-SpinnerAug 13, 2023
c61015b
Merge remote-tracking branch 'upstream/main' into partition_algo
Fidget-SpinnerAug 13, 2023
56c62eb
regen files
Fidget-SpinnerAug 13, 2023
3c08ebe
address review
Fidget-SpinnerAug 14, 2023
d5f16be
regen
Fidget-SpinnerAug 14, 2023
1e61c49
and env var to block tests
Fidget-SpinnerAug 14, 2023
6c24b49
regen again
Fidget-SpinnerAug 14, 2023
2be404d
fix generated files
Fidget-SpinnerAug 14, 2023
29e255d
Address review
Fidget-SpinnerAug 15, 2023
3c44117
fix up INSERT
Fidget-SpinnerAug 15, 2023
b758b47
remove experimental parts
Fidget-SpinnerAug 15, 2023
80c7f18
revert more changes
Fidget-SpinnerAug 15, 2023
6a2b204
use memmove
Fidget-SpinnerAug 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
address review
  • Loading branch information
@Fidget-Spinner
Fidget-Spinner committedAug 14, 2023
commit3c08ebeed2dc7ac6f8751faed8a1aa778376f2c7
2 changes: 1 addition & 1 deletionInclude/internal/pycore_uops.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,7 +8,7 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#define _Py_UOP_MAX_TRACE_LENGTH256
#define _Py_UOP_MAX_TRACE_LENGTH64

typedef struct {
int32_t opcode;
Expand Down
1 change: 1 addition & 0 deletionsLib/test/test_capi/test_misc.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2643,5 +2643,6 @@ def testfunc(loops):
binop_count = [opname for opname, _, _ in ex if opname == "_BINARY_OP_ADD_INT"]
self.assertEqual(len(binop_count), 1)


if __name__ == "__main__":
unittest.main()
2 changes: 2 additions & 0 deletionsMakefile.pre.in
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1553,10 +1553,12 @@ regen-cases:
-m $(srcdir)/Include/internal/pycore_opcode_metadata.h.new \
-e $(srcdir)/Python/executor_cases.c.h.new \
-p $(srcdir)/Lib/_opcode_metadata.py.new \
-a $(srcdir)/Python/abstract_interp_cases.c.h.new \
$(srcdir)/Python/bytecodes.c
$(UPDATE_FILE) $(srcdir)/Python/generated_cases.c.h $(srcdir)/Python/generated_cases.c.h.new
$(UPDATE_FILE) $(srcdir)/Include/internal/pycore_opcode_metadata.h $(srcdir)/Include/internal/pycore_opcode_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
1 change: 1 addition & 0 deletionsPython/abstract_interp_cases.c.h
View file
Open in desktop

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

3 changes: 1 addition & 2 deletionsPython/bytecodes.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3743,13 +3743,12 @@ dummy_func(
return frame;
}

op(INSERT, (--)) {
op(INSERT, (stuff[oparg], top -- top, stuff[oparg])) {
// Inserts TOS at position specified by oparg
PyObject *tos = TOP();
for (int i = 1; i < oparg + 1; i++) {
stack_pointer[i] = stack_pointer[i - 1];
Copy link
Member

Choose a reason for hiding this comment

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

Hm, doesn't this repeat the first stack element over and over? Maybememmove() would do what you want? (It is supposed to be good at overlaps, unlikememcpy().)

Copy link
MemberAuthor

@Fidget-SpinnerFidget-SpinnerAug 15, 2023
edited
Loading

Choose a reason for hiding this comment

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

Woops yeah thanks for catching this! Forgot to negate the indexes.

gvanrossum reacted with laugh emoji
}
POKE(oparg, tos);
}


Expand Down
7 changes: 6 additions & 1 deletionPython/executor_cases.c.h
View file
Open in desktop

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

2 changes: 1 addition & 1 deletionPython/optimizer_analysis.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -173,7 +173,7 @@ _Py_UOpsAbstractInterpContext_New(int stack_len, int locals_len, int curr_stackl
return NULL;
}

for (int i = 0; i < (locals_len + stack_len) * 2; i++) {
for (int i = 0; i < (locals_len + stack_len); i++) {
locals_with_stack[i] = PARTITIONNODE_NULLROOT;
}

Expand Down
9 changes: 3 additions & 6 deletionsTools/cases_generator/generate_cases.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,7 @@

INSTR_FMT_PREFIX = "INSTR_FMT_"

#@TODO generate all these after updating the DSL
# TODO: generate all these after updating the DSL
SPECIALLY_HANDLED_ABSTRACT_INSTR = {
"LOAD_FAST",
"LOAD_FAST_CHECK",
Expand DownExpand Up@@ -135,7 +135,7 @@ def effect_str(effects: list[StackEffect]) -> str:
pushed: str | None
match thing:
case parsing.InstDef():
if thing.kind!= "op" or(thing.kind != "inst" andself.instrs[thing.name].is_viable_uop()):
if thing.kind== "instr" or self.instrs[thing.name].is_viable_uop():
instr = self.instrs[thing.name]
popped = effect_str(instr.input_effects)
pushed = effect_str(instr.output_effects)
Expand DownExpand Up@@ -641,17 +641,14 @@ def write_abstract_interpreter_instructions(
for thing in self.everything:
match thing:
case OverriddenInstructionPlaceHolder():
# TODO: Is this helpful?
self.write_overridden_instr_place_holder(thing)
pass
case parsing.InstDef():
instr = AbstractInstruction(self.instrs[thing.name].inst)
if instr.is_viable_uop() and instr.name not in SPECIALLY_HANDLED_ABSTRACT_INSTR:
self.out.emit("")
with self.out.block(f"case {thing.name}:"):
instr.write(self.out, tier=TIER_TWO)
Copy link
Member

Choose a reason for hiding this comment

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

Note that ingh-107760 I'm removingInstruction.write altogether.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if you even need theAbstractInstruction class. Maybe you could just call a different method onInstruction?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I was thinking of how we might need to expand on it more in the future, so a separate class might be better.

Copy link
Member

Choose a reason for hiding this comment

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

When that happens in the future you can refactor the code. Until then, I recommend less code.

As you may have noticed this code gets refactored a lot. :-) It's easy because the generator is not a public API -- all we care about is whether it generates a handful of files correctly from bytecodes.c at build time. But I worry about copying and pasting code, because that's harder to refactor.

self.out.emit("break;")
# elif instr.kind != "op":
# print(f"NOTE: {thing.name} is not a viable uop")
case parsing.Macro():
pass
case parsing.Pseudo():
Expand Down
9 changes: 0 additions & 9 deletionsTools/cases_generator/instructions.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -255,15 +255,6 @@ def __init__(self, inst: parsing.InstDef):

def write(self, out: Formatter, tier: Tiers = TIER_ONE) -> None:
"""Write one abstract instruction, sans prologue and epilogue."""
# Write a static assertion that a family's cache size is correct
if family := self.family:
if self.name == family.name:
if cache_size := family.size:
out.emit(
f"static_assert({cache_size} == "
f'{self.cache_offset}, "incorrect cache size");'
)

stacking.write_single_instr_for_abstract_interp(self, out)

def write_body(
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp