Skip to content

Commit

Permalink
Revert "Import all available libraries in --repl mode (#10746)" (#10778)
Browse files Browse the repository at this point in the history
* Revert "Import all available libraries in --repl mode (#10746)"

This reverts commit 71285e6.

* trigger build
  • Loading branch information
hubertp authored Aug 9, 2024
1 parent 3581fd8 commit 0f5a3a7
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 176 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@
- [Space-precedence does not apply to value-level operators][10597]
- [Must specify `--repl` to enable debug server][10709]
- [Improved parser error reporting and performance][10734]
- [Import all available libraries in `--repl` mode][10746]

[10468]: https://github.com/enso-org/enso/pull/10468
[10535]: https://github.com/enso-org/enso/pull/10535
[10597]: https://github.com/enso-org/enso/pull/10597
[10709]: https://github.com/enso-org/enso/pull/10709
[10734]: https://github.com/enso-org/enso/pull/10734
[10746]: https://github.com/enso-org/enso/pull/10746

#### Enso IDE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public static class TopScope {
public static final String REGISTER_MODULE = "register_module";
public static final String UNREGISTER_MODULE = "unregister_module";
public static final String COMPILE = "compile";
public static final String LOCAL_LIBRARIES = "local_libraries";
}

public static class Module {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.enso.polyglot
import java.io.File
import org.enso.common.LanguageInfo

import org.graalvm.polyglot.{Context, Source}

/** Exposes language specific aliases for generic polyglot context operations.
* @param context the Graal polyglot context to use.
*/
class PolyglotContext(val context: Context) {

/** Evaluates provided code string as a new module.
*
* @param code the code to evaluate.
* @param moduleName the name for the newly parsed module.
* @return the module representing evaluated code.
*/
def evalModule(code: String, moduleName: String): Module = {
val source = Source
.newBuilder(LanguageInfo.ID, code, moduleName)
.build()
new Module(context.eval(source))
}

/** Evaluates provided code file as a new module.
*
* @param codeFile the code to evaluate.
* @return the module representing evaluated code.
*/
def evalModule(codeFile: File): Module = {
val source = Source.newBuilder(LanguageInfo.ID, codeFile).build
new Module(context.eval(source))
}

/** @return the top scope of Enso execution context
*/
def getTopScope: TopScope = {
new TopScope(context.getBindings(LanguageInfo.ID))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,4 @@ class TopScope(private val value: Value) {
def compile(shouldCompileDependencies: Boolean): Unit = {
value.invokeMember(COMPILE, shouldCompileDependencies)
}

def getLibraries(): Array[String] =
value.invokeMember(LOCAL_LIBRARIES).as(classOf[Array[String]])
}
15 changes: 11 additions & 4 deletions engine/runner/src/main/java/org/enso/runner/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,7 @@ private void runPackage(
}

private void runSingleFile(
PolyglotContext context, File file, java.util.List<String> additionalArgs)
throws IOException {
PolyglotContext context, File file, java.util.List<String> additionalArgs) {
var mainModule = context.evalModule(file);
runMain(mainModule, file, additionalArgs, "main");
}
Expand Down Expand Up @@ -894,6 +893,15 @@ private void runRepl(
boolean enableIrCaches,
boolean enableStaticAnalysis) {
var mainMethodName = "internal_repl_entry_point___";
var dummySourceToTriggerRepl =
"""
from Standard.Base import all
import Standard.Base.Runtime.Debug
$mainMethodName = Debug.breakpoint
"""
.replace("$mainMethodName", mainMethodName);
var replModuleName = "Internal_Repl_Module___";
var projectRoot = projectPath != null ? projectPath : "";
var options = Collections.singletonMap(DebugServerInfo.ENABLE_OPTION, "true");

Expand All @@ -909,8 +917,7 @@ private void runRepl(
.disableLinting(true)
.enableStaticAnalysis(enableStaticAnalysis)
.build());

var mainModule = context.evalReplModule(mainMethodName);
var mainModule = context.evalModule(dummySourceToTriggerRepl, replModuleName);
runMain(mainModule, null, Collections.emptyList(), mainMethodName);
throw exitSuccess();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ trait PackageRepository {
libraryName: LibraryName
): Either[PackageRepository.Error, Unit]

/** Iterates over all installed libraries.
*/
def findAvailableLocalLibraries(): Seq[LibraryName]

/** Checks if the library has already been loaded */
def isPackageLoaded(libraryName: LibraryName): Boolean

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ class ReplTest
): Unit = {

"initialize properly" in {
var counter = 0;
setSessionManager(executor => {
counter = counter + 1
executor.exit()
})
val mainFn = "my_main_fn__"
val replModule =
interpreterContext.executionContext.evalReplModule(mainFn)
replModule.evalExpression(mainFn)
counter shouldEqual 1
val code =
"""
|import Standard.Base.Runtime.Debug
|
|main = Debug.breakpoint
|""".stripMargin
setSessionManager(executor => executor.exit())
eval(code)
}

"be able to execute arbitrary code in the caller scope" in {
Expand Down Expand Up @@ -295,7 +293,7 @@ class ReplTest
}
eval(code)
val errorMsg =
"Compile error: The name `undefined` could not be found."
"Compile_Error.Error"
evalResult.left.value.getMessage shouldEqual errorMsg
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ EnsoObject getMembers(boolean includeInternal) {
MethodNames.TopScope.CREATE_MODULE,
MethodNames.TopScope.REGISTER_MODULE,
MethodNames.TopScope.UNREGISTER_MODULE,
MethodNames.TopScope.LOCAL_LIBRARIES,
MethodNames.TopScope.COMPILE);
}

Expand Down Expand Up @@ -166,18 +165,6 @@ private static Object unregisterModule(
return context.getNothing();
}

@CompilerDirectives.TruffleBoundary
private static EnsoObject localLibraries(EnsoContext context) {
var seq = context.getTopScope().packageRepository.findAvailableLocalLibraries();
String[] names = new String[seq.size()];
var it = seq.iterator();
var i = 0;
while (it.hasNext()) {
names[i++] = it.next().toString();
}
return ArrayLikeHelpers.wrapStrings(names);
}

private static Object leakContext(EnsoContext context) {
return context.asGuestValue(context);
}
Expand All @@ -199,19 +186,22 @@ private static Object compile(Object[] arguments, EnsoContext context)
@Specialization
static Object doInvoke(TopLevelScope scope, String member, Object[] arguments)
throws UnknownIdentifierException, ArityException, UnsupportedTypeException {
return switch (member) {
case MethodNames.TopScope.GET_MODULE -> getModule(scope, arguments);
case MethodNames.TopScope.CREATE_MODULE -> createModule(
scope, arguments, EnsoContext.get(null));
case MethodNames.TopScope.REGISTER_MODULE -> registerModule(
scope, arguments, EnsoContext.get(null));
case MethodNames.TopScope.UNREGISTER_MODULE -> unregisterModule(
scope, arguments, EnsoContext.get(null));
case MethodNames.TopScope.LEAK_CONTEXT -> leakContext(EnsoContext.get(null));
case MethodNames.TopScope.LOCAL_LIBRARIES -> localLibraries(EnsoContext.get(null));
case MethodNames.TopScope.COMPILE -> compile(arguments, EnsoContext.get(null));
default -> throw UnknownIdentifierException.create(member);
};
switch (member) {
case MethodNames.TopScope.GET_MODULE:
return getModule(scope, arguments);
case MethodNames.TopScope.CREATE_MODULE:
return createModule(scope, arguments, EnsoContext.get(null));
case MethodNames.TopScope.REGISTER_MODULE:
return registerModule(scope, arguments, EnsoContext.get(null));
case MethodNames.TopScope.UNREGISTER_MODULE:
return unregisterModule(scope, arguments, EnsoContext.get(null));
case MethodNames.TopScope.LEAK_CONTEXT:
return leakContext(EnsoContext.get(null));
case MethodNames.TopScope.COMPILE:
return compile(arguments, EnsoContext.get(null));
default:
throw UnknownIdentifierException.create(member);
}
}
}

Expand All @@ -228,7 +218,6 @@ boolean isMemberInvocable(String member) {
|| member.equals(MethodNames.TopScope.REGISTER_MODULE)
|| member.equals(MethodNames.TopScope.UNREGISTER_MODULE)
|| member.equals(MethodNames.TopScope.LEAK_CONTEXT)
|| member.equals(MethodNames.TopScope.LOCAL_LIBRARIES)
|| member.equals(MethodNames.TopScope.COMPILE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ private class DefaultPackageRepository(
go(component.name.split(LibraryName.separator))
}

override def findAvailableLocalLibraries(): Seq[LibraryName] = {
libraryProvider.findAvailableLocalLibraries()
}

/** @inheritdoc */
override def getModuleMap: PackageRepository.ModuleMap = loadedModules

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static void createProject(String projName, Set<SourceModule> modules, Pat
* main} method
*/
public static void testProjectRun(
Context.Builder ctxBuilder, Path projDir, Consumer<Value> resultConsumer) throws IOException {
Context.Builder ctxBuilder, Path projDir, Consumer<Value> resultConsumer) {
if (!(projDir.toFile().exists() && projDir.toFile().isDirectory())) {
throw new IllegalArgumentException(
"Project directory " + projDir + " must already be created");
Expand Down Expand Up @@ -115,8 +115,7 @@ public static void testProjectRun(
* @param resultConsumer Any action that is to be evaluated on the result of running the {@code
* main} method
*/
public static void testProjectRun(Path projDir, Consumer<Value> resultConsumer)
throws IOException {
public static void testProjectRun(Path projDir, Consumer<Value> resultConsumer) {
testProjectRun(ContextUtils.defaultContextBuilder(), projDir, resultConsumer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ class DefaultLibraryProvider(
private val logger = Logger[DefaultLibraryProvider]
private val resolver = LibraryResolver(localLibraryProvider)

override def findAvailableLocalLibraries(): Seq[LibraryName] = {
val libs = edition.getAllDefinedLibraries
libs.keys.toSeq
}

/** Resolves the library version that should be used based on the
* configuration and returns its location on the filesystem.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import org.enso.editions.{LibraryName, LibraryVersion}
/** A helper class for resolving libraries. */
trait ResolvingLibraryProvider {

/** Finds available library names */
def findAvailableLocalLibraries(): Seq[LibraryName]

/** Resolves which library version should be used and finds its path within
* local libraries or the cache.
*
Expand Down

0 comments on commit 0f5a3a7

Please sign in to comment.