Skip to content

Commit 3bb1b82

Browse files
authored
Merge pull request #48 from noti0na1/dotty-explicit-nulls-notNull
Merge upstream Dotty master
2 parents 46fc5cd + 0230180 commit 3bb1b82

File tree

629 files changed

+1080
-15935
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

629 files changed

+1080
-15935
lines changed

bench-run/inputs/tuples/apply.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sizeAndIndex:20 0,20 1,20 2,20 3,20 4,20 5,20 6,20 7,20 8,20 9,20 10,20 11,20 12,20 13,20 14,20 15,20 16,20 17,20 18,20 19

bench-run/inputs/tuples/concat.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sizes:15 0,15 1,15 2,15 3,15 4,15 5,15 6,15 7,15 8,15 9,15 10,15 11,15 12,15 13,15 14,15 15,15 16,15 17,15 18,15 19,15 20,15 21,15 22,15 23,15 24,15 25,15 26,15 27,15 28,15 29,15 30,15 31,15 32,15 33,15 34,15 35,15 36,15 37,15 38,15 39,15 40,15 41,15 42,15 43,15 44,15 45,15 46,15 47,15 48,15 49,15 50

bench-run/inputs/tuples/cons.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
size:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
size:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50

bench-run/inputs/tuples/map.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
size:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50

bench-run/inputs/tuples/tail.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
size:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50

