Skip to content

Commit 1fabc50

Browse files
timfelcosminbasca
authored andcommitted
do not serialize generator expressions as constants for now, instead inline their global references
1 parent 694ad91 commit 1fabc50

File tree

1 file changed

+15
-2
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code

1 file changed

+15
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ public boolean visit(Node node) {
249249
} else if (node instanceof FunctionDefinitionNode) {
250250
constants.add(new PCode(PythonBuiltinClassType.PCode, ((FunctionDefinitionNode) node).getCallTarget()));
251251
} else if (node instanceof GeneratorExpressionNode) {
252-
constants.add(new PCode(PythonBuiltinClassType.PCode, ((GeneratorExpressionNode) node).getCallTarget()));
252+
// TODO: we do it this way here since we cannot deserialize generator expressions right now
253+
constants.addAll(Arrays.asList(extractConstants(((GeneratorExpressionNode) node).getCallTarget().getRootNode())));
253254
}
254255
return true;
255256
}
@@ -259,7 +260,19 @@ public boolean visit(Node node) {
259260

260261
@TruffleBoundary
261262
private static Object[] extractNames(RootNode rootNode) {
262-
return NodeUtil.findAllNodeInstances(rootNodeForExtraction(rootNode), GlobalNode.class).stream().map((n) -> n.getAttributeId()).distinct().toArray();
263+
List<Object> names = new ArrayList<>();
264+
rootNode.accept(new NodeVisitor() {
265+
public boolean visit(Node node) {
266+
if (node instanceof GlobalNode) {
267+
names.add(((GlobalNode) node).getAttributeId());
268+
} else if (node instanceof GeneratorExpressionNode) {
269+
// TODO: since we do *not* add GeneratorExpressionNodes in #extractConstants, we need to find the names referenced in them here
270+
names.addAll(Arrays.asList(extractNames(((GeneratorExpressionNode) node).getCallTarget().getRootNode())));
271+
}
272+
return true;
273+
}
274+
});
275+
return names.toArray();
263276
}
264277

265278
private static RootNode rootNodeForExtraction(RootNode rootNode) {

0 commit comments

Comments
 (0)