Skip to content

Commit 8c69cb3

Browse files
committed
add check-hash-based-pycs cli option
1 parent b408c53 commit 8c69cb3

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public static void main(String[] args) {
8989
private Map<String, String> enginePolyglotOptions;
9090
private boolean dontWriteBytecode = false;
9191
private String warnOptions = null;
92+
private String checkHashPycsMode = "default";
9293

9394
@Override
9495
protected List<String> preprocessArguments(List<String> givenArgs, Map<String, String> polyglotOptions) {
@@ -240,6 +241,10 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
240241
addRelaunchArg(arg);
241242
unrecognized.add(arg);
242243
break;
244+
case "--check-hash-based-pycs":
245+
i += 1;
246+
checkHashPycsMode = arguments.get(i);
247+
break;
243248
default:
244249
if (!arg.startsWith("-")) {
245250
inputFile = arg;
@@ -453,6 +458,8 @@ protected void launch(Builder contextBuilder) {
453458
contextBuilder.option("python.TerminalWidth", Integer.toString(consoleHandler.getTerminalWidth()));
454459
contextBuilder.option("python.TerminalHeight", Integer.toString(consoleHandler.getTerminalHeight()));
455460

461+
contextBuilder.option("python.CheckHashPycsMode", checkHashPycsMode);
462+
456463
if (multiContext) {
457464
contextBuilder.engine(Engine.newBuilder().allowExperimentalOptions(true).options(enginePolyglotOptions).build());
458465
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
import com.oracle.graal.python.parser.sst.SerializationUtils;
8787
import com.oracle.graal.python.runtime.ExecutionContext.ForeignCallContext;
8888
import com.oracle.graal.python.runtime.PythonContext;
89+
import com.oracle.graal.python.runtime.PythonCore;
8990
import com.oracle.graal.python.runtime.PythonOptions;
9091
import com.oracle.graal.python.runtime.exception.PException;
9192
import com.oracle.graal.python.util.PythonUtils;
@@ -124,6 +125,14 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
124125
return ImpModuleBuiltinsFactory.getFactories();
125126
}
126127

128+
@Override
129+
public void postInitialize(PythonCore core) {
130+
super.postInitialize(core);
131+
PythonContext context = core.getContext();
132+
PythonModule mod = core.lookupBuiltinModule("_imp");
133+
mod.setAttribute("check_hash_based_pycs", context.getOption(PythonOptions.CheckHashPycsMode));
134+
}
135+
127136
@Builtin(name = "acquire_lock")
128137
@GenerateNodeFactory
129138
public abstract static class AcquireLock extends PythonBuiltinNode {
@@ -498,7 +507,7 @@ public abstract static class CreateBuiltin extends PythonBuiltinNode {
498507
@Specialization
499508
@TruffleBoundary
500509
public Object run(PythonObject moduleSpec,
501-
@Cached CastToJavaStringNode toJavaStringNode) {
510+
@Cached CastToJavaStringNode toJavaStringNode) {
502511
Object name = moduleSpec.getAttribute("name");
503512
PythonModule builtinModule = getCore().lookupBuiltinModule(toJavaStringNode.execute(name));
504513
if (builtinModule != null) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ private PythonOptions() {
120120
@Option(category = OptionCategory.USER, help = "Equivalent to setting the PYTHONWARNINGS environment variable for the standard launcher.", stability = OptionStability.STABLE) //
121121
public static final OptionKey<String> WarnOptions = new OptionKey<>("");
122122

123+
@Option(category = OptionCategory.USER, help = "Value of the --check-hash-based-pycs command line option" +
124+
"- 'default' means the 'check_source' flag in hash-based pycs" +
125+
" determines invalidation" +
126+
"- 'always' causes the interpreter to hash the source file for" +
127+
" invalidation regardless of value of 'check_source' bit" +
128+
"- 'never' causes the interpreter to always assume hash-based pycs are" +
129+
" valid" +
130+
"The default value is 'default'." +
131+
"See PEP 552 'Deterministic pycs' for more details.", stability = OptionStability.STABLE) //
132+
public static final OptionKey<String> CheckHashPycsMode = new OptionKey<>("default");
133+
123134
@Option(category = OptionCategory.INTERNAL, help = "Set the location of C API home. Overrides any environment variables or Java options.", stability = OptionStability.STABLE) //
124135
public static final OptionKey<String> CAPI = new OptionKey<>("");
125136

0 commit comments

Comments
 (0)