Skip to content

Commit

Permalink
[GR-28866] Allow languages to access scopes of other languages.
Browse files Browse the repository at this point in the history
PullRequest: graal/17875
  • Loading branch information
tzezula committed Jun 4, 2024
2 parents 1d06946 + 2b1814c commit ed97c13
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 108 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -42,6 +42,7 @@

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -245,7 +246,7 @@ public final class Builder {
* more than two then all language evaluation combinations will be allowed. This method
* potentially overrides already configured access rights with
* {@link #allowEval(String, String)} or {@link #denyEval(String, String)}. The given
* language array must be <code>null</code> and individual languages must not be
* language array must be non <code>null</code> and individual languages must not be
* <code>null</code>.
*
* @see #allowEval(String, String)
Expand All @@ -263,7 +264,12 @@ public Builder allowEvalBetween(String... languages) {
languageAccess = EconomicSet.create();
evalAccess.put(language, languageAccess);
}
languageAccess.addAll(Arrays.asList(languages));
Set<String> filteredList = new LinkedHashSet<>(Arrays.asList(languages));
// filter current language if it is not the only language
if (filteredList.size() > 1) {
filteredList.remove(language);
}
languageAccess.addAll(filteredList);
}
return this;
}
Expand All @@ -276,7 +282,7 @@ public Builder allowEvalBetween(String... languages) {
* more than two then all language access combinations will be denied. This method
* potentially overrides already configured access rights with
* {@link #allowEval(String, String)} or {@link #denyEval(String, String)}. The given
* language array must be <code>null</code> and individual languages must not be
* language array must be non <code>null</code> and individual languages must not be
* <code>null</code>.
*
* @see #denyEval(String, String)
Expand Down
2 changes: 2 additions & 0 deletions truffle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ This changelog summarizes major changes between Truffle versions relevant to lan
* 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`.
* 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.
* GR-49484 Deprecated `RootNode.isCaptureFramesForTrace()`. Implementers should use `RootNode.isCaptureFramesForTrace(Node)` instead.
* 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.
* GR-28866 Deprecated `TruffleLanguage.Env.isPolyglotEvalAllowed()`. Replace usages with `TruffleLanguage.Env.isPolyglotEvalAllowed(LanguageInfo)`. Please see javadoc for the updated usage.

## Version 24.0.0

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,7 @@ public void testCodeSharingTwoLayers() throws Exception {
assertTrue(env.isCreateThreadAllowed());
assertFalse(env.isHostLookupAllowed());
assertTrue(env.isNativeAccessAllowed());
assertTrue(env.isPolyglotEvalAllowed());
assertTrue(env.isPolyglotEvalAllowed(null));
assertTrue(env.isPolyglotBindingsAccessAllowed());
assertEquals(testId, env.getTimeZone());
firstContextInitialized.set(true);
Expand All @@ -1846,7 +1846,7 @@ public void testCodeSharingTwoLayers() throws Exception {
assertFalse(env.isCreateThreadAllowed());
assertFalse(env.isHostLookupAllowed());
assertFalse(env.isNativeAccessAllowed());
assertFalse(env.isPolyglotEvalAllowed());
assertFalse(env.isPolyglotEvalAllowed(null));
assertFalse(env.isPolyglotBindingsAccessAllowed());
assertFalse(env.getOptions().get(ContextPreInitializationTestSharedLanguage.Option1));
assertEquals(systemDefault, env.getTimeZone());
Expand Down Expand Up @@ -1970,7 +1970,7 @@ public void testCodeSharingCommonConfig() throws Exception {
assertFalse(env.isHostLookupAllowed());
assertFalse(env.isNativeAccessAllowed());
// polyglot access currently defaults to true for preinit. See GR-14657.
assertTrue(env.isPolyglotEvalAllowed());
assertTrue(env.isPolyglotEvalAllowed(null));
assertTrue(env.isPolyglotBindingsAccessAllowed());
assertEquals(systemDefault, env.getTimeZone());
firstContextInitialized.set(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ private static Boolean getPrivilege(Env env, int privilege) {
case CREATE_THREAD:
return env.isCreateThreadAllowed();
case POLYGLOT_ACCESS:
return env.isPolyglotBindingsAccessAllowed() || env.isPolyglotEvalAllowed();
return env.isPolyglotBindingsAccessAllowed() || env.isPolyglotEvalAllowed(null);
case ENVIRONMENT_ACCESS:
// environment access can only be observed with properties
String value = env.getEnvironment().get(OUTER_CONTEXT_TEST_KEY);
Expand Down
4 changes: 4 additions & 0 deletions truffle/src/com.oracle.truffle.api/snapshot.sigtest
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ meth public boolean isMimeTypeSupported(java.lang.String)
meth public boolean isNativeAccessAllowed()
meth public boolean isPolyglotBindingsAccessAllowed()
meth public boolean isPolyglotEvalAllowed()
anno 0 java.lang.Deprecated(boolean forRemoval=false, java.lang.String since="")
meth public boolean isPolyglotEvalAllowed(com.oracle.truffle.api.nodes.LanguageInfo)
meth public boolean isPreInitialization()
meth public boolean isSocketIOAllowed()
meth public com.oracle.truffle.api.TruffleContext getContext()
Expand Down Expand Up @@ -576,6 +578,8 @@ meth public java.lang.Object createHostAdapterClassWithStaticOverrides(java.lang
meth public java.lang.Object createHostAdapterWithClassOverrides(java.lang.Object[],java.lang.Object)
meth public java.lang.Object findMetaObject(java.lang.Object)
meth public java.lang.Object getPolyglotBindings()
meth public java.lang.Object getScopeInternal(com.oracle.truffle.api.nodes.LanguageInfo)
meth public java.lang.Object getScopePublic(com.oracle.truffle.api.nodes.LanguageInfo)
meth public java.lang.Object importSymbol(java.lang.String)
meth public java.lang.Object lookupHostSymbol(java.lang.String)
meth public java.lang.String getFileNameSeparator()
Expand Down
Loading

0 comments on commit ed97c13

Please sign in to comment.