From bc09c7b4c2956fb8d1eadcf18ba0db0e665011a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Wa=C5=9Bko?= Date: Mon, 24 Oct 2022 16:56:07 +0200 Subject: [PATCH] Remove obsolete Rust parser experiment, superseded by the much more mature new Rust parser integration (#3815) We've had an old attempt at integrating a Rust parser with our Scala/Java projects. It seems to have been abandoned and is not used anywhere - it is also superseded by the new integration of the Rust parser. I think it was used as an experiment to see how to approach such an integration. Since it is not used anymore - it make sense to remove it, because it only adds some (slight, but non-zero) maintenance effort. We can always bring it back from git history if necessary. --- build.sbt | 26 ------------ .../main/scala/org/enso/parser/Parser.scala | 41 ------------------ .../scala/org/enso/parser/ParserTest.scala | 19 --------- project/GenerateAST.scala | 42 ------------------- 4 files changed, 128 deletions(-) delete mode 100644 lib/scala/parser/src/main/scala/org/enso/parser/Parser.scala delete mode 100644 lib/scala/parser/src/test/scala/org/enso/parser/ParserTest.scala delete mode 100644 project/GenerateAST.scala diff --git a/build.sbt b/build.sbt index 8d34c8f2ac..3430e0c829 100644 --- a/build.sbt +++ b/build.sbt @@ -1193,32 +1193,6 @@ lazy val `language-server` = (project in file("engine/language-server")) .dependsOn(`library-manager-test` % Test) .dependsOn(`runtime-version-manager-test` % Test) -lazy val ast = (project in file("lib/scala/ast")) - .settings( - version := ensoVersion, - Compile / sourceGenerators += GenerateAST.task - ) - -lazy val parser = (project in file("lib/scala/parser")) - .settings( - fork := true, - Compile / compile / compileInputs := (Compile / compile / compileInputs) - .dependsOn(Cargo("build --project parser")) - .value, - javaOptions += { - val root = baseDirectory.value.getParentFile.getParentFile.getParentFile - s"-Djava.library.path=$root/target/rust/debug" - }, - libraryDependencies ++= Seq( - "org.scalatest" %%% "scalatest" % scalatestVersion % Test - ), - testFrameworks := List( - new TestFramework("org.scalatest.tools.Framework"), - new TestFramework("org.scalameter.ScalaMeterFramework") - ) - ) - .dependsOn(ast) - lazy val cleanInstruments = taskKey[Unit]( "Cleans fragile class files to force a full recompilation and preserve" + "consistency of instrumentation configuration." diff --git a/lib/scala/parser/src/main/scala/org/enso/parser/Parser.scala b/lib/scala/parser/src/main/scala/org/enso/parser/Parser.scala deleted file mode 100644 index 6894298e69..0000000000 --- a/lib/scala/parser/src/main/scala/org/enso/parser/Parser.scala +++ /dev/null @@ -1,41 +0,0 @@ -package org.enso.parser - -import org.enso.ast.Ast - -import scala.annotation.unused - -/** This is the Enso language parser. - * - * It is a wrapper of parser written in Rust that uses JNI to efficiently - * construct scala AST directly without any serialization overhead. - * - * The methods are loaded from a native shared library `parser` that is located - * in a directory specified by `-Djava.library.path` and has one of the extensions - * `.dll`, `.so` or `dylib` depending on the platform (windows, linux or mac). - * - * The shared library itself is generated into `target/rust/debug` by executing - * `cargo build -p parser`. Each method marked by `@native` must have a - * corresponding counterpart in rust, otherwise the loading of the shared library - * is going to fail at runtime with `UnsatisfiedLinkingError`. - */ -class Parser private () { - - /** Parses a content of a single source file. */ - @native def parseStr(@unused input: String): Ast.AnyAst - - /** Parses a single source file. */ - @native def parseFile(@unused filename: String): Ast.AnyAst - - /** Parses a content of a single source file into a stream of tokens. */ - @native def lexStr(@unused input: String): Ast.AnyAst - - /** Parses a single source file into a stream of tokens. */ - @native def lexFile(@unused filename: String): Ast.AnyAst -} - -object Parser { - System.loadLibrary("parser") - - /** Constructs a new parser */ - def apply(): Parser = new Parser() -} diff --git a/lib/scala/parser/src/test/scala/org/enso/parser/ParserTest.scala b/lib/scala/parser/src/test/scala/org/enso/parser/ParserTest.scala deleted file mode 100644 index 294b574790..0000000000 --- a/lib/scala/parser/src/test/scala/org/enso/parser/ParserTest.scala +++ /dev/null @@ -1,19 +0,0 @@ -package org.enso.parser - -import org.enso.ast.Ast - -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers - -class ParserTest extends AnyFlatSpec with Matchers { - val parser: Parser = Parser() - - it should "parse file" in { - val expected = - Ast.Ast(uid = None, len = 0, off = 0, ast = Ast.Txt.Text("Hello!")) - assert(expected == parser.parseStr("Hello!")) - assert(expected == parser.parseFile("Hello!")) - assert(expected == parser.lexStr("Hello!")) - assert(expected == parser.lexFile("Hello!")) - } -} diff --git a/project/GenerateAST.scala b/project/GenerateAST.scala deleted file mode 100644 index abfe4c80d5..0000000000 --- a/project/GenerateAST.scala +++ /dev/null @@ -1,42 +0,0 @@ -import sbt.Keys._ -import sbt._ -import sbt.internal.util.ManagedLogger - -object GenerateAST { - - lazy val task = Def.task { - val log = state.value.log - val lib = baseDirectory.value.getParentFile.getParentFile - val source = lib / "rust/ast/src/ast.rs" - val output = sourceManaged.value / "main/org/enso/ast/Ast.scala" - val cache = streams.value.cacheStoreFactory.make("ast_source") - - Tracked.diffInputs(cache, FileInfo.lastModified)(Set(source)) { - source: ChangeReport[File] => - if (source.modified.nonEmpty) { - output.getParentFile.mkdirs - generateAST(output, log) - } - } - - Seq(output) - } - - /** Generates the Scala AST in the specified file. All errors are reported in - * stderr and raise a runtime exception. - * - * @param out the file where the generated AST is going to be placed - */ - def generateAST(out: File, log: ManagedLogger): Unit = { - val args = s"run -p ast -- --generate-scala-ast $out" - - log.info(s"Generating Scala AST from Rust definitions.") - - try Cargo.run(args, log) - catch { - case ex: RuntimeException => - log.error(s"Generation of the Scala AST failed.") - throw ex - } - } -}