Move everything under kotlin-native folder

I was forced to manually do update the following files, because otherwise
they would be ignored according .gitignore settings. Probably they
should be deleted from repo.

Interop/.idea/compiler.xml
Interop/.idea/gradle.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml
Interop/.idea/modules.xml
Interop/.idea/modules/Indexer/Indexer.iml
Interop/.idea/modules/Runtime/Runtime.iml
Interop/.idea/modules/StubGenerator/StubGenerator.iml
backend.native/backend.native.iml
backend.native/bc.frontend/bc.frontend.iml
backend.native/cli.bc/cli.bc.iml
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt
backend.native/tests/link/lib/foo.kt
backend.native/tests/link/lib/foo2.kt
backend.native/tests/teamcity-test.property
This commit is contained in:
Stanislav Erokhin
2020-10-27 21:00:28 +03:00
parent 91e4162dad
commit f624800b84
2830 changed files with 0 additions and 0 deletions
@@ -0,0 +1,25 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
plugins {
id("swift-benchmarking")
}
val toolsPath = "../../tools"
val targetExtension = "Macos"
val defaultBuildType = NativeBuildType.RELEASE
swiftBenchmark {
applicationName = "swiftInterop"
commonSrcDirs = listOf("$toolsPath/benchmarks/shared/src/main/kotlin/report", "src", "../shared/src/main/kotlin")
nativeSrcDirs = listOf("../shared/src/main/kotlin-native/common", "../shared/src/main/kotlin-native/posix")
swiftSources = listOf("$projectDir/swiftSrc/benchmarks.swift", "$projectDir/swiftSrc/main.swift")
compileTasks = listOf("compileKotlinNative", "linkBenchmarkReleaseFrameworkNative")
buildType = (findProperty("nativeBuildType") as String?)?.let { NativeBuildType.valueOf(it) } ?: defaultBuildType
dependencies.common(project(":endorsedLibraries:kotlinx.cli"))
}
@@ -0,0 +1 @@
kotlin.native.home=../../dist
@@ -0,0 +1,122 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package org.jetbrains.model
import org.jetbrains.multigraph.*
import kotlin.comparisons.compareBy
enum class Transport { CAR, UNDERGROUND, BUS, TROLLEYBUS, TRAM, TAXI, FOOT }
enum class Interest { SIGHT, CULTURE, PARK, ENTERTAINMENT }
class PlaceAbsenceException(message: String): Exception(message) {}
data class RouteCost(val moneyCost: Double, val timeCost: Double, val interests: Set<Interest>, val transport: Set<Transport>): Cost {
private val comparator = compareBy<RouteCost>({ it.moneyCost }, { it.timeCost }, { it.interests.size }, { it.transport.size })
override operator fun plus(other: Cost) =
if (other is RouteCost) {
RouteCost(moneyCost + other.moneyCost, timeCost + other.timeCost,
interests.union(other.interests), transport.union(other.transport))
} else {
error("Expected type is RouteCost")
}
override operator fun minus(other: Cost) =
if (other is RouteCost) {
RouteCost(if (moneyCost > other.moneyCost) moneyCost - other.moneyCost else 0.0,
if (timeCost > other.timeCost) timeCost - other.timeCost else 0.0,
interests.subtract(other.interests), transport.subtract(other.transport))
} else {
error("Expected type is RouteCost")
}
override operator fun compareTo(other: Cost) =
if (other is RouteCost) {
comparator.compare(this, other)
} else {
error("Expected type is RouteCost")
}
}
internal var placeCounter = 0u
data class Place(val geoCoordinateX: Double, val geoCoordinateY: Double, val name: String, val interestCategory: Interest) {
private val comparator = compareBy<Place>({ it.geoCoordinateX }, { it.geoCoordinateY })
val id: UInt
init {
id = placeCounter
placeCounter++
}
val fullDescription: String
get() = "Place $name($geoCoordinateX;$geoCoordinateY)"
fun compareTo(other: Place) =
comparator.compare(this, other)
}
data class Path(val from: Place, val to: Place, val cost: RouteCost)
class CityMap {
data class RouteId(val id: UInt, val from: UInt, val to: UInt)
private val graph = Multigraph<Place>()
val allPlaces: Set<Place>
get() = graph.allVertexes
val allRoutes: List<RouteId>
get() {
val edges = graph.allEdges
val result = mutableListOf<RouteId>()
edges.forEach {
result.add(RouteId(it, graph.getFrom(it).id, graph.getTo(it).id))
}
return result
}
fun addRoute(from: Place, to: Place, cost: RouteCost): UInt {
return graph.addEdge(from, to, cost)
}
fun getPlaceById(id: UInt): Place {
graph.allVertexes.forEach {
if (it.id == id) {
return it
}
}
throw PlaceAbsenceException("Place with id $id wasn't found.")
}
fun removePlaceById(id: UInt) {
graph.allVertexes.forEach {
if (it.id == id) {
graph.removeVertex(it)
return
}
}
}
fun removeRouteById(id: UInt) {
graph.removeEdge(id)
}
fun getRoutes(start: Place, finish: Place, limits: RouteCost): List<List<Path>> {
val result = graph.searchRoutesWithLimits(start, finish, limits)
return result.map {
it.map {
Path(graph.getFrom(it), graph.getTo(it), graph.getCost(it) as RouteCost)
}
}
}
fun getRouteById(id: UInt) =
graph.getEdgeById(id)
fun getAllStraightRoutesFrom(place: Place) =
graph.getEdgesFrom(place).map { Path(graph.getFrom(it.id), graph.getTo(it.id), graph.getCost(it.id) as RouteCost) }
fun isEmpty() = graph.isEmpty()
}
@@ -0,0 +1,184 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package org.jetbrains.multigraph
import kotlin.math.pow
interface Cost {
operator fun plus(other: Cost): Cost
operator fun minus(other: Cost): Cost
override operator fun equals(other: Any?): Boolean
operator fun compareTo(other: Cost): Int
}
data class Edge<T>(val id: UInt, val from: T, val to: T, val cost: Cost) {
override operator fun equals(other: Any?): Boolean {
return if (other is Edge<*>) (from == other.from && to == other.to && cost == other.cost) else false
}
override fun hashCode(): Int =
from.hashCode() * 31.0.pow(2.0).toInt() + to.hashCode() * 31 + cost.hashCode()
}
class EdgeAbsenceMultigraphException(message: String): Exception(message) {}
class VertexAbsenceMultigraphException(message: String): Exception(message) {}
class Multigraph<T>() {
private var edges = mutableMapOf<T, MutableList<Edge<T>>>()
private var idCounter = 0u
val allVertexes: Set<T>
get() {
val outerVertexes = edges.keys
val innerVertexes = edges.map { (_, values) ->
values.map { it.to }.filter { it !in outerVertexes }
}.flatten()
return outerVertexes.union(innerVertexes)
}
val allEdges: List<UInt>
get() = edges.values.flatten().map { it.id }
fun getEdgeById(id: UInt): Edge<T> {
edges.forEach { (_, value) ->
value.forEach {
if (it.id == id)
return it
}
}
throw EdgeAbsenceMultigraphException("Edge with id $id wasn't found.")
}
fun copyMultigraph(): Multigraph<T> {
val newInstance = Multigraph<T>()
edges.forEach { (vertex, edges) ->
edges.forEach { edge ->
newInstance.addEdge(vertex, edge.to, edge.cost)
}
}
return newInstance
}
fun addEdge(from: T, to: T, cost: Cost): UInt {
val edge = Edge(idCounter, from, to, cost)
edges.getOrPut(from) { mutableListOf() }.add(edge)
idCounter++
return edge.id
}
fun removeEdge(id: UInt) {
try {
val edge = getEdgeById(id)
edges[edge.from]?.remove(edge)
} catch (exception: EdgeAbsenceMultigraphException) {
println("WARNING: no edge with id $id was found.")
}
}
fun removeVertex(vertex: T) {
edges.remove(vertex)
val edgesToRemove = edges.map { (_, values) ->
values.filter {
it.to == vertex
}
}.flatten()
edgesToRemove.forEach {
removeEdge(it.id)
}
}
fun checkVertexExistance(vertex: T): Boolean {
return vertex in allVertexes
}
fun getTo(edgeId: UInt) =
getEdgeById(edgeId).to
fun getFrom(edgeId: UInt) =
getEdgeById(edgeId).from
fun getCost(edgeId: UInt) =
getEdgeById(edgeId).cost
fun getEdgesFrom(vertex: T) =
edges[vertex] ?: listOf<Edge<T>>()
fun isEmpty() = edges.isEmpty()
fun searchRoutesWithLimits(start: T, finish: T, limits: Cost): List<List<UInt>> {
data class WaveStep(val costs: MutableList<Cost> = mutableListOf(),
val routes: MutableList<MutableList<UInt>> = mutableListOf(),
val vertexes: MutableList<MutableList<T>> = mutableListOf())
val currentStepsState = mutableMapOf<T, WaveStep>()
var oldFront = mutableSetOf<T>(start)
val newFront = mutableSetOf<T>()
if (!checkVertexExistance(start)) {
throw(VertexAbsenceMultigraphException("Start vertex wasn't found in graph."))
}
if (!checkVertexExistance(finish)) {
throw(VertexAbsenceMultigraphException("Finish vertex wasn't found in graph."))
}
allVertexes.forEach {
currentStepsState[it] = WaveStep()
}
while (!oldFront.isEmpty()) {
oldFront.forEach {
val currentStepState = currentStepsState[it] ?: WaveStep()
// Lookup all edges from vertex.
val values = edges.get(it) ?: mutableListOf<Edge<T>>()
values.forEach { edge ->
val newRoutes = mutableListOf<UInt>()
val toStep = currentStepsState[edge.to] ?: WaveStep()
// Create new pathes and count their costs.
if (currentStepState.routes.isEmpty()) {
val newVertexes = mutableListOf(edge.from, edge.to)
val newCost = edge.cost
if (newCost <= limits && edge.from != edge.to) {
newRoutes.add(edge.id)
toStep.routes.add(newRoutes)
toStep.costs.add(edge.cost)
toStep.vertexes.add(newVertexes)
currentStepsState[edge.to] = toStep
// Add new wave front.
if (edge.to != finish && edge.to !in oldFront) {
newFront.add(edge.to)
}
}
} else {
currentStepState.routes.forEachIndexed { index, it ->
val newRoutes = it.toMutableList()
val oldCost = currentStepState.costs.get(index)
val newCost = edge.cost + oldCost
val newVertexes = currentStepState.vertexes.get(index).toMutableList()
if (newCost <= limits && edge.to !in currentStepState.vertexes.get(index)) {
newRoutes.add(edge.id)
newVertexes.add(edge.to)
var addNewSequence = true
if (newRoutes !in toStep.routes) {
toStep.routes.add(newRoutes)
toStep.costs.add(newCost)
toStep.vertexes.add(newVertexes)
currentStepsState[edge.to] = toStep
if (edge.to != finish && edge.to !in oldFront) {
newFront.add(edge.to)
}
}
}
}
}
}
}
oldFront = newFront.toMutableSet()
newFront.clear()
}
return currentStepsState[finish]?.routes ?: listOf<List<UInt>>()
}
}
@@ -0,0 +1,225 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
import Foundation
import benchmark
class SimpleCost: Cost {
let value: Int
init(cost: Int) {
value = cost
}
func plus(other: Cost) -> Cost {
let otherInstance = other as! SimpleCost
return SimpleCost(cost: value + otherInstance.value)
}
func minus(other: Cost) -> Cost {
let otherInstance = other as! SimpleCost
return SimpleCost(cost: value - otherInstance.value)
}
func compareTo(other: Cost) -> Int32 {
let otherInstance = other as! SimpleCost
if (value < otherInstance.value) {
return -1
}
if (value == otherInstance.value) {
return 0
}
return 1
}
}
class SwiftInteropBenchmarks {
let BENCHMARK_SIZE = 10000
let SMALL_BENCHMARK_SIZE = 50
let MEDIUM_BENCHMARK_SIZE = 100
var multigraph = Multigraph<NSNumber>()
var cityMap = CityMap()
func randomInt(border: Int) -> Int {
return Int.random(in: 1 ..< border)
}
func randomDouble(border: Double) -> Double {
return Double.random(in: 0 ..< border)
}
func randomString(length: Int) -> String {
let letters = "abcdefghijklmnopqrst"
return String((0..<length).map{ _ in letters.randomElement()! })
}
func randomTransport() -> Transport {
let allValues = [Transport.car, Transport.underground, Transport.bus, Transport.trolleybus, Transport.tram, Transport.taxi, Transport.foot]
return allValues.randomElement()!
}
func randomInterest() -> Interest {
let allValues = [Interest.sight, Interest.culture, Interest.park, Interest.entertainment]
return allValues.randomElement()!
}
func randomPlace() -> Place {
return Place(geoCoordinateX: randomDouble(border: 180), geoCoordinateY: randomDouble(border: 90), name: randomString(length: 5), interestCategory: randomInterest())
}
func randomRouteCost() -> RouteCost {
let transportCount = randomInt(border: 7)
let interestCount = randomInt(border: 4)
var transports = Set<Transport>()
var interests = Set<Interest>()
for _ in 0...transportCount {
transports.insert(randomTransport())
}
for _ in 0...interestCount {
interests.insert(randomInterest())
}
return RouteCost(moneyCost: randomDouble(border: 10000), timeCost: randomDouble(border: 24), interests: interests, transport: transports)
}
func initMultigraph(size: Int) {
multigraph = Multigraph<NSNumber>()
for i in 1...size {
multigraph.addEdge(from: NSNumber(value: i), to: NSNumber(value: i + 1), cost: SimpleCost(cost: (i + 1) % i ))
multigraph.addEdge(from: NSNumber(value: i), to: NSNumber(value: i * 2), cost: SimpleCost(cost: (i * 2) % i))
multigraph.addEdge(from: NSNumber(value: i + 5), to: NSNumber(value: i), cost: SimpleCost(cost: (i + 5) % i))
}
}
func createMultigraphOfInt() {
initMultigraph(size: BENCHMARK_SIZE)
}
func fillCityMap() {
cityMap = CityMap()
for _ in 0...BENCHMARK_SIZE {
cityMap.addRoute(from: randomPlace(), to: randomPlace(), cost: randomRouteCost())
}
}
func initCityMap(size: Int) {
cityMap = CityMap()
let allValuesInterests = [Interest.sight, Interest.culture, Interest.park, Interest.entertainment]
let allValuesTransport = [Transport.car, Transport.underground, Transport.bus, Transport.trolleybus, Transport.tram, Transport.taxi, Transport.foot]
for i in 1...size {
let from = Place(geoCoordinateX: Double(i % 180), geoCoordinateY: Double(i % 90 + 90 % i),
name: randomString(length: 5), interestCategory: allValuesInterests[i % allValuesInterests.count])
let to = Place(geoCoordinateX: Double(i % 180 + 180 % i), geoCoordinateY: Double(i % 90),
name: randomString(length: 5), interestCategory: allValuesInterests[(i + 5) % allValuesInterests.count])
var transports = Set<Transport>()
var interests = Set<Interest>()
for j in 0...i % 2 + 1 {
interests.insert(allValuesInterests[(i + j) % allValuesInterests.count])
}
for j in 0...i % 2 + 1 {
transports.insert(allValuesTransport[i % allValuesTransport.count])
}
let cost = RouteCost(moneyCost: Double((i * 2) % 10000), timeCost: Double((i + 3) % 24), interests: interests, transport: transports)
cityMap.addRoute(from: from, to: to, cost: cost)
}
}
func searchRoutesInSwiftMultigraph() {
initMultigraph(size: SMALL_BENCHMARK_SIZE)
for _ in 0...SMALL_BENCHMARK_SIZE {
var vertexes = Array(multigraph.allVertexes)
var result = multigraph.searchRoutesWithLimits(start: 1,
finish: NSNumber(value: SMALL_BENCHMARK_SIZE / 2 + SMALL_BENCHMARK_SIZE / 4),
limits: SimpleCost(cost: SMALL_BENCHMARK_SIZE / 5))
var count = result.map{ $0.count }.reduce(0, +)
}
}
func searchTravelRoutes() {
cityMap = CityMap()
initCityMap(size: BENCHMARK_SIZE)
let transports: Set = [Transport.car, Transport.underground]
let interests: Set = [Interest.sight, Interest.culture]
let cost = RouteCost(moneyCost: 500, timeCost: 6, interests: interests, transport: transports)
for _ in 0...SMALL_BENCHMARK_SIZE {
var result = cityMap.getRoutes(start: Array(cityMap.allPlaces).first!, finish: Array(cityMap.allPlaces).last!, limits: cost)
var totalCost = result.flatMap{ $0 }.map { $0.cost.moneyCost }.reduce(0, +)
}
}
func availableTransportOnMap() {
cityMap = CityMap()
initCityMap(size: MEDIUM_BENCHMARK_SIZE)
Set(cityMap.allRoutes.map { (cityMap.getRouteById(id: $0.id).cost as! RouteCost).transport })
}
func allPlacesMapedByInterests() {
cityMap = CityMap()
initCityMap(size: MEDIUM_BENCHMARK_SIZE)
let placesByInterests = cityMap.allPlaces.reduce([Interest: Array<Place>]()) { (dict, place) -> [Interest: Array<Place>] in
var dict = dict
if (dict[place.interestCategory] != nil) {
dict[place.interestCategory]?.append(place)
} else {
dict[place.interestCategory] = [place]
}
return dict
}
}
func getAllPlacesWithStraightRoutesTo() {
cityMap = CityMap()
initCityMap(size: MEDIUM_BENCHMARK_SIZE)
for _ in 0...SMALL_BENCHMARK_SIZE {
let start = cityMap.allPlaces.randomElement()!
let availableRoutes = cityMap.getAllStraightRoutesFrom(place: start)
var _ = availableRoutes.map { $0.to }
}
}
func goToAllAvailablePlaces() {
cityMap = CityMap()
initCityMap(size: MEDIUM_BENCHMARK_SIZE)
for _ in 0...SMALL_BENCHMARK_SIZE {
let start = cityMap.allPlaces.randomElement()!
let availableRoutes = cityMap.getAllStraightRoutesFrom(place: start)
availableRoutes.map { 2 * $0.cost.moneyCost }
}
}
func removeVertexAndEdgesSwiftMultigraph() {
initMultigraph(size: SMALL_BENCHMARK_SIZE)
let multigraphCopy = multigraph.doCopyMultigraph()
var edges = multigraphCopy.allEdges
while (!edges.isEmpty) {
multigraphCopy.removeEdge(id: UInt32(edges.randomElement()!))
let vertexes = multigraphCopy.allVertexes as! Set<NSNumber>
multigraphCopy.removeVertex(vertex: vertexes.randomElement()!)
edges = multigraphCopy.allEdges
}
}
func stringInterop() {
cityMap = CityMap()
fillCityMap()
let place = cityMap.allPlaces.first!
for _ in 0...BENCHMARK_SIZE {
let _ = place.fullDescription
}
}
func simpleFunction() {
cityMap = CityMap()
fillCityMap()
let place = cityMap.allPlaces.first!
for _ in 0...BENCHMARK_SIZE {
let _ = place.compareTo(other:place)
}
}
}
@@ -0,0 +1,53 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
import Foundation
import benchmark
var runner = BenchmarksRunner()
let args = KotlinArray<NSString>(size: Int32(CommandLine.arguments.count - 1), init: {index in
CommandLine.arguments[Int(truncating: index) + 1] as NSString
})
let companion = BenchmarkEntryWithInit.Companion()
var swiftLauncher = SwiftLauncher()
swiftLauncher.add(name: "createMultigraphOfInt", benchmark: companion.create(ctor: { return SwiftInteropBenchmarks() },
lambda: { ($0 as! SwiftInteropBenchmarks).createMultigraphOfInt() }))
swiftLauncher.add(name: "fillCityMap", benchmark: companion.create(ctor: { return SwiftInteropBenchmarks() },
lambda: { ($0 as! SwiftInteropBenchmarks).fillCityMap() }))
swiftLauncher.add(name: "searchRoutesInSwiftMultigraph", benchmark: companion.create(ctor: { return SwiftInteropBenchmarks() },
lambda: { ($0 as! SwiftInteropBenchmarks).searchRoutesInSwiftMultigraph () }))
swiftLauncher.add(name: "searchTravelRoutes", benchmark: companion.create(ctor: { return SwiftInteropBenchmarks() },
lambda: { ($0 as! SwiftInteropBenchmarks).searchTravelRoutes() }))
swiftLauncher.add(name: "availableTransportOnMap", benchmark: companion.create(ctor: { return SwiftInteropBenchmarks() },
lambda: { ($0 as! SwiftInteropBenchmarks).availableTransportOnMap() }))
swiftLauncher.add(name: "allPlacesMapedByInterests", benchmark: companion.create(ctor: { return SwiftInteropBenchmarks() },
lambda: { ($0 as! SwiftInteropBenchmarks).allPlacesMapedByInterests() }))
swiftLauncher.add(name: "getAllPlacesWithStraightRoutesTo", benchmark: companion.create(ctor: { return SwiftInteropBenchmarks() },
lambda: { ($0 as! SwiftInteropBenchmarks).getAllPlacesWithStraightRoutesTo() }))
swiftLauncher.add(name: "goToAllAvailablePlaces", benchmark: companion.create(ctor: { return SwiftInteropBenchmarks() },
lambda: { ($0 as! SwiftInteropBenchmarks).goToAllAvailablePlaces() }))
swiftLauncher.add(name: "removeVertexAndEdgesSwiftMultigraph", benchmark: companion.create(ctor: { return SwiftInteropBenchmarks() },
lambda: { ($0 as! SwiftInteropBenchmarks).removeVertexAndEdgesSwiftMultigraph() }))
swiftLauncher.add(name: "stringInterop", benchmark: companion.create(ctor: { return SwiftInteropBenchmarks() },
lambda: { ($0 as! SwiftInteropBenchmarks).stringInterop() }))
swiftLauncher.add(name: "simpleFunction", benchmark: companion.create(ctor: { return SwiftInteropBenchmarks() },
lambda: { ($0 as! SwiftInteropBenchmarks).simpleFunction() }))
runner.runBenchmarks(args: args, run: { (arguments: BenchmarkArguments) -> [BenchmarkResult] in
if arguments is BaseBenchmarkArguments {
let argumentsList: BaseBenchmarkArguments = arguments as! BaseBenchmarkArguments
return swiftLauncher.launch(numWarmIterations: argumentsList.warmup,
numberOfAttempts: argumentsList.repeat,
prefix: argumentsList.prefix, filters: argumentsList.filter,
filterRegexes: argumentsList.filterRegex,
verbose: argumentsList.verbose)
}
return [BenchmarkResult]()
}, parseArgs: { (args: KotlinArray, benchmarksListAction: (() -> KotlinUnit)) -> BenchmarkArguments? in
return runner.parse(args: args, benchmarksListAction: swiftLauncher.benchmarksListAction) },
collect: { (benchmarks: [BenchmarkResult], arguments: BenchmarkArguments) -> Void in
runner.collect(results: benchmarks, arguments: arguments)
}, benchmarksListAction: swiftLauncher.benchmarksListAction)