Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Feb 19, 2024
1 parent c90aab7 commit d0e359b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 87 deletions.
122 changes: 46 additions & 76 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,27 @@ trait UnrollModule extends Cross.Module[String]{
def moduleDeps: Seq[CrossPlatformModule] = Nil
object downstream extends DownstreamModule{

object jvm extends InnerScalaModule with Unrolled{
object jvm extends InnerScalaModule with Unrolled {
def run(args: Task[Args] = T.task(Args())) = T.command{/*donothing*/}
def moduleDeps = Seq(CrossPlatformModule.this.jvm)
}
object js extends InnerScalaJsModule with Unrolled{
object js extends InnerScalaJsModule with Unrolled {
def run(args: Task[Args] = T.task(Args())) = T.command{/*donothing*/}
def moduleDeps = Seq(CrossPlatformModule.this.js)
}
object native extends InnerScalaNativeModule with Unrolled{
object native extends InnerScalaNativeModule with Unrolled {
def run(args: Task[Args] = T.task(Args())) = T.command{/*donothing*/}
def moduleDeps = Seq(CrossPlatformModule.this.native)
}
}

trait Unrolled extends InnerScalaModule with LocalMimaModule with PlatformScalaModule{
trait Unrolled extends InnerScalaModule with PlatformScalaModule{
def moduleDeps: Seq[JavaModule] = Seq(annotation)
def run(args: Task[Args] = T.task(Args())) = T.command{/*donothing*/}
def mimaPreviousArtifacts = T.traverse(mimaPrevious)(_.jvm.jar)()
def mimaPreviousArtifacts = T{
if (Tests.this.crossValue == "caseclass" && scalaVersion().startsWith("2.")) Nil
else T.traverse(mimaPrevious)(_.jvm.jar)()
}
def scalacPluginClasspath = T{ Agg(plugin.jar()) }

// override def scalaCompilerClasspath = T{
Expand All @@ -120,7 +123,7 @@ trait UnrollModule extends Cross.Module[String]{
//"-Ydebug-type-error",
//"-Ydebug-trace"
//"-Xprint:typer",
"-Xprint:unroll",
//"-Xprint:unroll",
//"-Xprint:patmat",
//"-Xprint:superaccessors"
)
Expand All @@ -133,115 +136,82 @@ trait UnrollModule extends Cross.Module[String]{
}
}

object jvm extends InnerScalaModule with Unrolled{
object jvm extends InnerScalaModule with Unrolled with LocalMimaModule{
def moduleDeps = super.moduleDeps ++ CrossPlatformModule.this.moduleDeps.map(_.jvm.asInstanceOf[Unrolled])
object test extends ScalaTests with UnrolledTestModule{
def moduleDeps = Seq(jvm, downstream.jvm)
}
}
object js extends InnerScalaJsModule with Unrolled{
object js extends InnerScalaJsModule with Unrolled with LocalMimaModule{
def moduleDeps = super.moduleDeps ++ CrossPlatformModule.this.moduleDeps.map(_.js.asInstanceOf[Unrolled])
object test extends ScalaJSTests with UnrolledTestModule{
def moduleDeps = Seq(js, downstream.js)
}
}
object native extends InnerScalaNativeModule with Unrolled{
object native extends InnerScalaNativeModule with Unrolled with LocalMimaModule{
def moduleDeps = super.moduleDeps ++ CrossPlatformModule.this.moduleDeps.map(_.native.asInstanceOf[Unrolled])
object test extends ScalaNativeTests with UnrolledTestModule{
def moduleDeps = Seq(native, downstream.native)
}
}
}


// Different versions of Unrolled.scala
object v1 extends CrossPlatformModule{
def mimaPrevious = Seq()
}

object v2 extends CrossPlatformModule {
def mimaPrevious = Seq(v1)
}

object v3 extends CrossPlatformModule {
def mimaPrevious = Seq(v1, v2)
}

// proxy modules used to make sure old versions of UnrolledTestMain.scala can
// successfully call newer versions of the Unrolled.scala
trait ComparativeModule extends Module{
def upstream: CrossPlatformModule
def downstream: CrossPlatformModule
def test: CrossPlatformModule
val items =
if (!crossValue.startsWith("abstract")) Seq("v3v2", "v3v1", "v2v1")
else Seq("v3v2", "v3v1", "v2v1", "v2v1v2", "v3v1v3", "v3v1v2", "v3v2v3")

object cross extends Cross[ComparativeModule](items)
trait ComparativeModule extends Cross.Module[String]{
def lookup(x: String): CrossPlatformModule = x match {
case "1" => v1
case "2" => v2
case "3" => v3
}
val (upstream, downstream, test) = crossValue match{
case s"v${a}v${b}v${c}" => (lookup(a), lookup(b), lookup(c))
case s"v${a}v${b}" => (lookup(a), lookup(a), lookup(b))
}

def run(args: Task[Args] = T.task(Args())) = T.command{/*donothing*/}
trait ComparativePlatformScalaModule extends PlatformScalaModule{
def sources = super.sources() ++ testutils.sources()
def mainClass = Some("unroll.UnrollTestMain")
}

object jvm extends InnerScalaModule with ComparativePlatformScalaModule{
def runClasspath =
super.runClasspath() ++
def runClasspath =
super.runClasspath() ++
Seq(test.jvm.test.compile().classes, upstream.jvm.compile().classes, downstream.downstream.jvm.compile().classes)

}

object js extends InnerScalaJsModule with ComparativePlatformScalaModule{
def runClasspath =
super.runClasspath() ++
def runClasspath =
super.runClasspath() ++
Seq(test.js.test.compile().classes, upstream.js.compile().classes, downstream.downstream.js.compile().classes)
}

object native extends InnerScalaNativeModule with ComparativePlatformScalaModule{
def runClasspath =
super.runClasspath() ++
super.runClasspath() ++
Seq(test.native.test.compile().classes, upstream.native.compile().classes, downstream.downstream.native.compile().classes)
}
}

// Different versions of Unrolled.scala
object v1 extends CrossPlatformModule{
def mimaPrevious = Seq()
}

object v2 extends CrossPlatformModule {
def mimaPrevious = Seq(v1)
}

object v3 extends CrossPlatformModule {
def mimaPrevious = Seq(v1, v2)
}

object v3v2 extends ComparativeModule{
def upstream = v3
def downstream = v3
def test = v2
}
object v3v1 extends ComparativeModule{
def upstream = v3
def downstream = v3
def test = v1
}
object v2v1 extends ComparativeModule{
def upstream = v2
def downstream = v2
def test = v1
}

object v2v1v2 extends ComparativeModule{
def upstream = v2
def downstream = v1
def test = v2
}

object v3v1v3 extends ComparativeModule{
def upstream = v3
def downstream = v1
def test = v3
}

object v3v1v2 extends ComparativeModule{
def upstream = v3
def downstream = v1
def test = v2
}


object v3v2v3 extends ComparativeModule{
def upstream = v3
def downstream = v2
def test = v3
}


def moduleDeps = Seq(v3)
}
}

Expand Down
16 changes: 5 additions & 11 deletions unroll/plugin/src-2/UnrollPhaseScala2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ class UnrollPhaseScala2(val global: Global) extends PluginComponent with TypingT
annotatedParamListIndex: Int,
paramLists: List[List[ValDef]]) = {

println()
println("generateSingleForwarder")
println("paramIndex " + paramIndex)
println("nextParamIndex " + nextParamIndex)
val forwarderDefSymbol = defdef.symbol.owner.newMethod(defdef.name)
val symbolReplacements = defdef
.vparamss
Expand All @@ -78,7 +74,6 @@ class UnrollPhaseScala2(val global: Global) extends PluginComponent with TypingT

val forwarderMethodType = forwarderMethodType0(defdef.symbol.tpe, 0)

println("forwarderMethodType " + forwarderMethodType)
forwarderDefSymbol.setInfo(forwarderMethodType)

val newParamLists = paramLists
Expand Down Expand Up @@ -152,12 +147,11 @@ class UnrollPhaseScala2(val global: Global) extends PluginComponent with TypingT
rhs = if (nextParamIndex == -1) EmptyTree else forwarderCall
).set(forwarderDefSymbol)

// No idea why this `if` guard is necessary, but without it we end
// if (defdef.symbol.owner.isTrait) {
// if ()
// defdef.symbol.owner.info.asInstanceOf[ClassInfoType].decls.enter(forwarderDefSymbol)
// defdef.symbol.owner.info.asInstanceOf[ClassInfoType].decls.
// }
// No idea why this `if` guard is necessary, but without it we end up missing
// some generated forwarders on trait methods inherited by static objects
if (defdef.symbol.owner.isTrait && !defdef.symbol.isAbstract) {
defdef.symbol.owner.info.asInstanceOf[ClassInfoType].decls.enter(forwarderDefSymbol)
}

val (fromSyms, toSyms) = symbolReplacements.toList.unzip
forwarderDef.substituteSymbols(fromSyms, toSyms).asInstanceOf[DefDef]
Expand Down

0 comments on commit d0e359b

Please sign in to comment.