Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing Truffle API dependency from runtime-compiler project #9785

Merged
merged 16 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 36 additions & 19 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ lazy val enso = (project in file("."))
`runtime-benchmarks`,
`runtime-parser`,
`runtime-compiler`,
`runtime-suggestions`,
`runtime-language-epb`,
`runtime-language-arrow`,
`runtime-instrument-common`,
Expand Down Expand Up @@ -679,12 +680,11 @@ lazy val pkg = (project in file("lib/scala/pkg"))
Compile / run / mainClass := Some("org.enso.pkg.Main"),
frgaalJavaCompilerSetting,
version := "0.1",
libraryDependencies ++= circe ++ Seq(
"org.graalvm.truffle" % "truffle-api" % graalMavenPackagesVersion,
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
"io.circe" %% "circe-yaml" % circeYamlVersion,
"org.apache.commons" % "commons-compress" % commonsCompressVersion,
"commons-io" % "commons-io" % commonsIoVersion
libraryDependencies ++= Seq(
"org.graalvm.truffle" % "truffle-api" % graalMavenPackagesVersion % "provided",
"io.circe" %% "circe-yaml" % circeYamlVersion % "provided",
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
"org.apache.commons" % "commons-compress" % commonsCompressVersion
)
)
.dependsOn(editions)
Expand Down Expand Up @@ -1294,6 +1294,7 @@ lazy val `language-server` = (project in file("engine/language-server"))
"com.typesafe.akka" %% "akka-http-testkit" % akkaHTTPVersion % Test,
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
"org.scalacheck" %% "scalacheck" % scalacheckVersion % Test,
"org.graalvm.truffle" % "truffle-api" % graalMavenPackagesVersion % "provided",
"org.graalvm.sdk" % "polyglot-tck" % graalMavenPackagesVersion % "provided",
"org.eclipse.jgit" % "org.eclipse.jgit" % jgitVersion,
"org.bouncycastle" % "bcutil-jdk18on" % "1.76" % Test,
Expand Down Expand Up @@ -1679,6 +1680,7 @@ lazy val runtime = (project in file("engine/runtime"))
.dependsOn(`polyglot-api`)
.dependsOn(`text-buffer`)
.dependsOn(`runtime-compiler`)
.dependsOn(`runtime-suggestions`)
.dependsOn(`connected-lock-manager`)
.dependsOn(testkit % Test)

Expand Down Expand Up @@ -1956,19 +1958,36 @@ lazy val `runtime-compiler` =
(project in file("engine/runtime-compiler"))
.settings(
frgaalJavaCompilerSetting,
instrumentationSettings,
(Test / fork) := true,
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % shapelessVersion,
"org.graalvm.truffle" % "truffle-api" % graalMavenPackagesVersion,
"junit" % "junit" % junitVersion % Test,
"com.github.sbt" % "junit-interface" % junitIfVersion % Test,
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
"org.netbeans.api" % "org-openide-util-lookup" % netbeansApiVersion % "provided"
)
)
.dependsOn(`runtime-parser`)
.dependsOn(pkg)
.dependsOn(`engine-common`)
.dependsOn(editions)
.dependsOn(`persistance-dsl` % "provided")

lazy val `runtime-suggestions` =
(project in file("engine/runtime-suggestions"))
.settings(
frgaalJavaCompilerSetting,
(Test / fork) := true,
libraryDependencies ++= Seq(
"junit" % "junit" % junitVersion % Test,
"com.github.sbt" % "junit-interface" % junitIfVersion % Test,
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
"org.netbeans.api" % "org-openide-util-lookup" % netbeansApiVersion % "provided"
)
)
.dependsOn(`runtime-parser`)
.dependsOn(pkg)
.dependsOn(`runtime-compiler`)
.dependsOn(`polyglot-api`)
.dependsOn(editions)
.dependsOn(`persistance-dsl` % "provided")

