Skip to content

Commit fbc9168

Browse files
committed
[GR-14266] [GR-14015] Update truffle import and set options to stable that are
PullRequest: graalpython/423
2 parents 2442232 + 51b618a commit fbc9168

File tree

8 files changed

+107
-65
lines changed

8 files changed

+107
-65
lines changed

ci.jsonnet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
},
134134
environment +: {
135135
CI: "true",
136+
GRAALVM_CHECK_EXPERIMENTAL_OPTIONS: "true",
136137
PATH: "$JAVA_HOME/bin:$PATH",
137138
},
138139
},

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

Lines changed: 74 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public static void main(String[] args) {
7575
private VersionAction versionAction = VersionAction.None;
7676
private String sulongLibraryPath = null;
7777
private List<String> givenArguments;
78+
private boolean wantsExperimental = false;
7879

7980
@Override
8081
protected List<String> preprocessArguments(List<String> givenArgs, Map<String, String> polyglotOptions) {
@@ -144,48 +145,85 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
144145
versionAction = VersionAction.PrintAndContinue;
145146
break;
146147
case "-CC":
147-
if (i != defaultEnvironmentArgs.size()) {
148-
throw new IllegalArgumentException("-CC must be the first given argument");
148+
if (wantsExperimental) {
149+
if (i != defaultEnvironmentArgs.size() + 1) {
150+
// +1 because we need the --experimental-options
151+
throw new IllegalArgumentException("-CC must be the first given argument");
152+
}
153+
GraalPythonCC.main(arguments.subList(i + 1, arguments.size()).toArray(new String[0]));
154+
System.exit(0);
155+
} else {
156+
unrecognized.add(arg);
149157
}
150-
GraalPythonCC.main(arguments.subList(i + 1, arguments.size()).toArray(new String[0]));
151-
System.exit(0);
152158
break;
153159
case "-LD":
154-
if (i != defaultEnvironmentArgs.size()) {
155-
throw new IllegalArgumentException("-LD must be the first given argument");
160+
if (wantsExperimental) {
161+
if (i != defaultEnvironmentArgs.size() + 1) {
162+
// +1 because we need the --experimental-options
163+
throw new IllegalArgumentException("-LD must be the first given argument");
164+
}
165+
GraalPythonLD.main(arguments.subList(i + 1, arguments.size()).toArray(new String[0]));
166+
System.exit(0);
167+
} else {
168+
unrecognized.add(arg);
156169
}
157-
GraalPythonLD.main(arguments.subList(i + 1, arguments.size()).toArray(new String[0]));
158-
System.exit(0);
159170
break;
160171
case "-LLI":
161-
runLLI = true;
172+
if (wantsExperimental) {
173+
runLLI = true;
174+
} else {
175+
unrecognized.add(arg);
176+
}
162177
break;
163178
case "-debug-java":
164-
if (!isAOT()) {
165-
subprocessArgs.add("Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=y");
166-
inputArgs.remove("-debug-java");
179+
if (wantsExperimental) {
180+
if (!isAOT()) {
181+
subprocessArgs.add("Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=y");
182+
inputArgs.remove("-debug-java");
183+
}
184+
} else {
185+
unrecognized.add(arg);
167186
}
168187
break;
169188
case "-debug-perf":
170-
subprocessArgs.add("Dgraal.TraceTruffleCompilation=true");
171-
subprocessArgs.add("Dgraal.TraceTrufflePerformanceWarnings=true");
172-
subprocessArgs.add("Dgraal.TruffleCompilationExceptionsArePrinted=true");
173-
subprocessArgs.add("Dgraal.TraceTruffleInlining=true");
174-
subprocessArgs.add("Dgraal.TruffleTraceSplittingSummary=true");
175-
inputArgs.remove("-debug-perf");
189+
if (wantsExperimental) {
190+
subprocessArgs.add("Dgraal.TraceTruffleCompilation=true");
191+
subprocessArgs.add("Dgraal.TraceTrufflePerformanceWarnings=true");
192+
subprocessArgs.add("Dgraal.TruffleCompilationExceptionsArePrinted=true");
193+
subprocessArgs.add("Dgraal.TraceTruffleInlining=true");
194+
subprocessArgs.add("Dgraal.TruffleTraceSplittingSummary=true");
195+
inputArgs.remove("-debug-perf");
196+
} else {
197+
unrecognized.add(arg);
198+
}
176199
break;
177200
case "-dump":
178-
subprocessArgs.add("Dgraal.Dump=");
179-
inputArgs.remove("-dump");
201+
if (wantsExperimental) {
202+
subprocessArgs.add("Dgraal.Dump=");
203+
inputArgs.remove("-dump");
204+
} else {
205+
unrecognized.add(arg);
206+
}
180207
break;
181208
case "-compile-truffle-immediately":
182-
subprocessArgs.add("Dgraal.TruffleCompileImmediately=true");
183-
subprocessArgs.add("Dgraal.TruffleCompilationExceptionsAreThrown=true");
184-
inputArgs.remove("-compile-truffle-immediately");
209+
if (wantsExperimental) {
210+
subprocessArgs.add("Dgraal.TruffleCompileImmediately=true");
211+
subprocessArgs.add("Dgraal.TruffleCompilationExceptionsAreThrown=true");
212+
inputArgs.remove("-compile-truffle-immediately");
213+
} else {
214+
unrecognized.add(arg);
215+
}
185216
break;
186217
case "-u":
187218
unbufferedIO = true;
188219
break;
220+
case "--experimental-options":
221+
case "--experimental-options=true":
222+
// this is the default Truffle experimental option flag. We also use it for
223+
// our custom launcher options
224+
wantsExperimental = true;
225+
unrecognized.add(arg);
226+
break;
189227
default:
190228
if (!arg.startsWith("-")) {
191229
inputFile = arg;
@@ -536,16 +574,9 @@ protected void printHelp(OptionCategory maxCategory) {
536574
// "-3 : warn about Python 3.x incompatibilities that 2to3 cannot trivially
537575
// fix\n" +
538576
"file : program read from script file\n" +
539-
// "- : program read from stdin (default; interactive mode if a tty)\n" +
577+
"- : program read from stdin\n" +
540578
"arg ...: arguments passed to program in sys.argv[1:]\n" +
541579
"\n" +
542-
"Arguments specific to GraalPython:\n" +
543-
"--show-version : print the Python version number and continue.\n" +
544-
"-CC : run the C compiler used for generating GraalPython C extensions.\n" +
545-
" All following arguments are passed to the compiler.\n" +
546-
"-LD : run the linker used for generating GraalPython C extensions.\n" +
547-
" All following arguments are passed to the linker.\n" +
548-
"\n" +
549580
"Other environment variables:\n" +
550581
"PYTHONSTARTUP: file executed on interactive startup (no default)\n" +
551582
"PYTHONPATH : ':'-separated list of directories prefixed to the\n" +
@@ -558,11 +589,18 @@ protected void printHelp(OptionCategory maxCategory) {
558589
" as specifying the -R option: a random value is used to seed the hashes of\n" +
559590
" str, bytes and datetime objects. It can also be set to an integer\n" +
560591
" in the range [0,4294967295] to get hash values with a predictable seed.\n" +
561-
"SULONG_LIBRARY_PATH: Specifies the library path for Sulong.\n" +
562-
" This is required when starting subprocesses of python.\n" +
563-
"GRAAL_PYTHON_OPTIONS: This environment variable can include default options that\n" +
564-
" are always passed to the launcher. These are not shell expanded and given to\n" +
565-
" the launcher as-is.");
592+
(wantsExperimental ? "\nArguments specific to the Graal Python launcher:\n" +
593+
"--show-version : print the Python version number and continue.\n" +
594+
"-CC : run the C compiler used for generating GraalPython C extensions.\n" +
595+
" All following arguments are passed to the compiler.\n" +
596+
"-LD : run the linker used for generating GraalPython C extensions.\n" +
597+
" All following arguments are passed to the linker.\n" +
598+
"\nEnvironment variables specific to the Graal Python launcher:\n" +
599+
"SULONG_LIBRARY_PATH: Specifies the library path for Sulong.\n" +
600+
" This is required when starting subprocesses of python.\n" +
601+
"GRAAL_PYTHON_OPTIONS: This environment variable can include default options that\n" +
602+
" are always passed to the launcher. These are not shell expanded and given to\n" +
603+
" the launcher as-is." : ""));
566604
}
567605

568606
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/PBaseException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public List<TruffleStackTraceElement> getStackTrace() {
192192
public void reifyException() {
193193
if (stackTrace == null && traceback == null) {
194194
TruffleStackTrace.fillIn(exception);
195-
stackTrace = TruffleStackTrace.getStacktrace(exception);
195+
stackTrace = TruffleStackTrace.getStackTrace(exception);
196196
Iterator<TruffleStackTraceElement> iter = stackTrace.iterator();
197197
while (iter.hasNext()) {
198198
TruffleStackTraceElement element = iter.next();

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
*/
2626
package com.oracle.graal.python.runtime;
2727

28-
import org.graalvm.options.OptionCategory;
29-
import org.graalvm.options.OptionDescriptors;
30-
import org.graalvm.options.OptionKey;
31-
3228
import com.oracle.graal.python.PythonLanguage;
3329
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
3430
import com.oracle.truffle.api.Option;
3531

32+
import org.graalvm.options.OptionCategory;
33+
import org.graalvm.options.OptionDescriptors;
34+
import org.graalvm.options.OptionKey;
35+
import org.graalvm.options.OptionStability;
36+
3637
@Option.Group(PythonLanguage.ID)
3738
public final class PythonOptions {
3839
private static final String EXECUTABLE_LIST_SEPARATOR = "🏆";
@@ -41,16 +42,16 @@ private PythonOptions() {
4142
// no instances
4243
}
4344

44-
@Option(category = OptionCategory.USER, help = "Set the location of sys.prefix. Overrides any environment variables or Java options.") //
45+
@Option(category = OptionCategory.USER, help = "Set the location of sys.prefix. Overrides any environment variables or Java options.", stability = OptionStability.STABLE) //
4546
public static final OptionKey<String> SysPrefix = new OptionKey<>("");
4647

47-
@Option(category = OptionCategory.EXPERT, help = "Set the location of sys.base_prefix. Overrides any environment variables or Java options.") //
48+
@Option(category = OptionCategory.EXPERT, help = "Set the location of sys.base_prefix. Overrides any environment variables or Java options.", stability = OptionStability.STABLE) //
4849
public static final OptionKey<String> SysBasePrefix = new OptionKey<>("");
4950

50-
@Option(category = OptionCategory.USER, help = "Set the location of lib-graalpython. Overrides any environment variables or Java options.") //
51+
@Option(category = OptionCategory.USER, help = "Set the location of lib-graalpython. Overrides any environment variables or Java options.", stability = OptionStability.STABLE) //
5152
public static final OptionKey<String> CoreHome = new OptionKey<>("");
5253

53-
@Option(category = OptionCategory.USER, help = "Set the location of lib-python/3. Overrides any environment variables or Java options.") //
54+
@Option(category = OptionCategory.USER, help = "Set the location of lib-python/3. Overrides any environment variables or Java options.", stability = OptionStability.STABLE) //
5455
public static final OptionKey<String> StdLibHome = new OptionKey<>("");
5556

5657
@Option(category = OptionCategory.USER, help = "This option makes reading from files return opaque objects. Imports can work with such data, " +
@@ -60,31 +61,31 @@ private PythonOptions() {
6061
@Option(category = OptionCategory.USER, help = "List of root paths for the opaque file system (default: '/'); use system-specific path separator.") //
6162
public static final OptionKey<String> OpaqueFilesystemPrefixes = new OptionKey<>("/");
6263

63-
@Option(category = OptionCategory.USER, help = "Equivalent to the Python -i flag. Inspect interactively after running a script.") //
64+
@Option(category = OptionCategory.USER, help = "Equivalent to the Python -i flag. Inspect interactively after running a script.", stability = OptionStability.STABLE) //
6465
public static final OptionKey<Boolean> InspectFlag = new OptionKey<>(false);
6566

66-
@Option(category = OptionCategory.USER, help = "Equivalent to the Python -q flag. Don't print version and copyright messages on interactive startup.") //
67+
@Option(category = OptionCategory.USER, help = "Equivalent to the Python -q flag. Don't print version and copyright messages on interactive startup.", stability = OptionStability.STABLE) //
6768
public static final OptionKey<Boolean> QuietFlag = new OptionKey<>(false);
6869

69-
@Option(category = OptionCategory.USER, help = "Equivalent to the Python -S flag. Don't imply 'import site' on initialization.") //
70+
@Option(category = OptionCategory.USER, help = "Equivalent to the Python -S flag. Don't imply 'import site' on initialization.", stability = OptionStability.STABLE) //
7071
public static final OptionKey<Boolean> NoSiteFlag = new OptionKey<>(false);
7172

72-
@Option(category = OptionCategory.USER, help = "Equivalent to the Python -s flag. Don't add user site directory to sys.path.") //
73+
@Option(category = OptionCategory.USER, help = "Equivalent to the Python -s flag. Don't add user site directory to sys.path.", stability = OptionStability.STABLE) //
7374
public static final OptionKey<Boolean> NoUserSiteFlag = new OptionKey<>(false);
7475

75-
@Option(category = OptionCategory.USER, help = "Equivalent to the Python -E flag. Ignore PYTHON* environment variables.") //
76+
@Option(category = OptionCategory.USER, help = "Equivalent to the Python -E flag. Ignore PYTHON* environment variables.", stability = OptionStability.STABLE) //
7677
public static final OptionKey<Boolean> IgnoreEnvironmentFlag = new OptionKey<>(false);
7778

78-
@Option(category = OptionCategory.USER, help = "Equivalent to setting the PYTHONPATH environment variable for the standard launcher. ':'-separated list of directories prefixed to the default module search path.") //
79+
@Option(category = OptionCategory.USER, help = "Equivalent to setting the PYTHONPATH environment variable for the standard launcher. ':'-separated list of directories prefixed to the default module search path.", stability = OptionStability.STABLE) //
7980
public static final OptionKey<String> PythonPath = new OptionKey<>("");
8081

81-
@Option(category = OptionCategory.USER, help = "Remove assert statements and any code conditional on the value of __debug__.") //
82+
@Option(category = OptionCategory.USER, help = "Remove assert statements and any code conditional on the value of __debug__.", stability = OptionStability.STABLE) //
8283
public static final OptionKey<Boolean> PythonOptimizeFlag = new OptionKey<>(false);
8384

84-
@Option(category = OptionCategory.USER, help = "Equivalent to the Python -v flag. Turn on verbose mode.") //
85+
@Option(category = OptionCategory.USER, help = "Equivalent to the Python -v flag. Turn on verbose mode.", stability = OptionStability.STABLE) //
8586
public static final OptionKey<Boolean> VerboseFlag = new OptionKey<>(false);
8687

87-
@Option(category = OptionCategory.USER, help = "Equivalent to the Python -u flag. Force stdout and stderr to be unbuffered.") //
88+
@Option(category = OptionCategory.USER, help = "Equivalent to the Python -u flag. Force stdout and stderr to be unbuffered.", stability = OptionStability.STABLE) //
8889
public static final OptionKey<Boolean> UnbufferedIO = new OptionKey<>(false);
8990

9091
@Option(category = OptionCategory.INTERNAL, help = "Expose internal sources as normal sources, so they will show up in the debugger and stacks") //
@@ -141,7 +142,7 @@ private PythonOptions() {
141142
@Option(category = OptionCategory.EXPERT, help = "Set by the launcher to the terminal height.") //
142143
public static final OptionKey<Integer> TerminalHeight = new OptionKey<>(25);
143144

144-
@Option(category = OptionCategory.EXPERT, help = "The sys.executable path. Set by the launcher, but can may need to be overridden in certain special situations.") //
145+
@Option(category = OptionCategory.EXPERT, help = "The sys.executable path. Set by the launcher, but can may need to be overridden in certain special situations.", stability = OptionStability.STABLE) //
145146
public static final OptionKey<String> Executable = new OptionKey<>("");
146147

147148
@Option(category = OptionCategory.EXPERT, help = "The executed command list as string joined by the executable list separator char. This must always correspond to the real, valid command list used to run GraalPython.") //

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private ExceptionUtils() {
5656

5757
@TruffleBoundary
5858
public static void printPythonLikeStackTrace(PException e) {
59-
List<TruffleStackTraceElement> stackTrace = TruffleStackTrace.getStacktrace(e);
59+
List<TruffleStackTraceElement> stackTrace = TruffleStackTrace.getStackTrace(e);
6060
ArrayList<String> stack = new ArrayList<>();
6161
for (TruffleStackTraceElement frame : stackTrace) {
6262

graalpython/lib-python/3/distutils/sysconfig_graalpython.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ def _init_posix():
6565
so_ext = _imp.extension_suffixes()[0]
6666

6767
g = {}
68-
g['CC'] = "%s -CC %s" % (sys.executable, "-v" if sys.flags.verbose else "")
69-
g['CXX'] = "%s -CC %s" % (sys.executable, "-v" if sys.flags.verbose else "")
68+
g['CC'] = "%s --experimental-options -CC %s" % (sys.executable, "-v" if sys.flags.verbose else "")
69+
g['CXX'] = "%s --experimental-options -CC %s" % (sys.executable, "-v" if sys.flags.verbose else "")
7070
g['OPT'] = "-DNDEBUG -O1"
7171
g['CFLAGS'] = "-DNDEBUG -O1"
7272
g['CCSHARED'] = "-fPIC"
73-
g['LDSHARED'] = "%s -LD %s" % (sys.executable, "-v" if sys.flags.verbose else "")
73+
g['LDSHARED'] = "%s --experimental-options -LD %s" % (sys.executable, "-v" if sys.flags.verbose else "")
7474
g['EXT_SUFFIX'] = so_ext
7575
g['SHLIB_SUFFIX'] = so_ext
7676
g['SO'] = so_ext # deprecated in Python 3, for backward compatibility

0 commit comments

Comments
 (0)