Skip to content

Commit 6aa7674

Browse files
msimacektomasstupka
authored andcommitted
Fix throw into unstarted generator
1 parent 8854af0 commit 6aa7674

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,10 @@ private Object doThrow(VirtualFrame frame, ResumeGeneratorNode resumeGeneratorNo
496496
Node location = self.getCurrentCallTarget().getRootNode();
497497
MaterializedFrame generatorFrame = PArguments.getGeneratorFrame(self.getArguments());
498498
PFrame pFrame = ensureMaterializeFrameNode().execute(null, location, false, false, generatorFrame);
499+
if (self.usesBytecode()) {
500+
FrameInfo info = (FrameInfo) generatorFrame.getFrameDescriptor().getInfo();
501+
pFrame.setLine(info.getRootNode().getFirstLineno());
502+
}
499503
PTraceback existingTraceback = null;
500504
if (instance.getTraceback() != null) {
501505
existingTraceback = ensureGetTracebackNode().execute(instance.getTraceback());

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CompilationUnit.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public final class CompilationUnit {
8787
Block currentBlock = startBlock;
8888
int maxStackSize = 0;
8989

90-
int startOffset;
90+
final int startOffset;
91+
int currentOffset;
9192

9293
CompilationUnit(CompilationScope scopeType, Scope scope, String name, CompilationUnit parent, int scopeDepth, int argCount, int positionalOnlyArgCount, int kwOnlyArgCount, boolean takesVarArgs,
9394
boolean takesVarKeywordArgs, int startOffset) {
@@ -100,6 +101,7 @@ public final class CompilationUnit {
100101
this.takesVarArgs = takesVarArgs;
101102
this.takesVarKeywordArgs = takesVarKeywordArgs;
102103
this.startOffset = startOffset;
104+
currentOffset = startOffset;
103105

104106
if (scopeType == Class) {
105107
privateName = name;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Compiler.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,22 +292,22 @@ private boolean containsAnnotations(StmtTy[] stmts) {
292292
}
293293

294294
private Void addOp(OpCodes code) {
295-
addOp(code, 0, null, unit.startOffset);
295+
addOp(code, 0, null, unit.currentOffset);
296296
return null;
297297
}
298298

299299
private void addOp(OpCodes code, Block target) {
300300
Block b = unit.currentBlock;
301-
b.instr.add(new Instruction(code, 0, null, target, unit.startOffset));
301+
b.instr.add(new Instruction(code, 0, null, target, unit.currentOffset));
302302
}
303303

304304
private Void addOp(OpCodes code, int arg) {
305-
addOp(code, arg, null, unit.startOffset);
305+
addOp(code, arg, null, unit.currentOffset);
306306
return null;
307307
}
308308

309309
private Void addOp(OpCodes code, int arg, byte[] followingArgs) {
310-
addOp(code, arg, followingArgs, unit.startOffset);
310+
addOp(code, arg, followingArgs, unit.currentOffset);
311311
return null;
312312
}
313313

@@ -440,8 +440,8 @@ private String getDocstring(StmtTy[] body) {
440440
}
441441

442442
private int setLocation(int offset) {
443-
int savedOffset = unit.startOffset;
444-
unit.startOffset = offset;
443+
int savedOffset = unit.currentOffset;
444+
unit.currentOffset = offset;
445445
return savedOffset;
446446
}
447447

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,6 +2256,15 @@ public int bciToLine(int bci) {
22562256
return -1;
22572257
}
22582258

2259+
@TruffleBoundary
2260+
public int getFirstLineno() {
2261+
if (source != null && source.hasCharacters()) {
2262+
// TODO the same problem as bciToLine
2263+
return source.createSection(co.startOffset, 0).getStartLine();
2264+
}
2265+
return -1;
2266+
}
2267+
22592268
@Override
22602269
public SourceSection getSourceSection() {
22612270
if (sourceSection != null) {

0 commit comments

Comments
 (0)