Skip to content

Commit 048f617

Browse files
committed
Force split on Pattern and Scanner regexp entry points
1 parent 545dde7 commit 048f617

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,16 @@ public Object doIt(PFunction func,
504504
}
505505
}
506506

507+
@Builtin(name = "force_split_direct_calls", minNumOfPositionalArgs = 1)
508+
@GenerateNodeFactory
509+
public abstract static class ForceSplitDirectCallsNode extends PythonUnaryBuiltinNode {
510+
@Specialization
511+
public Object doIt(PFunction func) {
512+
func.setForceSplitDirectCalls(true);
513+
return func;
514+
}
515+
}
516+
507517
@Builtin(name = "get_toolchain_tools_for_venv")
508518
@TypeSystemReference(PythonArithmeticTypes.class)
509519
@GenerateNodeFactory

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PFunction.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
public final class PFunction extends PythonObject {
5757
private TruffleString name;
5858
private TruffleString qualname;
59+
private boolean forceSplitDirectCalls;
5960
private final Assumption codeStableAssumption;
6061
private final Assumption defaultsStableAssumption;
6162
private final PythonObject globals;
@@ -89,6 +90,7 @@ public PFunction(PythonLanguage lang, TruffleString name, TruffleString qualname
8990
this.closure = closure;
9091
this.codeStableAssumption = codeStableAssumption;
9192
this.defaultsStableAssumption = defaultsStableAssumption;
93+
this.forceSplitDirectCalls = false;
9294
}
9395

9496
public Assumption getCodeStableAssumption() {
@@ -131,6 +133,14 @@ public void setBuiltin(boolean builtin) {
131133
isBuiltin = builtin;
132134
}
133135

136+
public void setForceSplitDirectCalls(boolean forceSplitDirectCalls) {
137+
this.forceSplitDirectCalls = forceSplitDirectCalls;
138+
}
139+
140+
public boolean forceSplitDirectCalls() {
141+
return forceSplitDirectCalls;
142+
}
143+
134144
@Override
135145
public final String toString() {
136146
CompilerAsserts.neverPartOfCompilation();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/FunctionInvokeNode.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ public abstract class FunctionInvokeNode extends DirectInvokeNode {
7272
private final PCell[] closure;
7373
protected final boolean isBuiltin;
7474

75-
protected FunctionInvokeNode(PFunction callee, CallTarget callTarget, PythonObject globals, PCell[] closure, boolean isBuiltin, boolean isGenerator) {
75+
protected FunctionInvokeNode(PFunction callee, CallTarget callTarget, PythonObject globals, PCell[] closure, boolean isBuiltin, boolean isGenerator, boolean split) {
7676
this.callee = callee;
7777
this.callNode = Truffle.getRuntime().createDirectCallNode(callTarget);
78-
if (isBuiltin && forceSplitBuiltins()) {
78+
if (split) {
7979
callNode.cloneCallTarget();
8080
}
8181
if (isGenerator && shouldInlineGenerators()) {
@@ -117,15 +117,15 @@ public final RootNode getCurrentRootNode() {
117117
@TruffleBoundary
118118
public static FunctionInvokeNode create(PFunction callee) {
119119
RootCallTarget callTarget = getCallTarget(callee);
120-
boolean builtin = isBuiltin(callee);
121-
return FunctionInvokeNodeGen.create(callee, callTarget, callee.getGlobals(), callee.getClosure(), builtin, callTarget.getRootNode() instanceof PBytecodeGeneratorFunctionRootNode);
120+
return FunctionInvokeNodeGen.create(callee, callTarget, callee.getGlobals(), callee.getClosure(), false, callTarget.getRootNode() instanceof PBytecodeGeneratorFunctionRootNode,
121+
callee.forceSplitDirectCalls());
122122
}
123123

124124
@TruffleBoundary
125125
public static FunctionInvokeNode create(PBuiltinFunction callee) {
126126
RootCallTarget callTarget = getCallTarget(callee);
127-
boolean builtin = isBuiltin(callee);
128-
return FunctionInvokeNodeGen.create(null, callTarget, null, null, builtin, false);
127+
boolean split = forceSplitBuiltins();
128+
return FunctionInvokeNodeGen.create(null, callTarget, null, null, true, false, split);
129129
}
130130

131131
/**
@@ -135,6 +135,6 @@ public static FunctionInvokeNode create(PBuiltinFunction callee) {
135135
*/
136136
@TruffleBoundary
137137
public static FunctionInvokeNode createBuiltinFunction(RootCallTarget callTarget) {
138-
return FunctionInvokeNodeGen.create(null, callTarget, null, null, true, false);
138+
return FunctionInvokeNodeGen.create(null, callTarget, null, null, true, false, forceSplitBuiltins());
139139
}
140140
}

graalpython/lib-graalpython/_sre.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,15 @@ def __class_getitem__(cls, item):
327327
def _search(self, string, pos, endpos, method=_METHOD_SEARCH, must_advance=False):
328328
return tregex_search(self, string, pos, endpos, method, must_advance)
329329

330+
@__graalpython__.force_split_direct_calls
330331
def search(self, string, pos=0, endpos=maxsize):
331332
return self._search(string, pos, endpos, method=_METHOD_SEARCH)
332333

334+
@__graalpython__.force_split_direct_calls
333335
def match(self, string, pos=0, endpos=maxsize):
334336
return self._search(string, pos, endpos, method=_METHOD_MATCH)
335337

338+
@__graalpython__.force_split_direct_calls
336339
def fullmatch(self, string, pos=0, endpos=maxsize):
337340
return self._search(string, pos, endpos, method=_METHOD_FULLMATCH)
338341

@@ -346,6 +349,7 @@ def __sanitize_out_type(self, elem):
346349
else:
347350
return str(elem)
348351

352+
@__graalpython__.force_split_direct_calls
349353
def finditer(self, string, pos=0, endpos=maxsize):
350354
for must_advance in [False, True]:
351355
if tregex_compile(self, _METHOD_SEARCH, must_advance) is None:
@@ -368,6 +372,7 @@ def __finditer_gen(self, string, substring, pos, endpos):
368372
must_advance = (result.getStart(0) == result.getEnd(0))
369373
return
370374

375+
@__graalpython__.force_split_direct_calls
371376
def findall(self, string, pos=0, endpos=maxsize):
372377
for must_advance in [False, True]:
373378
if tregex_compile(self, _METHOD_SEARCH, must_advance) is None:
@@ -392,9 +397,11 @@ def findall(self, string, pos=0, endpos=maxsize):
392397
must_advance = (result.getStart(0) == result.getEnd(0))
393398
return matchlist
394399

400+
@__graalpython__.force_split_direct_calls
395401
def sub(self, repl, string, count=0):
396402
return self.subn(repl, string, count)[0]
397403

404+
@__graalpython__.force_split_direct_calls
398405
def subn(self, repl, string, count=0):
399406
for must_advance in [False, True]:
400407
if tregex_compile(self, _METHOD_SEARCH, must_advance) is None:
@@ -440,6 +447,7 @@ def subn(self, repl, string, count=0):
440447
else:
441448
return "".join(result), n
442449

450+
@__graalpython__.force_split_direct_calls
443451
def split(self, string, maxsplit=0):
444452
for must_advance in [False, True]:
445453
if tregex_compile(self, _METHOD_SEARCH, must_advance) is None:
@@ -500,9 +508,11 @@ def __match_search(self, method):
500508
self.__must_advance = match.start() == self.__start
501509
return match
502510

511+
@__graalpython__.force_split_direct_calls
503512
def match(self):
504513
return self.__match_search(_METHOD_MATCH)
505514

515+
@__graalpython__.force_split_direct_calls
506516
def search(self):
507517
return self.__match_search(_METHOD_SEARCH)
508518

0 commit comments

Comments
 (0)