From 36b41da889f42e832deafd0a9b7da15cc7a37b20 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Thu, 26 Dec 2019 10:49:53 +0800 Subject: [PATCH] 1.9.9 reshuffle code to make classloading tests pass --- .../scala/ammonite/interp/Interpreter.scala | 27 ++--------------- .../main/scala/ammonite/interp/Parsers.scala | 30 +++++++++++++++++++ build.sc | 6 ++-- readme/Footer.scalatex | 9 ++---- 4 files changed, 39 insertions(+), 33 deletions(-) diff --git a/amm/interp/src/main/scala/ammonite/interp/Interpreter.scala b/amm/interp/src/main/scala/ammonite/interp/Interpreter.scala index 7f5f5ce66..f7227a67a 100644 --- a/amm/interp/src/main/scala/ammonite/interp/Interpreter.scala +++ b/amm/interp/src/main/scala/ammonite/interp/Interpreter.scala @@ -183,28 +183,7 @@ class Interpreter(val printer: Printer, } yield hookResults } - def parseImportHooks(source: CodeSource, stmts: Seq[String]) = synchronized{ - val hookedStmts = mutable.Buffer.empty[String] - val importTrees = mutable.Buffer.empty[ImportTree] - for(stmt <- stmts) { - parse(stmt, Parsers.ImportSplitter(_)) match{ - case f: Parsed.Failure => hookedStmts.append(stmt) - case Parsed.Success(parsedTrees, _) => - var currentStmt = stmt - for(importTree <- parsedTrees){ - if (importTree.prefix(0)(0) == '$') { - val length = importTree.end - importTree.start - currentStmt = currentStmt.patch( - importTree.start, (importTree.prefix(0) + ".$").padTo(length, ' '), length - ) - importTrees.append(importTree) - } - } - hookedStmts.append(currentStmt) - } - } - (hookedStmts.toSeq, importTrees.toSeq) - } + def resolveImportHooks(importTrees: Seq[ImportTree], hookedStmts: Seq[String], @@ -238,7 +217,7 @@ class Interpreter(val printer: Printer, Seq(Name("ammonite"), Name("$sess")), Some(wd/"(console)") ) - val (hookStmts, importTrees) = parseImportHooks(codeSource, stmts) + val (hookStmts, importTrees) = Parsers.parseImportHooks(codeSource, stmts) for{ _ <- Catching { case ex => Res.Exception(ex, "") } @@ -565,7 +544,7 @@ class Interpreter(val printer: Printer, for{ allSplittedChunks <- splittedScript (leadingSpaces, stmts) = allSplittedChunks(wrapperIndex - 1) - (hookStmts, importTrees) = parseImportHooks(codeSource, stmts) + (hookStmts, importTrees) = Parsers.parseImportHooks(codeSource, stmts) hookInfo <- resolveImportHooks( importTrees, hookStmts, codeSource, scriptCodeWrapper.wrapperPath ) diff --git a/amm/interp/src/main/scala/ammonite/interp/Parsers.scala b/amm/interp/src/main/scala/ammonite/interp/Parsers.scala index bc24f178a..b1d60d5e0 100644 --- a/amm/interp/src/main/scala/ammonite/interp/Parsers.scala +++ b/amm/interp/src/main/scala/ammonite/interp/Parsers.scala @@ -1,5 +1,10 @@ package ammonite.interp +import ammonite.util.ImportTree +import ammonite.util.Util.CodeSource + +import scala.collection.mutable + object Parsers { import fastparse._ @@ -103,4 +108,29 @@ object Parsers { case f: Parsed.Failure => stringWrap(s) } } + def parseImportHooks(source: CodeSource, stmts: Seq[String]) = synchronized{ + val hookedStmts = mutable.Buffer.empty[String] + val importTrees = mutable.Buffer.empty[ImportTree] + for(stmt <- stmts) { + // Call `fastparse.ParserInput.fromString` explicitly, to avoid generating a + // lambda in the class body and making the we-do-not-load-fastparse-on-cached-scripts + // test fail + parse(fastparse.ParserInput.fromString(stmt), Parsers.ImportSplitter(_)) match{ + case f: Parsed.Failure => hookedStmts.append(stmt) + case Parsed.Success(parsedTrees, _) => + var currentStmt = stmt + for(importTree <- parsedTrees){ + if (importTree.prefix(0)(0) == '$') { + val length = importTree.end - importTree.start + currentStmt = currentStmt.patch( + importTree.start, (importTree.prefix(0) + ".$").padTo(length, ' '), length + ) + importTrees.append(importTree) + } + } + hookedStmts.append(currentStmt) + } + } + (hookedStmts.toSeq, importTrees.toSeq) + } } diff --git a/build.sc b/build.sc index 0140fa6b0..8b415bcfc 100644 --- a/build.sc +++ b/build.sc @@ -170,7 +170,7 @@ object amm extends Cross[MainModule](fullCrossScalaVersions:_*){ def moduleDeps = Seq(ops(), amm.util(), interp.api(), amm.repl.api()) def crossFullScalaVersion = true def ivyDeps = Agg( - ivy"com.lihaoyi::upickle:0.9.3", + ivy"com.lihaoyi::upickle:0.9.5", ivy"com.lihaoyi::requests:0.4.6" ) } @@ -193,7 +193,7 @@ object amm extends Cross[MainModule](fullCrossScalaVersions:_*){ def ivyDeps = Agg( ivy"org.scala-lang:scala-compiler:$crossScalaVersion", ivy"org.scala-lang:scala-reflect:$crossScalaVersion", - ivy"com.lihaoyi::scalaparse:2.2.0", + ivy"com.lihaoyi::scalaparse:2.2.2", ivy"org.javassist:javassist:3.21.0-GA", ivy"org.scala-lang.modules::scala-xml:1.2.0" ) @@ -418,7 +418,7 @@ class IntegrationModule(val crossScalaVersion: String) extends AmmInternalModule object test extends Tests { def forkEnv = super.forkEnv() ++ Seq( "AMMONITE_SHELL" -> shell().jar().path.toString, - "AMMONITE_ASSEMBLY" -> amm().assembly().path.toString + "AMMONITE_ASSEMBLY" -> amm().launcher().path.toString ) } } diff --git a/readme/Footer.scalatex b/readme/Footer.scalatex index c8f471ab6..4b493a02f 100644 --- a/readme/Footer.scalatex +++ b/readme/Footer.scalatex @@ -123,14 +123,11 @@ @sect{Changelog} - @sect{1.9.8} + @sect{1.9.9} @ul @li - Bump PPrint to 0.5.7 - @sect{1.9.2} - @ul - @li - Bump FastParse to 2.2.0 + Bump PPrint to 0.5.7, FastParse to 2.2.2, uPickle to 0.9.6 + @sect{1.9.1} @ul @li