@mondaydotcomorg/atp-compiler 0.19.21 → 0.19.23
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 +129 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +129 -7
- package/dist/index.js.map +1 -1
- package/dist/transformer/array-transformer-batch-reconstruct.d.ts +11 -0
- package/dist/transformer/array-transformer-batch-reconstruct.d.ts.map +1 -0
- package/dist/transformer/array-transformer-batch-reconstruct.js +97 -0
- package/dist/transformer/array-transformer-batch-reconstruct.js.map +1 -0
- package/dist/transformer/array-transformer.d.ts.map +1 -1
- package/dist/transformer/array-transformer.js +15 -1
- package/dist/transformer/array-transformer.js.map +1 -1
- package/dist/transformer/batch-optimizer.d.ts.map +1 -1
- package/dist/transformer/batch-optimizer.js +15 -0
- package/dist/transformer/batch-optimizer.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 +155 -0
- package/src/transformer/array-transformer.ts +29 -1
- package/src/transformer/batch-optimizer.ts +16 -0
- package/src/transformer/index.ts +1 -0
- package/tsconfig.tsbuildinfo +1 -1
package/dist/index.js
CHANGED
|
@@ -481,6 +481,21 @@ var BatchOptimizer = class {
|
|
|
481
481
|
reason: "Simple conditional - can batch but consider array size"
|
|
482
482
|
};
|
|
483
483
|
}
|
|
484
|
+
const lastStmt = statements[statements.length - 1];
|
|
485
|
+
if (t7.isReturnStatement(lastStmt) && lastStmt.argument) {
|
|
486
|
+
if (t7.isObjectExpression(lastStmt.argument)) {
|
|
487
|
+
return {
|
|
488
|
+
canBatch: false,
|
|
489
|
+
reason: "Return statement is object expression - batch would lose structure"
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
if (t7.isArrayExpression(lastStmt.argument)) {
|
|
493
|
+
return {
|
|
494
|
+
canBatch: false,
|
|
495
|
+
reason: "Return statement is array expression - batch would lose structure"
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
}
|
|
484
499
|
return {
|
|
485
500
|
canBatch: true,
|
|
486
501
|
llmCallPattern: "single",
|
|
@@ -1224,6 +1239,100 @@ function transformToSequential(path, node, methodName, callback, onTransform) {
|
|
|
1224
1239
|
return true;
|
|
1225
1240
|
}
|
|
1226
1241
|
__name(transformToSequential, "transformToSequential");
|
|
1242
|
+
var traverse2 = typeof _traverse.default === "function" ? _traverse.default : _traverse;
|
|
1243
|
+
function transformToBatchWithReconstruction(path, node, methodName, callback, batchDetector, onTransform) {
|
|
1244
|
+
if (methodName !== "map") {
|
|
1245
|
+
return false;
|
|
1246
|
+
}
|
|
1247
|
+
const paramName = callback.params[0];
|
|
1248
|
+
if (!t7.isIdentifier(paramName)) {
|
|
1249
|
+
return false;
|
|
1250
|
+
}
|
|
1251
|
+
const param = paramName.name;
|
|
1252
|
+
const array = node.callee.object;
|
|
1253
|
+
const llmCall = findLLMCallExpression(callback.body);
|
|
1254
|
+
if (!llmCall) {
|
|
1255
|
+
return false;
|
|
1256
|
+
}
|
|
1257
|
+
const callInfo = batchDetector.extractCallInfo(llmCall);
|
|
1258
|
+
if (!callInfo) {
|
|
1259
|
+
return false;
|
|
1260
|
+
}
|
|
1261
|
+
const payloadNode = batchDetector.extractPayloadNode(llmCall);
|
|
1262
|
+
if (!payloadNode) {
|
|
1263
|
+
return false;
|
|
1264
|
+
}
|
|
1265
|
+
const methodId = generateUniqueId(`${methodName}_batch_reconstruct`);
|
|
1266
|
+
const resultsVar = `__batch_results_${methodId.replace(/[^a-zA-Z0-9]/g, "_")}`;
|
|
1267
|
+
const indexVar = "__idx";
|
|
1268
|
+
const payloadMapper = t7.arrowFunctionExpression([
|
|
1269
|
+
t7.identifier(param)
|
|
1270
|
+
], t7.objectExpression([
|
|
1271
|
+
t7.objectProperty(t7.identifier("type"), t7.stringLiteral(callInfo.type)),
|
|
1272
|
+
t7.objectProperty(t7.identifier("operation"), t7.stringLiteral(callInfo.operation)),
|
|
1273
|
+
t7.objectProperty(t7.identifier("payload"), t7.cloneNode(payloadNode, true))
|
|
1274
|
+
]));
|
|
1275
|
+
const clonedBody = t7.cloneNode(callback.body, true);
|
|
1276
|
+
const resultAccess = t7.memberExpression(t7.identifier(resultsVar), t7.identifier(indexVar), true);
|
|
1277
|
+
let traversableNode;
|
|
1278
|
+
if (t7.isBlockStatement(clonedBody)) {
|
|
1279
|
+
traversableNode = t7.functionDeclaration(t7.identifier("__temp"), [], clonedBody);
|
|
1280
|
+
} else {
|
|
1281
|
+
traversableNode = t7.expressionStatement(clonedBody);
|
|
1282
|
+
}
|
|
1283
|
+
let replaced = false;
|
|
1284
|
+
traverse2(t7.file(t7.program([
|
|
1285
|
+
traversableNode
|
|
1286
|
+
])), {
|
|
1287
|
+
AwaitExpression(awaitPath) {
|
|
1288
|
+
if (replaced) return;
|
|
1289
|
+
const arg = awaitPath.node.argument;
|
|
1290
|
+
if (t7.isCallExpression(arg)) {
|
|
1291
|
+
const info = batchDetector.extractCallInfo(arg);
|
|
1292
|
+
if (info && info.type === callInfo.type && info.operation === callInfo.operation) {
|
|
1293
|
+
awaitPath.replaceWith(resultAccess);
|
|
1294
|
+
replaced = true;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
},
|
|
1298
|
+
noScope: true
|
|
1299
|
+
});
|
|
1300
|
+
if (!replaced) {
|
|
1301
|
+
return false;
|
|
1302
|
+
}
|
|
1303
|
+
let reconstructBody;
|
|
1304
|
+
if (t7.isBlockStatement(clonedBody)) {
|
|
1305
|
+
reconstructBody = clonedBody;
|
|
1306
|
+
} else {
|
|
1307
|
+
reconstructBody = clonedBody;
|
|
1308
|
+
}
|
|
1309
|
+
const reconstructMapper = t7.arrowFunctionExpression([
|
|
1310
|
+
t7.identifier(param),
|
|
1311
|
+
t7.identifier(indexVar)
|
|
1312
|
+
], reconstructBody);
|
|
1313
|
+
reconstructMapper.async = false;
|
|
1314
|
+
const batchCall = t7.awaitExpression(t7.callExpression(t7.memberExpression(t7.identifier("__runtime"), t7.identifier("batchParallel")), [
|
|
1315
|
+
t7.callExpression(t7.memberExpression(t7.cloneNode(array, true), t7.identifier("map")), [
|
|
1316
|
+
payloadMapper
|
|
1317
|
+
]),
|
|
1318
|
+
t7.stringLiteral(methodId)
|
|
1319
|
+
]));
|
|
1320
|
+
const resultsDeclaration = t7.variableDeclaration("const", [
|
|
1321
|
+
t7.variableDeclarator(t7.identifier(resultsVar), batchCall)
|
|
1322
|
+
]);
|
|
1323
|
+
const reconstructCall = t7.callExpression(t7.memberExpression(t7.cloneNode(array, true), t7.identifier("map")), [
|
|
1324
|
+
reconstructMapper
|
|
1325
|
+
]);
|
|
1326
|
+
const iife = t7.callExpression(t7.arrowFunctionExpression([], t7.blockStatement([
|
|
1327
|
+
resultsDeclaration,
|
|
1328
|
+
t7.returnStatement(reconstructCall)
|
|
1329
|
+
]), true), []);
|
|
1330
|
+
const awaitIife = t7.awaitExpression(iife);
|
|
1331
|
+
path.replaceWith(awaitIife);
|
|
1332
|
+
onTransform();
|
|
1333
|
+
return true;
|
|
1334
|
+
}
|
|
1335
|
+
__name(transformToBatchWithReconstruction, "transformToBatchWithReconstruction");
|
|
1227
1336
|
|
|
1228
1337
|
// src/transformer/array-transformer.ts
|
|
1229
1338
|
var ArrayTransformer = class {
|
|
@@ -1250,6 +1359,19 @@ var ArrayTransformer = class {
|
|
|
1250
1359
|
return false;
|
|
1251
1360
|
}
|
|
1252
1361
|
const batchResult = this.batchOptimizer.canBatchArrayMethod(callback);
|
|
1362
|
+
if (!batchResult.canBatch && methodName === "map") {
|
|
1363
|
+
const reason = batchResult.reason || "";
|
|
1364
|
+
const hasObjectOrArrayReturn = reason.includes("object expression") || reason.includes("array expression");
|
|
1365
|
+
if (hasObjectOrArrayReturn) {
|
|
1366
|
+
const llmCall = findLLMCallExpression(callback.body);
|
|
1367
|
+
if (llmCall) {
|
|
1368
|
+
const success = transformToBatchWithReconstruction(path, node, methodName, callback, this.batchDetector, () => this.transformCount++);
|
|
1369
|
+
if (success) {
|
|
1370
|
+
return true;
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1253
1375
|
if (batchResult.canBatch && canUseBatchParallel(methodName)) {
|
|
1254
1376
|
const array = node.callee.object;
|
|
1255
1377
|
const decision = this.batchOptimizer.makeSmartBatchDecision(methodName, batchResult, array, this.batchSizeThreshold);
|
|
@@ -1553,7 +1675,7 @@ function isTransformationError(error) {
|
|
|
1553
1675
|
__name(isTransformationError, "isTransformationError");
|
|
1554
1676
|
|
|
1555
1677
|
// src/transformer/index.ts
|
|
1556
|
-
var
|
|
1678
|
+
var traverse3 = _traverse.default || _traverse;
|
|
1557
1679
|
var generate = _generate.default || _generate;
|
|
1558
1680
|
var ATPCompiler = class {
|
|
1559
1681
|
static {
|
|
@@ -1605,7 +1727,7 @@ var ATPCompiler = class {
|
|
|
1605
1727
|
this.loopTransformer.resetTransformCount();
|
|
1606
1728
|
this.arrayTransformer.resetTransformCount();
|
|
1607
1729
|
this.promiseTransformer.resetTransformCount();
|
|
1608
|
-
|
|
1730
|
+
traverse3(ast, {
|
|
1609
1731
|
ForOfStatement: /* @__PURE__ */ __name((path) => {
|
|
1610
1732
|
this.loopTransformer.transformForOfLoop(path);
|
|
1611
1733
|
}, "ForOfStatement"),
|
|
@@ -2288,7 +2410,7 @@ function createTransformPlugin(config) {
|
|
|
2288
2410
|
};
|
|
2289
2411
|
}
|
|
2290
2412
|
__name(createTransformPlugin, "createTransformPlugin");
|
|
2291
|
-
var
|
|
2413
|
+
var traverse4 = _traverse.default || _traverse;
|
|
2292
2414
|
var generate2 = _generate.default || _generate;
|
|
2293
2415
|
var PluggableCompiler = class {
|
|
2294
2416
|
static {
|
|
@@ -2409,7 +2531,7 @@ var PluggableCompiler = class {
|
|
|
2409
2531
|
}
|
|
2410
2532
|
}
|
|
2411
2533
|
}
|
|
2412
|
-
|
|
2534
|
+
traverse4(ast, visitors);
|
|
2413
2535
|
let optimizedAst = ast;
|
|
2414
2536
|
const optimizers = this.registry.getOptimizers();
|
|
2415
2537
|
for (const optimizer of optimizers) {
|
|
@@ -2801,7 +2923,7 @@ var AsyncTimeoutPlugin = class {
|
|
|
2801
2923
|
return null;
|
|
2802
2924
|
}
|
|
2803
2925
|
};
|
|
2804
|
-
var
|
|
2926
|
+
var traverse5 = _traverse.default || _traverse;
|
|
2805
2927
|
var SecurityValidatorPlugin = class {
|
|
2806
2928
|
static {
|
|
2807
2929
|
__name(this, "SecurityValidatorPlugin");
|
|
@@ -2838,7 +2960,7 @@ var SecurityValidatorPlugin = class {
|
|
|
2838
2960
|
}
|
|
2839
2961
|
let maxNestingFound = 0;
|
|
2840
2962
|
let complexityScore = 0;
|
|
2841
|
-
|
|
2963
|
+
traverse5(ast, {
|
|
2842
2964
|
enter(path) {
|
|
2843
2965
|
const depth = path.scope.path.node ? getDepth(path) : 0;
|
|
2844
2966
|
maxNestingFound = Math.max(maxNestingFound, depth);
|
|
@@ -2885,6 +3007,6 @@ function getDepth(path) {
|
|
|
2885
3007
|
}
|
|
2886
3008
|
__name(getDepth, "getDepth");
|
|
2887
3009
|
|
|
2888
|
-
export { ATPCompiler, ArrayTransformer, AsyncIterationDetector, AsyncTimeoutPlugin, BatchOptimizer, BatchParallelDetector, BatchPauseExecutionError, CheckpointError, CheckpointManager, CheckpointOperation, DEFAULT_COMPILER_CONFIG, DefaultArrayTransformerPlugin, DefaultDetectionPlugin, DefaultLoopTransformerPlugin, DefaultPromiseTransformerPlugin, IN_ISOLATE_RUNTIME_FUNCTIONS, InfiniteLoopDetectionError, LoopTransformer, PAUSABLE_CALL_PATTERNS, PluggableCompiler, PluginRegistry, PromiseTransformer, RuntimeFunction, SecurityValidationError, SecurityValidatorPlugin, TransformationError, batchParallel, cleanupRuntime, clearCheckpointManager, clearRuntimeContext, containsAwait, containsPausableCall, createDefaultCompiler, createRuntimeCall, createTransformPlugin, extractForOfParamName, generateUniqueId, getCheckpointManager, getMemberExpressionPath, getNodeLocation, getRuntimeContext, hasCheckpointManager, hasRuntimeContext, initializeRuntime, isArrayMethod, isAsyncFunction, isBatchPauseError, isCheckpointError, isCompiler, isInIsolateRuntimeFunction, isPausableCall, isPausableCallExpression, isTransformationError, resetIdCounter, resumableEvery, resumableFilter, resumableFind, resumableFlatMap, resumableForEach, resumableForLoop, resumableForOf, resumableMap, resumablePromiseAll, resumablePromiseAllSettled, resumableReduce, resumableSome, resumableWhile, setCheckpointManager, setRuntimeContext, wrapInAsyncFunction };
|
|
3010
|
+
export { ATPCompiler, ArrayTransformer, AsyncIterationDetector, AsyncTimeoutPlugin, BatchOptimizer, BatchParallelDetector, BatchPauseExecutionError, CheckpointError, CheckpointManager, CheckpointOperation, DEFAULT_COMPILER_CONFIG, DefaultArrayTransformerPlugin, DefaultDetectionPlugin, DefaultLoopTransformerPlugin, DefaultPromiseTransformerPlugin, IN_ISOLATE_RUNTIME_FUNCTIONS, InfiniteLoopDetectionError, LoopTransformer, PAUSABLE_CALL_PATTERNS, PluggableCompiler, PluginRegistry, PromiseTransformer, RuntimeFunction, SecurityValidationError, SecurityValidatorPlugin, TransformationError, batchParallel, cleanupRuntime, clearCheckpointManager, clearRuntimeContext, containsAwait, containsPausableCall, createDefaultCompiler, createRuntimeCall, createTransformPlugin, extractForOfParamName, generateUniqueId, getCheckpointManager, getMemberExpressionPath, getNodeLocation, getRuntimeContext, hasCheckpointManager, hasRuntimeContext, initializeRuntime, isArrayMethod, isAsyncFunction, isBatchPauseError, isCheckpointError, isCompiler, isInIsolateRuntimeFunction, isPausableCall, isPausableCallExpression, isTransformationError, resetIdCounter, resumableEvery, resumableFilter, resumableFind, resumableFlatMap, resumableForEach, resumableForLoop, resumableForOf, resumableMap, resumablePromiseAll, resumablePromiseAllSettled, resumableReduce, resumableSome, resumableWhile, setCheckpointManager, setRuntimeContext, transformToBatchWithReconstruction, wrapInAsyncFunction };
|
|
2889
3011
|
//# sourceMappingURL=index.js.map
|
|
2890
3012
|
//# sourceMappingURL=index.js.map
|