From 5b8ba21c0a79b2ff8944faccba0a82d07c709c9c Mon Sep 17 00:00:00 2001 From: Kien Dang Date: Tue, 28 Jan 2025 08:26:40 +0700 Subject: [PATCH] Fix publishing for 2.13.16 and 3.6.3 (#1603) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 3.6.3 - `DottyParser.blockStatSeq` signature change from 3.6.2 to 3.6.3 See https://github.com/scala/scala3/compare/3.6.2...3.6.3#diff-89e03cdd16b8e5fd6435d2df4b44a3e58c408a22adb7683c149015ab0d64f4bfR4717 Screenshot 2025-01-27 at 1 41 27 PM Thus the current `amm/compiler/src/main/scala-3/DottyParser.scala` is moved to `.../scala-3.0.0-3.6.2/DottyParser.scala`. A new `.../scala-3.6.3+/DottyParser.scala` was created with the new signature. `build.mill` was updated accordingly. # 2.13.16 - A change in upstream (scala/scala#10868) caused an error in autocompletion. Attempting to autocomplete `import java.|` would trigger the error. The workaround is to change the autocomplete code wrapper to ```scala object AutocompleteWrapper{ def main(args: Array[String])={ import java. () }} ``` (similar to Scala 3) instead of ```scala object AutocompleteWrapper{ import java.} ``` --------- Co-authored-by: Li Haoyi --- .github/workflows/run-tests.yml | 10 +-- .../scala-2/ammonite/compiler/Pressy.scala | 4 +- .../ammonite/compiler/DottyParser.scala | 0 .../ammonite/compiler/DottyParser.scala | 70 +++++++++++++++++++ build.mill | 19 +++-- readme/Footer.scalatex | 4 ++ readme/Index.scalatex | 12 ---- 7 files changed, 95 insertions(+), 24 deletions(-) rename amm/compiler/src/main/{scala-3 => scala-3.0.0-3.6.2}/ammonite/compiler/DottyParser.scala (100%) create mode 100644 amm/compiler/src/main/scala-3.6.3+/ammonite/compiler/DottyParser.scala diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 469aa6302..6360df1ba 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -22,21 +22,21 @@ jobs: command: 'terminal.__.test' - java-version: 11 - command: 'sshd[{2.12.20,2.13.15,3.3.4,3.4.3,3.5.1}].__.test' + command: 'sshd[{2.12.20,2.13.16,3.3.4,3.4.3,3.5.1,3.6.3}].__.test' - java-version: 11 command: 'amm.repl[2.12.{9,14,20}].__.test' - java-version: 17 - command: 'amm.repl[2.13.{4,9,15}].__.test' + command: 'amm.repl[2.13.{4,9,16}].__.test' - java-version: 21 - command: 'amm.repl[{3.3.4,3.4.3,3.5.1}].__.test' + command: 'amm.repl[{3.3.4,3.4.3,3.5.1,3.6.3}].__.test' - java-version: 11 command: 'amm[2.12.{9,14,20}].__.test' - java-version: 17 - command: 'amm[2.13.{4,9,15}].__.test' + command: 'amm[2.13.{4,9,16}].__.test' - java-version: 21 - command: 'amm[{3.3.4,3.4.3,3.5.1}].__.test' + command: 'amm[{3.3.4,3.4.3,3.5.1,3.6.3}].__.test' runs-on: ubuntu-latest steps: diff --git a/amm/compiler/src/main/scala-2/ammonite/compiler/Pressy.scala b/amm/compiler/src/main/scala-2/ammonite/compiler/Pressy.scala index c8c0b6e4f..687a90bd0 100644 --- a/amm/compiler/src/main/scala-2/ammonite/compiler/Pressy.scala +++ b/amm/compiler/src/main/scala-2/ammonite/compiler/Pressy.scala @@ -320,8 +320,8 @@ object Pressy { } def complete(snippetIndex: Int, previousImports: String, snippet: String) = { - val prefix = previousImports + newLine + "object AutocompleteWrapper{" + newLine - val suffix = newLine + "}" + val prefix = previousImports + newLine + "object AutocompleteWrapper{def main(args: Array[String])={" + newLine + val suffix = newLine + "()" + newLine + "}" + "}" val allCode = prefix + snippet + suffix val index = snippetIndex + prefix.length diff --git a/amm/compiler/src/main/scala-3/ammonite/compiler/DottyParser.scala b/amm/compiler/src/main/scala-3.0.0-3.6.2/ammonite/compiler/DottyParser.scala similarity index 100% rename from amm/compiler/src/main/scala-3/ammonite/compiler/DottyParser.scala rename to amm/compiler/src/main/scala-3.0.0-3.6.2/ammonite/compiler/DottyParser.scala diff --git a/amm/compiler/src/main/scala-3.6.3+/ammonite/compiler/DottyParser.scala b/amm/compiler/src/main/scala-3.6.3+/ammonite/compiler/DottyParser.scala new file mode 100644 index 000000000..b74911010 --- /dev/null +++ b/amm/compiler/src/main/scala-3.6.3+/ammonite/compiler/DottyParser.scala @@ -0,0 +1,70 @@ +package ammonite.compiler + +import dotty.tools.dotc +import dotc.ast.untpd +import dotc.core.Contexts.Context +import dotc.core.Flags +import dotc.core.StdNames.nme +import dotc.parsing.Parsers.{Location, Parser} +import dotc.parsing.Tokens +import dotc.reporting.IllegalStartOfStatement +import dotc.util.SourceFile + +import scala.collection.mutable + +class DottyParser(source: SourceFile)(using Context) extends Parser(source) with CompatibilityParser { + + // From + // https://github.com/lampepfl/dotty/blob/3.0.0-M3/ + // compiler/src/dotty/tools/dotc/parsing/Parsers.scala/#L67-L71 + extension (buf: mutable.ListBuffer[untpd.Tree]) + def +++=(x: untpd.Tree) = x match { + case x: untpd.Thicket => buf ++= x.trees + case x => buf += x + } + + private val oursLocalModifierTokens = Tokens.localModifierTokens + Tokens.PRIVATE + + override def localDef( + start: Int, + implicitMods: untpd.Modifiers = untpd.EmptyModifiers + ): untpd.Tree = { + var mods = defAnnotsMods(oursLocalModifierTokens) + for (imod <- implicitMods.mods) mods = addMod(mods, imod) + if (mods.is(Flags.Final)) + // A final modifier means the local definition is "class-like". + // FIXME: Deal with modifiers separately + tmplDef(start, mods) + else + defOrDcl(start, mods) + } + + // Adapted from + // https://github.com/lampepfl/dotty/blob/3.2.0/ + // compiler/src/dotty/tools/dotc/parsing/Parsers.scala#L4075-L4094 + // Unlike it, we accept private modifiers for top-level definitions. + override def blockStatSeq(outermost: Boolean = false): List[untpd.Tree] = checkNoEscapingPlaceholders { + val stats = new mutable.ListBuffer[untpd.Tree] + while + var empty = false + if (in.token == Tokens.IMPORT) + stats ++= compatibilityImportClause() + else if (isExprIntro) + stats += expr(Location.InBlock) + else if in.token == Tokens.IMPLICIT && !in.inModifierPosition() then + stats += closure( + in.offset, + Location.InBlock, + modifiers(scala.collection.immutable.BitSet(Tokens.IMPLICIT)) + ) + else if isIdent(nme.extension) && followingIsExtension() then + stats += extension() + else if isDefIntro(oursLocalModifierTokens, excludedSoftModifiers = Set(nme.`opaque`)) then + stats +++= localDef(in.offset) + else + empty = true + statSepOrEnd(stats, noPrevStat = empty, altEnd = Tokens.CASE) + do () + stats.toList + } +} diff --git a/build.mill b/build.mill index 5862b3bc1..fef51d9c2 100644 --- a/build.mill +++ b/build.mill @@ -63,16 +63,17 @@ val commitsSinceTaggedVersion = latestTaggedVersion match { val scala2_12Versions = 9.to(20) // .dropWhile(v => isJava21 && v < 18) .map(v => s"2.12.${v}") -val scala2_13Versions = 2.to(15) +val scala2_13Versions = 2.to(16) // .dropWhile(v => isJava21 && v < 11) .map(v => s"2.13.${v}") // TODO: We can't have 3.4.0 & 3.4.1 until we solve https://github.com/com-lihaoyi/Ammonite/issues/1395 val scala33Versions = Seq("3.3.4") val scala34Versions = Seq("3.4.2", "3.4.3") val scala35Versions = Seq("3.5.0", "3.5.1") +val scala36Versions = Seq("3.6.2", "3.6.3") val scala2Versions = scala2_12Versions ++ scala2_13Versions -val scala3Versions = scala33Versions ++ scala34Versions ++ scala35Versions +val scala3Versions = scala33Versions ++ scala34Versions ++ scala35Versions ++ scala36Versions val binCrossScalaVersions = Seq(scala2_12Versions.last, scala2_13Versions.last, scala33Versions.last) @@ -81,7 +82,8 @@ val assemblyCrossScalaVersions = Seq( scala2_13Versions.last, scala33Versions.last, scala34Versions.last, - scala35Versions.last + scala35Versions.last, + scala36Versions.last ) def isScala2_12_10OrLater(sv: String): Boolean = { (sv.startsWith("2.12.") && sv.stripPrefix("2.12.").length > 1) || sv.startsWith("2.13.") @@ -238,7 +240,7 @@ trait AmmInternalModule extends CrossSbtModule with Bloop.Module { Seq(PathRef(millSourcePath / "src" / "main" / "scala-2.13-or-3")) else Nil val extraDir5 = - if (sv.startsWith("3.5")) + if (sv.startsWith("3.5") || sv.startsWith("3.6")) Seq(PathRef(millSourcePath / "src" / "main" / "scala-3.5.0+")) else if (sv.startsWith("3.4")) if (sv.stripPrefix("3.4.").toInt < 2) @@ -250,8 +252,15 @@ trait AmmInternalModule extends CrossSbtModule with Bloop.Module { else if (sv.startsWith("3")) Seq(PathRef(millSourcePath / "src" / "main" / "scala-3.0.0-3.3.1")) else Nil + val extraDir6 = + if (sv.startsWith("3")) + if (sv.startsWith("3.6.") && sv.stripPrefix("3.6.").toInt >= 3) + Seq(PathRef(millSourcePath / "src" / "main" / "scala-3.6.3+")) + else + Seq(PathRef(millSourcePath / "src" / "main" / "scala-3.0.0-3.6.2")) + else Nil - super.sources() ++ extraDir ++ extraDir2 ++ extraDir3 ++ extraDir4 ++ extraDir5 + super.sources() ++ extraDir ++ extraDir2 ++ extraDir3 ++ extraDir4 ++ extraDir5 ++ extraDir6 } def externalSources = T { resolveDeps(allBoundIvyDeps, sources = true)() diff --git a/readme/Footer.scalatex b/readme/Footer.scalatex index da42dfa41..aaf1c0615 100644 --- a/readme/Footer.scalatex +++ b/readme/Footer.scalatex @@ -127,6 +127,10 @@ @sect{Changelog} + @sect{3.0.1} + @ul + @li + Support for Scala 2.13.16, 3.3.4 @sect{3.0.0} @ul @li diff --git a/readme/Index.scalatex b/readme/Index.scalatex index f5be9d4a5..d9a780f1c 100644 --- a/readme/Index.scalatex +++ b/readme/Index.scalatex @@ -116,18 +116,6 @@ want to run it later, save it into some @sect.ref{Scala Scripts} and run those later. - @p - For a video overview of the project and it's motivation, check out this talk: - - @iframe( - src := "https://player.vimeo.com/video/148552858", - width := 800, - height := 600, - attr("frameborder") := 0, - attr("webkitallowfullscreen") := 1, - attr("mozallowfullscreen") := 1, - attr("allowfullscreen") := 1 - ) @p If you are already working in Scala, you no longer have to drop down to Python or Bash for your scripting needs: