Skip to content

Commit ca2abd7

Browse files
committed
Add small local test project
1 parent f8ff12f commit ca2abd7

File tree

6 files changed

+132
-3
lines changed

6 files changed

+132
-3
lines changed

local/project/dummy/arrows.scala

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package dummy
2+
3+
import language.experimental.captureChecking
4+
import caps.*
5+
6+
trait Arrows:
7+
val a: AnyRef^
8+
val b: AnyRef^
9+
val c: AnyRef^
10+
11+
val purev: Int -> Int
12+
val purev2: Int ->{} Int
13+
val impurev: Int => Int
14+
val impurev2: Int ->{a,b,c} Int
15+
val impurev3: Int ->{a,b,c} Int => Int
16+
17+
def pure(f: Int -> Int): Int
18+
def pure2(f: Int ->{} Int): Int
19+
def impure(f: Int => Int): Int
20+
def impure2(f: Int ->{a,b,c} Int): Int
21+
def impure3(f: Int ->{a,b,c} Int => Int): Int
22+
23+
def uses(@use a: AnyRef^): Any
24+
def uses2(@use x: AnyRef^{a}, @use y: AnyRef^{b}): Any
25+
26+
def consumes(@consume a: AnyRef^): Any
27+
def consumes2(@consume x: AnyRef^{a}, @consume y: AnyRef^{b}): Any
28+
29+
def usesAndConsumes(@use a: AnyRef^, @consume b: AnyRef^): Any
30+
def usesAndConsumes2(@use @consume x: AnyRef^{a}): Any
31+
def consumesAndUses(@consume @use x: AnyRef^{a}): Any
32+
33+
def byNamePure(f: -> Int): Int
34+
def byNameImpure(f: ->{a,b,c} Int): Int
35+
def byNameImpure2(f: => Int): Int

local/project/dummy/capturevars.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package dummy
2+
3+
import language.experimental.captureChecking
4+
5+
trait Test:
6+
type T[-C^]
7+
type U[+C^]
8+
type C^
9+
type D^
10+
def foo[C^](x: T[C]): Unit
11+
def bar(x: T[{}]): Unit
12+
def baz(x: T[{caps.cap}]): Unit
13+
def foo2[C^](x: U[C]): Unit
14+
def bar2(x: U[{}]): Unit
15+
def baz2(x: U[{caps.cap}]): Unit
16+
def test[E^, F^ >: {caps.cap} <: {}](x: T[E], y: U[F]): Unit

local/project/dummy/colltest.scala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package dummy
2+
3+
import language.experimental.captureChecking
4+
// Showing a problem with recursive references
5+
object CollectionStrawMan5 {
6+
7+
/** Base trait for generic collections */
8+
trait Iterable[+A] extends IterableLike[A] {
9+
def iterator: Iterator[A]^{this}
10+
def coll: Iterable[A]^{this} = this
11+
}
12+
13+
trait IterableLike[+A]:
14+
def coll: Iterable[A]^{this}
15+
def partition(p: A => Boolean): Unit =
16+
val pn = Partition(coll, p)
17+
()
18+
19+
/** Concrete collection type: View */
20+
trait View[+A] extends Iterable[A] with IterableLike[A]
21+
22+
case class Partition[A](val underlying: Iterable[A]^, p: A => Boolean) {
23+
24+
class Partitioned(expected: Boolean) extends View[A]:
25+
this: Partitioned^{Partition.this} =>
26+
def iterator: Iterator[A]^{this} =
27+
underlying.iterator.filter((x: A) => p(x) == expected)
28+
29+
val left: Partitioned^{Partition.this} = Partitioned(true)
30+
val right: Partitioned^{Partition.this} = Partitioned(false)
31+
}
32+
33+
34+
}

mystuff.sbt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import sbt._
2+
import sbt.io.IO
3+
4+
import sbt.dsl.LinterLevel.Ignore
5+
6+
lazy val compileSrcTree = taskKey[Unit]("Example project")
7+
8+
compileSrcTree := {
9+
val log = streams.value.log
10+
val baseDir = baseDirectory.value
11+
val srcTreeDir = baseDir / "local" / "project"
12+
val outDir = baseDir / "local" / "out"
13+
14+
IO.delete(outDir)
15+
IO.createDirectory(outDir) // mkdir -p
16+
17+
val sources: Seq[String] =
18+
(srcTreeDir ** "*.scala").get.map(_.getPath) // find all .scala
19+
20+
if (sources.isEmpty)
21+
streams.value.log.warn(s"No .scala files found under $srcTreeDir")
22+
else {
23+
val cmd = ("scalac" +: "-d" +: outDir.getPath +: sources).mkString(" ")
24+
Command.process(cmd, state.value)
25+
}
26+
}
27+
28+
lazy val ensureApiDir = taskKey[Unit]("Create <repo>/local/api if it’s missing")
29+
30+
ensureApiDir := {
31+
val dir = (ThisBuild / baseDirectory).value / "local" / "api"
32+
IO.createDirectory(dir)
33+
}
34+
35+
addCommandAlias(
36+
"myrefresh",
37+
";compileSrcTree; ensureApiDir ; scaladoc/runMain dotty.tools.scaladoc.Main -siteroot /dev/null -project Foo -project-version 0.0.1 -d local/api local/out"
38+
)
39+
40+
addCommandAlias(
41+
"myscaladoc",
42+
"; ensureApiDir ; scaladoc/runMain dotty.tools.scaladoc.Main -siteroot /dev/null -project Foo -project-version 0.0.1 -d local/api local/out"
43+
)

scaladoc/src/dotty/tools/scaladoc/cc/CaptureOps.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ def decomposeCaptureRefs(using qctx: Quotes)(typ0: qctx.reflect.TypeRepr): Optio
4747
case t @ ThisType(_) => buffer += t; true
4848
case t @ TermRef(_, _) => buffer += t; true
4949
case t @ ParamRef(_, _) => buffer += t; true
50+
case t if t.typeSymbol == defn.NothingClass => true
5051
// TODO: are atoms only ever the above? Then we could refine the return type
51-
case _ => report.warning(s"Unexpected type tree $typ while trying to extract capture references from $typ0"); System.exit(1); false // TODO remove warning eventually
52+
case _ => report.warning(s"Unexpected type tree $typ while trying to extract capture references from $typ0"); false // TODO remove warning eventually
5253
if traverse(typ0) then Some(buffer.toList) else None
5354
end decomposeCaptureRefs
5455

scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ trait TypesSupport:
109109
case List(ref) if ref.isCaptureRoot =>
110110
keyword("=> ") :: inner(tpe)
111111
case refs =>
112-
keyword("->") :: (renderCaptureSet(refs) ++ inner(tpe))
113-
case ByNameType(tpe) => keyword("=> ") :: inner(tpe) // FIXME: does it need change for CC?
112+
keyword("->") :: (renderCaptureSet(refs) ++ (plain(" ") :: inner(tpe)))
113+
case ByNameType(tpe) => keyword("=>!! ") :: inner(tpe) // FIXME: does it need change for CC?
114114
case ConstantType(constant) =>
115115
plain(constant.show).l
116116
case ThisType(tpe) =>

0 commit comments

Comments
 (0)