Skip to content

Commit 8891043

Browse files
committed
[GR-38700] Bytecode DSL: various fixes.
PullRequest: graalpython/4125
2 parents 8a0b6dc + 60b0fc4 commit 8891043

File tree

15 files changed

+106
-63
lines changed

15 files changed

+106
-63
lines changed

graalpython/com.oracle.graal.python.pegparser.test/testData/parser/goldenFiles/YieldStatementTests/customIter01.scope

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ScopeEnvironment
2727
StopIteration: [Use, GlobalImplicit]
2828
self: [DefParam, Local]
2929
Scope gen Function
30-
Flags: [IsNested, HasFreeVars, IsGenerator]
30+
Flags: [IsNested, HasFreeVars, IsGenerator, IsGeneratorWithYieldFrom]
3131
Symbols:
3232
MyIter: [Use, Free]
33-
ret: [DefLocal, DefNonLocal, Free]
33+
ret: [DefLocal, DefNonLocal, Free]

graalpython/com.oracle.graal.python.pegparser.test/testData/parser/goldenFiles/YieldStatementTests/yield12.scope

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ ScopeEnvironment
33
Symbols:
44
f: [DefLocal, Local]
55
Scope f Function
6-
Flags: [IsGenerator]
6+
Flags: [IsGenerator, IsGeneratorWithYieldFrom]

graalpython/com.oracle.graal.python.pegparser.test/testData/parser/goldenFiles/YieldStatementTests/yield13.scope

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ ScopeEnvironment
33
Symbols:
44
f: [DefLocal, Local]
55
Scope f Function
6-
Flags: [IsGenerator]
6+
Flags: [IsGenerator, IsGeneratorWithYieldFrom]
77
Symbols:
8-
f: [Use, GlobalImplicit]
8+
f: [Use, GlobalImplicit]

graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/scope/Scope.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ enum ScopeFlags {
119119
NeedsClassClosure,
120120
NeedsClassDict,
121121
IsVisitingIterTarget,
122-
CanSeeClassScope
122+
CanSeeClassScope,
123+
IsGeneratorWithYieldFrom,
123124
}
124125

125126
EnumSet<ScopeFlags> flags = EnumSet.noneOf(ScopeFlags.class);
@@ -243,6 +244,10 @@ public boolean isGenerator() {
243244
return flags.contains(ScopeFlags.IsGenerator);
244245
}
245246

247+
public boolean isGeneratorWithYieldFrom() {
248+
return flags.contains(ScopeFlags.IsGeneratorWithYieldFrom);
249+
}
250+
246251
public boolean isCoroutine() {
247252
return flags.contains(ScopeFlags.IsCoroutine);
248253
}

graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/scope/ScopeEnvironment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ public Void visit(ExprTy.YieldFrom node) {
920920
node.value.accept(this);
921921
}
922922
currentScope.flags.add(ScopeFlags.IsGenerator);
923+
currentScope.flags.add(ScopeFlags.IsGeneratorWithYieldFrom);
923924
if (currentScope.flags.contains(ScopeFlags.IsComprehension)) {
924925
throw raiseIfComprehensionBlock(node);
925926
}

