fix(ivy): `pureFunctionV` takes an array of values (#24039)
PR Close #24039
This commit is contained in:
parent
280a784fe3
commit
188ff848d2
|
@ -574,6 +574,15 @@ const pureFunctionIdentifiers = [
|
||||||
R3.pureFunction0, R3.pureFunction1, R3.pureFunction2, R3.pureFunction3, R3.pureFunction4,
|
R3.pureFunction0, R3.pureFunction1, R3.pureFunction2, R3.pureFunction3, R3.pureFunction4,
|
||||||
R3.pureFunction5, R3.pureFunction6, R3.pureFunction7, R3.pureFunction8
|
R3.pureFunction5, R3.pureFunction6, R3.pureFunction7, R3.pureFunction8
|
||||||
];
|
];
|
||||||
|
|
||||||
|
function pureFunctionCallInfo(args: o.Expression[]) {
|
||||||
|
const identifier = pureFunctionIdentifiers[args.length];
|
||||||
|
return {
|
||||||
|
identifier: identifier || R3.pureFunctionV,
|
||||||
|
isVarLength: !identifier,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function getLiteralFactory(
|
function getLiteralFactory(
|
||||||
constantPool: ConstantPool, literal: o.LiteralArrayExpr | o.LiteralMapExpr,
|
constantPool: ConstantPool, literal: o.LiteralArrayExpr | o.LiteralMapExpr,
|
||||||
allocateSlots: (numSlots: number) => number): o.Expression {
|
allocateSlots: (numSlots: number) => number): o.Expression {
|
||||||
|
@ -581,14 +590,22 @@ function getLiteralFactory(
|
||||||
// Allocate 1 slot for the result plus 1 per argument
|
// Allocate 1 slot for the result plus 1 per argument
|
||||||
const startSlot = allocateSlots(1 + literalFactoryArguments.length);
|
const startSlot = allocateSlots(1 + literalFactoryArguments.length);
|
||||||
literalFactoryArguments.length > 0 || error(`Expected arguments to a literal factory function`);
|
literalFactoryArguments.length > 0 || error(`Expected arguments to a literal factory function`);
|
||||||
let pureFunctionIdent =
|
const {identifier, isVarLength} = pureFunctionCallInfo(literalFactoryArguments);
|
||||||
pureFunctionIdentifiers[literalFactoryArguments.length] || R3.pureFunctionV;
|
|
||||||
|
|
||||||
// Literal factories are pure functions that only need to be re-invoked when the parameters
|
// Literal factories are pure functions that only need to be re-invoked when the parameters
|
||||||
// change.
|
// change.
|
||||||
return o.importExpr(pureFunctionIdent).callFn([
|
const args = [
|
||||||
o.literal(startSlot), literalFactory, ...literalFactoryArguments
|
o.literal(startSlot),
|
||||||
]);
|
literalFactory,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isVarLength) {
|
||||||
|
args.push(o.literalArr(literalFactoryArguments));
|
||||||
|
} else {
|
||||||
|
args.push(...literalFactoryArguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
return o.importExpr(identifier).callFn(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -548,7 +548,7 @@ describe('compiler compliance', () => {
|
||||||
if (rf & 2) {
|
if (rf & 2) {
|
||||||
$r3$.ɵp(
|
$r3$.ɵp(
|
||||||
0, 'names',
|
0, 'names',
|
||||||
$r3$.ɵb($r3$.ɵfV(10, $e0_ff$, ctx.n0, ctx.n1, ctx.n2, ctx.n3, ctx.n4, ctx.n5, ctx.n6, ctx.n7, ctx.n8)));
|
$r3$.ɵb($r3$.ɵfV(10, $e0_ff$, [ctx.n0, ctx.n1, ctx.n2, ctx.n3, ctx.n4, ctx.n5, ctx.n6, ctx.n7, ctx.n8])));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
directives: [MyComp]
|
directives: [MyComp]
|
||||||
|
|
|
@ -3662,6 +3662,9 @@
|
||||||
{
|
{
|
||||||
"name": "pureArrayDef"
|
"name": "pureArrayDef"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "pureFunctionCallInfo"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "pureFunctionIdentifiers"
|
"name": "pureFunctionIdentifiers"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue