Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1476,10 +1476,12 @@ private BytecodeDSLCodeUnit readBytecodeDSLCodeUnit() {
int endColumn = readInt();
int classcellIndex = readInt();
int selfIndex = readInt();
int yieldFromGeneratorIndex = readInt();
int instrumentationDataIndex = readInt();

BytecodeSupplier provider = new BytecodeSupplier(serialized, bytecodeFile, bytecodeOffset, bytecodeSize, cacheKey);
return new BytecodeDSLCodeUnit(name, qualname, argCount, kwOnlyArgCount, positionalOnlyArgCount, flags, names, varnames, cellvars, freevars, cell2arg, constants,
startLine, startColumn, endLine, endColumn, classcellIndex, selfIndex, provider);
startLine, startColumn, endLine, endColumn, classcellIndex, selfIndex, yieldFromGeneratorIndex, instrumentationDataIndex, provider);
}

private void writeCodeUnit(CodeUnit code) throws IOException {
Expand Down Expand Up @@ -1553,6 +1555,8 @@ private void writeBytecodeDSLCodeUnit(BytecodeDSLCodeUnit code) throws IOExcepti
writeInt(code.endColumn);
writeInt(code.classcellIndex);
writeInt(code.selfIndex);
writeInt(code.yieldFromGeneratorIndex);
writeInt(code.instrumentationDataIndex);
}

private PCode readCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1113,9 +1113,9 @@ static Object settrace(Object function,
PythonLanguage language = context.getLanguage(inliningTarget);
PythonContext.PythonThreadState state = context.getThreadState(language);
if (function == PNone.NONE) {
state.setTraceFun(null, language);
state.setTraceFun(inliningTarget, null, language);
} else {
state.setTraceFun(function, language);
state.setTraceFun(inliningTarget, function, language);
}
return PNone.NONE;
}
Expand All @@ -1132,9 +1132,9 @@ static Object settrace(Object function,
PythonLanguage language = context.getLanguage(inliningTarget);
PythonContext.PythonThreadState state = context.getThreadState(language);
if (function == PNone.NONE) {
state.setProfileFun(null, language);
state.setProfileFun(inliningTarget, null, language);
} else {
state.setProfileFun(function, language);
state.setProfileFun(inliningTarget, function, language);
}
return PNone.NONE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ public Object getYieldFrom() {

if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
PBytecodeDSLRootNode rootNode = getBytecodeDSLState().rootNode;
if (rootNode.yieldFromGeneratorIndex == -1 || !getBytecodeDSLState().isStarted) {
if (!rootNode.hasYieldFromGenerator() || !getBytecodeDSLState().isStarted) {
return null;
}
return getContinuationBytecodeNode().getLocalValue(0, getGeneratorFrame(), rootNode.yieldFromGeneratorIndex);
return rootNode.readYieldFromGenerator(getContinuationBytecodeNode(), getGeneratorFrame());
} else {
return ((BytecodeFrameInfo) frameInfo).getYieldFrom(frame, getBci(), getBytecodeState().getCurrentRootNode().getResumeStackTop());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ public final class RootNodeCompiler implements BaseBytecodeDSLVisitor<BytecodeDS
private BytecodeLocal currentSaveExceptionLocal;
private BytecodeLocal prevSaveExceptionLocal;

private BytecodeLocal instrumentationDataLocal;

public RootNodeCompiler(BytecodeDSLCompilerContext ctx, RootNodeCompiler parent, SSTNode rootNode, EnumSet<FutureFeature> futureFeatures) {
this(ctx, parent, null, rootNode, rootNode, futureFeatures);
}
Expand Down Expand Up @@ -458,12 +460,10 @@ flags, orderedTruffleStringArray(names),
sourceRange.endColumn,
classcellIndex,
selfIndex,
yieldFromGenerator != null ? yieldFromGenerator.getLocalIndex() : -1,
instrumentationDataLocal.getLocalIndex(),
new BytecodeSupplier(nodes));
rootNode.setMetadata(codeUnit, ctx.errorCallback);
if (codeUnit.isCoroutine() || codeUnit.isAsyncGenerator() || scope.isGeneratorWithYieldFrom()) {
rootNode.yieldFromGeneratorIndex = yieldFromGenerator.getLocalIndex();
}

return new BytecodeDSLCompilerResult(rootNode, codeUnit);
}

Expand Down Expand Up @@ -1413,10 +1413,18 @@ private void emitYield(Consumer<StatementCompiler> yieldValueProducer, Statement
savedExLocal = currentSaveExceptionLocal;
}

statementCompiler.b.beginResumeYield(generatorExceptionStateLocal, savedExLocal);
statementCompiler.b.beginResumeYield();
statementCompiler.b.beginResumeInstrumentedYield();
statementCompiler.b.beginPreResumeYield(generatorExceptionStateLocal, savedExLocal);

statementCompiler.b.beginYieldValue();
statementCompiler.b.beginTraceYieldValue();
yieldValueProducer.accept(statementCompiler);
statementCompiler.b.endTraceYieldValue();
statementCompiler.b.endYieldValue();

statementCompiler.b.endPreResumeYield();
statementCompiler.b.endResumeInstrumentedYield();
statementCompiler.b.endResumeYield();
}

