From 3350292ab7a1b128e374fbd6823bc86582ce5394 Mon Sep 17 00:00:00 2001
From: Lukas Stadler <lukas.stadler@oracle.com>
Date: Thu, 12 May 2016 10:01:27 +0200
Subject: [PATCH] unwrap VirtualEvalFrames when creating environments

---
 .../oracle/truffle/r/runtime/env/REnvironment.java  | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/env/REnvironment.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/env/REnvironment.java
index 0ec6b5a67f..b012e5c19b 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/env/REnvironment.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/env/REnvironment.java
@@ -38,6 +38,7 @@ import com.oracle.truffle.r.runtime.RInternalError;
 import com.oracle.truffle.r.runtime.RRuntime;
 import com.oracle.truffle.r.runtime.RType;
 import com.oracle.truffle.r.runtime.Utils;
+import com.oracle.truffle.r.runtime.VirtualEvalFrame;
 import com.oracle.truffle.r.runtime.context.RContext;
 import com.oracle.truffle.r.runtime.data.RAttributeProfiles;
 import com.oracle.truffle.r.runtime.data.RAttributeStorage;
@@ -610,12 +611,13 @@ public abstract class REnvironment extends RAttributeStorage implements RTypedVa
      * be materialized.
      */
     public static REnvironment frameToEnvironment(MaterializedFrame frame) {
-        REnvironment env = RArguments.getEnvironment(frame);
+        MaterializedFrame f = frame instanceof VirtualEvalFrame ? ((VirtualEvalFrame) frame).getOriginalFrame() : frame;
+        REnvironment env = RArguments.getEnvironment(f);
         if (env == null) {
-            if (RArguments.getFunction(frame) == null) {
+            if (RArguments.getFunction(f) == null) {
                 throw RInternalError.shouldNotReachHere();
             }
-            env = createEnclosingEnvironments(frame);
+            env = createEnclosingEnvironments(f);
         }
         return env;
     }
@@ -628,10 +630,11 @@ public abstract class REnvironment extends RAttributeStorage implements RTypedVa
      */
     @TruffleBoundary
     public static REnvironment createEnclosingEnvironments(MaterializedFrame frame) {
-        REnvironment env = RArguments.getEnvironment(frame);
+        MaterializedFrame f = frame instanceof VirtualEvalFrame ? ((VirtualEvalFrame) frame).getOriginalFrame() : frame;
+        REnvironment env = RArguments.getEnvironment(f);
         if (env == null) {
             // parent is the env of the enclosing frame
-            env = REnvironment.Function.create(frame);
+            env = REnvironment.Function.create(f);
         }
         return env;
     }
-- 
GitLab