4747import javax .lang .model .util .Types ;
4848import javax .tools .Diagnostic ;
4949import javax .tools .Diagnostic .Kind ;
50-
5150import javax .tools .JavaFileObject ;
5251
5352public final class FFIProcessor extends AbstractProcessor {
@@ -319,6 +318,7 @@ private void generateCallClass(ExecutableElement m) throws IOException {
319318 w .append ("import com.oracle.truffle.api.library.ExportMessage;\n " );
320319 w .append ("import com.oracle.truffle.api.nodes.ControlFlowException;\n " );
321320 w .append ("import com.oracle.truffle.api.dsl.Cached;\n " );
321+ w .append ("import com.oracle.truffle.api.library.CachedLibrary;\n " );
322322 w .append ("import com.oracle.truffle.api.profiles.ValueProfile;\n " );
323323 w .append ("import com.oracle.truffle.r.ffi.impl.upcalls.UpCallsRFFI.HandleUpCallExceptionNode;\n " );
324324 w .append ("import com.oracle.truffle.r.runtime.RError;\n " );
@@ -353,10 +353,6 @@ private void generateCallClass(ExecutableElement m) throws IOException {
353353 w .append ("import com.oracle.truffle.r.runtime.ffi.FFIMaterializeNode;\n " );
354354 w .append ("import com.oracle.truffle.r.runtime.ffi.FFIToNativeMirrorNode;\n " );
355355 }
356- w .append ("import com.oracle.truffle.api.TruffleLanguage.ContextReference;\n " );
357- w .append ("import com.oracle.truffle.api.dsl.CachedContext;\n " );
358- w .append ("import com.oracle.truffle.r.runtime.context.TruffleRLanguage;\n " );
359-
360356 w .append ("\n " );
361357
362358 w .append ("// Checkstyle: stop method name check\n " );
@@ -381,11 +377,11 @@ private void generateCallClass(ExecutableElement m) throws IOException {
381377 if (unwrapNodes .length () > 0 ) {
382378 w .append (unwrapNodes );
383379 }
380+ w .append (" @CachedLibrary(\" this\" ) InteropLibrary interopLib,\n " );
384381
385- w .append (" @CachedContext(TruffleRLanguage.class) ContextReference<RContext> ctxRef,\n " );
386382 if (needsCallTarget ) {
387383 w .append (" @Cached() com.oracle.truffle.r.ffi.impl.upcalls.UpCallBase.CallNode callNode,\n " );
388- w .append (" @Cached(value = \" createCallTarget(ctxRef )\" , allowUncached = true) CallTarget callTarget,\n " );
384+ w .append (" @Cached(value = \" createCallTarget(interopLib )\" , allowUncached = true) CallTarget callTarget,\n " );
389385 } else if (needsNode ) {
390386 if (nodeClass .getModifiers ().contains (Modifier .ABSTRACT )) {
391387 w .append (" @Cached() " + nodeClassName + " node,\n " );
@@ -412,7 +408,7 @@ private void generateCallClass(ExecutableElement m) throws IOException {
412408 w .append (" if (RFFILog.logEnabled()) {\n " );
413409 w .append (" RFFILog.logUpCall(\" " + name + "\" , arguments);\n " );
414410 w .append (" }\n " );
415- w .append (" RContext ctx = ctxRef.get( );\n " );
411+ w .append (" RContext ctx = RContext.getInstance(interopLib );\n " );
416412 w .append (" RFFIContext rffiCtx = ctxProfile.profile(ctx.getStateRFFI());\n " );
417413
418414 if (returnKind != TypeKind .VOID ) {
@@ -498,8 +494,9 @@ private void generateCallClass(ExecutableElement m) throws IOException {
498494 w .append ("\n " );
499495
500496 if (needsCallTarget ) {
501- w .append (" protected static CallTarget createCallTarget(ContextReference<RContext> ctxRef) {\n " );
502- w .append (" RFFIUpCallTargets targets = ctxRef.get().getRFFIUpCallTargets();\n " );
497+ w .append (" protected static CallTarget createCallTarget(InteropLibrary interopLib) {\n " );
498+ w .append (" RContext ctx = RContext.getInstance(interopLib);\n " );
499+ w .append (" RFFIUpCallTargets targets = ctx.getRFFIUpCallTargets();\n " );
503500 w .append (" if(targets." ).append (nodeClassName ).append (" == null) {\n " );
504501 w .append (" targets." ).append (nodeClassName ).append (" = new NodeRootNode().getCallTarget();\n " );
505502 w .append (" }\n " );
0 commit comments