Skip to content

Commit ed97c13

Browse files
committed
[GR-28866] Allow languages to access scopes of other languages.
PullRequest: graal/17875
2 parents 1d06946 + 2b1814c commit ed97c13

File tree

12 files changed

+293
-108
lines changed

12 files changed

+293
-108
lines changed

sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/PolyglotAccess.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -42,6 +42,7 @@
4242

4343
import java.util.Arrays;
4444
import java.util.LinkedHashMap;
45+
import java.util.LinkedHashSet;
4546
import java.util.Map;
4647
import java.util.Objects;
4748
import java.util.Set;
@@ -245,7 +246,7 @@ public final class Builder {
245246
* more than two then all language evaluation combinations will be allowed. This method
246247
* potentially overrides already configured access rights with
247248
* {@link #allowEval(String, String)} or {@link #denyEval(String, String)}. The given
248-
* language array must be <code>null</code> and individual languages must not be
249+
* language array must be non <code>null</code> and individual languages must not be
249250
* <code>null</code>.
250251
*
251252
* @see #allowEval(String, String)
@@ -263,7 +264,12 @@ public Builder allowEvalBetween(String... languages) {
263264
languageAccess = EconomicSet.create();
264265
evalAccess.put(language, languageAccess);
265266
}
266-
languageAccess.addAll(Arrays.asList(languages));
267+
Set<String> filteredList = new LinkedHashSet<>(Arrays.asList(languages));
268+
// filter current language if it is not the only language
269+
if (filteredList.size() > 1) {
270+
filteredList.remove(language);
271+
}
272+
languageAccess.addAll(filteredList);
267273
}
268274
return this;
269275
}
@@ -276,7 +282,7 @@ public Builder allowEvalBetween(String... languages) {
276282
* more than two then all language access combinations will be denied. This method
277283
* potentially overrides already configured access rights with
278284
* {@link #allowEval(String, String)} or {@link #denyEval(String, String)}. The given
279-
* language array must be <code>null</code> and individual languages must not be
285+
* language array must be non <code>null</code> and individual languages must not be
280286
* <code>null</code>.
281287
*
282288
* @see #denyEval(String, String)

truffle/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ This changelog summarizes major changes between Truffle versions relevant to lan
1616
* GR-54085 Added [`MathUtils`](https://www.graalvm.org/truffle/javadoc/com/oracle/truffle/api/utilities/MathUtils.html) API providing additional mathematical functions useful for language implementations, namely: `asinh`, `acosh`, and `atanh`.
1717
* GR-49484 Added `TruffleStackFrameElement.getBytecodeIndex()` to access bytecode indices of a stack frame. Bytecode based languages should consider implementing `RootNode#findBytecodeIndex(Node, Frame)` to resolve the bytecode index.
1818
* GR-49484 Deprecated `RootNode.isCaptureFramesForTrace()`. Implementers should use `RootNode.isCaptureFramesForTrace(Node)` instead.
19+
* GR-28866 Added `TruffleLanguage.Env.getScopePublic(LanguageInfo)` and `TruffleLanguage.Env.getScopeInternal(LanguageInfo)` to allow languages direct access to other language scopes to implement new polyglot builtins.
20+
* GR-28866 Deprecated `TruffleLanguage.Env.isPolyglotEvalAllowed()`. Replace usages with `TruffleLanguage.Env.isPolyglotEvalAllowed(LanguageInfo)`. Please see javadoc for the updated usage.
1921

2022
## Version 24.0.0
2123

truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/ContextPolyglotAccessTest.java

Lines changed: 94 additions & 65 deletions
Large diffs are not rendered by default.

truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/ContextPreInitializationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,7 +1836,7 @@ public void testCodeSharingTwoLayers() throws Exception {
18361836
assertTrue(env.isCreateThreadAllowed());
18371837
assertFalse(env.isHostLookupAllowed());
18381838
assertTrue(env.isNativeAccessAllowed());
1839-
assertTrue(env.isPolyglotEvalAllowed());
1839+
assertTrue(env.isPolyglotEvalAllowed(null));
18401840
assertTrue(env.isPolyglotBindingsAccessAllowed());
18411841
assertEquals(testId, env.getTimeZone());
18421842
firstContextInitialized.set(true);
@@ -1846,7 +1846,7 @@ public void testCodeSharingTwoLayers() throws Exception {
18461846
assertFalse(env.isCreateThreadAllowed());
18471847
assertFalse(env.isHostLookupAllowed());
18481848
assertFalse(env.isNativeAccessAllowed());
1849-
assertFalse(env.isPolyglotEvalAllowed());
1849+
assertFalse(env.isPolyglotEvalAllowed(null));
18501850
assertFalse(env.isPolyglotBindingsAccessAllowed());
18511851
assertFalse(env.getOptions().get(ContextPreInitializationTestSharedLanguage.Option1));
18521852
assertEquals(systemDefault, env.getTimeZone());
@@ -1970,7 +1970,7 @@ public void testCodeSharingCommonConfig() throws Exception {
19701970
assertFalse(env.isHostLookupAllowed());
19711971
assertFalse(env.isNativeAccessAllowed());
19721972
// polyglot access currently defaults to true for preinit. See GR-14657.
1973-
assertTrue(env.isPolyglotEvalAllowed());
1973+
assertTrue(env.isPolyglotEvalAllowed(null));
19741974
assertTrue(env.isPolyglotBindingsAccessAllowed());
19751975
assertEquals(systemDefault, env.getTimeZone());
19761976
firstContextInitialized.set(true);

truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/LanguageSPITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ private static Boolean getPrivilege(Env env, int privilege) {
990990
case CREATE_THREAD:
991991
return env.isCreateThreadAllowed();
992992
case POLYGLOT_ACCESS:
993-
return env.isPolyglotBindingsAccessAllowed() || env.isPolyglotEvalAllowed();
993+
return env.isPolyglotBindingsAccessAllowed() || env.isPolyglotEvalAllowed(null);
994994
case ENVIRONMENT_ACCESS:
995995
// environment access can only be observed with properties
996996
String value = env.getEnvironment().get(OUTER_CONTEXT_TEST_KEY);

truffle/src/com.oracle.truffle.api/snapshot.sigtest

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,8 @@ meth public boolean isMimeTypeSupported(java.lang.String)
544544
meth public boolean isNativeAccessAllowed()
545545
meth public boolean isPolyglotBindingsAccessAllowed()
546546
meth public boolean isPolyglotEvalAllowed()
547+
anno 0 java.lang.Deprecated(boolean forRemoval=false, java.lang.String since="")
548+
meth public boolean isPolyglotEvalAllowed(com.oracle.truffle.api.nodes.LanguageInfo)
547549
meth public boolean isPreInitialization()
548550
meth public boolean isSocketIOAllowed()
549551
meth public com.oracle.truffle.api.TruffleContext getContext()
@@ -576,6 +578,8 @@ meth public java.lang.Object createHostAdapterClassWithStaticOverrides(java.lang
576578
meth public java.lang.Object createHostAdapterWithClassOverrides(java.lang.Object[],java.lang.Object)
577579
meth public java.lang.Object findMetaObject(java.lang.Object)
578580
meth public java.lang.Object getPolyglotBindings()
581+
meth public java.lang.Object getScopeInternal(com.oracle.truffle.api.nodes.LanguageInfo)
582+
meth public java.lang.Object getScopePublic(com.oracle.truffle.api.nodes.LanguageInfo)
579583
meth public java.lang.Object importSymbol(java.lang.String)
580584
meth public java.lang.Object lookupHostSymbol(java.lang.String)
581585
meth public java.lang.String getFileNameSeparator()

0 commit comments

Comments
 (0)