-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-132732: Automatically constant evaluate pure operations #132733
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
1ffbb6b
691084d
b89e4dc
0959918
2541683
d5b2208
71ced86
a10d5a1
d22f165
8ae38c7
712a810
dc2d922
f3f2a69
53ce10f
17634a8
4937c2f
ae08b79
c0c6600
6bdd3f9
de8e170
c2f8e22
ac7e343
05b822f
b4c2e93
d229f57
c4aae6c
8552182
703dfc9
b278734
73a8b00
4116a31
548b67c
74a0208
6a5dc12
3896775
507c80a
dc68b45
41a271c
e88b71a
866510f
01be0c6
fce79a6
9bef4a4
1f76e2c
efb9888
029c92b
738d20e
202af76
4c0c52c
e24e9a3
f362866
d54a6f2
2644cb9
634ed26
0e9ce84
f2fc3fc
2408fb0
e40cb06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,11 +22,9 @@ | |
write_header, | ||
Emitter, | ||
TokenIterator, | ||
emit_to, | ||
skip_to, | ||
) | ||
from cwriter import CWriter | ||
from typing import TextIO, Callable | ||
from typing import TextIO | ||
from lexer import Token | ||
from stack import Local, Stack, StackError, Storage | ||
|
||
|
@@ -87,7 +85,7 @@ def stackref_type_name(var: StackItem) -> str: | |
assert False, "Unsafe to convert a symbol to an array-like StackRef." | ||
if var.type: | ||
return var.type | ||
return f"_PyStackRef " | ||
return "_PyStackRef " | ||
|
||
def declare_variables(uop: Uop, out: CWriter, skip_inputs: bool) -> None: | ||
variables = {"unused"} | ||
|
@@ -210,17 +208,19 @@ def write_uop_pure_evaluation_region_header( | |
# No reference management of outputs needed. | ||
for var in storage.outputs: | ||
var.in_local = True | ||
emitter.emit_tokens(uop, storage, None, False, is_abstract=True) | ||
emitter.emit("/* Start of pure uop copied from bytecodes for constant evaluation */\n") | ||
emitter.emit_tokens(uop, storage, inst=None, emit_braces=False, is_abstract=True) | ||
out.start_line() | ||
emitter.emit("/* End of pure uop copied from bytecodes for constant evaluation */\n") | ||
# Finally, assign back the output stackrefs to symbolics. | ||
for outp in uop.stack.outputs: | ||
# All new stackrefs are created from new references. | ||
# That's how the stackref contract works. | ||
if not outp.peek: | ||
out.emit(f"{outp.name} = sym_new_const_steal(ctx, PyStackRef_AsPyObjectBorrow({outp.name}_stackref));\n") | ||
emitter.emit(f"{outp.name} = sym_new_const_steal(ctx, PyStackRef_AsPyObjectBorrow({outp.name}_stackref));\n") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may just be a week of conference sleep schedule, but my brain hurts trying to reason about the refcounting here. Why are we stealing a borrow? Shouldn't we be stealing a steal, or borrowing a borrow? Currently:
(I haven't looked at the peek code yet.) Another option, that I might like better, is making all of our constant symbols use stackrefs under-the-hood. Then we could avoid refcounting entirely. But that's a bigger change that could happen later if needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first thing is the tag bit is always unsets for new objects, at least for pure operations. If it's set, then the thing is likely immortal anyways, which we can ignore reference count semantics for. This ignores the FT build's deferred references. On the stackref side, I could just change it to use PyStackRef_AsPyObjectSteal, as this seems more correct. |
||
else: | ||
out.emit(f"{outp.name} = sym_new_const(ctx, PyStackRef_AsPyObjectBorrow({outp.name}_stackref));\n") | ||
storage.flush(out) | ||
emitter.emit(f"{outp.name} = sym_new_const(ctx, PyStackRef_AsPyObjectBorrow({outp.name}_stackref));\n") | ||
storage.flush(out) | ||
emitter.emit("}\n") | ||
emitter.emit("else {\n") | ||
|
||
|
@@ -266,7 +266,8 @@ def write_uop( | |
out.start_line() | ||
if override: | ||
emitter = OptimizerEmitter(out, {}) | ||
_, storage = emitter.emit_tokens(override, storage, None, False, is_abstract=True) | ||
_, storage = emitter.emit_tokens(override, storage, inst=None, | ||
emit_braces=False, is_abstract=True) | ||
storage.flush(out) | ||
else: | ||
emit_default(out, uop, stack) | ||
|
Uh oh!
There was an error while loading. Please reload this page.