Cleanup type variance in Task builder

This commit is contained in:
Alexander Nozik 2020-04-13 15:34:26 +03:00
parent f67fb63c45
commit 0434360d46
4 changed files with 14 additions and 8 deletions

View File

@ -31,7 +31,7 @@ class MapActionBuilder<T, R>(var name: Name, var meta: MetaBuilder, val actionMe
class MapAction<T : Any, out R : Any>( class MapAction<T : Any, out R : Any>(
val inputType: KClass<out T>, val inputType: KClass<T>,
val outputType: KClass<out R>, val outputType: KClass<out R>,
private val block: MapActionBuilder<T, R>.() -> Unit private val block: MapActionBuilder<T, R>.() -> Unit
) : Action<T, R> { ) : Action<T, R> {

View File

@ -72,7 +72,7 @@ class ReduceGroupBuilder<T : Any, R : Any>(val actionMeta: Meta) {
* The same rules as for KPipe * The same rules as for KPipe
*/ */
class ReduceAction<T : Any, R : Any>( class ReduceAction<T : Any, R : Any>(
val inputType: KClass<out T>, val inputType: KClass<T>,
val outputType: KClass<out R>, val outputType: KClass<out R>,
private val action: ReduceGroupBuilder<T, R>.() -> Unit private val action: ReduceGroupBuilder<T, R>.() -> Unit
) : Action<T, R> { ) : Action<T, R> {

View File

@ -33,7 +33,7 @@ class SplitBuilder<T : Any, R : Any>(val name: Name, val meta: Meta) {
} }
class SplitAction<T : Any, R : Any>( class SplitAction<T : Any, R : Any>(
val inputType: KClass<out T>, val inputType: KClass<T>,
val outputType: KClass<out R>, val outputType: KClass<out R>,
private val action: SplitBuilder<T, R>.() -> Unit private val action: SplitBuilder<T, R>.() -> Unit
) : Action<T, R> { ) : Action<T, R> {

View File

@ -16,7 +16,8 @@ import kotlin.reflect.KClass
@DFBuilder @DFBuilder
class TaskBuilder<R : Any>(val name: Name, val type: KClass<out R>) { class TaskBuilder<R : Any>(val name: Name, val type: KClass<out R>) {
private var modelTransform: TaskModelBuilder.(Meta) -> Unit = { allData() } private var modelTransform: TaskModelBuilder.(Meta) -> Unit = { allData() }
// private val additionalDependencies = HashSet<Dependency>()
// private val additionalDependencies = HashSet<Dependency>()
var descriptor: NodeDescriptor? = null var descriptor: NodeDescriptor? = null
private val dataTransforms: MutableList<DataTransformation> = ArrayList() private val dataTransforms: MutableList<DataTransformation> = ArrayList()
@ -96,7 +97,7 @@ class TaskBuilder<R : Any>(val name: Name, val type: KClass<out R>) {
} }
class TaskEnv(val name: Name, val meta: Meta, val context: Context, val data: DataNode<Any>) { class TaskEnv(val name: Name, val meta: Meta, val context: Context, val data: DataNode<Any>) {
operator fun <T : Any> DirectTaskDependency<T>.invoke(): DataNode<T> = if(placement.isEmpty()){ operator fun <T : Any> DirectTaskDependency<T>.invoke(): DataNode<T> = if (placement.isEmpty()) {
data.cast(task.type) data.cast(task.type)
} else { } else {
data[placement].node?.cast(task.type) data[placement].node?.cast(task.type)
@ -113,10 +114,13 @@ class TaskBuilder<R : Any>(val name: Name, val type: KClass<out R>) {
crossinline block: MapActionBuilder<T, R>.(TaskEnv) -> Unit crossinline block: MapActionBuilder<T, R>.(TaskEnv) -> Unit
) { ) {
action(from, to) { action(from, to) {
val env = this
MapAction( MapAction(
inputType = T::class, inputType = T::class,
outputType = type outputType = type
) { block(this@action) } ) {
block(env)
}
} }
} }
@ -150,10 +154,11 @@ class TaskBuilder<R : Any>(val name: Name, val type: KClass<out R>) {
crossinline block: ReduceGroupBuilder<T, R>.(TaskEnv) -> Unit //TODO needs KEEP-176 crossinline block: ReduceGroupBuilder<T, R>.(TaskEnv) -> Unit //TODO needs KEEP-176
) { ) {
action(from, to) { action(from, to) {
val env = this
ReduceAction( ReduceAction(
inputType = T::class, inputType = T::class,
outputType = type outputType = type
) { block(this@action) } ) { block(env) }
} }
} }
@ -189,10 +194,11 @@ class TaskBuilder<R : Any>(val name: Name, val type: KClass<out R>) {
crossinline block: SplitBuilder<T, R>.(TaskEnv) -> Unit //TODO needs KEEP-176 crossinline block: SplitBuilder<T, R>.(TaskEnv) -> Unit //TODO needs KEEP-176
) { ) {
action(from, to) { action(from, to) {
val env = this
SplitAction( SplitAction(
inputType = T::class, inputType = T::class,
outputType = type outputType = type
) { block(this@action) } ) { block(env) }
} }
} }