@mondaydotcomorg/atp-compiler 0.19.22 → 0.19.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +247 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +247 -13
- package/dist/index.js.map +1 -1
- package/dist/transformer/array-transformer-batch-reconstruct.d.ts +12 -0
- package/dist/transformer/array-transformer-batch-reconstruct.d.ts.map +1 -0
- package/dist/transformer/array-transformer-batch-reconstruct.js +117 -0
- package/dist/transformer/array-transformer-batch-reconstruct.js.map +1 -0
- package/dist/transformer/array-transformer-utils.d.ts +29 -1
- package/dist/transformer/array-transformer-utils.d.ts.map +1 -1
- package/dist/transformer/array-transformer-utils.js +159 -8
- package/dist/transformer/array-transformer-utils.js.map +1 -1
- package/dist/transformer/array-transformer.d.ts.map +1 -1
- package/dist/transformer/array-transformer.js +26 -1
- package/dist/transformer/array-transformer.js.map +1 -1
- package/dist/transformer/index.d.ts +1 -0
- package/dist/transformer/index.d.ts.map +1 -1
- package/dist/transformer/index.js +1 -0
- package/dist/transformer/index.js.map +1 -1
- package/package.json +5 -5
- package/src/transformer/array-transformer-batch-reconstruct.ts +179 -0
- package/src/transformer/array-transformer-utils.ts +187 -7
- package/src/transformer/array-transformer.ts +44 -1
- package/src/transformer/index.ts +1 -0
- package/tsconfig.tsbuildinfo +1 -1
package/dist/index.cjs
CHANGED
|
@@ -863,15 +863,102 @@ var BatchParallelDetector = class {
|
|
|
863
863
|
return void 0;
|
|
864
864
|
}
|
|
865
865
|
};
|
|
866
|
-
function
|
|
867
|
-
|
|
866
|
+
function collectReferencedIdentifiers(node) {
|
|
867
|
+
const identifiers = /* @__PURE__ */ new Set();
|
|
868
|
+
const visit = /* @__PURE__ */ __name((n) => {
|
|
869
|
+
if (t7__namespace.isIdentifier(n)) {
|
|
870
|
+
identifiers.add(n.name);
|
|
871
|
+
}
|
|
872
|
+
Object.keys(n).forEach((key) => {
|
|
873
|
+
if (key === "type" || key === "loc" || key === "start" || key === "end") return;
|
|
874
|
+
const value = n[key];
|
|
875
|
+
if (Array.isArray(value)) {
|
|
876
|
+
value.forEach((item) => {
|
|
877
|
+
if (item && typeof item === "object" && item.type) {
|
|
878
|
+
visit(item);
|
|
879
|
+
}
|
|
880
|
+
});
|
|
881
|
+
} else if (value && typeof value === "object" && value.type) {
|
|
882
|
+
visit(value);
|
|
883
|
+
}
|
|
884
|
+
});
|
|
885
|
+
}, "visit");
|
|
886
|
+
visit(node);
|
|
887
|
+
return identifiers;
|
|
888
|
+
}
|
|
889
|
+
__name(collectReferencedIdentifiers, "collectReferencedIdentifiers");
|
|
890
|
+
function collectLocalVariables(body) {
|
|
891
|
+
const locals = /* @__PURE__ */ new Set();
|
|
892
|
+
const visit = /* @__PURE__ */ __name((node) => {
|
|
893
|
+
if (t7__namespace.isVariableDeclaration(node)) {
|
|
894
|
+
for (const decl of node.declarations) {
|
|
895
|
+
if (t7__namespace.isIdentifier(decl.id)) {
|
|
896
|
+
locals.add(decl.id.name);
|
|
897
|
+
} else if (t7__namespace.isObjectPattern(decl.id)) {
|
|
898
|
+
for (const prop of decl.id.properties) {
|
|
899
|
+
if (t7__namespace.isObjectProperty(prop) && t7__namespace.isIdentifier(prop.value)) {
|
|
900
|
+
locals.add(prop.value.name);
|
|
901
|
+
} else if (t7__namespace.isRestElement(prop) && t7__namespace.isIdentifier(prop.argument)) {
|
|
902
|
+
locals.add(prop.argument.name);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
} else if (t7__namespace.isArrayPattern(decl.id)) {
|
|
906
|
+
for (const elem of decl.id.elements) {
|
|
907
|
+
if (t7__namespace.isIdentifier(elem)) {
|
|
908
|
+
locals.add(elem.name);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
if (t7__namespace.isFunction(node)) {
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
Object.keys(node).forEach((key) => {
|
|
918
|
+
if (key === "type" || key === "loc" || key === "start" || key === "end") return;
|
|
919
|
+
const value = node[key];
|
|
920
|
+
if (Array.isArray(value)) {
|
|
921
|
+
value.forEach((item) => {
|
|
922
|
+
if (item && typeof item === "object" && item.type) {
|
|
923
|
+
visit(item);
|
|
924
|
+
}
|
|
925
|
+
});
|
|
926
|
+
} else if (value && typeof value === "object" && value.type) {
|
|
927
|
+
visit(value);
|
|
928
|
+
}
|
|
929
|
+
});
|
|
930
|
+
}, "visit");
|
|
931
|
+
visit(body);
|
|
932
|
+
return locals;
|
|
933
|
+
}
|
|
934
|
+
__name(collectLocalVariables, "collectLocalVariables");
|
|
935
|
+
function hasLLMCallDependencies(body, batchDetector, itemParamName) {
|
|
936
|
+
const localVariables = collectLocalVariables(body);
|
|
937
|
+
if (localVariables.size === 0) {
|
|
938
|
+
return false;
|
|
939
|
+
}
|
|
940
|
+
const allCalls = findAllAwaitedMemberCalls(body);
|
|
941
|
+
for (const call of allCalls) {
|
|
942
|
+
const payloadNode = batchDetector.extractPayloadNode(call);
|
|
943
|
+
if (payloadNode) {
|
|
944
|
+
const referencedIds = collectReferencedIdentifiers(payloadNode);
|
|
945
|
+
for (const id of referencedIds) {
|
|
946
|
+
if (localVariables.has(id) && id !== itemParamName) {
|
|
947
|
+
return true;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
return false;
|
|
953
|
+
}
|
|
954
|
+
__name(hasLLMCallDependencies, "hasLLMCallDependencies");
|
|
955
|
+
function findAllAwaitedMemberCalls(body) {
|
|
956
|
+
const calls = [];
|
|
868
957
|
const visit = /* @__PURE__ */ __name((node) => {
|
|
869
|
-
if (found) return;
|
|
870
958
|
if (t7__namespace.isAwaitExpression(node) && t7__namespace.isCallExpression(node.argument)) {
|
|
871
959
|
const call = node.argument;
|
|
872
960
|
if (t7__namespace.isMemberExpression(call.callee)) {
|
|
873
|
-
|
|
874
|
-
return;
|
|
961
|
+
calls.push(call);
|
|
875
962
|
}
|
|
876
963
|
}
|
|
877
964
|
Object.keys(node).forEach((key) => {
|
|
@@ -888,7 +975,30 @@ function findLLMCallExpression(body) {
|
|
|
888
975
|
});
|
|
889
976
|
}, "visit");
|
|
890
977
|
visit(body);
|
|
891
|
-
return
|
|
978
|
+
return calls;
|
|
979
|
+
}
|
|
980
|
+
__name(findAllAwaitedMemberCalls, "findAllAwaitedMemberCalls");
|
|
981
|
+
function findAllLLMCallExpressions(body, batchDetector) {
|
|
982
|
+
const allCalls = findAllAwaitedMemberCalls(body);
|
|
983
|
+
const llmCalls = [];
|
|
984
|
+
for (const call of allCalls) {
|
|
985
|
+
const callInfo = batchDetector.extractCallInfo(call);
|
|
986
|
+
const payloadNode = batchDetector.extractPayloadNode(call);
|
|
987
|
+
if (callInfo && payloadNode) {
|
|
988
|
+
llmCalls.push({
|
|
989
|
+
callNode: call,
|
|
990
|
+
callInfo,
|
|
991
|
+
payloadNode,
|
|
992
|
+
key: `${callInfo.type}:${callInfo.operation}`
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
return llmCalls;
|
|
997
|
+
}
|
|
998
|
+
__name(findAllLLMCallExpressions, "findAllLLMCallExpressions");
|
|
999
|
+
function findLLMCallExpression(body) {
|
|
1000
|
+
const calls = findAllAwaitedMemberCalls(body);
|
|
1001
|
+
return calls[0] ?? null;
|
|
892
1002
|
}
|
|
893
1003
|
__name(findLLMCallExpression, "findLLMCallExpression");
|
|
894
1004
|
function getArrayMethodName(node) {
|
|
@@ -1265,6 +1375,114 @@ function transformToSequential(path, node, methodName, callback, onTransform) {
|
|
|
1265
1375
|
return true;
|
|
1266
1376
|
}
|
|
1267
1377
|
__name(transformToSequential, "transformToSequential");
|
|
1378
|
+
var traverse2 = typeof _traverse__default.default.default === "function" ? _traverse__default.default.default : _traverse__default.default;
|
|
1379
|
+
function transformToBatchWithReconstruction(path, node, methodName, callback, batchDetector, onTransform) {
|
|
1380
|
+
if (methodName !== "map") {
|
|
1381
|
+
return false;
|
|
1382
|
+
}
|
|
1383
|
+
const paramName = callback.params[0];
|
|
1384
|
+
if (!t7__namespace.isIdentifier(paramName)) {
|
|
1385
|
+
return false;
|
|
1386
|
+
}
|
|
1387
|
+
const param = paramName.name;
|
|
1388
|
+
const array = node.callee.object;
|
|
1389
|
+
const llmCalls = findAllLLMCallExpressions(callback.body, batchDetector);
|
|
1390
|
+
if (llmCalls.length === 0) {
|
|
1391
|
+
return false;
|
|
1392
|
+
}
|
|
1393
|
+
const methodId = generateUniqueId(`${methodName}_batch_reconstruct`);
|
|
1394
|
+
const originalIndexParam = callback.params[1];
|
|
1395
|
+
const indexVar = originalIndexParam && t7__namespace.isIdentifier(originalIndexParam) ? originalIndexParam.name : "__idx";
|
|
1396
|
+
const batchDeclarations = [];
|
|
1397
|
+
const resultVarByCallIndex = /* @__PURE__ */ new Map();
|
|
1398
|
+
for (let i = 0; i < llmCalls.length; i++) {
|
|
1399
|
+
const call = llmCalls[i];
|
|
1400
|
+
const resultsVar = `__batch_results_${i}_${methodId.replace(/[^a-zA-Z0-9]/g, "_")}`;
|
|
1401
|
+
resultVarByCallIndex.set(i, resultsVar);
|
|
1402
|
+
const payloadMapper = t7__namespace.arrowFunctionExpression([
|
|
1403
|
+
t7__namespace.identifier(param)
|
|
1404
|
+
], t7__namespace.objectExpression([
|
|
1405
|
+
t7__namespace.objectProperty(t7__namespace.identifier("type"), t7__namespace.stringLiteral(call.callInfo.type)),
|
|
1406
|
+
t7__namespace.objectProperty(t7__namespace.identifier("operation"), t7__namespace.stringLiteral(call.callInfo.operation)),
|
|
1407
|
+
t7__namespace.objectProperty(t7__namespace.identifier("payload"), t7__namespace.cloneNode(call.payloadNode, true))
|
|
1408
|
+
]));
|
|
1409
|
+
const batchCall = t7__namespace.awaitExpression(t7__namespace.callExpression(t7__namespace.memberExpression(t7__namespace.identifier("__runtime"), t7__namespace.identifier("batchParallel")), [
|
|
1410
|
+
t7__namespace.callExpression(t7__namespace.memberExpression(t7__namespace.cloneNode(array, true), t7__namespace.identifier("map")), [
|
|
1411
|
+
payloadMapper
|
|
1412
|
+
]),
|
|
1413
|
+
t7__namespace.stringLiteral(`${methodId}_${i}`)
|
|
1414
|
+
]));
|
|
1415
|
+
batchDeclarations.push(t7__namespace.variableDeclaration("const", [
|
|
1416
|
+
t7__namespace.variableDeclarator(t7__namespace.identifier(resultsVar), batchCall)
|
|
1417
|
+
]));
|
|
1418
|
+
}
|
|
1419
|
+
const clonedBody = t7__namespace.cloneNode(callback.body, true);
|
|
1420
|
+
let traversableNode;
|
|
1421
|
+
if (t7__namespace.isBlockStatement(clonedBody)) {
|
|
1422
|
+
traversableNode = t7__namespace.functionDeclaration(t7__namespace.identifier("__temp"), [], clonedBody);
|
|
1423
|
+
} else {
|
|
1424
|
+
traversableNode = t7__namespace.expressionStatement(clonedBody);
|
|
1425
|
+
}
|
|
1426
|
+
let replacementCount = 0;
|
|
1427
|
+
traverse2(t7__namespace.file(t7__namespace.program([
|
|
1428
|
+
traversableNode
|
|
1429
|
+
])), {
|
|
1430
|
+
AwaitExpression(awaitPath) {
|
|
1431
|
+
const arg = awaitPath.node.argument;
|
|
1432
|
+
if (!t7__namespace.isCallExpression(arg)) return;
|
|
1433
|
+
const info = batchDetector.extractCallInfo(arg);
|
|
1434
|
+
if (!info) return;
|
|
1435
|
+
const key = `${info.type}:${info.operation}`;
|
|
1436
|
+
let matchedIndex = -1;
|
|
1437
|
+
for (let i = 0; i < llmCalls.length; i++) {
|
|
1438
|
+
const original = llmCalls[i];
|
|
1439
|
+
if (original.key === key && resultVarByCallIndex.has(i)) {
|
|
1440
|
+
matchedIndex = i;
|
|
1441
|
+
break;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
if (matchedIndex === -1) return;
|
|
1445
|
+
const resultsVar = resultVarByCallIndex.get(matchedIndex);
|
|
1446
|
+
if (!resultsVar) return;
|
|
1447
|
+
resultVarByCallIndex.delete(matchedIndex);
|
|
1448
|
+
const resultAccess = t7__namespace.memberExpression(t7__namespace.identifier(resultsVar), t7__namespace.identifier(indexVar), true);
|
|
1449
|
+
awaitPath.replaceWith(resultAccess);
|
|
1450
|
+
replacementCount++;
|
|
1451
|
+
},
|
|
1452
|
+
noScope: true
|
|
1453
|
+
});
|
|
1454
|
+
if (replacementCount === 0) {
|
|
1455
|
+
return false;
|
|
1456
|
+
}
|
|
1457
|
+
let reconstructBody;
|
|
1458
|
+
if (t7__namespace.isBlockStatement(clonedBody)) {
|
|
1459
|
+
reconstructBody = clonedBody;
|
|
1460
|
+
} else {
|
|
1461
|
+
reconstructBody = clonedBody;
|
|
1462
|
+
}
|
|
1463
|
+
const reconstructMapper = t7__namespace.arrowFunctionExpression([
|
|
1464
|
+
t7__namespace.identifier(param),
|
|
1465
|
+
t7__namespace.identifier(indexVar)
|
|
1466
|
+
], reconstructBody);
|
|
1467
|
+
reconstructMapper.async = false;
|
|
1468
|
+
const reconstructCall = t7__namespace.callExpression(t7__namespace.memberExpression(t7__namespace.cloneNode(array, true), t7__namespace.identifier("map")), [
|
|
1469
|
+
reconstructMapper
|
|
1470
|
+
]);
|
|
1471
|
+
const iife = t7__namespace.callExpression(t7__namespace.arrowFunctionExpression(
|
|
1472
|
+
[],
|
|
1473
|
+
t7__namespace.blockStatement([
|
|
1474
|
+
...batchDeclarations,
|
|
1475
|
+
t7__namespace.returnStatement(reconstructCall)
|
|
1476
|
+
]),
|
|
1477
|
+
true
|
|
1478
|
+
// async
|
|
1479
|
+
), []);
|
|
1480
|
+
const awaitIife = t7__namespace.awaitExpression(iife);
|
|
1481
|
+
path.replaceWith(awaitIife);
|
|
1482
|
+
onTransform();
|
|
1483
|
+
return true;
|
|
1484
|
+
}
|
|
1485
|
+
__name(transformToBatchWithReconstruction, "transformToBatchWithReconstruction");
|
|
1268
1486
|
|
|
1269
1487
|
// src/transformer/array-transformer.ts
|
|
1270
1488
|
var ArrayTransformer = class {
|
|
@@ -1291,6 +1509,22 @@ var ArrayTransformer = class {
|
|
|
1291
1509
|
return false;
|
|
1292
1510
|
}
|
|
1293
1511
|
const batchResult = this.batchOptimizer.canBatchArrayMethod(callback);
|
|
1512
|
+
if (!batchResult.canBatch && methodName === "map") {
|
|
1513
|
+
const reason = batchResult.reason || "";
|
|
1514
|
+
const canTryBatchReconstruct = reason.includes("object expression") || reason.includes("array expression") || reason.includes("Multiple pausable calls");
|
|
1515
|
+
if (canTryBatchReconstruct) {
|
|
1516
|
+
const llmCall = findLLMCallExpression(callback.body);
|
|
1517
|
+
const itemParam = callback.params[0];
|
|
1518
|
+
const itemParamName = t7__namespace.isIdentifier(itemParam) ? itemParam.name : void 0;
|
|
1519
|
+
const hasDependencies = hasLLMCallDependencies(callback.body, this.batchDetector, itemParamName);
|
|
1520
|
+
if (llmCall && !hasDependencies) {
|
|
1521
|
+
const success = transformToBatchWithReconstruction(path, node, methodName, callback, this.batchDetector, () => this.transformCount++);
|
|
1522
|
+
if (success) {
|
|
1523
|
+
return true;
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1294
1528
|
if (batchResult.canBatch && canUseBatchParallel(methodName)) {
|
|
1295
1529
|
const array = node.callee.object;
|
|
1296
1530
|
const decision = this.batchOptimizer.makeSmartBatchDecision(methodName, batchResult, array, this.batchSizeThreshold);
|
|
@@ -1594,7 +1828,7 @@ function isTransformationError(error) {
|
|
|
1594
1828
|
__name(isTransformationError, "isTransformationError");
|
|
1595
1829
|
|
|
1596
1830
|
// src/transformer/index.ts
|
|
1597
|
-
var
|
|
1831
|
+
var traverse3 = _traverse__default.default.default || _traverse__default.default;
|
|
1598
1832
|
var generate = _generate__default.default.default || _generate__default.default;
|
|
1599
1833
|
var ATPCompiler = class {
|
|
1600
1834
|
static {
|
|
@@ -1646,7 +1880,7 @@ var ATPCompiler = class {
|
|
|
1646
1880
|
this.loopTransformer.resetTransformCount();
|
|
1647
1881
|
this.arrayTransformer.resetTransformCount();
|
|
1648
1882
|
this.promiseTransformer.resetTransformCount();
|
|
1649
|
-
|
|
1883
|
+
traverse3(ast, {
|
|
1650
1884
|
ForOfStatement: /* @__PURE__ */ __name((path) => {
|
|
1651
1885
|
this.loopTransformer.transformForOfLoop(path);
|
|
1652
1886
|
}, "ForOfStatement"),
|
|
@@ -2329,7 +2563,7 @@ function createTransformPlugin(config) {
|
|
|
2329
2563
|
};
|
|
2330
2564
|
}
|
|
2331
2565
|
__name(createTransformPlugin, "createTransformPlugin");
|
|
2332
|
-
var
|
|
2566
|
+
var traverse4 = _traverse__default.default.default || _traverse__default.default;
|
|
2333
2567
|
var generate2 = _generate__default.default.default || _generate__default.default;
|
|
2334
2568
|
var PluggableCompiler = class {
|
|
2335
2569
|
static {
|
|
@@ -2450,7 +2684,7 @@ var PluggableCompiler = class {
|
|
|
2450
2684
|
}
|
|
2451
2685
|
}
|
|
2452
2686
|
}
|
|
2453
|
-
|
|
2687
|
+
traverse4(ast, visitors);
|
|
2454
2688
|
let optimizedAst = ast;
|
|
2455
2689
|
const optimizers = this.registry.getOptimizers();
|
|
2456
2690
|
for (const optimizer of optimizers) {
|
|
@@ -2842,7 +3076,7 @@ var AsyncTimeoutPlugin = class {
|
|
|
2842
3076
|
return null;
|
|
2843
3077
|
}
|
|
2844
3078
|
};
|
|
2845
|
-
var
|
|
3079
|
+
var traverse5 = _traverse__default.default.default || _traverse__default.default;
|
|
2846
3080
|
var SecurityValidatorPlugin = class {
|
|
2847
3081
|
static {
|
|
2848
3082
|
__name(this, "SecurityValidatorPlugin");
|
|
@@ -2879,7 +3113,7 @@ var SecurityValidatorPlugin = class {
|
|
|
2879
3113
|
}
|
|
2880
3114
|
let maxNestingFound = 0;
|
|
2881
3115
|
let complexityScore = 0;
|
|
2882
|
-
|
|
3116
|
+
traverse5(ast, {
|
|
2883
3117
|
enter(path) {
|
|
2884
3118
|
const depth = path.scope.path.node ? getDepth(path) : 0;
|
|
2885
3119
|
maxNestingFound = Math.max(maxNestingFound, depth);
|
|
@@ -2994,6 +3228,7 @@ exports.resumableSome = resumableSome;
|
|
|
2994
3228
|
exports.resumableWhile = resumableWhile;
|
|
2995
3229
|
exports.setCheckpointManager = setCheckpointManager;
|
|
2996
3230
|
exports.setRuntimeContext = setRuntimeContext;
|
|
3231
|
+
exports.transformToBatchWithReconstruction = transformToBatchWithReconstruction;
|
|
2997
3232
|
exports.wrapInAsyncFunction = wrapInAsyncFunction;
|
|
2998
3233
|
//# sourceMappingURL=index.cjs.map
|
|
2999
3234
|
//# sourceMappingURL=index.cjs.map
|