graalpython/com.oracle.graal.python.test/src/tests/test_generators.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,4 +476,34 @@ def generator():
476476
assert type(g.send(None)) == NotImplementedError # 13
477477
assert type(g.send(None)) == NameError # 14
478478
assert g.send(None) is None # 15
479-
assert g.send(None) is None # 16
479+
assert g.send(None) is None # 16
480+
481+
482+
def test_generator_gi_yieldfrom_multiple():
483+
# the same test as in CPython test suite, but with multiple yield from
484+
def a():
485+
yield
486+
487+
def q():
488+
yield
489+
490+
def b():
491+
yield from a()
492+
yield
493+
yield from q()
494+
yield
495+
496+
gen_b = b()
497+
assert gen_b.gi_yieldfrom is None
498+
499+
gen_b.send(None)
500+
assert gen_b.gi_yieldfrom.gi_code.co_name == 'a'
501+
502+
gen_b.send(None)
503+
assert gen_b.gi_yieldfrom is None
504+
505+
gen_b.send(None)
506+
assert gen_b.gi_yieldfrom.gi_code.co_name == 'q'
507+
508+
gen_b.send(None)
509+
assert gen_b.gi_yieldfrom is None

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags_bytecode_dsl/test_code.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
DocTestCase.test.test_code @ linux-x86_64
12
test.test_code.CodeTest.test_code_hash_uses_bytecode @ linux-x86_64
23
test.test_code.CodeTest.test_constructor @ linux-x86_64
34
test.test_code.CodeTest.test_qualname @ linux-x86_64

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags_bytecode_dsl/test_generators.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ test.test_generators.GeneratorThrowTest.test_exception_context_with_yield_from @
3434
test.test_generators.GeneratorThrowTest.test_exception_context_with_yield_from_with_context_cycle @ linux-x86_64
3535
test.test_generators.GeneratorThrowTest.test_exception_context_with_yield_inside_generator @ linux-x86_64
3636
test.test_generators.GeneratorThrowTest.test_throw_after_none_exc_type @ linux-x86_64
37+
test.test_generators.YieldFromTests.test_generator_gi_yieldfrom @ linux-x86_64
38+

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags_bytecode_dsl/test_threading.txt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ test.test_threading.ExceptHookTests.test_custom_excepthook_fail @ linux-x86_64
7676
test.test_threading.ExceptHookTests.test_excepthook @ linux-x86_64
7777
test.test_threading.ExceptHookTests.test_original_excepthook @ linux-x86_64
7878
test.test_threading.ExceptHookTests.test_system_exit @ linux-x86_64
79+
# Transient on Darwin (at least)
80+
!test.test_threading.InterruptMainTests.test_can_interrupt_tight_loops
7981
test.test_threading.InterruptMainTests.test_interrupt_main_noerror @ linux-x86_64
8082
test.test_threading.LockTests.test_acquire_contended @ linux-x86_64
8183
test.test_threading.LockTests.test_acquire_destroy @ linux-x86_64
@@ -123,21 +125,23 @@ test.test_threading.SemaphoreTests.test_repr @ linux-x86_64
123125
test.test_threading.SemaphoreTests.test_try_acquire @ linux-x86_64
124126
test.test_threading.SemaphoreTests.test_try_acquire_contended @ linux-x86_64
125127
test.test_threading.SemaphoreTests.test_with @ linux-x86_64
126-
!test.test_threading.ThreadJoinOnShutdown.test_4_daemon_threads
128+
# Can transiently fail with java.lang.AssertionError: The TruffleContext must be entered
129+
!test.test_threading.ThreadJoinOnShutdown.test_1_join_on_shutdown
130+
test.test_threading.ThreadJoinOnShutdown.test_4_daemon_threads @ linux-x86_64
127131
test.test_threading.ThreadJoinOnShutdown.test_thread_from_thread @ linux-x86_64
128132
test.test_threading.ThreadTests.test_BoundedSemaphore_limit @ linux-x86_64
129133
test.test_threading.ThreadTests.test_args_argument @ linux-x86_64
130134
test.test_threading.ThreadTests.test_boolean_target @ linux-x86_64
131135
test.test_threading.ThreadTests.test_daemon_param @ linux-x86_64
132136
test.test_threading.ThreadTests.test_enumerate_after_join @ linux-x86_64
133-
!test.test_threading.ThreadTests.test_finalization_shutdown
134-
!test.test_threading.ThreadTests.test_finalize_with_trace
137+
test.test_threading.ThreadTests.test_finalization_shutdown @ linux-x86_64
138+
test.test_threading.ThreadTests.test_finalize_with_trace @ linux-x86_64
135139
test.test_threading.ThreadTests.test_foreign_thread @ linux-x86_64
136140
test.test_threading.ThreadTests.test_getprofile @ linux-x86_64
137141
test.test_threading.ThreadTests.test_gettrace @ linux-x86_64
138142
test.test_threading.ThreadTests.test_ident_of_no_threading_threads @ linux-x86_64
139-
!test.test_threading.ThreadTests.test_import_from_another_thread
140-
!test.test_threading.ThreadTests.test_join_nondaemon_on_shutdown
143+
test.test_threading.ThreadTests.test_import_from_another_thread @ linux-x86_64
144+
test.test_threading.ThreadTests.test_join_nondaemon_on_shutdown @ linux-x86_64
141145
test.test_threading.ThreadTests.test_leak_without_join @ linux-x86_64
142146
test.test_threading.ThreadTests.test_limbo_cleanup @ linux-x86_64
143147
test.test_threading.ThreadTests.test_main_thread @ linux-x86_64
@@ -153,8 +157,8 @@ test.test_threading.ThreadingExceptionTests.test_daemonize_active_thread @ linux
153157
test.test_threading.ThreadingExceptionTests.test_joining_current_thread @ linux-x86_64
154158
test.test_threading.ThreadingExceptionTests.test_joining_inactive_thread @ linux-x86_64
155159
test.test_threading.ThreadingExceptionTests.test_multithread_modify_file_noerror @ linux-x86_64
156-
!test.test_threading.ThreadingExceptionTests.test_print_exception
157-
!test.test_threading.ThreadingExceptionTests.test_print_exception_stderr_is_none_1
158-
!test.test_threading.ThreadingExceptionTests.test_print_exception_stderr_is_none_2
160+
test.test_threading.ThreadingExceptionTests.test_print_exception @ linux-x86_64
161+
test.test_threading.ThreadingExceptionTests.test_print_exception_stderr_is_none_1 @ linux-x86_64
162+
test.test_threading.ThreadingExceptionTests.test_print_exception_stderr_is_none_2 @ linux-x86_64
159163
test.test_threading.ThreadingExceptionTests.test_start_thread_again @ linux-x86_64
160164
test.test_threading.TimerTests.test_init_immutable_default_args @ linux-x86_64

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import com.oracle.graal.python.runtime.object.PFactory;
4545
import com.oracle.truffle.api.CompilerDirectives;
4646
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
47-
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4847
import com.oracle.truffle.api.RootCallTarget;
4948
import com.oracle.truffle.api.TruffleStackTraceElement;
5049
import com.oracle.truffle.api.bytecode.BytecodeLocation;
@@ -238,10 +237,6 @@ public static Frame unwrapDSLGeneratorFrame(TruffleStackTraceElement element) {
238237
return element.getFrame();
239238
}
240239

