Skip to content

Commit 96eb044

Browse files
committed
[GR-23310] Make test_compile pass.
PullRequest: graalpython/1691
2 parents a8f8e23 + 0832bd7 commit 96eb044

File tree

4 files changed

+12
-24
lines changed

4 files changed

+12
-24
lines changed

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_base64.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
*graalpython.lib-python.3.test.test_base64.TestMain.test_decode
2626
*graalpython.lib-python.3.test.test_base64.TestMain.test_encode_decode
2727
*graalpython.lib-python.3.test.test_base64.TestMain.test_encode_file
28+
*graalpython.lib-python.3.test.test_base64.TestMain.test_encode_from_stdin

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_compile.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
*graalpython.lib-python.3.test.test_compile.TestSpecifics.test_annotation_limit
99
*graalpython.lib-python.3.test.test_compile.TestSpecifics.test_argument_handling
1010
*graalpython.lib-python.3.test.test_compile.TestSpecifics.test_argument_order
11+
*graalpython.lib-python.3.test.test_compile.TestSpecifics.test_compile_ast
1112
*graalpython.lib-python.3.test.test_compile.TestSpecifics.test_compiler_recursion_limit
1213
*graalpython.lib-python.3.test.test_compile.TestSpecifics.test_dead_blocks_do_not_generate_bytecode
14+
*graalpython.lib-python.3.test.test_compile.TestSpecifics.test_dict_evaluation_order
1315
*graalpython.lib-python.3.test.test_compile.TestSpecifics.test_duplicate_global_local
1416
*graalpython.lib-python.3.test.test_compile.TestSpecifics.test_empty
1517
*graalpython.lib-python.3.test.test_compile.TestSpecifics.test_exec_with_general_mapping_for_locals

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/literal/DictLiteralNode.java

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -104,35 +104,21 @@ protected DynamicDictLiteralNode(ExpressionNode[] keys, ExpressionNode[] values)
104104
}
105105
}
106106

107-
static final class Keys {
108-
public final Object[] keys;
109-
public final boolean allStrings;
110-
111-
Keys(Object[] keys, boolean allStrings) {
112-
this.keys = keys;
113-
this.allStrings = allStrings;
114-
}
115-
}
116-
117107
@ExplodeLoop
118-
private Keys evalKeys(VirtualFrame frame) {
108+
private HashingStorage eval(VirtualFrame frame, PythonLanguage lang, ConditionProfile hasFrame) {
119109
boolean allStrings = true;
120110
Object[] evalKeys = new Object[this.keys.length];
111+
Object[] evalValues = new Object[this.values.length];
121112
for (int i = 0; i < values.length; i++) {
122113
evalKeys[i] = keys[i].execute(frame);
123-
if (!(evalKeys[i] instanceof String)) {
114+
evalValues[i] = values[i].execute(frame);
115+
if (allStrings && !(evalKeys[i] instanceof String)) {
124116
allStrings = false;
125117
}
126118
}
127-
return new Keys(evalKeys, allStrings);
128-
}
129-
130-
@ExplodeLoop
131-
private HashingStorage evalAndSetValues(VirtualFrame frame, HashingStorage dictStorage, Keys evalKeys, ConditionProfile hasFrame) {
132-
HashingStorage storage = dictStorage;
119+
HashingStorage storage = PDict.createNewStorage(lang, allStrings, evalKeys.length);
133120
for (int i = 0; i < values.length; i++) {
134-
Object val = values[i].execute(frame);
135-
storage = libs[i].setItemWithFrame(storage, evalKeys.keys[i], val, hasFrame, frame);
121+
storage = libs[i].setItemWithFrame(storage, evalKeys[i], evalValues[i], hasFrame, frame);
136122
}
137123
return storage;
138124
}
@@ -141,9 +127,7 @@ private HashingStorage evalAndSetValues(VirtualFrame frame, HashingStorage dictS
141127
public PDict create(VirtualFrame frame,
142128
@CachedLanguage PythonLanguage lang,
143129
@Cached("createBinaryProfile()") ConditionProfile hasFrame) {
144-
Keys evalKeys = evalKeys(frame);
145-
HashingStorage dictStorage = PDict.createNewStorage(lang, evalKeys.allStrings, evalKeys.keys.length);
146-
dictStorage = evalAndSetValues(frame, dictStorage, evalKeys, hasFrame);
130+
HashingStorage dictStorage = eval(frame, lang, hasFrame);
147131
return factory.createDict(dictStorage);
148132
}
149133
}

graalpython/lib-python/3/test/test_compile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import tempfile
88
import types
99
from test import support
10-
from test.support import script_helper, FakePath
10+
from test.support import script_helper, FakePath, impl_detail
1111

1212
class TestSpecifics(unittest.TestCase):
1313

@@ -421,6 +421,7 @@ def f():
421421
self.assertIn("_A__mangled_mod", A.f.__code__.co_varnames)
422422
self.assertIn("__package__", A.f.__code__.co_varnames)
423423

424+
@impl_detail("ast module", graalvm=False)
424425
def test_compile_ast(self):
425426
fname = __file__
426427
if fname.lower().endswith('pyc'):

0 commit comments

Comments
 (0)