From 00507469d16a36995f25f7968435648e3bb926c1 Mon Sep 17 00:00:00 2001
From: Florian Angerer <florian.angerer@oracle.com>
Date: Thu, 13 Jul 2017 10:50:02 +0200
Subject: [PATCH] Finally disabling warnings for invalid source files during
 deserialization.

---
 .../com/oracle/truffle/r/runtime/RSerialize.java | 16 ++++++++++------
 .../com/oracle/truffle/r/runtime/RSrcref.java    | 11 ++++++++---
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSerialize.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSerialize.java
index 13399a622a..1c4f702778 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSerialize.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSerialize.java
@@ -1821,7 +1821,8 @@ public class RSerialize {
                 if (ss != null) {
                     String path = RSource.getPathInternal(ss.getSource());
                     if (path != null) {
-                        REnvironment createSrcfile = RSrcref.createSrcfile(path);
+                        Path relPath = Paths.get(REnvVars.rHome()).relativize(Paths.get(path));
+                        REnvironment createSrcfile = RSrcref.createSrcfile(relPath);
                         Object createLloc = RSrcref.createLloc(ss, createSrcfile);
                         writePairListEntry(RRuntime.R_SRCREF, createLloc);
                         writePairListEntry(RRuntime.R_SRCFILE, createSrcfile);
@@ -2492,9 +2493,7 @@ public class RSerialize {
         SourceSection ss = getFileSourceSection(syntaxElement);
         if (ss != null && serObj instanceof RAttributable) {
             String pathInternal = RSource.getPathInternal(ss.getSource());
-            String wd = REnvVars.rHome();
-            Path wdPath = Paths.get(wd);
-            Path relPath = wdPath.relativize(Paths.get(pathInternal));
+            Path relPath = Paths.get(REnvVars.rHome()).relativize(Paths.get(pathInternal));
             RAttributable attributable = (RAttributable) serObj;
             attributable.setAttr(RRuntime.R_SRCFILE, RSrcref.createSrcfile(relPath));
             RList createBlockSrcrefs = RSrcref.createBlockSrcrefs(syntaxElement);
@@ -2739,10 +2738,15 @@ public class RSerialize {
                     }
                 }
             } catch (NoSuchFileException e) {
-                RError.warning(RError.SHOW_CALLER, RError.Message.GENERIC, "Missing source file: " + e.getMessage());
+                assert debugWarning("Missing source file: " + e.getMessage());
             } catch (IOException e) {
-                RError.warning(RError.SHOW_CALLER, RError.Message.GENERIC, "Cannot access source file: " + e.getMessage());
+                assert debugWarning("Cannot access source file: " + e.getMessage());
             }
         }
     }
+
+    private static boolean debugWarning(String message) {
+        RError.warning(RError.SHOW_CALLER, RError.Message.GENERIC, message);
+        return true;
+    }
 }
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSrcref.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSrcref.java
index a79bfefa18..e8da4c611e 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSrcref.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSrcref.java
@@ -224,15 +224,20 @@ public class RSrcref {
             int length = getLineStartOffset(source, srcrefVec.getDataAt(2)) + srcrefVec.getDataAt(3) - startIdx + 1;
             return source.createSection(startLine, startColumn, length);
         } catch (NoSuchFileException e) {
-            RError.warning(RError.SHOW_CALLER, RError.Message.GENERIC, "Missing source file: " + e.getMessage());
+            assert debugWarning("Missing source file: " + e.getMessage());
         } catch (IOException e) {
-            RError.warning(RError.SHOW_CALLER, RError.Message.GENERIC, "Cannot access source file: " + e.getMessage());
+            assert debugWarning("Cannot access source file: " + e.getMessage());
         } catch (IllegalArgumentException e) {
-            RError.warning(RError.SHOW_CALLER, RError.Message.GENERIC, "Invalid source reference: " + e.getMessage());
+            assert debugWarning("Invalid source reference: " + e.getMessage());
         }
         return RSourceSectionNode.LAZY_DEPARSE;
     }
 
+    private static boolean debugWarning(String message) {
+        RError.warning(RError.SHOW_CALLER, RError.Message.GENERIC, message);
+        return true;
+    }
+
     private static int getLineStartOffset(Source source, int lineNum) {
         try {
             return source.getLineStartOffset(lineNum);
-- 
GitLab