mirror of
https://github.com/morluto/rea.git
synced 2026-11-13 02:02:36 +00:00
fix(javascript)!: preserve operator influence in semantic traces (#7939)
* fix(javascript)!: preserve operator influence in semantic traces * test(javascript): align semantic influence regressions * style(javascript): format semantic IR * test(javascript): follow literal argument seed influence * fix(javascript): keep one literal node per operator operand Reuse an existing literal for operator influence, and treat TypeScript assertion wrappers as transparent when deciding whether a call result is used. * test(mcp): assert bundle path issues by field compare_bundles reports each relative path as an invalid_format issue instead of one joined diagnostic sentence. * fix(javascript): index operator literals by range and initializer Repeated string operands rescanned every retained literal and every initializer flow. Lookup now uses those indexes, and a 1200-declaration file still projects one literal per operand. * fix(javascript): keep literal and call facts on their own occurrences Operator literals match their own source range, so a nested function does not inherit the enclosing declaration's literal. A direct argument still reaches the call, while the assigned result follows modeled returns. for-loop initializers and updates are discarded call results. * test(javascript): expect conditional operand literals beside binding values A conditional binding keeps one candidate literal per union value and one operator literal per operand token. Those are different facts, so the aggregate payload check counts four nodes and compares literal seeds in query order. * perf(javascript): index call return flows by call site projectCalls filtered every call return for each assigned result. Group those flows once while projecting returns-to-call edges. --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
1 parent
6fa48f201f
commit
5c05eb88e5
24 files changed
+1384
-39
No files matched your search
@@ -14,9 +14,11 @@ import {
|
||||
} from "../../domain/javascript/javascriptSemanticGraphSchemas.js";
|
||||
import type {
|
||||
JavaScriptSemanticCallArgument,
|
||||
JavaScriptSemanticCallReturnFlow,
|
||||
JavaScriptSemanticIr,
|
||||
} from "../../domain/javascript/javascriptSemanticIr.js";
|
||||
import { sourceRangesEqual as rangesEqual } from "../../domain/javascript/javascriptStaticAnalysisHelpers.js";
|
||||
import { javascriptSourceRangeKey } from "../../domain/javascript/javascriptSourceCoordinates.js";
|
||||
import type { JavaScriptApplicationGraph } from "../../domain/javascript/javascriptApplicationGraph.js";
|
||||
import type { JavaScriptArtifactFile } from "../../domain/javascript/javascriptArtifactFiles.js";
|
||||
import {
|
||||
@@ -31,6 +33,7 @@ import {
|
||||
} from "./JavaScriptSemanticGraphDataProjection.js";
|
||||
import { projectSemanticResources } from "./JavaScriptSemanticGraphResourceProjection.js";
|
||||
import { projectSemanticAssignments } from "./JavaScriptSemanticGraphAssignmentProjection.js";
|
||||
import { projectSemanticExpressionInfluence } from "./JavaScriptSemanticGraphExpressionProjection.js";
|
||||
import { projectSemanticObjects } from "./JavaScriptSemanticGraphObjectProjection.js";
|
||||
import { projectSemanticValues } from "./JavaScriptSemanticGraphValueProjection.js";
|
||||
import {
|
||||
@@ -935,6 +938,11 @@ function* projectDefinitionsAndReferences(
|
||||
}
|
||||
|
||||
const projectCalls = (context: FileContext): void => {
|
||||
const expressions = new Set(
|
||||
context.ir.expressionFlows.map((flow) =>
|
||||
javascriptSourceRangeKey(flow.location),
|
||||
),
|
||||
);
|
||||
for (const call of context.ir.callSites) {
|
||||
const callNode = context.callSiteNodes.get(call.callSiteId);
|
||||
if (callNode === undefined) continue;
|
||||
@@ -959,7 +967,40 @@ const projectCalls = (context: FileContext): void => {
|
||||
`${call.callSiteId}\u0000${String(argument.index)}`,
|
||||
argumentNode,
|
||||
);
|
||||
const references = context.referenceNodesWithin(argument.location);
|
||||
if (!argument.spread && Object.hasOwn(argument, "literal"))
|
||||
addRelation(context.state, {
|
||||
source: argumentNode,
|
||||
target: callNode,
|
||||
relation: "influences",
|
||||
resolution: "resolved",
|
||||
});
|
||||
if (
|
||||
call.resolution !== "exact" &&
|
||||
call.resultUsed &&
|
||||
argumentNode !== null
|
||||
)
|
||||
addSemanticGraphUnknown(context.state, {
|
||||
node_id: argumentNode.node_id,
|
||||
family: "data-flow",
|
||||
relation_kinds: ["influences"],
|
||||
reason: "dynamic-call",
|
||||
detail:
|
||||
"The dynamic call's return dependency on this argument is unknown.",
|
||||
candidate_node_ids: [],
|
||||
evidence: unknownSemanticEvidence(context.file, argument.location),
|
||||
});
|
||||
const references =
|
||||
argument.valueExpressionLocation !== null &&
|
||||
expressions.has(
|
||||
javascriptSourceRangeKey(argument.valueExpressionLocation),
|
||||
)
|
||||
? []
|
||||
: context
|
||||
.referenceNodesWithin(argument.location)
|
||||
.filter(
|
||||
(reference) =>
|
||||
reference.function_node_id === callNode.function_node_id,
|
||||
);
|
||||
for (const reference of references)
|
||||
addRelation(context.state, {
|
||||
source: reference,
|
||||
@@ -994,20 +1035,46 @@ const projectCalls = (context: FileContext): void => {
|
||||
resolution: context.callResolutions.get(flow.callSiteId) ?? "candidate",
|
||||
});
|
||||
}
|
||||
for (const flow of context.ir.callReturnFlows)
|
||||
const returnFlowsByCallSite = new Map<
|
||||
string,
|
||||
JavaScriptSemanticCallReturnFlow[]
|
||||
>();
|
||||
for (const flow of context.ir.callReturnFlows) {
|
||||
const grouped = returnFlowsByCallSite.get(flow.callSiteId);
|
||||
if (grouped === undefined)
|
||||
returnFlowsByCallSite.set(flow.callSiteId, [flow]);
|
||||
else grouped.push(flow);
|
||||
addRelation(context.state, {
|
||||
source: context.returnSiteNodes.get(flow.returnSiteId),
|
||||
target: context.callSiteNodes.get(flow.callSiteId),
|
||||
relation: "returns-to-call",
|
||||
resolution: context.callResolutions.get(flow.callSiteId) ?? "candidate",
|
||||
});
|
||||
for (const flow of context.ir.callResultFlows)
|
||||
addRelation(context.state, {
|
||||
source: context.callSiteNodes.get(flow.callSiteId),
|
||||
target: context.bindingNodes.get(flow.bindingId),
|
||||
relation: "aliases",
|
||||
resolution: context.callResolutions.get(flow.callSiteId) ?? "candidate",
|
||||
});
|
||||
}
|
||||
for (const flow of context.ir.callResultFlows) {
|
||||
const resolution =
|
||||
context.callResolutions.get(flow.callSiteId) ?? "candidate";
|
||||
const target = context.bindingNodes.get(flow.bindingId);
|
||||
const returns = returnFlowsByCallSite.get(flow.callSiteId) ?? [];
|
||||
// A literal argument may influence the invocation. The assigned value
|
||||
// comes from modeled returns, so an ignored parameter does not reach it.
|
||||
if (returns.length === 0) {
|
||||
addRelation(context.state, {
|
||||
source: context.callSiteNodes.get(flow.callSiteId),
|
||||
target,
|
||||
relation: "aliases",
|
||||
resolution,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
for (const item of returns)
|
||||
addRelation(context.state, {
|
||||
source: context.returnSiteNodes.get(item.returnSiteId),
|
||||
target,
|
||||
relation: "aliases",
|
||||
resolution,
|
||||
});
|
||||
}
|
||||
projectSemanticReturnValues(context);
|
||||
};
|
||||
|
||||
@@ -1025,6 +1092,14 @@ const createArgumentNode = (
|
||||
? "spread argument"
|
||||
: `argument ${String(argument.index)}`,
|
||||
functionNodeId: callNode.function_node_id,
|
||||
...(!argument.spread && Object.hasOwn(argument, "literal")
|
||||
? {
|
||||
properties: {
|
||||
literal_argument_value: argument.literal ?? null,
|
||||
literal_argument_call_site_node_id: callNode.node_id,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
});
|
||||
|
||||
/** Per-file projection passes, run in this order with a yield between each. */
|
||||
@@ -1035,6 +1110,7 @@ const FILE_PROJECTION_PASSES: readonly ((
|
||||
projectSemanticObjects,
|
||||
projectSemanticAssignments,
|
||||
projectCalls,
|
||||
projectSemanticExpressionInfluence,
|
||||
projectSemanticPromises,
|
||||
projectSemanticEvents,
|
||||
projectSemanticTimers,
|
||||
|
||||
Reference in new issue
Block a user