feat(ivy): add support for short-circuiting (#24039)
Short-circuitable expressions (using ternary & binary operators) could not use the regular binding mechanism as it relies on the bindings being checked every single time - the index is incremented as part of checking the bindings. Then for pure function kind of bindings we use a different mechanism with a fixed index. As such short circuiting a binding check does not mess with the expected binding index. Note that all pure function bindings are handled the same wether or not they actually are short-circuitable. This allows to keep the compiler and compiled code simple - and there is no runtime perf cost anyway. PR Close #24039
This commit is contained in:

committed by
Matias Niemelä

parent
83bb5d1922
commit
4f36340de7
@ -65,11 +65,12 @@ function getPipeDef(name: string, registry: PipeDefList | null): PipeDef<any> {
|
||||
* the pipe only when an input to the pipe changes.
|
||||
*
|
||||
* @param index Pipe index where the pipe was stored on creation.
|
||||
* @param slotOffset the offset in the reserved slot space {@link reserveSlots}
|
||||
* @param v1 1st argument to {@link PipeTransform#transform}.
|
||||
*/
|
||||
export function pipeBind1(index: number, v1: any): any {
|
||||
export function pipeBind1(index: number, slotOffset: number, v1: any): any {
|
||||
const pipeInstance = load<PipeTransform>(index);
|
||||
return isPure(index) ? pureFunction1(pipeInstance.transform, v1, pipeInstance) :
|
||||
return isPure(index) ? pureFunction1(slotOffset, pipeInstance.transform, v1, pipeInstance) :
|
||||
pipeInstance.transform(v1);
|
||||
}
|
||||
|
||||
@ -80,12 +81,13 @@ export function pipeBind1(index: number, v1: any): any {
|
||||
* the pipe only when an input to the pipe changes.
|
||||
*
|
||||
* @param index Pipe index where the pipe was stored on creation.
|
||||
* @param slotOffset the offset in the reserved slot space {@link reserveSlots}
|
||||
* @param v1 1st argument to {@link PipeTransform#transform}.
|
||||
* @param v2 2nd argument to {@link PipeTransform#transform}.
|
||||
*/
|
||||
export function pipeBind2(index: number, v1: any, v2: any): any {
|
||||
export function pipeBind2(index: number, slotOffset: number, v1: any, v2: any): any {
|
||||
const pipeInstance = load<PipeTransform>(index);
|
||||
return isPure(index) ? pureFunction2(pipeInstance.transform, v1, v2, pipeInstance) :
|
||||
return isPure(index) ? pureFunction2(slotOffset, pipeInstance.transform, v1, v2, pipeInstance) :
|
||||
pipeInstance.transform(v1, v2);
|
||||
}
|
||||
|
||||
@ -96,14 +98,16 @@ export function pipeBind2(index: number, v1: any, v2: any): any {
|
||||
* the pipe only when an input to the pipe changes.
|
||||
*
|
||||
* @param index Pipe index where the pipe was stored on creation.
|
||||
* @param slotOffset the offset in the reserved slot space {@link reserveSlots}
|
||||
* @param v1 1st argument to {@link PipeTransform#transform}.
|
||||
* @param v2 2nd argument to {@link PipeTransform#transform}.
|
||||
* @param v3 4rd argument to {@link PipeTransform#transform}.
|
||||
*/
|
||||
export function pipeBind3(index: number, v1: any, v2: any, v3: any): any {
|
||||
export function pipeBind3(index: number, slotOffset: number, v1: any, v2: any, v3: any): any {
|
||||
const pipeInstance = load<PipeTransform>(index);
|
||||
return isPure(index) ? pureFunction3(pipeInstance.transform, v1, v2, v3, pipeInstance) :
|
||||
pipeInstance.transform(v1, v2, v3);
|
||||
return isPure(index) ?
|
||||
pureFunction3(slotOffset, pipeInstance.transform, v1, v2, v3, pipeInstance) :
|
||||
pipeInstance.transform(v1, v2, v3);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -113,15 +117,18 @@ export function pipeBind3(index: number, v1: any, v2: any, v3: any): any {
|
||||
* the pipe only when an input to the pipe changes.
|
||||
*
|
||||
* @param index Pipe index where the pipe was stored on creation.
|
||||
* @param slotOffset the offset in the reserved slot space {@link reserveSlots}
|
||||
* @param v1 1st argument to {@link PipeTransform#transform}.
|
||||
* @param v2 2nd argument to {@link PipeTransform#transform}.
|
||||
* @param v3 3rd argument to {@link PipeTransform#transform}.
|
||||
* @param v4 4th argument to {@link PipeTransform#transform}.
|
||||
*/
|
||||
export function pipeBind4(index: number, v1: any, v2: any, v3: any, v4: any): any {
|
||||
export function pipeBind4(
|
||||
index: number, slotOffset: number, v1: any, v2: any, v3: any, v4: any): any {
|
||||
const pipeInstance = load<PipeTransform>(index);
|
||||
return isPure(index) ? pureFunction4(pipeInstance.transform, v1, v2, v3, v4, pipeInstance) :
|
||||
pipeInstance.transform(v1, v2, v3, v4);
|
||||
return isPure(index) ?
|
||||
pureFunction4(slotOffset, pipeInstance.transform, v1, v2, v3, v4, pipeInstance) :
|
||||
pipeInstance.transform(v1, v2, v3, v4);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,11 +138,12 @@ export function pipeBind4(index: number, v1: any, v2: any, v3: any, v4: any): an
|
||||
* the pipe only when an input to the pipe changes.
|
||||
*
|
||||
* @param index Pipe index where the pipe was stored on creation.
|
||||
* @param slotOffset the offset in the reserved slot space {@link reserveSlots}
|
||||
* @param values Array of arguments to pass to {@link PipeTransform#transform} method.
|
||||
*/
|
||||
export function pipeBindV(index: number, values: any[]): any {
|
||||
export function pipeBindV(index: number, slotOffset: number, values: any[]): any {
|
||||
const pipeInstance = load<PipeTransform>(index);
|
||||
return isPure(index) ? pureFunctionV(pipeInstance.transform, values, pipeInstance) :
|
||||
return isPure(index) ? pureFunctionV(slotOffset, pipeInstance.transform, values, pipeInstance) :
|
||||
pipeInstance.transform.apply(pipeInstance, values);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user