Skip to content

Commit cea2fa9

Browse files
committed
Merge commit '3e01e4d5fdfa1a0ca65704d7d7f0ae8a49f5dc96' into release/graal-vm/1.0
2 parents 4ac5dcc + 3e01e4d commit cea2fa9

File tree

188 files changed

+9572
-1689
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+9572
-1689
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,28 @@
33
This changelog summarizes major changes between GraalVM versions of the Python
44
language runtime. The main focus is on user-observable behavior of the engine.
55

6+
## Version 1.0.0 RC11
7+
8+
* Support running setuptools to build and install various packages
9+
* Support running a source release version of NumPy out of the box
10+
* Improve performance of member access to C API objects
11+
* Improve performance of binary operations on C API objects
12+
* Add support for `yield from`
13+
* Support assignment to `object.__dict__` and ensure that managed subclasses of native types also have a `__dict__`
14+
* Fix `[]` access with non-integer keys for array-like foreign objects
15+
* Fix various performance regressions introduced in the last RC
16+
* Implement more built-in methods on the `time` module
17+
* Python no longer exposes internal languages through `polyglot.eval`
18+
* Improve performance of `os.scandir` and functions that build on it (such as `glob`)
19+
* More correct implementation of standard streams, including buffering
20+
* Properly support the `-m` switch to run modules
21+
* Support the standard `zipfile` module
22+
* Add the built-in `_cvs` module
23+
* Add support for `__slots__`
24+
* Allow arbitrary callable objects in methods, not only functions
25+
* Report that we have a TTY console if we are launched on a Terminal through our launcher
26+
* Add the `ginstall` custom module to install known packages such as NumPy and setuptools
27+
628
## Version 1.0.0 RC10
729

