Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ export type LoggerEvent =
| CompileDiagnosticEvent
| CompileSkipEvent
| PipelineErrorEvent
| TimingEvent;
| TimingEvent
| AutoDepsDecorations;

export type CompileErrorEvent = {
kind: 'CompileError';
Expand Down Expand Up @@ -219,6 +220,11 @@ export type TimingEvent = {
kind: 'Timing';
measurement: PerformanceMeasure;
};
export type AutoDepsDecorations = {
kind: 'AutoDepsDecorations';
useEffectCallExpr: t.SourceLocation | null;
decorations: Array<t.SourceLocation | null>;
};

export type Logger = {
logEvent: (filename: string | null, event: LoggerEvent) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ function runWithEnvironment(

if (env.config.inferEffectDependencies) {
inferEffectDependencies(hir);
log({
kind: 'hir',
name: 'InferEffectDependencies',
value: hir,
});
}

if (env.config.inlineJsxTransform) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export function inferEffectDependencies(fn: HIRFunction): void {
* the `infer-effect-deps/pruned-nonreactive-obj` fixture for an
* explanation.
*/
const usedDeps = [];
for (const dep of scopeInfo.deps) {
if (
((isUseRefType(dep.identifier) ||
Expand All @@ -207,8 +208,19 @@ export function inferEffectDependencies(fn: HIRFunction): void {
);
newInstructions.push(...instructions);
effectDeps.push(place);
usedDeps.push(dep);
}

// For LSP autodeps feature.
fn.env.logger?.logEvent(fn.env.filename, {
kind: 'AutoDepsDecorations',
useEffectCallExpr:
typeof value.loc !== 'symbol' ? value.loc : null,
decorations: collectDepUsages(usedDeps, fnExpr.value).map(loc =>
typeof loc !== 'symbol' ? loc : null,
),
});

newInstructions.push({
id: makeInstructionId(0),
loc: GeneratedSource,
Expand Down Expand Up @@ -340,3 +352,31 @@ function inferReactiveIdentifiers(fn: HIRFunction): Set<IdentifierId> {
}
return reactiveIds;
}

function collectDepUsages(
deps: Array<ReactiveScopeDependency>,
fnExpr: FunctionExpression,
): Array<SourceLocation> {
const identifiers: Map<IdentifierId, ReactiveScopeDependency> = new Map();
const loadedDeps: Set<IdentifierId> = new Set();
const sourceLocations = [];
for (const dep of deps) {
identifiers.set(dep.identifier.id, dep);
}

for (const [, block] of fnExpr.loweredFunc.func.body.blocks) {
for (const instr of block.instructions) {
if (instr.value.kind === 'LoadLocal') {
loadedDeps.add(instr.lvalue.identifier.id);
}
for (const place of eachInstructionOperand(instr)) {
if (loadedDeps.has(place.identifier.id)) {
// TODO(@jbrown215): handle member exprs!!
sourceLocations.push(place.identifier.loc);
}
}
}
}

return sourceLocations;
}
Loading