Skip to content

Commit c065df1

Browse files
committed
Remove polyglot access check for parsing
1 parent d23f69f commit c065df1

File tree

5 files changed

+36
-35
lines changed

5 files changed

+36
-35
lines changed

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRInterop.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,6 @@ public static void testingMode() {
118118
isTesting = true;
119119
}
120120

121-
private static void checkPolyglotAccess(Env env) {
122-
if (!env.isPolyglotAccessAllowed()) {
123-
throw RError.error(RError.SHOW_CALLER, RError.Message.GENERIC, "Polyglot bindings are not accessible for this language. Use --polyglot or allowPolyglotAccess when building the context.");
124-
}
125-
}
126-
127121
@RBuiltin(name = "eval.polyglot", visibility = CUSTOM, kind = PRIMITIVE, parameterNames = {"languageId", "code", "path"}, behavior = COMPLEX)
128122
public abstract static class Eval extends RBuiltinNode.Arg3 {
129123

@@ -176,7 +170,6 @@ protected Object eval(@SuppressWarnings("unused") RMissing languageId, @Suppress
176170
protected CallTarget parse(String languageId, String code) {
177171
CompilerAsserts.neverPartOfCompilation();
178172
Env env = RContext.getInstance().getEnv();
179-
checkPolyglotAccess(env);
180173
LanguageInfo languageInfo = languageId != null ? env.getLanguages().get(languageId) : null;
181174
if ((languageId != null && languageInfo == null) || (languageInfo != null && languageInfo.isInternal())) {
182175
throw error(RError.Message.LANGUAGE_NOT_AVAILABLE, languageId);
@@ -230,7 +223,6 @@ private Object parseFileAndCall(String path, String languageId) {
230223
protected CallTarget parseFile(String path, String languageIdArg) {
231224
CompilerAsserts.neverPartOfCompilation();
232225
Env env = RContext.getInstance().getEnv();
233-
checkPolyglotAccess(env);
234226
TruffleFile tFile = env.getTruffleFile(Utils.tildeExpand(path, false)).getAbsoluteFile();
235227
LanguageInfo languageInfo = null;
236228
try {
@@ -266,6 +258,12 @@ protected Object eval(@SuppressWarnings("unused") RMissing code, @SuppressWarnin
266258
}
267259
}
268260

261+
private static void checkPolyglotAccess(Env env) {
262+
if (!env.isPolyglotAccessAllowed()) {
263+
throw RError.error(RError.SHOW_CALLER, RError.Message.POLYGLOT_BINDING_NOT_AVAILABLE);
264+
}
265+
}
266+
269267
@RBuiltin(name = "export", visibility = OFF, kind = PRIMITIVE, parameterNames = {"name", "value"}, behavior = COMPLEX)
270268
public abstract static class Export extends RBuiltinNode.Arg2 {
271269

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,8 @@ public enum Message {
10321032
"SET_ATTRIB: tag in the attributes pairlist must be a symbol. %s given. It is possible that the code intends to set the TAG after the call to SET_ATTRIB, but this is not supported in FastR."),
10331033
WRONG_ARGS_COMBINATION("Wrong arguments combination, please refer to ?%s for more details."),
10341034
COULD_NOT_FIND_LANGUAGE("Could not find language corresponding to extension '%s', you can specify the language id explicitly, please refer to ?%s for more details."),
1035-
LANGUAGE_NOT_AVAILABLE("Language with id '%s' is not available. Did you start R with --polyglot?"),
1035+
LANGUAGE_NOT_AVAILABLE("Language with id '%s' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?"),
1036+
POLYGLOT_BINDING_NOT_AVAILABLE("Polyglot bindings are not accessible for this language. Use --polyglot or allowPolyglotAccess when building the context."),
10361037
NO_LANGUAGE_PROVIDED("No language id provided, please refer to ?%s for more details."),
10371038
NO_CODE_OR_PATH_PROVIDED("No code or path provided, please refer to ?%s for more details."),
10381039
LENGTH_OF_NULL_UNCHANGED("length of NULL cannot be changed"),

com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29314,6 +29314,10 @@ NULL
2931429314
#environment(print)
2931529315
<environment: namespace:base>
2931629316

29317+
##com.oracle.truffle.r.test.builtins.TestBuiltin_environment.testEnvironment#
29318+
#{ env <- list2env(list(customenvvar = 42)); fst <- function(fstvar) do.call(environment, list(), envir = env); a <- fst(0); ls(a) }
29319+
[1] "customenvvar"
29320+
2931729321
##com.oracle.truffle.r.test.builtins.TestBuiltin_environment.testEnvironment#
2931829322
#{ f <- y~z; class(f) <- c('myclass', class(f)); environment(f) }
2931929323
<environment: R_GlobalEnv>
@@ -54093,47 +54097,47 @@ expression(for (i in 1:10) {
5409354097
x[i] <- i
5409454098
})
5409554099

54096-
##com.oracle.truffle.r.test.builtins.TestBuiltin_parse.testSource#Output.IgnoreWarningMessage#
54100+
##com.oracle.truffle.r.test.builtins.TestBuiltin_parse.testSource#
5409754101
#{ source("test/r/simple/data/tree2/setx.r") ; x }
5409854102
Error in file(filename, "r", encoding = encoding) :
5409954103
cannot open the connection
5410054104
In addition: Warning message:
5410154105
In file(filename, "r", encoding = encoding) :
5410254106
cannot open file 'test/r/simple/data/tree2/setx.r': No such file or directory
5410354107

54104-
##com.oracle.truffle.r.test.builtins.TestBuiltin_parse.testSource#Output.IgnoreWarningMessage#
54108+
##com.oracle.truffle.r.test.builtins.TestBuiltin_parse.testSource#
5410554109
#{ source("test/r/simple/data/tree2/setx.r", local=TRUE) ; x }
5410654110
Error in file(filename, "r", encoding = encoding) :
5410754111
cannot open the connection
5410854112
In addition: Warning message:
5410954113
In file(filename, "r", encoding = encoding) :
5411054114
cannot open file 'test/r/simple/data/tree2/setx.r': No such file or directory
5411154115

54112-
##com.oracle.truffle.r.test.builtins.TestBuiltin_parse.testSource#Output.IgnoreWarningMessage#
54116+
##com.oracle.truffle.r.test.builtins.TestBuiltin_parse.testSource#
5411354117
#{ x <- 1; f <- function() { source("test/r/simple/data/tree2/incx.r", local=FALSE) ; x } ; c(f(), x) }
5411454118
Error in file(filename, "r", encoding = encoding) :
5411554119
cannot open the connection
5411654120
In addition: Warning message:
5411754121
In file(filename, "r", encoding = encoding) :
5411854122
cannot open file 'test/r/simple/data/tree2/incx.r': No such file or directory
5411954123

54120-
##com.oracle.truffle.r.test.builtins.TestBuiltin_parse.testSource#Output.IgnoreWarningMessage#
54124+
##com.oracle.truffle.r.test.builtins.TestBuiltin_parse.testSource#
5412154125
#{ x <- 1; f <- function() { source("test/r/simple/data/tree2/incx.r", local=TRUE) ; x } ; c(f(), x) }
5412254126
Error in file(filename, "r", encoding = encoding) :
5412354127
cannot open the connection
5412454128
In addition: Warning message:
5412554129
In file(filename, "r", encoding = encoding) :
5412654130
cannot open file 'test/r/simple/data/tree2/incx.r': No such file or directory
5412754131

54128-
##com.oracle.truffle.r.test.builtins.TestBuiltin_parse.testSource#Output.IgnoreWarningMessage#
54132+
##com.oracle.truffle.r.test.builtins.TestBuiltin_parse.testSource#
5412954133
#{ x <- 1; f <- function() { source("test/r/simple/data/tree2/setx.r", local=FALSE) ; x } ; c(f(), x) }
5413054134
Error in file(filename, "r", encoding = encoding) :
5413154135
cannot open the connection
5413254136
In addition: Warning message:
5413354137
In file(filename, "r", encoding = encoding) :
5413454138
cannot open file 'test/r/simple/data/tree2/setx.r': No such file or directory
5413554139

54136-
##com.oracle.truffle.r.test.builtins.TestBuiltin_parse.testSource#Output.IgnoreWarningMessage#
54140+
##com.oracle.truffle.r.test.builtins.TestBuiltin_parse.testSource#
5413754141
#{ x <- 1; f <- function() { source("test/r/simple/data/tree2/setx.r", local=TRUE) ; x } ; c(f(), x) }
5413854142
Error in file(filename, "r", encoding = encoding) :
5413954143
cannot open the connection
@@ -150330,24 +150334,24 @@ Error: unexpected ';' in "if (!any(R.version$engine == "FastR")) { TRUE } else {
150330150334
[1] "123"
150331150335

150332150336
##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEval#
150333-
#if (!any(R.version$engine == "FastR")) { cat('Error in eval.polyglot("foo", "bar") :\n Language with id \'foo\' is not available. Did you start R with --polyglot?\n') } else { eval.polyglot('foo', 'bar') }
150337+
#if (!any(R.version$engine == "FastR")) { cat('Error in eval.polyglot("foo", "bar") :\n Language with id \'foo\' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?\n') } else { eval.polyglot('foo', 'bar') }
150334150338
Error in eval.polyglot("foo", "bar") :
150335-
Language with id 'foo' is not available. Did you start R with --polyglot?
150339+
Language with id 'foo' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?
150336150340

150337150341
##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEval#
150338-
#if (!any(R.version$engine == "FastR")) { cat('Error in eval.polyglot("foo", , "bar") :\n Language with id \'foo\' is not available. Did you start R with --polyglot?\n') } else { eval.polyglot('foo',, 'bar') }
150342+
#if (!any(R.version$engine == "FastR")) { cat('Error in eval.polyglot("foo", , "bar") :\n Language with id \'foo\' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?\n') } else { eval.polyglot('foo',, 'bar') }
150339150343
Error in eval.polyglot("foo", , "bar") :
150340-
Language with id 'foo' is not available. Did you start R with --polyglot?
150344+
Language with id 'foo' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?
150341150345

150342150346
##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEval#
150343-
#if (!any(R.version$engine == "FastR")) { cat('Error in eval.polyglot("nfi", "foo.bar") :\n Language with id \'nfi\' is not available. Did you start R with --polyglot?\n') } else { eval.polyglot('nfi', 'foo.bar') }
150347+
#if (!any(R.version$engine == "FastR")) { cat('Error in eval.polyglot("nfi", "foo.bar") :\n Language with id \'nfi\' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?\n') } else { eval.polyglot('nfi', 'foo.bar') }
150344150348
Error in eval.polyglot("nfi", "foo.bar") :
150345-
Language with id 'nfi' is not available. Did you start R with --polyglot?
150349+
Language with id 'nfi' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?
150346150350

150347150351
##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEval#
150348-
#if (!any(R.version$engine == "FastR")) { cat('Error in eval.polyglot("nfi", , "foo.bar") :\n Language with id \'nfi\' is not available. Did you start R with --polyglot?\n') } else { eval.polyglot('nfi',,'foo.bar') }
150352+
#if (!any(R.version$engine == "FastR")) { cat('Error in eval.polyglot("nfi", , "foo.bar") :\n Language with id \'nfi\' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?\n') } else { eval.polyglot('nfi',,'foo.bar') }
150349150353
Error in eval.polyglot("nfi", , "foo.bar") :
150350-
Language with id 'nfi' is not available. Did you start R with --polyglot?
150354+
Language with id 'nfi' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?
150351150355

150352150356
##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEval#
150353150357
#if (!any(R.version$engine == "FastR")) { cat('Error in eval.polyglot(, "bar") :\n No language id provided, please refer to ?eval.polyglot for more details.\n') } else { eval.polyglot(, 'bar') }
@@ -150369,9 +150373,9 @@ Error in eval.polyglot("js", "console.log(42)", "file.js") :
150369150373
Wrong arguments combination, please refer to ?eval.polyglot for more details.
150370150374

150371150375
##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEvalFile#
150372-
#if (!any(R.version$engine == "FastR")) { cat('Error in eval.polyglot("nonExistentLanguage", "code") :<<<NEWLINE>>> Language with id \'nonExistentLanguage\' is not available. Did you start R with --polyglot?\n') } else { eval.polyglot('nonExistentLanguage', 'code') }
150376+
#if (!any(R.version$engine == "FastR")) { cat('Error in eval.polyglot("nonExistentLanguage", "code") :<<<NEWLINE>>> Language with id \'nonExistentLanguage\' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?\n') } else { eval.polyglot('nonExistentLanguage', 'code') }
150373150377
Error in eval.polyglot("nonExistentLanguage", "code") :
150374-
Language with id 'nonExistentLanguage' is not available. Did you start R with --polyglot?
150378+
Language with id 'nonExistentLanguage' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?
150375150379

150376150380
##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEvalFile#
150377150381
#if (!any(R.version$engine == "FastR")) { cat('Error in eval.polyglot("someLanguage") :<<<NEWLINE>>> No code or path provided, please refer to ?eval.polyglot for more details.\n') } else { eval.polyglot('someLanguage') }

com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestInterop.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.io.IOException;
2727
import java.nio.ByteBuffer;
2828

29-
import org.graalvm.polyglot.Context;
3029
import org.graalvm.polyglot.PolyglotAccess;
3130
import org.graalvm.polyglot.PolyglotException;
3231
import org.junit.Assert;
@@ -91,13 +90,13 @@ public void cleanup() {
9190

9291
@Test
9392
public void testPolyglotAccessWhenPolyglotBindingsAreDisabled() {
94-
String message = "no PolyglotException exception occurred";
9593
try (org.graalvm.polyglot.Context context = FastRSession.getContextBuilder("R").allowPolyglotAccess(PolyglotAccess.NONE).build()) {
9694
context.eval("R", "eval.polyglot('js', '1+3')");
95+
Assert.fail("no PolyglotException exception occurred");
9796
} catch (PolyglotException ex) {
98-
message = ex.getMessage();
97+
String message = ex.getMessage();
98+
assertTrue(message, message.contains("Language with id 'js' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?"));
9999
}
100-
assertTrue(message, message.contains("Polyglot bindings are not accessible for this language. Use --polyglot or allowPolyglotAccess when building the context."));
101100
}
102101

103102
@Test
@@ -115,14 +114,14 @@ public void testInteropEval() {
115114
"cat('Error in eval.polyglot(, , \"bar\") :\\n Could not find language corresponding to extension \\'bar\\', you can specify the language id explicitly, please refer to ?eval.polyglot for more details.\\n')");
116115
// Checkstyle: resume
117116
assertEvalFastR("eval.polyglot('foo', 'bar')",
118-
"cat('Error in eval.polyglot(\"foo\", \"bar\") :\\n Language with id \\'foo\\' is not available. Did you start R with --polyglot?\\n')");
117+
"cat('Error in eval.polyglot(\"foo\", \"bar\") :\\n Language with id \\'foo\\' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?\\n')");
119118
assertEvalFastR("eval.polyglot('nfi', 'foo.bar')",
120-
"cat('Error in eval.polyglot(\"nfi\", \"foo.bar\") :\\n Language with id \\'nfi\\' is not available. Did you start R with --polyglot?\\n')");
119+
"cat('Error in eval.polyglot(\"nfi\", \"foo.bar\") :\\n Language with id \\'nfi\\' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?\\n')");
121120
// Checkstyle: stop
122121
assertEvalFastR("eval.polyglot('foo',, 'bar')",
123-
"cat('Error in eval.polyglot(\"foo\", , \"bar\") :\\n Language with id \\'foo\\' is not available. Did you start R with --polyglot?\\n')");
122+
"cat('Error in eval.polyglot(\"foo\", , \"bar\") :\\n Language with id \\'foo\\' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?\\n')");
124123
assertEvalFastR("eval.polyglot('nfi',,'foo.bar')",
125-
"cat('Error in eval.polyglot(\"nfi\", , \"foo.bar\") :\\n Language with id \\'nfi\\' is not available. Did you start R with --polyglot?\\n')");
124+
"cat('Error in eval.polyglot(\"nfi\", , \"foo.bar\") :\\n Language with id \\'nfi\\' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?\\n')");
126125
// Checkstyle: resume
127126
}
128127

@@ -160,7 +159,7 @@ public void testInteropEvalFile() {
160159
assertEvalFastR("f<-paste0(tempfile(),'.nonLanguageExtension'); file.create(f); tryCatch(eval.polyglot(path=f), finally=file.remove(f))",
161160
"cat('Error in eval.polyglot(path = f) :\n Could not find language corresponding to extension \\'nonLanguageExtension\\', you can specify the language id explicitly, please refer to ?eval.polyglot for more details.\\n')");
162161
assertEvalFastR("eval.polyglot('nonExistentLanguage', 'code')",
163-
"cat('Error in eval.polyglot(\"nonExistentLanguage\", \"code\") :\n Language with id \\'nonExistentLanguage\\' is not available. Did you start R with --polyglot?\\n')");
162+
"cat('Error in eval.polyglot(\"nonExistentLanguage\", \"code\") :\n Language with id \\'nonExistentLanguage\\' is not available. Did you start R with --polyglot or use allowPolyglotAccess when building the context?\\n')");
164163
assertEvalFastR("eval.polyglot(code='')", "cat('Error in eval.polyglot(code = \"\") :\n No language id provided, please refer to ?eval.polyglot for more details.\\n')");
165164
assertEvalFastR("eval.polyglot(languageId='js')", "cat('Error in eval.polyglot(languageId = \"js\") :\n No code or path provided, please refer to ?eval.polyglot for more details.\\n')");
166165
}

com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.util.Iterator;
3535
import java.util.List;
3636

37-
import org.graalvm.polyglot.Context;
3837
import org.graalvm.polyglot.PolyglotException;
3938
import org.junit.Assert;
4039
import org.junit.Before;

0 commit comments

Comments
 (0)