830
* Improve performance of C API upcalls

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@ To try it, you can use the bundled releases from
1414
some examples of what you can do with it, check out the
1515
[reference](https://www.graalvm.org/docs/reference-manual/languages/python/).
1616

17+
### Installing packages
18+
19+
At the moment not enough of the standard library is implemented to run the
20+
standard package installers for many packages. As a convenience, we provide a
21+
simple module to install packages that we know to be working (including
22+
potential patches required for those packages). Try the following to find out
23+
more:
24+
25+
```
26+
graalpython -m ginstall --help
27+
```
28+
29+
As a slightly more exciting example, try:
30+
31+
```
32+
graalpython -m ginstall install numpy
33+
```
34+
35+
If all goes well (you'll need to have `clang`, `llvm-link`, `llvm-extract`,
36+
`llvm-nm`, and `opt` in your `PATH` in addition to the normal NumPy build
37+
dependencies), you should be able to `import numpy` afterwards.
38+
1739
### Licensing
1840

1941
This Graal/Truffle-based implementation of Python is copyright (c) 2017, 2018
@@ -23,3 +45,4 @@ Universal Permissive License v 1.0 as shown at
2345
implementation is in part derived from and contains additional code from 3rd
2446
parties, the copyrights and licensing of which is detailed in the
2547
[LICENSE](LICENSE) and [3rd_party_licenses.txt](3rd_party_licenses.txt) files.
48+

ci.jsonnet

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
overlay: "ffde557d62fff381069838b745c31b79c90e6e2a",
2+
overlay: "3cf78c3623442ad827eed58a1780784a6eb95676",
33

44
// ======================================================================================================
55
//
@@ -251,6 +251,8 @@
251251
// unittests
252252
testGate(type="unittest", platform="linux"),
253253
testGate(type="unittest", platform="darwin"),
254+
testGate(type="svm-unittest", platform="linux"),
255+
testGate(type="svm-unittest", platform="darwin"),
254256

255257
// junit
256258
testGate(type="junit", platform="linux"),

graalpython/com.oracle.graal.python.cext/src/dictobject.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ PyObject* PyDict_GetItem(PyObject* d, PyObject* k) {
5757
return UPCALL_CEXT_O(_jls_PyDict_GetItem, native_to_java(d), native_to_java(k));
5858
}
5959

60+
PyObject* _PyDict_GetItemId(PyObject* d, _Py_Identifier* id) {
61+
return PyDict_GetItemString(d, id->string);
62+
}
63+
6064
UPCALL_ID(PyDict_DelItem);
6165
int PyDict_DelItem(PyObject *d, PyObject *k) {
6266
return UPCALL_CEXT_I(_jls_PyDict_DelItem, native_to_java(d), native_to_java(k));

graalpython/com.oracle.graal.python.cext/src/exceptions.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ PyObject * PyExc_AssertionError = NULL;
8181
PyObject * PyExc_UnboundLocalError = NULL;
8282
PyObject * PyExc_NotImplementedError = NULL;
8383
PyObject * PyExc_RecursionError = NULL;
84+
PyObject * PyExc_UnicodeEncodeError = NULL;
8485

8586
void initialize_exceptions() {
8687
PyExc_AttributeError = PY_EXCEPTION("AttributeError");
@@ -118,6 +119,7 @@ void initialize_exceptions() {
118119
PyExc_NotImplementedError = PY_EXCEPTION("NotImplementedError");
119120
PyExc_RecursionError = PY_EXCEPTION("RecursionError");
120121
PyExc_NotImplementedError = PY_EXCEPTION("NotImplementedError");
122+
PyExc_UnicodeEncodeError = PY_EXCEPTION("UnicodeEncodeError");
121123
}
122124

123125

graalpython/com.oracle.graal.python.cext/src/object.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ PyObject* _PyObject_GC_New(PyTypeObject *tp) {
388388
return _PyObject_New(tp);
389389
}
390390

391+
PyVarObject* _PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems) {
392+
return _PyObject_NewVar(tp, nitems);
393+
}
394+
391395
PyVarObject *
392396
_PyObject_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
393397
{

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,14 @@ public int read() throws IOException {
109109
}
110110
};
111111
}
112+
113+
public int getTerminalWidth() {
114+
// deafult value
115+
return 80;
116+
}
117+
118+
public int getTerminalHeight() {
119+
// default value
120+
return 25;
121+
}
112122
}
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
/*
2+
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.graal.python.shell;
42+
43+
import java.io.IOException;
44+
import java.nio.file.Files;
45+
import java.nio.file.Path;
46+
import java.nio.file.Paths;
47+
import java.nio.file.StandardCopyOption;
48+
import java.nio.file.attribute.PosixFilePermission;
49+
import java.util.ArrayList;
50+
import java.util.Arrays;
51+
import java.util.HashSet;
52+
import java.util.List;
53+
54+
public class GraalPythonCC extends GraalPythonCompiler {
55+
private String outputFilename;
56+
private boolean linkExecutable;
57+
private boolean link;
58+
private boolean linkLLI;
59+
private Boolean compile;
60+
private List<String> clangArgs;
61+
private List<String> execLinkArgs;
62+
private List<String> fileInputs;
63+
64+
GraalPythonCC() {
65+
}
66+
67+
private static List<String> execLinkPrefix = Arrays.asList(new String[]{
68+
"clang",
69+
"-fembed-bitcode",
70+
"-fPIC",
71+
"-ggdb",
72+
"-O1",
73+
});
74+
private static List<String> clangPrefix = Arrays.asList(new String[]{
75+
"clang",
76+
"-emit-llvm",
77+
"-fPIC",
78+
"-Wno-int-to-void-pointer-cast",
79+
"-Wno-int-conversion",
80+
"-Wno-incompatible-pointer-types-discards-qualifiers",
81+
"-ggdb",
82+
"-O1",
83+
});
84+
private static List<String> optPrefix = Arrays.asList(new String[]{
85+
"opt",
86+
"-mem2reg",
87+
"-globalopt",
88+
"-simplifycfg",
89+
"-constprop",
90+
"-always-inline",
91+
"-instcombine",
92+
"-dse",
93+
"-loop-simplify",
94+
"-reassociate",
95+
"-licm",
96+
"-gvn",
97+
"-o",
98+
});
99+
100+
static void main(String[] args) {
101+
new GraalPythonCC().run(args);
102+
}
103+
104+
private void run(String[] args) {
105+
parseOptions(args);
106+
launchCC();
107+
}
108+
109+
private void parseOptions(String[] args) {
110+
outputFilename = A_OUT;
111+
linkExecutable = true;
112+
linkLLI = false;
113+
link = true;
114+
verbose = false;
115+
compile = null;
116+
clangArgs = new ArrayList<>(clangPrefix);
117+
execLinkArgs = new ArrayList<>(execLinkPrefix);
118+
fileInputs = new ArrayList<>();
119+
for (int i = 0; i < args.length; i++) {
120+
String arg = args[i];
121+
switch (arg) {
122+
case "-o":
123+
clangArgs.add(arg);
124+
i++;
125+
if (i >= args.length) {
126+
throw new RuntimeException("-o needs an argument");
127+
}
128+
outputFilename = arg = args[i];
129+
break;
130+
case "-shared":
131+
linkExecutable = false;
132+
break;
133+
case "-c":
134+
link = false;
135+
linkExecutable = false;
136+
break;
137+
case "--link-lli-scripts":
138+
linkLLI = true;
139+
continue; // skip adding this to clang args
140+
case "-v":
141+
if (!verbose) {
142+
verbose = true;
143+
continue; // the first verbose is not passed on to clang
144+
}
145+
break;
146+
default:
147+
if (arg.endsWith(".o") || arg.endsWith(".bc")) {
148+
if (compile == null) {
149+
compile = false;
150+
} else if (compile != false) {
151+
throw new RuntimeException("cannot mix source and compiled sources");
152+
}
153+
fileInputs.add(arg);
154+
} else if (arg.endsWith(".c") || arg.endsWith(".cpp") || arg.endsWith(".cxx")) {
155+
if (compile == null) {
156+
compile = true;
157+
} else if (compile != true) {
158+
throw new RuntimeException("cannot mix source and compiled sources");
159+
}
160+
fileInputs.add(arg);
161+
} else {
162+
execLinkArgs.add(arg);
163+
}
164+
}
165+
clangArgs.add(arg);
166+
}
167+
String targetFlags = System.getenv("LLVM_TARGET_FLAGS");
168+
if (targetFlags != null) {
169+
clangArgs.addAll(Arrays.asList(targetFlags.split(" ")));
170+
}
171+
}
172+
173+
private void launchCC() {
174+
// run the clang compiler to generate bc files
175+
try {
176+
Files.delete(Paths.get(outputFilename));
177+
} catch (IOException e) {
178+
// no matter;
179+
}
180+
181+
if (compile) {
182+
exec(clangArgs);
183+
logV("opt: ", fileInputs);
184+
if (!Files.exists(Paths.get(outputFilename))) {
185+
// if no explicit output filename was given or produced, we search the commandline
186+
// for files for which now have a bc file and optimize those. This happens when you
187+
// pass multiple .c files to clang and ask it to emit llvm bitcode
188+
for (String f : fileInputs) {
189+
String bcFile = bcFileFromFilename(f);
190+
assert Files.exists(Paths.get(bcFile));
191+
optFile(bcFile);
192+
try {
193+
String objFile = objectFileFromFilename(f);
194+
logV("Optimized:", bcFile, "->", objFile);
195+
Files.move(Paths.get(bcFile), Paths.get(objFile));
196+
} catch (IOException e) {
197+
throw new RuntimeException(e);
198+
}
199+
}
200+
} else {
201+
optFile(outputFilename);
202+
}
203+
}
204+
205+
if (link) {
206+
linkShared(fileInputs);
207+
if (linkExecutable) {
208+
try {
209+
Path linkedBCfile = Files.move(Paths.get(outputFilename), Paths.get(bcFileFromFilename(outputFilename)), StandardCopyOption.REPLACE_EXISTING);
210+
linkExecutable(outputFilename, linkedBCfile.toString());
211+
} catch (IOException e) {
212+
throw new RuntimeException(e);
213+
}
214+
}
215+
}
216+
}
217+
218+
private void linkExecutable(String executableScript, String linkedBcFile) throws IOException {
219+
if (linkLLI) {
220+
List<String> cmdline = GraalPythonMain.getCmdline(Arrays.asList(), Arrays.asList());
221+
cmdline.add("-LLI");
222+
cmdline.add(linkedBcFile);
223+
Path executablePath = Paths.get(executableScript);
224+
Files.write(executablePath, String.join(" ", cmdline).getBytes());
225+
HashSet<PosixFilePermission> perms = new HashSet<>(Arrays.asList(new PosixFilePermission[]{PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_EXECUTE}));
226+
perms.addAll(Files.getPosixFilePermissions(executablePath));
227+
} else {
228+
execLinkArgs.add(linkedBcFile);
229+
execLinkArgs.add("-o");
230+
execLinkArgs.add(executableScript);
231+
exec(execLinkArgs);
232+
}
233+
}
234+
235+
private void linkShared(List<String> bitcodeFiles) {
236+
if (fileInputs.size() > 0) {
237+
ArrayList<String> ldCmd = new ArrayList<>(bitcodeFiles);
238+
if (verbose) {
239+
ldCmd.add("-v");
240+
}
241+
ldCmd.add("-o");
242+
ldCmd.add(outputFilename);
243+
GraalPythonLD.main(ldCmd.toArray(new String[0]));
244+
}
245+
}
246+
247+
private void optFile(String bcFile) {
248+
List<String> opt = new ArrayList<>(optPrefix);
249+
opt.add(bcFile);
250+
opt.add(bcFile);
251+
exec(opt);
252+
}
253+
254+
private static String bcFileFromFilename(String f) {
255+
int dotIdx = f.lastIndexOf('.');
256+
if (dotIdx > 1) {
257+
return f.substring(0, dotIdx + 1) + "bc";
258+
} else {
259+
return f + ".bc";
260+
}
261+
}
262+
263+
private static String objectFileFromFilename(String f) {
264+
return bcFileFromFilename(f).replaceAll("\\.bc$", ".o");
265+
}
266+
}

0 commit comments

Comments
 (0)