bench-run/inputs/tuples/zip.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
size:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package dotty.tools.benchmarks
2+
3+
import org.openjdk.jmh.results.RunResult
4+
import org.openjdk.jmh.runner.Runner
5+
import org.openjdk.jmh.annotations._
6+
import org.openjdk.jmh.results.format._
7+
import org.openjdk.jmh.runner.options._
8+
import java.util.concurrent.TimeUnit
9+
10+
import scala.io.Source
11+
12+
object Bench {
13+
def main(args: Array[String]): Unit = {
14+
if (args.contains("--help")) {
15+
printUsage()
16+
return
17+
}
18+
19+
val (intArgs, args1) = args.span(x => try { x.toInt; true } catch { case _: Throwable => false } )
20+
21+
def getIntArg(i: Int, default: Int): Int =
22+
if (intArgs.length > i) intArgs(i).toInt else default
23+
24+
val warmup = getIntArg(0, 20)
25+
val iterations = getIntArg(1, 20)
26+
val forks = getIntArg(2, 1)
27+
28+
if (args1.isEmpty) {
29+
println("Error: no benchmark was specified.")
30+
printUsage()
31+
return
32+
}
33+
34+
var builder = new OptionsBuilder()
35+
.shouldFailOnError(true)
36+
.jvmArgs("-Xms2G", "-Xmx2G")
37+
.mode(Mode.AverageTime)
38+
.timeUnit(TimeUnit.NANOSECONDS)
39+
.warmupIterations(warmup)
40+
.warmupTime(TimeValue.milliseconds(750))
41+
.measurementIterations(iterations)
42+
.measurementTime(TimeValue.milliseconds(500))
43+
.forks(forks)
44+
.include(args1(0))
45+
.resultFormat(ResultFormatType.CSV)
46+
47+
if (args1.length > 1 && args1(1) != "--") {
48+
for ((param, values) <- paramsFromFile("inputs/" ++ args1(1)))
49+
builder = builder.param(param, values: _*)
50+
}
51+
52+
if (args1.length > 2) {
53+
builder = builder.result(args1(2))
54+
}
55+
56+
val runner = new Runner(builder.build)
57+
runner.run
58+
}
59+
60+
def paramsFromFile(file: String): Array[(String, Array[String])] = {
61+
Source.fromFile(file).getLines.toArray.map { l =>
62+
val Array(param, values) = l split ':'
63+
(param, values split ',')
64+
}
65+
}
66+
67+
def printUsage(): Unit = {
68+
println()
69+
println("Usage:")
70+
println()
71+
println("dotty-bench-run/jmh:run [<warmup>] [<iterations>] [<forks>] <regexp> [<input>|--] [<output>]")
72+
println()
73+
println("warmup: warmup iterations. defaults to 20.")
74+
println("iterations: benchmark iterations. defaults to 20.")
75+
println("forks: number of forks. defaults to 1.")
76+
println("regexp: regular expression that selects which benchmarks to run.")
77+
println("input: input vector file. each line should have format \'<paramName>: <comma-separated-values>\'")
78+
println("output: output file for the results of benchmarks.")
79+
println()
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package dotty.tools.benchmarks.tuples
2+
3+
import org.openjdk.jmh.annotations._
4+
import scala.runtime.DynamicTuple
5+
6+
@State(Scope.Thread)
7+
class Apply {
8+
@Param(Array("1 0"))
9+
var sizeAndIndex: String = _
10+
var tuple: NonEmptyTuple = _
11+
var index: Int = _
12+
13+
@Setup
14+
def setup(): Unit = {
15+
val size = sizeAndIndex.split(' ')(0).toInt
16+
index = sizeAndIndex.split(' ')(1).toInt
17+
tuple = "elem" *: ()
18+
19+
for (i <- 1 until size)
20+
tuple = "elem" *: tuple
21+
}
22+
23+
@Benchmark
24+
def tupleApply(): Any = {
25+
DynamicTuple.dynamicApply(tuple, index)
26+
}
27+
28+
@Benchmark
29+
def productElement(): Any = {
30+
tuple.asInstanceOf[Product].productElement(index)
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package dotty.tools.benchmarks.tuples
2+
3+
import org.openjdk.jmh.annotations._
4+
import scala.runtime.DynamicTuple
5+
6+
@State(Scope.Thread)
7+
class ArrayOps {
8+
@Param(Array("1"))
9+
var size: Int = _
10+
var tuple: Tuple = _
11+
var array: Array[Object] = _
12+
var iarray: IArray[Object] = _
13+
14+
@Setup
15+
def setup(): Unit = {
16+
tuple = ()
17+
18+
for (i <- 1 to size)
19+
tuple = "elem" *: tuple
20+
21+
array = Array.fill(size)("elem")
22+
iarray = IArray.fill(size)("elem")
23+
}
24+
25+
@Benchmark
26+
def tupleToArray(): Array[Object] = {
27+
DynamicTuple.dynamicToArray(tuple)
28+
}
29+
30+
@Benchmark
31+
def tupleToIArray(): IArray[Object] = {
32+
DynamicTuple.dynamicToIArray(tuple)
33+
}
34+
35+
@Benchmark
36+
def tupleFromArray(): Tuple = {
37+
DynamicTuple.dynamicFromArray(array)
38+
}
39+
40+
@Benchmark
41+
def tupleFromIArray(): Tuple = {
42+
DynamicTuple.dynamicFromIArray(iarray)
43+
}
44+
45+
@Benchmark
46+
def productToArray(): Array[Object] = {
47+
DynamicTuple.productToArray(tuple.asInstanceOf[Product])
48+
}
49+
50+
@Benchmark
51+
def cloneArray(): Array[Object] = {
52+
array.clone()
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package dotty.tools.benchmarks.tuples
2+
3+
import org.openjdk.jmh.annotations._
4+
import org.openjdk.jmh.infra.Blackhole
5+
import scala.runtime.DynamicTuple
6+
7+
@State(Scope.Thread)
8+
class Concat {
9+
@Param(Array("0 0"))
10+
var sizes: String = _
11+
var tuple1: Tuple = _
12+
var tuple2: Tuple = _
13+
var array1: Array[Object] = _
14+
var array2: Array[Object] = _
15+
16+
def tupleOfSize(n: Int): Tuple = {
17+
var t: Tuple = ()
18+
for (i <- 1 to n)
19+
t = "elem" *: t
20+
t
21+
}
22+
23+
@Setup
24+
def setup(): Unit = {
25+
val size1 = sizes.split(' ')(0).toInt
26+
val size2 = sizes.split(' ')(1).toInt
27+
tuple1 = tupleOfSize(size1)
28+
tuple2 = tupleOfSize(size2)
29+
array1 = Array.fill(size1)("elem")
30+
array2 = Array.fill(size2)("elem")
31+
}
32+
33+
@Benchmark
34+
def tupleConcat(): Tuple = {
35+
DynamicTuple.dynamicConcat(tuple1, tuple2)
36+
}
37+
38+
@Benchmark
39+
def arrayConcat(): Array[Object] = {
40+
array1 ++ array2
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package dotty.tools.benchmarks.tuples
2+
3+
import org.openjdk.jmh.annotations._
4+
import scala.runtime.DynamicTuple
5+
6+
@State(Scope.Thread)
7+
class Cons {
8+
@Param(Array("0"))
9+
var size: Int = _
10+
var tuple: Tuple = _
11+
var array: Array[Object] = _
12+
13+
@Setup
14+
def setup(): Unit = {
15+
tuple = ()
16+
17+
for (i <- 1 to size)
18+
tuple = "elem" *: tuple
19+
20+
array = Array.fill(size)("elem")
21+
}
22+
23+
@Benchmark
24+
def tupleCons(): Tuple = {
25+
DynamicTuple.dynamicCons("elem", tuple)
26+
}
27+
28+
@Benchmark
29+
def arrayCons(): Array[Object] = {
30+
DynamicTuple.cons$Array("elem", array)
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package dotty.tools.benchmarks.tuples
2+
3+
import org.openjdk.jmh.annotations._
4+
import scala.runtime.DynamicTuple
5+
6+
@State(Scope.Thread)
7+
class Map {
8+
@Param(Array("0"))
9+
var size: Int = _
10+
var tuple: Tuple = _
11+
var array: Array[Object] = _
12+
13+
@Setup
14+
def setup(): Unit = {
15+
tuple = ()
16+
17+
for (i <- 1 to size)
18+
tuple = "elem" *: tuple
19+
20+
array = Array.fill(size)("elem")
21+
}
22+
23+
def f: PolyFunction = new PolyFunction {
24+
def apply[T](x: T): T = {
25+
x.asInstanceOf[String].updated(0, 'a').asInstanceOf[T]
26+
}
27+
}
28+
29+
type Id[X] = X
30+
31+
@Benchmark
32+
def tupleMap(): Tuple = {
33+
DynamicTuple.dynamicMap[Tuple, Id](tuple, [T] => (x:T) => x.asInstanceOf[String].updated(0, 'a').asInstanceOf[T])
34+
}
35+
36+
@Benchmark
37+
def arrayMap(): Array[Object] = {
38+
array.map(x => x.asInstanceOf[String].updated(0, 'a'))
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package dotty.tools.benchmarks.tuples
2+
3+
import org.openjdk.jmh.annotations._
4+
import scala.runtime.DynamicTuple
5+
6+
@State(Scope.Thread)
7+
class Tail {
8+
@Param(Array("1"))
9+
var size: Int = _
10+
var tuple: NonEmptyTuple = _
11+
var array: Array[Object] = _
12+
13+
@Setup
14+
def setup(): Unit = {
15+
tuple = "elem" *: ()
16+
17+
for (i <- 1 until size)
18+
tuple = "elem" *: tuple
19+
20+
array = Array.fill(size)("elem")
21+
}
22+
23+
@Benchmark
24+
def tupleTail(): Tuple = {
25+
DynamicTuple.dynamicTail(tuple)
26+
}
27+
28+
@Benchmark
29+
def arrayTail(): Array[Object] = {
30+
array.tail
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package dotty.tools.benchmarks.tuples
2+
3+
import org.openjdk.jmh.annotations._
4+
5+
@State(Scope.Thread)
6+
class TupleOps {
7+
var tuple1: Tuple = _
8+
var tuple2: Tuple = _
9+
10+
@Setup
11+
def setup(): Unit = {
12+
tuple1 = ()
13+
for (i <- 1 until 15)
14+
tuple1 = s"elem$i" *: tuple1
15+
16+
tuple2 = ()
17+
for (i <- 1 until 10)
18+
tuple2 = s"elem$i" *: tuple2
19+
}
20+
21+
def tupleFlatMap(tuple: Tuple, f: [A] => A => Tuple): Tuple = {
22+
def tailRecFlatMap(t: Tuple, acc: Tuple): Tuple = t match {
23+
case () => acc
24+
case x *: rest => tailRecFlatMap(rest, acc ++ f(x))
25+
}
26+
tailRecFlatMap(tuple, ())
27+
}
28+
29+
def tupleReverse(tuple: Tuple): Tuple = {
30+
def tailRecReverse(t: Tuple, acc: Tuple): Tuple = t match {
31+
case () => acc
32+
case x *: rest => tailRecReverse(rest, x *: acc)
33+
}
34+
tailRecReverse(tuple, ())
35+
}
36+
37+
@Benchmark
38+
def reverse(): Tuple = {
39+
tupleReverse(tuple1)
40+
}
41+
42+
@Benchmark
43+
def flatMap(): Tuple = {
44+
tupleFlatMap(tuple2, [A] => (x: A) => (x, x))
45+
}
46+
}

0 commit comments

Comments
 (0)