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

Add partial cross-compilation for Scala 3 #4549

Merged
merged 31 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f4b01bc
Add Scala3 sources
adkian-sifive Nov 20, 2024
cbaeaa5
Update build.sc
adkian-sifive Nov 20, 2024
fa910dc
Fix SerializableModuleGenerator
adkian-sifive Nov 20, 2024
88c18b6
Fix D/I sources to cross compile
adkian-sifive Nov 20, 2024
c8a1fcc
Move SerializableModuleGenerator
adkian-sifive Nov 20, 2024
fe3a9a7
Remove copy method from IR
adkian-sifive Nov 20, 2024
cb866e2
Explicit import in ModuleImpl
adkian-sifive Nov 20, 2024
8103a01
Cross compilation fixes
adkian-sifive Nov 25, 2024
dbd96b7
Convert cloneType to an extension method
adkian-sifive Nov 25, 2024
a5afb37
Updates
adkian-sifive Nov 26, 2024
416cdda
Add missing return type to unary_~
adkian-sifive Nov 27, 2024
182770d
Remove do-apply pattern from Definition and Instance
adkian-sifive Nov 27, 2024
3fb5779
Rebase fixes
adkian-sifive Dec 4, 2024
65d04a1
Switch Scala3 sourceInfo implicits to contextual parameters
adkian-sifive Dec 4, 2024
8d32700
Add Scala 3 compilation to CI
adkian-sifive Dec 4, 2024
365e084
Update workflows with explicit scala version
adkian-sifive Dec 4, 2024
cee3eea
CI and build.sc updates
adkian-sifive Dec 4, 2024
2f3df15
Revert "Convert cloneType to an extension method"
jackkoenig Dec 5, 2024
c0fe7bb
Get things working with this.type
jackkoenig Dec 5, 2024
65f87c1
Move plugins to plugin/src/main/scala-2
adkian-sifive Dec 12, 2024
5763b57
Add plugin 3.3.4 stub and change version to 3.3.4
adkian-sifive Dec 12, 2024
04821b7
Code review updates
adkian-sifive Dec 17, 2024
77a10f4
Add compileAll function in build.sc
adkian-sifive Dec 17, 2024
e694a6a
Update Printf.scala
adkian-sifive Dec 18, 2024
88cb4d3
Hierarchy updates
adkian-sifive Dec 18, 2024
bc6ff61
Fix Instance.scala
adkian-sifive Dec 18, 2024
9a8b282
Fix ChiselEnum
adkian-sifive Dec 18, 2024
f46d276
Add remaining units to buildUnits build.sc
adkian-sifive Dec 18, 2024
dfd3245
Code review updates
adkian-sifive Dec 19, 2024
d754f9f
Code review updates
adkian-sifive Dec 19, 2024
8ccc39c
Merge branch 'main' into adkian-sifive/scala3-v0.1
jackkoenig Dec 19, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
$CHISEL_FIRTOOL_PATH/firtool -version >> $GITHUB_STEP_SUMMARY
echo \`\`\` >> $GITHUB_STEP_SUMMARY
- name: Test
run: ./mill -j0 firrtl[_].test + svsim[_].test + chisel[_].test
run: ./mill -j0 firrtl[].test + svsim[].test + chisel[].test
- name: Binary compatibility
# TODO either make this also check the plugin or decide that we don't
# support binary compatibility for the plugin
Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:
$CHISEL_FIRTOOL_PATH/firtool -version >> $GITHUB_STEP_SUMMARY
echo \`\`\` >> $GITHUB_STEP_SUMMARY
- name: Compile with Mill
run: ./mill __.compile
run: ./mill compileAll

doc:
name: Formatting
Expand Down Expand Up @@ -183,7 +183,7 @@ jobs:
dir=$(dirname $(which firtool))
echo "CHISEL_FIRTOOL_PATH=$dir" >> "$GITHUB_ENV"
- name: Integration Tests
run: ./mill -j0 integrationTests[_].test
run: ./mill -j0 integrationTests[].test

# Currently just a sanity check that the benchmarking flow works
benchmark:
Expand Down
28 changes: 24 additions & 4 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,25 @@ object v extends Module {
val java21Min213 = 11
val minVersion = if (javaVersion > 11) java21Min213 else 0
val versions = minVersion to latest213
versions.map(v => s"2.13.$v").toSeq
val versionSeq = versions.map(v => s"2.13.$v").toSeq
versionSeq ++ Seq("3.3.4")
}

val scalaCrossVersions = Seq(
"2.13.15"
"2.13.15",
"3.3.4"
)
adkian-sifive marked this conversation as resolved.
Show resolved Hide resolved

def isScala3(ver: String): Boolean = ver.startsWith("3.")

def buildUnits(): Seq[ScalaModule] = {
scalaCrossVersions.flatMap { ver =>
Seq(chisel(ver), stdlib(ver), unipublish)
} ++ scalaCrossVersions.filterNot(isScala3(_)).flatMap { ver2 =>
Seq(chisel(ver2).test, firrtl(ver2).test, svsim(ver2).test, integrationTests(ver2).test, litutility(ver2), panamaconverter(ver2), panamalib(ver2), panamaom(ver2))
}
}

val scalaVersion = scalaCrossVersions.head
val jmhVersion = "1.37"
val osLib = ivy"com.lihaoyi::os-lib:0.10.0"
Expand Down Expand Up @@ -96,6 +106,10 @@ object v extends Module {
)
}

def compileAll() = T.command {
T.traverse(v.buildUnits())(_.compile)()
}

trait ChiselPublishModule extends CiReleaseModule {
// Publish information
def pomSettings = PomSettings(
Expand Down Expand Up @@ -251,7 +265,7 @@ trait Core extends CrossSbtModule with HasScala2MacroAnno with ScalafmtModule {
)

override def ivyDeps = if (v.isScala3(crossScalaVersion)) {
super.ivyDeps() ++ commonDeps
super.ivyDeps() ++ commonDeps ++ Agg(v.firtoolResolver.withDottyCompat(scalaVersion()))
} else {
super.ivyDeps() ++ commonDeps ++ Agg(v.firtoolResolver)
}
Expand Down Expand Up @@ -309,7 +323,13 @@ trait Plugin extends CrossSbtModule with ScalafmtModule with ChiselPublishModule
def scalaReflectIvy = v.scalaReflect(crossScalaVersion)
def scalaCompilerIvy: Dep = v.scalaCompiler(crossScalaVersion)

def ivyDeps = super.ivyDeps() ++ Agg(scalaLibraryIvy, scalaReflectIvy, scalaCompilerIvy)
def ivyDeps = T {
if (!v.isScala3(crossScalaVersion)) {
super.ivyDeps() ++ Agg(scalaLibraryIvy, scalaReflectIvy, scalaCompilerIvy)
} else {
super.ivyDeps()
}
}
}

object chisel extends Cross[Chisel](v.scalaCrossVersions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import scala.reflect.macros.blackbox.Context
*/
sealed trait ChiselSubtypeOf[A, B]

// return an empty tree here instead of a quasiquote for scala3 compatibility
object ChiselSubtypeOf {
// TODO return an empty tree here instead of a quasiquote for scala3 compatibility
def genChiselSubtypeOf[A: c.WeakTypeTag, B: c.WeakTypeTag](c: Context): c.Tree = {
Expand Down
54 changes: 54 additions & 0 deletions core/src/main/scala-2/chisel3/experimental/hierarchy/IsA.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package chisel3.experimental.hierarchy.core

import chisel3._
import scala.reflect.runtime.universe.TypeTag

trait HierarchyProto[+A] {
private[chisel3] def underlying: Underlying[A]
private[chisel3] def proto: A = underlying match {
case Proto(value) => value
case Clone(i: IsClone[A]) => i.getProto
}
}

trait HierarchyIsA[+A] extends HierarchyProto[A] {
// This code handles a special-case where, within an mdoc context, the type returned from
// scala reflection (typetag) looks different than when returned from java reflection.
// This function detects this case and reshapes the string to match.
private def modifyReplString(clz: String): String = {
if (clz != null) {
clz.split('.').toList match {
case "repl" :: "MdocSession" :: app :: rest => s"$app.this." + rest.mkString(".")
case other => clz
}
} else clz
}

private lazy val superClasses = calculateSuperClasses(super.proto.getClass())
private def calculateSuperClasses(clz: Class[_]): Set[String] = {
if (clz != null) {
Set(modifyReplString(clz.getCanonicalName())) ++
clz.getInterfaces().flatMap(i => calculateSuperClasses(i)) ++
calculateSuperClasses(clz.getSuperclass())
} else {
Set.empty[String]
}
}
private def inBaseClasses(clz: String): Boolean = superClasses.contains(clz)

/** Determine whether underlying proto is of type provided.
*
* @note IMPORTANT: this function requires summoning a TypeTag[B], which will fail if B is an inner class.
* @note IMPORTANT: this function IGNORES type parameters, akin to normal type erasure.
* @note IMPORTANT: this function relies on Java reflection for underlying proto, but Scala reflection for provided type
*
* E.g. isA[List[Int]] will return true, even if underlying proto is of type List[String]
* @return Whether underlying proto is of provided type (with caveats outlined above)
*/
def isA[B: TypeTag]: Boolean = {
val tptag = implicitly[TypeTag[B]]
// drop any type information for the comparison, because the proto will not have that information.
val name = tptag.tpe.toString.takeWhile(_ != '[')
inBaseClasses(name)
}
}
Loading
Loading