Skip to content

Commit 0c29294

Browse files
committed
fix(compiler): structural shape merge and compound zero-delay recognition
mergeShapes used reference equality (===) for returned-array and returned-object shapes. Each returnShape call allocates a fresh wrapper, so two branches returning the same repacked tuple always failed the check and dropped setter provenance. Add shapesEqual that structurally compares kind, element count + identity, and property map entries. zeroDelayPromise only matched Identifier and direct Promise.resolve/ reject calls. Compound forms—SequenceExpression, ConditionalExpression, LogicalExpression, and nested AwaitExpression—fell through as real yields even though they settle before the next paint. Extend zeroDelayPromise to recurse through those forms, checking each leaf with nonPromise || zeroDelayPromise.
1 parent bda3634 commit 0c29294

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎packages/octane/src/compiler/strong-effects.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,22 @@ export function createStrongEffectPolicy({ ast, analysis, callNames, report }) {
179179
if (node?.type === 'Identifier') {
180180
return depth < 8 && zeroDelayPromise(stableInitOf(node), depth + 1);
181181
}
182+
if (node?.type === 'AwaitExpression')
183+
return nonPromise(node.argument) || zeroDelayPromise(node.argument, depth);
184+
if (node?.type === 'SequenceExpression')
185+
return zeroDelayPromise(node.expressions?.at(-1), depth);
186+
if (node?.type === 'ConditionalExpression') {
187+
return (
188+
(nonPromise(node.consequent) || zeroDelayPromise(node.consequent, depth)) &&
189+
(nonPromise(node.alternate) || zeroDelayPromise(node.alternate, depth))
190+
);
191+
}
192+
if (node?.type === 'LogicalExpression') {
193+
return (
194+
(nonPromise(node.left) || zeroDelayPromise(node.left, depth)) &&
195+
(nonPromise(node.right) || zeroDelayPromise(node.right, depth))
196+
);
197+
}
182198
if (node?.type !== 'CallExpression') return false;
183199
const callee = unwrap(node.callee);
184200
if (callee?.type !== 'MemberExpression' || keyOf(callee.object) !== 'g:Promise') return false;

‎packages/octane/src/compiler/strong-mode.js‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2739,9 +2739,28 @@ export function analyzeStrongMode(ast, source, filename, options = {}) {
27392739
return shapeMember(node, scope);
27402740
}
27412741

2742+
function shapesEqual(a, b) {
2743+
if (a === b) return true;
2744+
if (a == null || b == null || a.kind !== b.kind) return false;
2745+
if (a.kind === 'returned-array') {
2746+
return (
2747+
a.elements.length === b.elements.length &&
2748+
a.elements.every((element, index) => element === b.elements[index])
2749+
);
2750+
}
2751+
if (a.kind === 'returned-object') {
2752+
if (a.properties.size !== b.properties.size) return false;
2753+
for (const [key, value] of a.properties) {
2754+
if (b.properties.get(key) !== value) return false;
2755+
}
2756+
return true;
2757+
}
2758+
return false;
2759+
}
2760+
27422761
function mergeShapes(shapes) {
27432762
const [first] = shapes;
2744-
return first != null && shapes.every((shape) => shape === first) ? first : null;
2763+
return first != null && shapes.every((shape) => shapesEqual(shape, first)) ? first : null;
27452764
}
27462765

27472766
function bindReturnedShape(pattern, shape, bind) {

0 commit comments

Comments
 (0)