Skip to content

Commit 706cf13

Browse files
committed
[GR-34551] Replace deprecated Frame API usages
PullRequest: graalpython/2059
2 parents d2a7554 + 98aa4a2 commit 706cf13

File tree

498 files changed

+4814
-5367
lines changed

Some content is hidden

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

498 files changed

+4814
-5367
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/parser/BasicTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.junit.Test;
4848

4949
import com.oracle.graal.python.builtins.objects.str.StringUtils;
50+
import com.oracle.graal.python.nodes.frame.PythonFrame;
5051
import com.oracle.graal.python.runtime.PythonParser;
5152
import com.oracle.truffle.api.Truffle;
5253
import com.oracle.truffle.api.frame.Frame;
@@ -129,11 +130,8 @@ public void assert04() throws Exception {
129130
}
130131

131132
@Test
132-
@SuppressWarnings("deprecation") // new Frame API
133133
public void inline01() throws Exception {
134-
FrameDescriptor fd = new FrameDescriptor(44);
135-
fd.addFrameSlot("a");
136-
fd.addFrameSlot("b");
134+
FrameDescriptor fd = PythonFrame.createTestFrameDescriptor("a", "b");
137135
Frame frame = Truffle.getRuntime().createVirtualFrame(new Object[]{2, 3, null}, fd);
138136
checkTreeResult("a + b", PythonParser.ParserMode.InlineEvaluation, frame);
139137
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/parser/ParserTestBase.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@
6565
import com.oracle.graal.python.runtime.PythonParser;
6666
import com.oracle.graal.python.runtime.exception.PException;
6767
import com.oracle.graal.python.test.PythonTests;
68+
import com.oracle.truffle.api.CompilerDirectives;
6869
import com.oracle.truffle.api.TruffleFile;
6970
import com.oracle.truffle.api.frame.Frame;
71+
import com.oracle.truffle.api.frame.VirtualFrame;
7072
import com.oracle.truffle.api.interop.ExceptionType;
7173
import com.oracle.truffle.api.interop.InteropLibrary;
7274
import com.oracle.truffle.api.interop.UnsupportedMessageException;
7375
import com.oracle.truffle.api.nodes.Node;
76+
import com.oracle.truffle.api.nodes.RootNode;
7477
import com.oracle.truffle.api.source.Source;
7578

7679
public class ParserTestBase {
@@ -113,10 +116,28 @@ protected Source createSource(File testFile) throws Exception {
113116

114117
public Node parse(String src, String moduleName, PythonParser.ParserMode mode, Frame fd) {
115118
Source source = Source.newBuilder(PythonLanguage.ID, src, moduleName).build();
119+
Node result = parseInternal(source, mode, fd);
120+
return result;
121+
}
122+
123+
private Node parseInternal(Source source, PythonParser.ParserMode mode, Frame fd) {
116124
PythonParser parser = context.getParser();
117125
Node result = ((PythonParserImpl) parser).parseN(mode, 0, context, source, fd, null);
118126
lastGlobalScope = ((PythonParserImpl) parser).getLastGlobaScope();
119127
lastSST = ((PythonParserImpl) parser).getLastSST();
128+
// ensure that node parent pointers are set:
129+
if (result instanceof RootNode) {
130+
((RootNode) result).getCallTarget();
131+
} else {
132+
new RootNode(null, fd.getFrameDescriptor()) {
133+
@Child private Node adopted = result;
134+
135+
@Override
136+
public Object execute(VirtualFrame frame) {
137+
throw CompilerDirectives.shouldNotReachHere();
138+
}
139+
}.getCallTarget();
140+
}
120141
return result;
121142
}
122143

@@ -125,11 +146,7 @@ public Node parse(String src, String moduleName, PythonParser.ParserMode mode) {
125146
}
126147

127148
public Node parse(Source source, PythonParser.ParserMode mode) {
128-
PythonParser parser = context.getParser();
129-
Node result = ((PythonParserImpl) parser).parseN(mode, 0, context, source, null, null);
130-
lastGlobalScope = ((PythonParserImpl) parser).getLastGlobaScope();
131-
lastSST = ((PythonParserImpl) parser).getLastSST();
132-
return result;
149+
return parseInternal(source, mode, null);
133150
}
134151

135152
protected ScopeInfo getLastGlobalScope() {
@@ -334,7 +351,7 @@ protected void assertDescriptionMatches(String actual, String expected, String s
334351
return; // Only difference is in line separation --> Test passed
335352
}
336353

337-
// There are some diffrerences between expected and actual content --> Test failed
354+
// There are some differences between expected and actual content --> Test failed
338355

339356
assertTrue("Not matching results: " + (someName == null ? "" : someName) + lineSeparator(2) + getContentDifferences(expectedUnified, actualUnified), false);
340357
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/parser/ParserTreePrinter.java

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141

4242
package com.oracle.graal.python.test.parser;
4343

44-
import java.util.Set;
44+
import java.util.Collection;
45+
import java.util.TreeSet;
4546

4647
import com.oracle.graal.python.builtins.objects.function.Signature;
4748
import com.oracle.graal.python.nodes.ModuleRootNode;
@@ -59,6 +60,7 @@
5960
import com.oracle.graal.python.nodes.frame.AccessNameNode;
6061
import com.oracle.graal.python.nodes.frame.FrameSlotIDs;
6162
import com.oracle.graal.python.nodes.frame.FrameSlotNode;
63+
import com.oracle.graal.python.nodes.frame.PythonFrame;
6264
import com.oracle.graal.python.nodes.frame.ReadGlobalOrBuiltinNode;
6365
import com.oracle.graal.python.nodes.frame.WriteGlobalNode;
6466
import com.oracle.graal.python.nodes.frame.WriteIdentifierNode;
@@ -106,7 +108,7 @@ public boolean visit(ModuleRootNode module) {
106108
nodeHeader(module, module.getName());
107109
level++;
108110
addSignature(module.getSignature());
109-
addInfoPCloserRootNode(module);
111+
addInfoPClosureRootNode(module);
110112
indent(level);
111113
sb.append("Documentation: ");
112114
add(module.getDoc());
@@ -121,10 +123,10 @@ private void addInfoPClosureFunctionRootNode(PClosureFunctionRootNode node) {
121123
sb.append("CelVars: ");
122124
add(node.getCellVars());
123125
newLine();
124-
addInfoPCloserRootNode(node);
126+
addInfoPClosureRootNode(node);
125127
}
126128

127-
private void addInfoPCloserRootNode(PClosureRootNode node) {
129+
private void addInfoPClosureRootNode(PClosureRootNode node) {
128130
indent(level);
129131
sb.append("FreeVars: ");
130132
add(node.getFreeVars());
@@ -141,7 +143,7 @@ private void addInfoPRootNode(PRootNode node) {
141143
}
142144

143145
private void addInfoRootNode(RootNode node) {
144-
addFrameDescriptor(node.getFrameDescriptor());
146+
addIdentifiers(PythonFrame.getIdentifiersAsString(node.getFrameDescriptor()));
145147
}
146148

147149
private void addFunctionDefinitionNode(FunctionDefinitionNode node) {
@@ -188,16 +190,16 @@ private void addFunctionDefinitionNode(FunctionDefinitionNode node) {
188190
}
189191
indent(level);
190192
sb.append("FreeVarSlots: ");
191-
add(node.getFreeVarDefinitionSlots());
193+
add(node.getFreeVarDefinitions());
192194
newLine();
193-
add(node.getExecutionCellSlots());
195+
add(node.getExecutionCellSlots(), node.getCallTarget().getRootNode().getFrameDescriptor());
194196
visit(node.getFunctionRoot());
195197
}
196198

197199
public boolean visit(GeneratorFunctionDefinitionNode node) {
198200
nodeHeader(node, node.getFunctionName());
199201
level++;
200-
addFrameDescriptor(node.getFrameDescriptor());
202+
addIdentifiers(PythonFrame.getIdentifiersAsString(node.getFrameDescriptor()));
201203
indent(level);
202204
GeneratorInfo generatorInfo = node.getGeneratorInfo();
203205
sb.append("Active Flags: ").append(generatorInfo.getNumOfActiveFlags());
@@ -228,7 +230,7 @@ public boolean visit(FunctionRootNode node) {
228230
sb.append("Name: ").append(node.getName());
229231
newLine();
230232
addInfoPClosureFunctionRootNode(node);
231-
add(node.getExecutionCellSlots());
233+
add(node.getExecutionCellSlots(), node.getFrameDescriptor());
232234
level--;
233235
return true;
234236
}
@@ -347,12 +349,12 @@ public boolean visit(GeneratorExpressionNode node) {
347349
indent(level);
348350
sb.append("Name: ").append(node.getName());
349351
newLine();
350-
addFrameDescriptor(node.getFrameDescriptor());
352+
addIdentifiers(PythonFrame.getIdentifiersAsString(node.getFrameDescriptor()));
351353
indent(level);
352354
sb.append("Enclosing");
353355
newLine();
354356
level++;
355-
addFrameDescriptor(node.getEnclosingFrameDescriptor());
357+
addIdentifiers(node.getEnclosingFrameDescriptor());
356358
level--;
357359
indent(level);
358360
GeneratorInfo generatorInfo = node.getGeneratorInfo();
@@ -482,24 +484,20 @@ private void addSignature(Signature signature) {
482484
level--;
483485
}
484486

485-
@SuppressWarnings("deprecation") // new Frame API
486-
private void addFrameDescriptor(FrameDescriptor fd) {
487+
private void addIdentifiers(Collection<? extends Object> identifiers) {
487488
indent(level);
488489
sb.append("FrameDescriptor: ");
489-
if (fd.getSlots().size() == 0) {
490+
if (identifiers.isEmpty()) {
490491
sb.append(" Empty");
491492
newLine();
492493
return;
493494
}
494-
sb.append(fd.getSlots().size()).append(" slots [");
495-
Set<Object> identifiers = fd.getIdentifiers();
496-
String[] names = new String[identifiers.size()];
497-
int i = 0;
498-
String name;
495+
sb.append(identifiers.size()).append(" slots [");
496+
TreeSet<String> names = new TreeSet<>();
499497
for (Object identifier : identifiers) {
500-
name = identifier.toString();
498+
String name = identifier.toString();
501499
if (printTmpSlots || (!printTmpSlots && !name.startsWith("<>temp"))) {
502-
names[i++] = name;
500+
names.add(name);
503501
}
504502
}
505503
add(names);
@@ -535,55 +533,55 @@ private void add(String[] array) {
535533
}
536534
}
537535

538-
@SuppressWarnings("deprecation") // new Frame API
539-
private void add(com.oracle.truffle.api.frame.FrameSlot[] slots) {
540-
if (slots == null || slots.length == 0) {
536+
private void add(Collection<String> array) {
537+
if (array == null || array.isEmpty()) {
541538
sb.append("None");
542539
} else {
543540
boolean first = true;
544-
for (com.oracle.truffle.api.frame.FrameSlot slot : slots) {
541+
for (String text : array) {
545542
if (!first) {
546543
sb.append(", ");
547544
} else {
548545
first = false;
549546
}
550-
sb.append(slot.getIdentifier()).append(", ");
547+
sb.append(text);
551548
}
552549
}
553550
}
554551

555-
@SuppressWarnings("deprecation") // new Frame API
556-
private void add(com.oracle.truffle.api.frame.FrameSlot slot) {
552+
private void add(FrameSlotNode slot) {
553+
FrameDescriptor descriptor = ((Node) slot).getRootNode().getFrameDescriptor();
554+
String full = "[" + slot.getSlotIndex() + "," + slot.getSlotIdentifier(descriptor) + "," + slot.getSlotKind(descriptor) + "]";
557555
if (printTmpSlots) {
558-
sb.append(slot.toString());
556+
sb.append(full);
559557
} else {
560-
Object identifier = slot.getIdentifier();
558+
Object identifier = slot.getSlotIdentifier(descriptor);
561559
if (identifier instanceof String) {
562-
sb.append(slot.toString());
560+
sb.append(full);
563561
} else if (identifier == FrameSlotIDs.RETURN_SLOT_ID) {
564562
sb.append("<return_val>");
565563
} else if (identifier == FrameSlotIDs.FREEVAR__CLASS__) {
566564
sb.append("<>freevar__class__");
567565
} else if (identifier.toString().startsWith("<>temp")) {
568566
sb.append("<>temp");
569567
} else {
570-
sb.append(slot.toString());
568+
sb.append(full);
571569
}
572570
}
573571
}
574572

575-
private void add(ExecutionCellSlots executionCellSlots) {
573+
private void add(ExecutionCellSlots executionCellSlots, FrameDescriptor descriptor) {
576574
indent(level);
577575
sb.append("ExecutionSlots:");
578576
newLine();
579577
level++;
580578
indent(level);
581579
sb.append("FreeVarsSlots: ");
582-
add(executionCellSlots.getFreeVarSlots());
580+
add(PythonFrame.extractSlotNames(descriptor, executionCellSlots.getFreeVarSlots()));
583581
newLine();
584582
indent(level);
585583
sb.append("CellVarsSlots: ");
586-
add(executionCellSlots.getCellVarSlots());
584+
add(PythonFrame.extractSlotNames(descriptor, executionCellSlots.getCellVarSlots()));
587585
newLine();
588586
level--;
589587
}
@@ -694,7 +692,7 @@ public boolean visit(Node node) {
694692
if (node instanceof FrameSlotNode) {
695693
indent(level);
696694
sb.append("Frame: ");
697-
add(((FrameSlotNode) node).getSlot());
695+
add((FrameSlotNode) node);
698696
newLine();
699697
}
700698
if (node instanceof WriteGlobalNode) {

0 commit comments

Comments
 (0)