lazy val `runtime-instrument-common` =
(project in file("engine/runtime-instrument-common"))
Expand Down Expand Up @@ -2493,9 +2512,8 @@ lazy val editions = project
.settings(
frgaalJavaCompilerSetting,
libraryDependencies ++= Seq(
"com.typesafe.scala-logging" %% "scala-logging" % scalaLoggingVersion,
"io.circe" %% "circe-yaml" % circeYamlVersion,
"org.scalatest" %% "scalatest" % scalatestVersion % Test
"io.circe" %% "circe-yaml" % circeYamlVersion % "provided",
"org.scalatest" %% "scalatest" % scalatestVersion % Test
)
)
.settings(
Expand Down Expand Up @@ -2523,11 +2541,10 @@ lazy val semver = project
.settings(
frgaalJavaCompilerSetting,
libraryDependencies ++= Seq(
"com.typesafe.scala-logging" %% "scala-logging" % scalaLoggingVersion,
"io.circe" %% "circe-yaml" % circeYamlVersion,
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
"junit" % "junit" % junitVersion % Test,
"com.github.sbt" % "junit-interface" % junitIfVersion % Test
"io.circe" %% "circe-yaml" % circeYamlVersion % "provided",
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
"junit" % "junit" % junitVersion % Test,
"com.github.sbt" % "junit-interface" % junitIfVersion % Test
)
)
.settings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,10 @@ void initializeBuiltinsIr(

CompilationStage getCompilationStage(Module module);

org.enso.polyglot.data.TypeGraph getTypeHierarchy();

Future<Boolean> serializeLibrary(
Compiler compiler, LibraryName libraryName, boolean useGlobalCacheLocations);

scala.Option<List<org.enso.polyglot.Suggestion>> deserializeSuggestions(LibraryName libraryName)
throws InterruptedException;
scala.Option<Object> deserializeSuggestions(LibraryName libraryName) throws InterruptedException;

Future<Boolean> serializeModule(
Compiler compiler, Module module, boolean useGlobalCacheLocations, boolean usePool);
Expand All @@ -129,6 +126,8 @@ public static interface Updater {
public abstract static class Module {
public abstract Source getSource() throws IOException;

public abstract CharSequence getCharacters() throws IOException;

public abstract String getPath();

public abstract Package<TruffleFile> getPackage();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.enso.compiler;

import static org.junit.Assert.fail;

import org.junit.Ignore;
import org.junit.Test;

public final class CompilerDependenciesTest {
@Ignore
@Test
public void noTruffleDependency() {
assertNoClass("com.oracle.truffle.api.nodes.Node");
}

@Test
public void noCirceDependency() {
assertNoClass("io.circe.Error");
}

private static void assertNoClass(String name) {
try {
var c = Class.forName(name);
var sb = new StringBuilder();
sb.append("This class shouldn't be loaded: ").append(c.getName());
sb.append("\nloaded from: ").append(c.getProtectionDomain().getCodeSource().getLocation());
sb.append("\nclassloader: ").append(c.getClassLoader());
sb.append("\nclasspath : ").append(System.getProperty("java.class.path"));
fail(sb.toString());
} catch (ClassNotFoundException ex) {
return;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.logging.Level;
import org.enso.common.LanguageInfo;
import org.enso.common.MethodNames;
import org.enso.compiler.context.SimpleUpdate;
import org.enso.compiler.suggestions.SimpleUpdate;
import org.enso.interpreter.instrument.Endpoint;
import org.enso.interpreter.instrument.MethodCallsCache;
import org.enso.interpreter.instrument.NotificationHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.enso.compiler.core.Implicits.AsMetadata
import org.enso.compiler.core.ir.Literal
import org.enso.compiler.core.ir.Location
import org.enso.compiler.core.ir.Name
import org.enso.compiler.suggestions.SimpleUpdate
import org.enso.compiler.core.ir.module.scope.definition
import org.enso.compiler.pass.analyse.DataflowAnalysis
import org.enso.interpreter.instrument.execution.model.PendingEdit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.enso.interpreter.instrument.job

import org.enso.compiler.context.{
ExportsBuilder,
import org.enso.compiler.context.ExportsBuilder
import org.enso.compiler.suggestions.{
ModuleExportsDiff,
SuggestionBuilder,
SuggestionDiff
Expand Down Expand Up @@ -49,10 +49,13 @@ final class AnalyzeModuleInScopeJob(
ctx.executionService.getLogger
.log(Level.FINEST, s"Analyzing module in scope {0}", module.getName)
val moduleName = module.getName
val compiler = ctx.executionService.getContext.getCompiler
val types = Module.findTypeHierarchy(compiler.context)
val newSuggestions =
SuggestionBuilder(
module.asCompilerModule(),
ctx.executionService.getContext.getCompiler
types,
compiler
)
.build(moduleName, state.ir)
.filter(Suggestion.isGlobal)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.enso.interpreter.instrument.job

import org.enso.compiler.context.{
Changeset,
ExportsBuilder,
import org.enso.compiler.context.Changeset
import org.enso.compiler.context.ExportsBuilder
import org.enso.compiler.suggestions.{
ModuleExportsDiff,
SuggestionBuilder,
SuggestionDiff
Expand Down Expand Up @@ -70,11 +70,12 @@ object AnalyzeModuleJob {
if (state.isIndexed) {
ctx.executionService.getLogger
.log(Level.FINEST, "Analyzing indexed module {0}", moduleName)
val types = Module.findTypeHierarchy(compiler.context)
val prevSuggestions =
SuggestionBuilder(changeset.source, compiler)
SuggestionBuilder(changeset.source, types, compiler)
.build(moduleName, changeset.ir)
val newSuggestions =
SuggestionBuilder(module.asCompilerModule(), compiler)
SuggestionBuilder(module.asCompilerModule(), types, compiler)
.build(moduleName, newIr)
val diff = SuggestionDiff
.compute(prevSuggestions, newSuggestions)
Expand All @@ -100,8 +101,9 @@ object AnalyzeModuleJob {
} else {
ctx.executionService.getLogger
.log(Level.FINEST, s"Analyzing not-indexed module {0}", module.getName)
val types = Module.findTypeHierarchy(compiler.context)
val newSuggestions =
SuggestionBuilder(module.asCompilerModule(), compiler)
SuggestionBuilder(module.asCompilerModule(), types, compiler)
.build(moduleName, state.ir)
val prevExports = ModuleExports(moduleName.toString, Set())
val newExports = exportsBuilder.build(moduleName, state.ir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.enso.polyglot.runtime.Runtime.Api
import java.util.logging.Level

import scala.jdk.CollectionConverters._
import org.enso.polyglot.Suggestion

/** A job responsible for deserializing suggestions of loaded library.
*
Expand Down Expand Up @@ -36,11 +37,13 @@ final class DeserializeLibrarySuggestionsJob(
cc
.deserializeSuggestions(libraryName)
.foreach { cachedSuggestions =>
val suggestions =
cachedSuggestions.asInstanceOf[java.util.List[Suggestion]]
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
ctx.endpoint.sendToClient(
Api.Response(
Api.SuggestionsDatabaseSuggestionsLoadedNotification(
libraryName,
cachedSuggestions.asScala.toVector
suggestions.asScala.toVector
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ private void clearLibraryCache(LibraryName libraryName) {
}

@Test
@SuppressWarnings("unchecked")
public void serializeLibrarySuggestions()
throws ExecutionException, InterruptedException, TimeoutException {
LibraryName standardBaseLibrary = new LibraryName("Standard", "Base");
Expand All @@ -94,7 +95,8 @@ public void serializeLibrarySuggestions()
Assert.assertEquals(Boolean.TRUE, result);

var cachedSuggestions =
ensoContext.getCompiler().context().deserializeSuggestions(standardBaseLibrary).get();
(java.util.List<Suggestion>)
ensoContext.getCompiler().context().deserializeSuggestions(standardBaseLibrary).get();

Supplier<Stream<Suggestion.Constructor>> cachedConstructorSuggestions =
() ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import org.enso.compiler.context.SuggestionBuilder
import org.enso.compiler.suggestions.SuggestionBuilder
import org.enso.compiler.core.ir.Module
import org.enso.interpreter.runtime
import org.enso.interpreter.runtime.EnsoContext
Expand Down Expand Up @@ -3722,6 +3722,10 @@ class SuggestionBuilderTest extends AnyWordSpecLike with Matchers {
source: String,
ir: Module,
module: QualifiedName = Module
): Tree.Root[Suggestion] =
SuggestionBuilder(source, langCtx.getCompiler).build(module, ir)
): Tree.Root[Suggestion] = {
val compiler = langCtx.getCompiler
val types =
org.enso.interpreter.runtime.Module.findTypeHierarchy(compiler.context)
SuggestionBuilder(source, types, compiler).build(module, ir)
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.enso.compiler.context;
package org.enso.compiler.suggestions;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;

import org.enso.pkg.QualifiedName;
import org.enso.polyglot.ExportedSymbol;
import org.enso.polyglot.ModuleExports;
import org.enso.polyglot.Suggestion;

import scala.runtime.BoxedUnit;

public final class ExportsMap {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.enso.compiler.context
package org.enso.compiler.suggestions

import org.enso.polyglot.ModuleExports
import org.enso.polyglot.runtime.Runtime.Api
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.enso.compiler.context;
package org.enso.compiler.suggestions;

import org.enso.compiler.core.ir.Literal;
import org.enso.text.editing.model.TextEdit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.enso.compiler.context
package org.enso.compiler.suggestions

import org.enso.compiler.Compiler
import org.enso.compiler.context.CompilerContext
import org.enso.compiler.core.Implicits.AsMetadata
import org.enso.compiler.core.{ExternalID, IR}
import org.enso.compiler.core.ir.expression.{Application, Operator}
Expand Down Expand Up @@ -784,14 +785,16 @@ object SuggestionBuilder {
/** Creates the suggestion builder for a module.
*
* @param module the module to index
* @param typeGraph the type hierarchy
* @param compiler the compiler instance
* @return the suggestions builder for the module
*/
def apply(
module: CompilerContext.Module,
typeGraph: TypeGraph,
compiler: Compiler
): SuggestionBuilder[CharSequence] =
SuggestionBuilder(module.getSource.getCharacters, compiler)
SuggestionBuilder(module.getCharacters, typeGraph, compiler)

/** Create the suggestion builder.
*
Expand All @@ -807,22 +810,6 @@ object SuggestionBuilder {
): SuggestionBuilder[A] =
new SuggestionBuilder[A](source, typeGraph, compiler)

/** Create the suggestion builder.
*
* @param source the text source
* @param compiler the compiler instance
* @tparam A the type of the text source
*/
def apply[A: IndexedSource](
source: A,
compiler: Compiler
): SuggestionBuilder[A] =
new SuggestionBuilder[A](
source,
compiler.context.getTypeHierarchy(),
compiler
)

/** A single level of an `IR`.
*
* @param queue the nodes in the scope
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.enso.compiler.context
package org.enso.compiler.suggestions

import org.enso.polyglot.Suggestion
import org.enso.polyglot.data.{These, Tree}
Expand Down
Loading
Loading