Skip to content

Commit 822dea0

Browse files
committed
[GR-17517] Implement a few gc module stubs for timeit module
PullRequest: graalpython/607
2 parents 953dc00 + 8109a56 commit 822dea0

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ language runtime. The main focus is on user-observable behavior of the engine.
55

66
## Version 19.3.0
77

8+
* Implement `gc.{enable,disable,isenabled}` as stubs
89
* Implement `charmap_build` function
910
* Implement `hexversion` in sys module
1011
* Implement `_lzma` module
@@ -13,6 +14,7 @@ language runtime. The main focus is on user-observable behavior of the engine.
1314
* Fix destructuring assignments of arbitrary iterators
1415
* Fix `dict.__contains__` for dictionaries with only `str` keys for subclasses of `str`
1516
* Support NumPy 1.16.4 and Pandas 0.25.0
17+
* Support `timeit` module
1618
* Support importing Java classes using normal Python import syntax when the package is known
1719
* Improve performance across many Python benchmarks
1820

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.oracle.graal.python.builtins.Builtin;
3333
import com.oracle.graal.python.builtins.CoreFunctions;
3434
import com.oracle.graal.python.builtins.PythonBuiltins;
35+
import com.oracle.graal.python.builtins.objects.PNone;
3536
import com.oracle.graal.python.builtins.objects.cext.PythonNativeClass;
3637
import com.oracle.graal.python.builtins.objects.cext.PythonNativeObject;
3738
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
@@ -50,11 +51,11 @@ protected List<com.oracle.truffle.api.dsl.NodeFactory<? extends PythonBuiltinNod
5051
return GcModuleBuiltinsFactory.getFactories();
5152
}
5253

53-
@Builtin(name = "collect", minNumOfPositionalArgs = 0)
54+
@Builtin(name = "collect", minNumOfPositionalArgs = 0, maxNumOfPositionalArgs = 1)
5455
@GenerateNodeFactory
5556
abstract static class GcCollectNode extends PythonBuiltinNode {
5657
@Specialization
57-
int collect(VirtualFrame frame) {
58+
int collect(VirtualFrame frame, @SuppressWarnings("unused") Object level) {
5859
doGc();
5960
// collect some weak references now
6061
getContext().triggerAsyncActions(frame, this);
@@ -67,6 +68,32 @@ private static void doGc() {
6768
}
6869
}
6970

71+
@Builtin(name = "isenabled", minNumOfPositionalArgs = 0)
72+
@GenerateNodeFactory
73+
abstract static class GcIsEnabledNode extends PythonBuiltinNode {
74+
@Specialization
75+
boolean isenabled() {
76+
return true;
77+
}
78+
}
79+
80+
abstract static class StubNode extends PythonBuiltinNode {
81+
@Specialization
82+
PNone disable() {
83+
return PNone.NONE;
84+
}
85+
}
86+
87+
@Builtin(name = "disable", minNumOfPositionalArgs = 0)
88+
@GenerateNodeFactory
89+
abstract static class DisableNode extends StubNode {
90+
}
91+
92+
@Builtin(name = "enable", minNumOfPositionalArgs = 0)
93+
@GenerateNodeFactory
94+
abstract static class EnableNode extends StubNode {
95+
}
96+
7097
@Builtin(name = "get_count", minNumOfPositionalArgs = 0)
7198
@GenerateNodeFactory
7299
abstract static class GcCountNode extends PythonBuiltinNode {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/ReadAttributeFromDynamicObjectNode.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ protected static boolean checkShape(@SuppressWarnings("unused") DynamicObject dy
8181
return cachedObject.getShape() == cachedShape;
8282
}
8383

84-
private static boolean assertFinal(DynamicObject dynamicObject, Object key, Object cachedValue) {
85-
Object other = dynamicObject.get(key) == null ? PNone.NO_VALUE : dynamicObject.get(key);
86-
return cachedValue == other || cachedValue instanceof Number && other instanceof Number && ((Number) cachedValue).doubleValue() == ((Number) other).doubleValue();
87-
}
88-
8984
@SuppressWarnings("unused")
9085
@Specialization(limit = "1", //
9186
guards = {
@@ -110,7 +105,6 @@ protected Object readDirectFinal(DynamicObject dynamicObject, Object key,
110105
@Cached("loc.getFinalAssumption()") Assumption finalAssumption,
111106
@SuppressWarnings("unused") @Cached("singleContextAssumption()") Assumption singleContextAssumption,
112107
@Cached("readFinalValue(dynamicObject, loc)") Object cachedValue) {
113-
assert assertFinal(dynamicObject, attrKey, cachedValue);
114108
return cachedValue;
115109
}
116110

0 commit comments

Comments
 (0)