241-
public static Frame getDSLGeneratorFrame(Object[] continuationCallArguments) {
242-
return (Frame) continuationCallArguments[0];
243-
}
244-
245240
public static RootNode unwrapContinuationRoot(RootNode rootNode) {
246241
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER &&
247242
rootNode instanceof ContinuationRootNode continuationRoot) {
@@ -251,20 +246,7 @@ public static RootNode unwrapContinuationRoot(RootNode rootNode) {
251246
}
252247

253248
public static PBytecodeDSLRootNode unwrapContinuationRoot(ContinuationRootNode continuationRoot) {
254-
if (CompilerDirectives.isPartialEvaluationConstant(continuationRoot)) {
255-
return (PBytecodeDSLRootNode) continuationRoot.getSourceRootNode();
256-
} else {
257-
/*
258-
* TODO We know that the continuation root node is always the same type, but we can't
259-
* cast to it because it's not public. So we end up with a virtual call.
260-
*/
261-
return unwrapContinuationRootBoundary(continuationRoot);
262-
}
263-
}
264-
265-
@TruffleBoundary
266-
private static PBytecodeDSLRootNode unwrapContinuationRootBoundary(ContinuationRootNode continuationRoot) {
267-
return (PBytecodeDSLRootNode) continuationRoot.getSourceRootNode();
249+
return PBytecodeDSLRootNode.cast(continuationRoot);
268250
}
269251

270252
public static boolean isGeneratorFrame(Frame frame) {

0 commit comments

Comments
 (0)