parallelize-async-work
ComputerGuy 5 days ago
parent 41eeabaa4b
commit 24164f9a9d

@ -1,6 +1,7 @@
/** @import { Expression, ExpressionStatement, Node, Program } from 'estree' */ /** @import { Expression, ExpressionStatement, Node, Program } from 'estree' */
/** @import { ComponentContext, ParallelizedChunk } from '../types' */ /** @import { ComponentContext, ParallelizedChunk } from '../types' */
import * as b from '#compiler/builders'; import * as b from '#compiler/builders';
import { is_expression_async } from '../../../../utils/ast.js';
import { get_rune } from '../../../scope.js'; import { get_rune } from '../../../scope.js';
import { can_be_parallelized } from '../utils.js'; import { can_be_parallelized } from '../utils.js';
@ -30,6 +31,7 @@ export function ExpressionStatement(node, context) {
} }
if ( if (
node.expression.type === 'AwaitExpression' && node.expression.type === 'AwaitExpression' &&
!is_expression_async(node.expression.argument) &&
context.state.analysis.instance?.scope === context.state.scope context.state.analysis.instance?.scope === context.state.scope
) { ) {
const current_chunk = context.state.current_parallelized_chunk; const current_chunk = context.state.current_parallelized_chunk;

@ -2,7 +2,7 @@
/** @import { Binding } from '#compiler' */ /** @import { Binding } from '#compiler' */
/** @import { ComponentContext, ParallelizedChunk } from '../types' */ /** @import { ComponentContext, ParallelizedChunk } from '../types' */
import { dev, is_ignored, locate_node } from '../../../../state.js'; import { dev, is_ignored, locate_node } from '../../../../state.js';
import { extract_paths } from '../../../../utils/ast.js'; import { extract_paths, is_expression_async } from '../../../../utils/ast.js';
import * as b from '#compiler/builders'; import * as b from '#compiler/builders';
import * as assert from '../../../../utils/assert.js'; import * as assert from '../../../../utils/assert.js';
import { get_rune } from '../../../scope.js'; import { get_rune } from '../../../scope.js';
@ -49,7 +49,8 @@ export function VariableDeclaration(node, context) {
} }
if ( if (
init?.type === 'AwaitExpression' && init?.type === 'AwaitExpression' &&
context.state.analysis.instance?.scope === context.state.scope context.state.analysis.instance?.scope === context.state.scope &&
!is_expression_async(init.argument)
) { ) {
const current_chunk = context.state.current_parallelized_chunk; const current_chunk = context.state.current_parallelized_chunk;
const parallelize = can_be_parallelized( const parallelize = can_be_parallelized(
@ -182,6 +183,7 @@ export function VariableDeclaration(node, context) {
declarator.id.type === 'Identifier' && declarator.id.type === 'Identifier' &&
context.state.analysis.instance?.scope === context.state.scope && context.state.analysis.instance?.scope === context.state.scope &&
value.type === 'AwaitExpression' && value.type === 'AwaitExpression' &&
!is_expression_async(value.argument) &&
can_be_parallelized(value.argument, context.state.scope, context.state.analysis, [ can_be_parallelized(value.argument, context.state.scope, context.state.analysis, [
...(current_chunk?.bindings ?? []), ...(current_chunk?.bindings ?? []),
...bindings ...bindings
@ -317,10 +319,12 @@ export function VariableDeclaration(node, context) {
const current_chunk = context.state.current_parallelized_chunk; const current_chunk = context.state.current_parallelized_chunk;
if ( if (
is_async && is_async &&
init.type === 'AwaitExpression' &&
context.state.analysis.instance && context.state.analysis.instance &&
context.state.scope === context.state.analysis.instance.scope && context.state.scope === context.state.analysis.instance.scope &&
// TODO make it work without this // TODO make it work without this
declarator.id.type === 'Identifier' declarator.id.type === 'Identifier' &&
!is_expression_async(init.argument)
) { ) {
parallelize = can_be_parallelized(value, context.state.scope, context.state.analysis, [ parallelize = can_be_parallelized(value, context.state.scope, context.state.analysis, [
...(current_chunk?.bindings ?? []), ...(current_chunk?.bindings ?? []),

Loading…
Cancel
Save