From 0434360d46b2e76f8409c24df97dbcf5b34da196 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 13 Apr 2020 15:34:26 +0300 Subject: [PATCH] Cleanup type variance in Task builder --- .../kotlin/hep/dataforge/data/MapAction.kt | 2 +- .../kotlin/hep/dataforge/data/ReduceAction.kt | 2 +- .../kotlin/hep/dataforge/data/SplitAction.kt | 2 +- .../hep/dataforge/workspace/TaskBuilder.kt | 16 +++++++++++----- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/MapAction.kt b/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/MapAction.kt index 89e887db..61598349 100644 --- a/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/MapAction.kt +++ b/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/MapAction.kt @@ -31,7 +31,7 @@ class MapActionBuilder(var name: Name, var meta: MetaBuilder, val actionMe class MapAction( - val inputType: KClass, + val inputType: KClass, val outputType: KClass, private val block: MapActionBuilder.() -> Unit ) : Action { diff --git a/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/ReduceAction.kt b/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/ReduceAction.kt index 9bb49151..0efb5506 100644 --- a/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/ReduceAction.kt +++ b/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/ReduceAction.kt @@ -72,7 +72,7 @@ class ReduceGroupBuilder(val actionMeta: Meta) { * The same rules as for KPipe */ class ReduceAction( - val inputType: KClass, + val inputType: KClass, val outputType: KClass, private val action: ReduceGroupBuilder.() -> Unit ) : Action { diff --git a/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/SplitAction.kt b/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/SplitAction.kt index a4f82931..dc29394c 100644 --- a/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/SplitAction.kt +++ b/dataforge-data/src/commonMain/kotlin/hep/dataforge/data/SplitAction.kt @@ -33,7 +33,7 @@ class SplitBuilder(val name: Name, val meta: Meta) { } class SplitAction( - val inputType: KClass, + val inputType: KClass, val outputType: KClass, private val action: SplitBuilder.() -> Unit ) : Action { diff --git a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/TaskBuilder.kt b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/TaskBuilder.kt index 9ce9cf27..502c669d 100644 --- a/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/TaskBuilder.kt +++ b/dataforge-workspace/src/commonMain/kotlin/hep/dataforge/workspace/TaskBuilder.kt @@ -16,7 +16,8 @@ import kotlin.reflect.KClass @DFBuilder class TaskBuilder(val name: Name, val type: KClass) { private var modelTransform: TaskModelBuilder.(Meta) -> Unit = { allData() } -// private val additionalDependencies = HashSet() + + // private val additionalDependencies = HashSet() var descriptor: NodeDescriptor? = null private val dataTransforms: MutableList = ArrayList() @@ -96,7 +97,7 @@ class TaskBuilder(val name: Name, val type: KClass) { } class TaskEnv(val name: Name, val meta: Meta, val context: Context, val data: DataNode) { - operator fun DirectTaskDependency.invoke(): DataNode = if(placement.isEmpty()){ + operator fun DirectTaskDependency.invoke(): DataNode = if (placement.isEmpty()) { data.cast(task.type) } else { data[placement].node?.cast(task.type) @@ -113,10 +114,13 @@ class TaskBuilder(val name: Name, val type: KClass) { crossinline block: MapActionBuilder.(TaskEnv) -> Unit ) { action(from, to) { + val env = this MapAction( inputType = T::class, outputType = type - ) { block(this@action) } + ) { + block(env) + } } } @@ -150,10 +154,11 @@ class TaskBuilder(val name: Name, val type: KClass) { crossinline block: ReduceGroupBuilder.(TaskEnv) -> Unit //TODO needs KEEP-176 ) { action(from, to) { + val env = this ReduceAction( inputType = T::class, outputType = type - ) { block(this@action) } + ) { block(env) } } } @@ -189,10 +194,11 @@ class TaskBuilder(val name: Name, val type: KClass) { crossinline block: SplitBuilder.(TaskEnv) -> Unit //TODO needs KEEP-176 ) { action(from, to) { + val env = this SplitAction( inputType = T::class, outputType = type - ) { block(this@action) } + ) { block(env) } } }