Skip to content

Commit

Permalink
fix visit of flow nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
gabritto committed Jan 3, 2024
1 parent ea3fe85 commit 1b7489f
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44241,9 +44241,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const nodeId = getNodeId(container);
if (!queryTypeParameterReferencesCache.has(nodeId)) {
const flowNodes = collectFlowNodes(container); // >> TODO: collectFlowNodes may have duplicates

Check failure on line 44243 in src/compiler/checker.ts

View workflow job for this annotation

GitHub Actions / lint

The generic type arguments should be specified as part of the constructor type arguments
// >> TODO: this will cause us to possibly visit the same flow nodes more than once.
// >> Dedupe work.
flowNodes.forEach(flowNode => visitFlowNode(flowNode, collectNode));
visitFlowNodes(flowNodes, collectNode);
queryTypeParameterReferencesCache.set(nodeId, references);
}
return queryTypeParameterReferencesCache.get(nodeId)!;
Expand Down Expand Up @@ -44431,18 +44429,26 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return !!(flow.flags & (FlowFlags.Assignment | FlowFlags.Condition | FlowFlags.SwitchClause | FlowFlags.ArrayMutation | FlowFlags.Call | FlowFlags.ReduceLabel));
}

function visitFlowNode(flow: FlowNode, visit: (n: FlowNode) => void): void {
visit(flow);
const flags = flow.flags;
if (flags & FlowFlags.Label) {
return (flow as FlowLabel).antecedents?.forEach(f => visitFlowNode(f, visit));
}
if (flags & FlowFlags.ReduceLabel) {
(flow as FlowReduceLabel).antecedents.forEach(f => visitFlowNode(f, visit));
// >> TODO: also visit flow.target?
}
if (hasFlowAntecedent(flow)) {
return visitFlowNode((flow as HasFlowAntecedent).antecedent, visit);
function visitFlowNodes(flowNodes: FlowNode[], visit: (n: FlowNode) => void): void {
const visited = new Set<number>();
flowNodes.forEach(visitFlowNode);
function visitFlowNode(flow: FlowNode): void {
const id = getFlowNodeId(flow);
if (visited.has(id)) return;
visited.add(id);

visit(flow);
const flags = flow.flags;
if (flags & FlowFlags.Label) {
return (flow as FlowLabel).antecedents?.forEach(visitFlowNode);
}
if (flags & FlowFlags.ReduceLabel) {
(flow as FlowReduceLabel).antecedents.forEach(visitFlowNode);
// >> TODO: also visit flow.target?
}
if (hasFlowAntecedent(flow)) {
return visitFlowNode((flow as HasFlowAntecedent).antecedent);
}
}
}

Expand Down

0 comments on commit 1b7489f

Please sign in to comment.