38
38
39
39
import java .util .List ;
40
40
41
+ import com .oracle .graal .python .PythonLanguage ;
41
42
import com .oracle .graal .python .builtins .Builtin ;
42
43
import com .oracle .graal .python .builtins .CoreFunctions ;
43
44
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
69
70
import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
70
71
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
71
72
import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
73
+ import com .oracle .graal .python .runtime .PythonContext ;
74
+ import com .oracle .graal .python .runtime .PythonOptions ;
72
75
import com .oracle .graal .python .runtime .exception .PException ;
73
76
import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
74
77
import com .oracle .graal .python .util .PythonUtils ;
75
78
import com .oracle .truffle .api .CallTarget ;
76
79
import com .oracle .truffle .api .CompilerDirectives ;
77
80
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
78
81
import com .oracle .truffle .api .RootCallTarget ;
82
+ import com .oracle .truffle .api .TruffleLanguage .ContextReference ;
79
83
import com .oracle .truffle .api .dsl .Cached ;
84
+ import com .oracle .truffle .api .dsl .Cached .Shared ;
85
+ import com .oracle .truffle .api .dsl .CachedContext ;
80
86
import com .oracle .truffle .api .dsl .Fallback ;
81
87
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
82
88
import com .oracle .truffle .api .dsl .ImportStatic ;
@@ -387,35 +393,37 @@ private void checkExceptionClass(Object type) {
387
393
@ Specialization
388
394
Object sendThrow (VirtualFrame frame , PGenerator self , Object typ , Object val , @ SuppressWarnings ("unused" ) PNone tb ,
389
395
@ Cached PrepareExceptionNode prepareExceptionNode ,
390
- @ Cached BranchProfile alreadyRunning ) {
396
+ @ Cached BranchProfile alreadyRunning ,
397
+ @ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
391
398
if (self .isRunning ()) {
392
399
alreadyRunning .enter ();
393
400
throw raise (ValueError , ErrorMessages .GENERATOR_ALREADY_EXECUTING );
394
401
}
395
402
PBaseException instance = prepareExceptionNode .execute (frame , typ , val );
396
- return doThrow (self , instance );
403
+ return doThrow (self , instance , contextRef . get () );
397
404
}
398
405
399
406
@ Specialization
400
407
Object sendThrow (VirtualFrame frame , PGenerator self , Object typ , Object val , PTraceback tb ,
401
408
@ Cached PrepareExceptionNode prepareExceptionNode ,
402
- @ Cached BranchProfile alreadyRunning ) {
409
+ @ Cached BranchProfile alreadyRunning ,
410
+ @ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
403
411
if (self .isRunning ()) {
404
412
alreadyRunning .enter ();
405
413
throw raise (ValueError , ErrorMessages .GENERATOR_ALREADY_EXECUTING );
406
414
}
407
415
PBaseException instance = prepareExceptionNode .execute (frame , typ , val );
408
416
instance .setTraceback (tb );
409
- return doThrow (self , instance );
417
+ return doThrow (self , instance , contextRef . get () );
410
418
}
411
419
412
- private Object doThrow (PGenerator self , PBaseException instance ) {
420
+ private Object doThrow (PGenerator self , PBaseException instance , PythonContext context ) {
413
421
instance .setContext (null ); // Will be filled when caught
414
422
if (self .isStarted ()) {
415
423
instance .ensureReified ();
416
424
// Pass it to the generator where it will be thrown by the last yield, the location
417
425
// will be filled there
418
- PException pException = PException .fromObject (instance , null );
426
+ PException pException = PException .fromObject (instance , null , context . getOption ( PythonOptions . WithJavaStacktrace ) );
419
427
return resumeGenerator (self , pException );
420
428
} else {
421
429
// Unstarted generator, we cannot pass the exception into the generator as there is
@@ -431,7 +439,7 @@ private Object doThrow(PGenerator self, PBaseException instance) {
431
439
}
432
440
PTraceback newTraceback = factory ().createTraceback (pFrame , pFrame .getLine (), existingTraceback );
433
441
instance .setTraceback (newTraceback );
434
- throw PException .fromObject (instance , location );
442
+ throw PException .fromObject (instance , location , context . getOption ( PythonOptions . WithJavaStacktrace ) );
435
443
}
436
444
}
437
445
@@ -466,7 +474,8 @@ Object close(PGenerator self,
466
474
@ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ,
467
475
@ Cached IsBuiltinClassProfile isGeneratorExit ,
468
476
@ Cached IsBuiltinClassProfile isStopIteration ,
469
- @ Cached BranchProfile alreadyRunning ) {
477
+ @ Cached BranchProfile alreadyRunning ,
478
+ @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
470
479
if (self .isRunning ()) {
471
480
alreadyRunning .enter ();
472
481
throw raise (ValueError , ErrorMessages .GENERATOR_ALREADY_EXECUTING );
@@ -475,7 +484,7 @@ Object close(PGenerator self,
475
484
PBaseException pythonException = factory ().createBaseException (GeneratorExit );
476
485
// Pass it to the generator where it will be thrown by the last yield, the location
477
486
// will be filled there
478
- PException pException = PException .fromObject (pythonException , null );
487
+ PException pException = PException .fromObject (pythonException , null , contextRef . get (). getOption ( PythonOptions . WithJavaStacktrace ) );
479
488
try {
480
489
resumeGenerator (self , pException );
481
490
} catch (PException pe ) {
0 commit comments