Expand Down Expand Up @@ -1696,6 +1704,11 @@ public void setUpFrame(ArgumentsTy args, Builder b) {
if (scope.isGeneratorWithYieldFrom() || scope.isCoroutine()) {
yieldFromGenerator = b.createLocal();
}

// We always create this local, but it is used only by TRACE_AND_PROFILE_CONFIG
// configuration
instrumentationDataLocal = b.createLocal();
b.emitEnterInstrumentedRoot();
}

private void copyArguments(ArgumentsTy args, Builder b) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3309,7 +3309,7 @@ private void invokeTraceFunction(VirtualFrame virtualFrame, Object arg, PythonCo
pyFrame.setLocalTraceFun(null);
}
} catch (Throwable e) {
threadState.setTraceFun(null, getLanguage());
threadState.setTraceFun(null, null, getLanguage());
throw e;
} finally {
if (line != -1) {
Expand Down Expand Up @@ -3377,7 +3377,7 @@ private void invokeProfileFunction(VirtualFrame virtualFrame, Object arg, Python
Object realResult = result == PNone.NONE ? null : result;
pyFrame.setLocalTraceFun(realResult);
} catch (Throwable e) {
threadState.setProfileFun(null, getLanguage());
threadState.setProfileFun(null, null, getLanguage());
throw e;
} finally {
threadState.profilingStop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,19 @@
public final class BytecodeDSLCodeUnit extends CodeUnit {
public final int classcellIndex;
public final int selfIndex;
public final int yieldFromGeneratorIndex;
public final int instrumentationDataIndex;
private final BytecodeSupplier supplier;

public BytecodeDSLCodeUnit(TruffleString name, TruffleString qualname, int argCount, int kwOnlyArgCount, int positionalOnlyArgCount, int flags, TruffleString[] names, TruffleString[] varnames,
TruffleString[] cellvars, TruffleString[] freevars, int[] cell2arg, Object[] constants, int startLine, int startColumn, int endLine, int endColumn,
int classcellIndex, int selfIndex, BytecodeSupplier supplier) {
int classcellIndex, int selfIndex, int yieldFromGeneratorIndex, int instrumentationDataIndex, BytecodeSupplier supplier) {
super(name, qualname, argCount, kwOnlyArgCount, positionalOnlyArgCount, flags, names, varnames, cellvars, freevars, cell2arg, constants, startLine, startColumn, endLine, endColumn);
this.classcellIndex = classcellIndex;
this.selfIndex = selfIndex;
this.supplier = supplier;
this.yieldFromGeneratorIndex = yieldFromGeneratorIndex;
this.instrumentationDataIndex = instrumentationDataIndex;
}

public abstract static class BytecodeSupplier {
Expand All @@ -71,7 +75,7 @@ public abstract static class BytecodeSupplier {
public BytecodeDSLCodeUnit withFlags(int flags) {
return new BytecodeDSLCodeUnit(name, qualname, argCount, kwOnlyArgCount, positionalOnlyArgCount, flags,
names, varnames, cellvars, freevars, cell2arg, constants,
startLine, startColumn, endLine, endColumn, classcellIndex, selfIndex, supplier);
startLine, startColumn, endLine, endColumn, classcellIndex, selfIndex, yieldFromGeneratorIndex, instrumentationDataIndex, supplier);
}

@TruffleBoundary
Expand Down
Loading
Loading