Skip to content

Commit cbe46bf

Browse files
committed
delete obsolete code for caching stdlib modules
1 parent fbb2366 commit cbe46bf

File tree

2 files changed

+0
-151
lines changed

2 files changed

+0
-151
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,6 @@ protected void initializeMultipleContexts() {
737737
}
738738

739739
private final ConcurrentHashMap<String, CallTarget> cachedCode = new ConcurrentHashMap<>();
740-
private final ConcurrentHashMap<String, String[]> cachedCodeModulePath = new ConcurrentHashMap<>();
741740

742741
@TruffleBoundary
743742
public CallTarget cacheCode(String filename, Supplier<CallTarget> createCode) {
@@ -747,23 +746,6 @@ public CallTarget cacheCode(String filename, Supplier<CallTarget> createCode) {
747746
});
748747
}
749748

750-
@TruffleBoundary
751-
public String[] cachedCodeModulePath(String name) {
752-
return cachedCodeModulePath.get(name);
753-
}
754-
755-
@TruffleBoundary
756-
public boolean hasCachedCode(String name) {
757-
return cachedCode.get(name) != null;
758-
}
759-
760-
@TruffleBoundary
761-
public CallTarget cacheCode(String filename, Supplier<CallTarget> createCode, String[] modulepath) {
762-
CallTarget ct = cacheCode(filename, createCode);
763-
cachedCodeModulePath.computeIfAbsent(filename, t -> modulepath);
764-
return ct;
765-
}
766-
767749
@Override
768750
protected boolean isThreadAccessAllowed(Thread thread, boolean singleThreaded) {
769751
if (singleThreaded) {

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

Lines changed: 0 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -341,139 +341,6 @@ private static Object[] convertToObjectArray(String[] arr) {
341341
return objectArr;
342342
}
343343

344-
@Builtin(name = "cache_module_code", minNumOfPositionalArgs = 3)
345-
@GenerateNodeFactory
346-
public abstract static class CacheModuleCode extends PythonTernaryBuiltinNode {
347-
private static final TruffleLogger LOGGER = PythonLanguage.getLogger(CacheModuleCode.class);
348-
349-
@Specialization
350-
public Object run(String modulename, String moduleFile, @SuppressWarnings("unused") PNone modulepath) {
351-
return doCache(modulename, moduleFile, PythonUtils.EMPTY_STRING_ARRAY, PythonContext.get(this), getLanguage());
352-
}
353-
354-
@Specialization
355-
public Object run(String modulename, String moduleFile, PList modulepath,
356-
@Cached SequenceStorageNodes.LenNode lenNode,
357-
@Shared("cast") @Cached CastToJavaStringNode castString) {
358-
SequenceStorage sequenceStorage = modulepath.getSequenceStorage();
359-
int n = lenNode.execute(sequenceStorage);
360-
Object[] pathList = sequenceStorage.getInternalArray();
361-
assert n <= pathList.length;
362-
String[] paths = new String[n];
363-
for (int i = 0; i < n; i++) {
364-
try {
365-
paths[i] = castString.execute(pathList[i]);
366-
} catch (CannotCastException e) {
367-
CompilerDirectives.transferToInterpreterAndInvalidate();
368-
throw new IllegalStateException();
369-
}
370-
}
371-
return doCache(modulename, moduleFile, paths, PythonContext.get(this), getLanguage());
372-
}
373-
374-
private Object doCache(String modulename, String moduleFile, String[] modulepath, PythonContext ctxt, PythonLanguage lang) {
375-
assert !ctxt.isInitialized() : "this can only be called during initialization";
376-
final CallTarget ct = lang.cacheCode(moduleFile, () -> null);
377-
if (ct == null) {
378-
throw raise(NotImplementedError, "cannot cache something we haven't cached before");
379-
}
380-
return cacheWithModulePath(modulename, modulepath, lang, ct);
381-
}
382-
383-
private static Object cacheWithModulePath(String modulename, String[] modulepath, PythonLanguage lang, final CallTarget ct) {
384-
CallTarget cachedCt = lang.cacheCode(modulename, () -> ct, modulepath);
385-
if (cachedCt != ct) {
386-
LOGGER.log(Level.WARNING, () -> "Invalid attempt to re-cache " + modulename);
387-
}
388-
return PNone.NONE;
389-
}
390-
391-
@Specialization
392-
public Object run(String modulename, PCode code, @SuppressWarnings("unused") PNone modulepath) {
393-
final CallTarget ct = CodeNodes.GetCodeCallTargetNode.getUncached().execute(code);
394-
if (ct == null) {
395-
throw raise(NotImplementedError, "cannot cache a synthetically constructed code object");
396-
}
397-
return cacheWithModulePath(modulename, PythonUtils.EMPTY_STRING_ARRAY, getLanguage(), ct);
398-
}
399-
400-
@Specialization
401-
public Object run(String modulename, PCode code, PList modulepath,
402-
@Shared("cast") @Cached CastToJavaStringNode castString) {
403-
final CallTarget ct = CodeNodes.GetCodeCallTargetNode.getUncached().execute(code);
404-
if (ct == null) {
405-
throw raise(NotImplementedError, "cannot cache a synthetically constructed code object");
406-
}
407-
Object[] pathList = modulepath.getSequenceStorage().getInternalArray();
408-
String[] paths = new String[pathList.length];
409-
for (int i = 0; i < pathList.length; i++) {
410-
try {
411-
paths[i] = castString.execute(pathList[i]);
412-
} catch (CannotCastException e) {
413-
CompilerDirectives.transferToInterpreterAndInvalidate();
414-
throw new IllegalStateException();
415-
}
416-
}
417-
return cacheWithModulePath(modulename, paths, getLanguage(), ct);
418-
}
419-
}
420-
421-
@Builtin(name = "has_cached_code", minNumOfPositionalArgs = 1)
422-
@GenerateNodeFactory
423-
public abstract static class HasCachedCode extends PythonUnaryBuiltinNode {
424-
private static final TruffleLogger LOGGER = PythonLanguage.getLogger(HasCachedCode.class);
425-
426-
@Specialization
427-
public boolean run(String modulename) {
428-
boolean b = PythonContext.get(this).getOption(PythonOptions.WithCachedSources) && getLanguage().hasCachedCode(modulename);
429-
if (b) {
430-
LOGGER.log(Level.FINEST, () -> "Cached code re-used for " + modulename);
431-
}
432-
return b;
433-
}
434-
}
435-
436-
@Builtin(name = "get_cached_code_path", minNumOfPositionalArgs = 1)
437-
@GenerateNodeFactory
438-
public abstract static class CachedCodeIsPackage extends PythonUnaryBuiltinNode {
439-
private static final TruffleLogger LOGGER = PythonLanguage.getLogger(CachedCodeIsPackage.class);
440-
441-
@Specialization
442-
public Object run(String modulename) {
443-
String[] modulePath = null;
444-
if (PythonContext.get(this).getOption(PythonOptions.WithCachedSources)) {
445-
modulePath = getLanguage().cachedCodeModulePath(modulename);
446-
}
447-
if (modulePath != null) {
448-
Object[] outPath = new Object[modulePath.length];
449-
PythonUtils.arraycopy(modulePath, 0, outPath, 0, modulePath.length);
450-
LOGGER.log(Level.FINEST, () -> "Cached code re-used for " + modulename);
451-
return factory().createList(outPath);
452-
} else {
453-
return PNone.NONE;
454-
}
455-
}
456-
457-
@Fallback
458-
public Object run(@SuppressWarnings("unused") Object modulename) {
459-
return PNone.NONE;
460-
}
461-
}
462-
463-
@Builtin(name = "get_cached_code", minNumOfPositionalArgs = 1)
464-
@GenerateNodeFactory
465-
public abstract static class GetCachedCode extends PythonUnaryBuiltinNode {
466-
@Specialization
467-
public Object run(String modulename) {
468-
final CallTarget ct = getLanguage().cacheCode(modulename, () -> null);
469-
if (ct == null) {
470-
throw raise(ImportError, ErrorMessages.NO_CACHED_CODE, modulename);
471-
} else {
472-
return factory().createCode((RootCallTarget) ct);
473-
}
474-
}
475-
}
476-
477344
@Builtin(name = "read_file", minNumOfPositionalArgs = 1)
478345
@GenerateNodeFactory
479346
public abstract static class ReadFileNode extends PythonUnaryBuiltinNode {

0 commit comments

Comments
 (0)