Skip to content

Commit

Permalink
Fix publishing for 2.13.16 and 3.6.3 (#1603)
Browse files Browse the repository at this point in the history
# 3.6.3

- `DottyParser.blockStatSeq` signature change from 3.6.2 to 3.6.3

See
scala/scala3@3.6.2...3.6.3#diff-89e03cdd16b8e5fd6435d2df4b44a3e58c408a22adb7683c149015ab0d64f4bfR4717
<img width="816" alt="Screenshot 2025-01-27 at 1 41 27 PM"
src="https://github.com/user-attachments/assets/d35ac655-9ece-48c0-a3bd-46ba3de02c1b"
/>

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 <[email protected]>
  • Loading branch information
kiendang and lihaoyi authored Jan 28, 2025
1 parent c7a1191 commit 5b8ba21
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 24 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions amm/compiler/src/main/scala-2/ammonite/compiler/Pressy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
19 changes: 14 additions & 5 deletions build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.")
Expand Down Expand Up @@ -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)
Expand All @@ -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)()
Expand Down
4 changes: 4 additions & 0 deletions readme/Footer.scalatex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions readme/Index.scalatex
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5b8ba21

Please sign in to comment.