Skip to content

Commit

Permalink
Add version-specific source directories in the library
Browse files Browse the repository at this point in the history
And replace Tuple.scala with a Scala 2 implementation and a Scala 3
implementation. The Scala 2 implementaion of Tuple.scala is not strictly
necessary but could be useful if non-version-specific library sources
end up referencing scala.Tuple.
  • Loading branch information
smarter committed Aug 14, 2018
1 parent d43a22f commit d0b063a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
5 changes: 4 additions & 1 deletion compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ class CompilationTests extends ParallelTesting {
Array("-Ycheck-reentrant", "-Yemit-tasty-in-class")
)

val libraryDirs = List(Paths.get("library/src"), Paths.get("library/src-scala3"))
val librarySources = libraryDirs.flatMap(d => sources(Files.walk(d)))

val lib =
compileDir("library/src",
compileList("src", librarySources,
defaultOptions.and("-Ycheck-reentrant", "-strict", "-priorityclasspath", defaultOutputDir))(libGroup)

val compilerDir = Paths.get("compiler/src")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ sealed trait Tuple extends Any

@showAsInfix
sealed class *:[+H, +T <: Tuple] extends Tuple {
@`rewrite` def head: H = ???
@`rewrite` def tail: T = ???
def head: H = ???
def tail: T = ???
}

object *: {
@`rewrite` def unapply[H, T <: Tuple](x: H *: T) = Some((x.head, x.tail))
def unapply[H, T <: Tuple](x: H *: T) = Some((x.head, x.tail))
}
26 changes: 26 additions & 0 deletions library/src-scala3/scala/Tuple.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package scala
import annotation.showAsInfix

object typelevel {
erased def erasedValue[T]: T = ???
}

import typelevel._

sealed trait Tuple extends Any

@showAsInfix
sealed class *:[+H, +T <: Tuple] extends Tuple {
rewrite def head: H = ???
rewrite def tail: T = ???

rewrite private def _size(xs: Tuple): Int = //rewrite
xs match {
case _: Unit => 0
case _: *:[_, xs1] => _size(erasedValue[xs1]) + 1
}
}

object *: {
rewrite def unapply[H, T <: Tuple](x: H *: T) = Some((x.head, x.tail))
}
12 changes: 11 additions & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,17 @@ object Build {

// Settings shared between dotty-library and dotty-library-bootstrapped
lazy val dottyLibrarySettings = Seq(
libraryDependencies += "org.scala-lang" % "scala-library" % scalacVersion
libraryDependencies += "org.scala-lang" % "scala-library" % scalacVersion,
// Add version-specific source directories:
// - files in src-scala3 will only be compiled by dotty
// - files in src-scala2 will only be compiled by scalac
unmanagedSourceDirectories in Compile += {
val baseDir = baseDirectory.value
if (isDotty.value)
baseDir / "src-scala3"
else
baseDir / "src-scala2"
}
)

lazy val `dotty-library` = project.in(file("library")).asDottyLibrary(NonBootstrapped)
Expand Down

0 comments on commit d0b063a

Please sign in to comment.