Skip to content

Commit 0f5a3a7

Browse files
authored
Revert "Import all available libraries in --repl mode (#10746)" (#10778)
* Revert "Import all available libraries in --repl mode (#10746)" This reverts commit 71285e6. * trigger build
1 parent 3581fd8 commit 0f5a3a7

File tree

14 files changed

+78
-176
lines changed

14 files changed

+78
-176
lines changed

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@
2323
- [Space-precedence does not apply to value-level operators][10597]
2424
- [Must specify `--repl` to enable debug server][10709]
2525
- [Improved parser error reporting and performance][10734]
26-
- [Import all available libraries in `--repl` mode][10746]
2726

2827
[10468]: https://github.com/enso-org/enso/pull/10468
2928
[10535]: https://github.com/enso-org/enso/pull/10535
3029
[10597]: https://github.com/enso-org/enso/pull/10597
3130
[10709]: https://github.com/enso-org/enso/pull/10709
3231
[10734]: https://github.com/enso-org/enso/pull/10734
33-
[10746]: https://github.com/enso-org/enso/pull/10746
3432

3533
#### Enso IDE
3634

engine/common/src/main/java/org/enso/common/MethodNames.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public static class TopScope {
99
public static final String REGISTER_MODULE = "register_module";
1010
public static final String UNREGISTER_MODULE = "unregister_module";
1111
public static final String COMPILE = "compile";
12-
public static final String LOCAL_LIBRARIES = "local_libraries";
1312
}
1413

1514
public static class Module {

engine/polyglot-api/src/main/java/org/enso/polyglot/PolyglotContext.java

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.enso.polyglot
2+
import java.io.File
3+
import org.enso.common.LanguageInfo
4+
5+
import org.graalvm.polyglot.{Context, Source}
6+
7+
/** Exposes language specific aliases for generic polyglot context operations.
8+
* @param context the Graal polyglot context to use.
9+
*/
10+
class PolyglotContext(val context: Context) {
11+
12+
/** Evaluates provided code string as a new module.
13+
*
14+
* @param code the code to evaluate.
15+
* @param moduleName the name for the newly parsed module.
16+
* @return the module representing evaluated code.
17+
*/
18+
def evalModule(code: String, moduleName: String): Module = {
19+
val source = Source
20+
.newBuilder(LanguageInfo.ID, code, moduleName)
21+
.build()
22+
new Module(context.eval(source))
23+
}
24+
25+
/** Evaluates provided code file as a new module.
26+
*
27+
* @param codeFile the code to evaluate.
28+
* @return the module representing evaluated code.
29+
*/
30+
def evalModule(codeFile: File): Module = {
31+
val source = Source.newBuilder(LanguageInfo.ID, codeFile).build
32+
new Module(context.eval(source))
33+
}
34+
35+
/** @return the top scope of Enso execution context
36+
*/
37+
def getTopScope: TopScope = {
38+
new TopScope(context.getBindings(LanguageInfo.ID))
39+
}
40+
}

engine/polyglot-api/src/main/scala/org/enso/polyglot/TopScope.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,4 @@ class TopScope(private val value: Value) {
3737
def compile(shouldCompileDependencies: Boolean): Unit = {
3838
value.invokeMember(COMPILE, shouldCompileDependencies)
3939
}
40-
41-
def getLibraries(): Array[String] =
42-
value.invokeMember(LOCAL_LIBRARIES).as(classOf[Array[String]])
4340
}

engine/runner/src/main/java/org/enso/runner/Main.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,7 @@ private void runPackage(
818818
}
819819

820820
private void runSingleFile(
821-
PolyglotContext context, File file, java.util.List<String> additionalArgs)
822-
throws IOException {
821+
PolyglotContext context, File file, java.util.List<String> additionalArgs) {
823822
var mainModule = context.evalModule(file);
824823
runMain(mainModule, file, additionalArgs, "main");
825824
}
@@ -894,6 +893,15 @@ private void runRepl(
894893
boolean enableIrCaches,
895894
boolean enableStaticAnalysis) {
896895
var mainMethodName = "internal_repl_entry_point___";
896+
var dummySourceToTriggerRepl =
897+
"""
898+
from Standard.Base import all
899+
import Standard.Base.Runtime.Debug
900+
901+
$mainMethodName = Debug.breakpoint
902+
"""
903+
.replace("$mainMethodName", mainMethodName);
904+
var replModuleName = "Internal_Repl_Module___";
897905
var projectRoot = projectPath != null ? projectPath : "";
898906
var options = Collections.singletonMap(DebugServerInfo.ENABLE_OPTION, "true");
899907

@@ -909,8 +917,7 @@ private void runRepl(
909917
.disableLinting(true)
910918
.enableStaticAnalysis(enableStaticAnalysis)
911919
.build());
912-
913-
var mainModule = context.evalReplModule(mainMethodName);
920+
var mainModule = context.evalModule(dummySourceToTriggerRepl, replModuleName);
914921
runMain(mainModule, null, Collections.emptyList(), mainMethodName);
915922
throw exitSuccess();
916923
}

engine/runtime-compiler/src/main/scala/org/enso/compiler/PackageRepository.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ trait PackageRepository {
2929
libraryName: LibraryName
3030
): Either[PackageRepository.Error, Unit]
3131

32-
/** Iterates over all installed libraries.
33-
*/
34-
def findAvailableLocalLibraries(): Seq[LibraryName]
35-
3632
/** Checks if the library has already been loaded */
3733
def isPackageLoaded(libraryName: LibraryName): Boolean
3834

engine/runtime-integration-tests/src/test/java/org/enso/interpreter/runtime/ListLibrariesTest.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

engine/runtime-integration-tests/src/test/scala/org/enso/interpreter/test/instrument/ReplTest.scala

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@ class ReplTest
2121
): Unit = {
2222

2323
"initialize properly" in {
24-
var counter = 0;
25-
setSessionManager(executor => {
26-
counter = counter + 1
27-
executor.exit()
28-
})
29-
val mainFn = "my_main_fn__"
30-
val replModule =
31-
interpreterContext.executionContext.evalReplModule(mainFn)
32-
replModule.evalExpression(mainFn)
33-
counter shouldEqual 1
24+
val code =
25+
"""
26+
|import Standard.Base.Runtime.Debug
27+
|
28+
|main = Debug.breakpoint
29+
|""".stripMargin
30+
setSessionManager(executor => executor.exit())
31+
eval(code)
3432
}
3533

3634
"be able to execute arbitrary code in the caller scope" in {
@@ -295,7 +293,7 @@ class ReplTest
295293
}
296294
eval(code)
297295
val errorMsg =
298-
"Compile error: The name `undefined` could not be found."
296+
"Compile_Error.Error"
299297
evalResult.left.value.getMessage shouldEqual errorMsg
300298
}
301299

engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/TopLevelScope.java

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ EnsoObject getMembers(boolean includeInternal) {
117117
MethodNames.TopScope.CREATE_MODULE,
118118
MethodNames.TopScope.REGISTER_MODULE,
119119
MethodNames.TopScope.UNREGISTER_MODULE,
120-
MethodNames.TopScope.LOCAL_LIBRARIES,
121120
MethodNames.TopScope.COMPILE);
122121
}
123122

