Skip to content

Commit 35c73b9

Browse files
committed
[GR-18538] Do not build managed C API in CE
PullRequest: graalpython/689
2 parents d95ad66 + 3322705 commit 35c73b9

File tree

7 files changed

+32
-30
lines changed

7 files changed

+32
-30
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ overlay: "41b5d34c082c57db236d3a620b1dc1d367537fac" }
1+
{ overlay: "bb8c47317088fde566681fdc692580d3439600c7" }

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ protected void initializeContext(PythonContext context) {
211211

212212
@Override
213213
protected CallTarget parse(ParsingRequest request) {
214-
PythonContext context = this.getContextReference().get();
214+
PythonContext context = getCurrentContext(PythonLanguage.class);
215215
PythonCore core = context.getCore();
216216
Source source = request.getSource();
217217
CompilerDirectives.transferToInterpreter();
@@ -258,7 +258,7 @@ protected ExecutableNode parse(InlineParsingRequest request) {
258258
final Source source = request.getSource();
259259
final MaterializedFrame requestFrame = request.getFrame();
260260
final ExecutableNode executableNode = new ExecutableNode(this) {
261-
private final ContextReference<PythonContext> contextRef = getContextReference();
261+
private final ContextReference<PythonContext> contextRef = getContextRef();
262262
@CompilationFinal private volatile PythonContext cachedContext;
263263
@Child private ExpressionNode expression;
264264

@@ -334,6 +334,7 @@ public static PythonLanguage getCurrent() {
334334
return getCurrentLanguage(PythonLanguage.class);
335335
}
336336

337+
@SuppressWarnings("deprecation") // TODO: GR-18870
337338
public static ContextReference<PythonContext> getContextRef() {
338339
return getCurrentLanguage(PythonLanguage.class).getContextReference();
339340
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/DynamicObjectStorage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private DynamicObjectStorage(DynamicObject store) {
7373

7474
@Override
7575
public int length() {
76-
return store.size();
76+
return store.getShape().getPropertyCount();
7777
}
7878

7979
@Override
@@ -122,7 +122,7 @@ public Iterable<Object> keys() {
122122
@Override
123123
@TruffleBoundary
124124
public Iterable<Object> values() {
125-
ArrayList<Object> entries = new ArrayList<>(store.size());
125+
ArrayList<Object> entries = new ArrayList<>(store.getShape().getPropertyCount());
126126
for (Object key : getKeysIterable()) {
127127
entries.add(store.get(key));
128128
}
@@ -132,7 +132,7 @@ public Iterable<Object> values() {
132132
@Override
133133
@TruffleBoundary
134134
public Iterable<DictEntry> entries() {
135-
ArrayList<DictEntry> entries = new ArrayList<>(store.size());
135+
ArrayList<DictEntry> entries = new ArrayList<>(store.getShape().getPropertyCount());
136136
for (Object key : getKeysIterable()) {
137137
entries.add(new DictEntry(key, store.get(key)));
138138
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/TopLevelExceptionHandler.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import com.oracle.graal.python.runtime.exception.PythonExitException;
7777
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
7878
import com.oracle.truffle.api.CompilerDirectives;
79+
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
7980
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
8081
import com.oracle.truffle.api.RootCallTarget;
8182
import com.oracle.truffle.api.Truffle;
@@ -88,8 +89,8 @@
8889
public class TopLevelExceptionHandler extends RootNode {
8990
private final RootCallTarget innerCallTarget;
9091
private final PException exception;
91-
private final ContextReference<PythonContext> context;
9292
private final SourceSection sourceSection;
93+
@CompilationFinal private ContextReference<PythonContext> context;
9394

9495
@Child private CreateArgumentsNode createArgs = CreateArgumentsNode.create();
9596
@Child private LookupAndCallUnaryNode callStrNode = LookupAndCallUnaryNode.create(__STR__);
@@ -101,26 +102,32 @@ public class TopLevelExceptionHandler extends RootNode {
101102
public TopLevelExceptionHandler(PythonLanguage language, RootNode child) {
102103
super(language);
103104
this.sourceSection = child.getSourceSection();
104-
this.context = language.getContextReference();
105105
this.innerCallTarget = Truffle.getRuntime().createCallTarget(child);
106106
this.exception = null;
107107
}
108108

109109
public TopLevelExceptionHandler(PythonLanguage language, PException exception) {
110110
super(language);
111111
this.sourceSection = exception.getSourceLocation();
112-
this.context = language.getContextReference();
113112
this.innerCallTarget = null;
114113
this.exception = exception;
115114
}
116115

116+
private PythonContext getContext() {
117+
if (context == null) {
118+
CompilerDirectives.transferToInterpreterAndInvalidate();
119+
context = lookupContextReference(PythonLanguage.class);
120+
}
121+
return context.get();
122+
}
123+
117124
@Override
118125
public Object execute(VirtualFrame frame) {
119126
if (exception != null) {
120127
printExc(frame, exception);
121128
return null;
122129
} else {
123-
assert context.get().getCurrentException() == null;
130+
assert getContext().getCurrentException() == null;
124131
try {
125132
return run(frame);
126133
} catch (PException e) {
@@ -132,15 +139,15 @@ public Object execute(VirtualFrame frame) {
132139
e.getExceptionObject().setTraceback(tbHead);
133140
}
134141
printExc(frame, e);
135-
if (PythonOptions.getOption(context.get(), PythonOptions.WithJavaStacktrace)) {
142+
if (PythonOptions.getOption(getContext(), PythonOptions.WithJavaStacktrace)) {
136143
printStackTrace(e);
137144
}
138145
return null;
139146
} catch (Exception | StackOverflowError e) {
140147
boolean exitException = e instanceof TruffleException && ((TruffleException) e).isExit();
141148
if (!exitException) {
142149
ExceptionUtils.printPythonLikeStackTrace(e);
143-
if (PythonOptions.getOption(context.get(), PythonOptions.WithJavaStacktrace)) {
150+
if (PythonOptions.getOption(getContext(), PythonOptions.WithJavaStacktrace)) {
144151
printStackTrace(e);
145152
}
146153
}
@@ -160,7 +167,7 @@ public SourceSection getSourceSection() {
160167
*/
161168
private void printExc(VirtualFrame frame, PException e) {
162169
CompilerDirectives.transferToInterpreter();
163-
PythonContext theContext = context.get();
170+
PythonContext theContext = getContext();
164171
PythonCore core = theContext.getCore();
165172
if (IsBuiltinClassProfile.profileClassSlowPath(e.getExceptionObject().getLazyPythonClass(), SystemExit)) {
166173
handleSystemExit(frame, e);
@@ -201,7 +208,7 @@ private void printExc(VirtualFrame frame, PException e) {
201208
}
202209

203210
private void handleSystemExit(VirtualFrame frame, PException e) {
204-
PythonContext theContext = context.get();
211+
PythonContext theContext = getContext();
205212
if (PythonOptions.getOption(theContext, PythonOptions.InspectFlag) && !getSourceSection().getSource().isInteractive()) {
206213
// Don't exit if -i flag was given and we're not yet running interactively
207214
return;
@@ -259,7 +266,7 @@ private Object run(VirtualFrame frame) {
259266
for (int i = 0; i < frame.getArguments().length; i++) {
260267
PArguments.setArgument(arguments, i, frame.getArguments()[i]);
261268
}
262-
PythonContext pythonContext = context.get();
269+
PythonContext pythonContext = getContext();
263270
if (getSourceSection().getSource().isInternal()) {
264271
// internal sources are not run in the main module
265272
PArguments.setGlobals(arguments, pythonContext.getCore().factory().createDict());

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/FunctionRootNode.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.oracle.graal.python.runtime.PythonContext;
3737
import com.oracle.truffle.api.CompilerAsserts;
3838
import com.oracle.truffle.api.CompilerDirectives;
39+
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
3940
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
4041
import com.oracle.truffle.api.frame.Frame;
4142
import com.oracle.truffle.api.frame.FrameDescriptor;
@@ -52,7 +53,7 @@
5253
* RootNode of a Python Function body. It is invoked by a CallTarget.
5354
*/
5455
public class FunctionRootNode extends PClosureFunctionRootNode {
55-
private final ContextReference<PythonContext> contextRef;
56+
@CompilationFinal private ContextReference<PythonContext> contextRef;
5657
private final PCell[] cells;
5758
private final ExecutionCellSlots executionCellSlots;
5859
private final String functionName;
@@ -70,7 +71,6 @@ public class FunctionRootNode extends PClosureFunctionRootNode {
7071
public FunctionRootNode(PythonLanguage language, SourceSection sourceSection, String functionName, boolean isGenerator, boolean isRewritten, FrameDescriptor frameDescriptor, ExpressionNode body,
7172
ExecutionCellSlots executionCellSlots, Signature signature) {
7273
super(language, frameDescriptor, executionCellSlots, signature);
73-
this.contextRef = language.getContextReference();
7474
this.executionCellSlots = executionCellSlots;
7575
this.cells = new PCell[this.cellVarSlots.length];
7676

@@ -141,6 +141,10 @@ private void initClosureAndCellVars(VirtualFrame frame) {
141141
public Object execute(VirtualFrame frame) {
142142
CalleeContext.enter(frame, customLocalsProfile);
143143
if (CompilerDirectives.inInterpreter() || CompilerDirectives.inCompilationRoot()) {
144+
if (contextRef == null) {
145+
CompilerDirectives.transferToInterpreterAndInvalidate();
146+
contextRef = lookupContextReference(PythonLanguage.class);
147+
}
144148
contextRef.get().triggerAsyncActions(frame, this);
145149
}
146150
try {

mx.graalpython/mx_graalpython.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,6 @@ def find_eclipse():
281281
return
282282

283283

284-
def python_build_svm(args):
285-
return python_svm(args + ["--version"])
286-
287-
288284
@contextlib.contextmanager
289285
def set_env(**environ):
290286
"Temporarily set the process environment variables"
@@ -319,7 +315,7 @@ def _python_graalvm_launcher(args):
319315
dy = "/vm,/tools,/substratevm"
320316
if "sandboxed" in args:
321317
args.remove("sandboxed")
322-
dy += ",/sulong-managed"
318+
dy += ",/sulong-managed,/graalpython-enterprise"
323319
dy = ["--dynamicimports", dy]
324320
mx.run_mx(dy + ["build"])
325321
out = mx.OutputCapture()
@@ -1201,12 +1197,6 @@ def build(self):
12011197
mx.ensure_dir_exists(cwd)
12021198
rc = self.run(args, cwd=cwd)
12031199
shutil.rmtree(cwd) # remove the temporary build files
1204-
# TODO: GR-18535
1205-
if mx.suite("sulong-managed", fatalIfMissing=False):
1206-
mx.log("Building C API project com.oracle.graal.python.cext managed ...")
1207-
mx.ensure_dir_exists(cwd)
1208-
rc = self.run(["--llvm.managed"] + args, cwd=cwd)
1209-
shutil.rmtree(cwd) # remove the temporary build files
12101200
return min(rc, 1)
12111201

12121202
def src_dir(self):

mx.graalpython/suite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@
4444
},
4545
{
4646
"name": "sulong",
47-
"version": "2e92894481917d92f170a713a9f03f99db600fe6",
47+
"version": "b06ba4554dfab182980b3a3d64264bb19559a0c4",
4848
"subdir": True,
4949
"urls": [
5050
{"url": "https://github.com/oracle/graal", "kind": "git"},
5151
]
5252
},
5353
{
5454
"name": "regex",
55-
"version": "2e92894481917d92f170a713a9f03f99db600fe6",
55+
"version": "b06ba4554dfab182980b3a3d64264bb19559a0c4",
5656
"subdir": True,
5757
"urls": [
5858
{"url": "https://github.com/oracle/graal", "kind": "git"},

0 commit comments

Comments
 (0)