Skip to content

Commit 2daa0e4

Browse files
JIT optimizer: Ignore escaping functions if inputs are pure
1 parent 12ce16b commit 2daa0e4

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

Python/optimizer_cases.c.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/cases_generator/generators_common.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ class Emitter:
106106
out: CWriter
107107
labels: dict[str, Label]
108108
_replacers: dict[str, ReplacementFunctionType]
109+
cannot_escape: bool
109110

110-
def __init__(self, out: CWriter, labels: dict[str, Label]):
111+
def __init__(self, out: CWriter, labels: dict[str, Label], cannot_escape: bool = False):
111112
self._replacers = {
112113
"EXIT_IF": self.exit_if,
113114
"DEOPT_IF": self.deopt_if,
@@ -127,6 +128,7 @@ def __init__(self, out: CWriter, labels: dict[str, Label]):
127128
}
128129
self.out = out
129130
self.labels = labels
131+
self.cannot_escape = cannot_escape
130132

131133
def dispatch(
132134
self,
@@ -238,7 +240,8 @@ def decref_inputs(
238240
next(tkn_iter)
239241
self._print_storage("DECREF_INPUTS", storage)
240242
try:
241-
storage.close_inputs(self.out)
243+
if not self.cannot_escape:
244+
storage.close_inputs(self.out)
242245
except StackError as ex:
243246
raise analysis_error(ex.args[0], tkn)
244247
except Exception as ex:
@@ -476,7 +479,7 @@ def emit_SimpleStmt(
476479
reachable = True
477480
tkn = stmt.contents[-1]
478481
try:
479-
if stmt in uop.properties.escaping_calls:
482+
if stmt in uop.properties.escaping_calls and not self.cannot_escape:
480483
escape = uop.properties.escaping_calls[stmt]
481484
if escape.kills is not None:
482485
self.stackref_kill(escape.kills, storage, True)
@@ -513,7 +516,7 @@ def emit_SimpleStmt(
513516
self.out.emit(tkn)
514517
else:
515518
self.out.emit(tkn)
516-
if stmt in uop.properties.escaping_calls:
519+
if stmt in uop.properties.escaping_calls and not self.cannot_escape:
517520
self.emit_reload(storage)
518521
return reachable, None, storage
519522
except StackError as ex:

Tools/cases_generator/optimizer_generator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ def __init__(self, out: CWriter, labels: dict[str, Label], original_uop: Uop, st
245245
outp.name: self.emit_stackref_override for outp in self.original_uop.stack.outputs
246246
}
247247
self._replacers = {**self._replacers, **overrides}
248+
self.cannot_escape = True
248249

249250
def emit_to_with_replacement(
250251
self,

0 commit comments

Comments
 (0)