Skip to content

Commit e77d92a

Browse files
committed
cut of recursion behind a TruffleBoundary call
1 parent 820b543 commit e77d92a

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/AbstractImportNode.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import com.oracle.truffle.api.TruffleLanguage.LanguageReference;
7979
import com.oracle.truffle.api.dsl.Cached;
8080
import com.oracle.truffle.api.dsl.Specialization;
81+
import com.oracle.truffle.api.frame.MaterializedFrame;
8182
import com.oracle.truffle.api.frame.VirtualFrame;
8283
import com.oracle.truffle.api.instrumentation.StandardTags;
8384
import com.oracle.truffle.api.instrumentation.Tag;
@@ -267,11 +268,15 @@ static Object genericImport(VirtualFrame frame, PythonContext context, String na
267268
}
268269
if (level == 0) {
269270
String front = name.substring(0, dotIndex);
270-
// recursion up number of dots in the name
271-
return levelZeroNoFromlist(frame, context, front, null, null, 0,
271+
// recursion up number of dots in the name. we use a boundary call here to avoid PE going recursive
272+
return genericImportBoundary(frame.materialize(), context, front, null, PythonUtils.EMPTY_STRING_ARRAY, 0,
273+
null, // resolveName is not used with level == 0
272274
raiseNode, // raiseNode only needed if front.length() == 0 at this point
273275
getModuleNode, // used multiple times to get the 'front' module
274276
ensureInitialized, // used multiple times on the 'front' module
277+
null, // getPathNode is not used with fromList.length == 0
278+
null, // callHandleFromlist not used with fromList.length == 0
279+
null, // factory not used with fromList.length == 0
275280
findAndLoad); // used multiple times, but always to call the exact same function
276281
} else {
277282
int cutoff = nameLength - dotIndex;
@@ -297,6 +302,27 @@ static Object genericImport(VirtualFrame frame, PythonContext context, String na
297302
}
298303
}
299304
}
305+
306+
@TruffleBoundary
307+
static Object genericImportBoundary(MaterializedFrame frame, PythonContext context, String name, Object globals, String[] fromList, int level,
308+
ResolveName resolveName,
309+
PRaiseNode raiseNode,
310+
PyDictGetItem getModuleNode,
311+
EnsureInitializedNode ensureInitialized,
312+
PyObjectLookupAttr getPathNode,
313+
PyObjectCallMethodObjArgs callHandleFromlist,
314+
PythonObjectFactory factory,
315+
FindAndLoad findAndLoad) {
316+
return genericImport(frame, context, name, globals, fromList, level,
317+
resolveName,
318+
raiseNode,
319+
getModuleNode,
320+
ensureInitialized,
321+
getPathNode,
322+
callHandleFromlist,
323+
factory,
324+
findAndLoad);
325+
}
300326
}
301327

302328
/**

0 commit comments

Comments
 (0)