@@ -166,18 +165,6 @@ private static Object unregisterModule(
166165
return context.getNothing();
167166
}
168167

169-
@CompilerDirectives.TruffleBoundary
170-
private static EnsoObject localLibraries(EnsoContext context) {
171-
var seq = context.getTopScope().packageRepository.findAvailableLocalLibraries();
172-
String[] names = new String[seq.size()];
173-
var it = seq.iterator();
174-
var i = 0;
175-
while (it.hasNext()) {
176-
names[i++] = it.next().toString();
177-
}
178-
return ArrayLikeHelpers.wrapStrings(names);
179-
}
180-
181168
private static Object leakContext(EnsoContext context) {
182169
return context.asGuestValue(context);
183170
}
@@ -199,19 +186,22 @@ private static Object compile(Object[] arguments, EnsoContext context)
199186
@Specialization
200187
static Object doInvoke(TopLevelScope scope, String member, Object[] arguments)
201188
throws UnknownIdentifierException, ArityException, UnsupportedTypeException {
202-
return switch (member) {
203-
case MethodNames.TopScope.GET_MODULE -> getModule(scope, arguments);
204-
case MethodNames.TopScope.CREATE_MODULE -> createModule(
205-
scope, arguments, EnsoContext.get(null));
206-
case MethodNames.TopScope.REGISTER_MODULE -> registerModule(
207-
scope, arguments, EnsoContext.get(null));
208-
case MethodNames.TopScope.UNREGISTER_MODULE -> unregisterModule(
209-
scope, arguments, EnsoContext.get(null));
210-
case MethodNames.TopScope.LEAK_CONTEXT -> leakContext(EnsoContext.get(null));
211-
case MethodNames.TopScope.LOCAL_LIBRARIES -> localLibraries(EnsoContext.get(null));
212-
case MethodNames.TopScope.COMPILE -> compile(arguments, EnsoContext.get(null));
213-
default -> throw UnknownIdentifierException.create(member);
214-
};
189+
switch (member) {
190+
case MethodNames.TopScope.GET_MODULE:
191+
return getModule(scope, arguments);
192+
case MethodNames.TopScope.CREATE_MODULE:
193+
return createModule(scope, arguments, EnsoContext.get(null));
194+
case MethodNames.TopScope.REGISTER_MODULE:
195+
return registerModule(scope, arguments, EnsoContext.get(null));
196+
case MethodNames.TopScope.UNREGISTER_MODULE:
197+
return unregisterModule(scope, arguments, EnsoContext.get(null));
198+
case MethodNames.TopScope.LEAK_CONTEXT:
199+
return leakContext(EnsoContext.get(null));
200+
case MethodNames.TopScope.COMPILE:
201+
return compile(arguments, EnsoContext.get(null));
202+
default:
203+
throw UnknownIdentifierException.create(member);
204+
}
215205
}
216206
}
217207

@@ -228,7 +218,6 @@ boolean isMemberInvocable(String member) {
228218
|| member.equals(MethodNames.TopScope.REGISTER_MODULE)
229219
|| member.equals(MethodNames.TopScope.UNREGISTER_MODULE)
230220
|| member.equals(MethodNames.TopScope.LEAK_CONTEXT)
231-
|| member.equals(MethodNames.TopScope.LOCAL_LIBRARIES)
232221
|| member.equals(MethodNames.TopScope.COMPILE);
233222
}
234223

0 commit comments

Comments
 (0)