diff --git a/compiler/forget/src/IR/FuncTopLevel.ts b/compiler/forget/src/IR/FuncTopLevel.ts index c4c70488cb..59aa8f1dcb 100644 --- a/compiler/forget/src/IR/FuncTopLevel.ts +++ b/compiler/forget/src/IR/FuncTopLevel.ts @@ -77,7 +77,10 @@ export class FuncTopLevel { } /** - * All "uses" of {@link Val}. + * All usages. + * - all references to declarations, regardless of the ref kind. + * - all references to expressions. + * - all references to free variables (behind a flag). */ get uses(): Ref[] { return [ @@ -88,16 +91,23 @@ export class FuncTopLevel { } /** - * All mutable uses. This needs to be lazy so it's computed after refinements. + * All usages that are considered potentially mutable (not readonly). */ get mutableUses(): Ref[] { return this.uses.filter((use) => !use.immutable); } /** - * All defs. This needs to be lazy since it depends on {@link mutableUses}. + * All "defs". + * - all declarations + * - all expressions (yea they are immediately defined and referenced) + * - all mutable uses */ get defs(): Val[] { - return [...this.decls, ...this.mutableUses.map((use) => use.val)]; + return [ + ...this.decls, + ...this.refsToExprs.map((use) => use.val), + ...this.mutableUses.map((use) => use.val), + ]; } } diff --git a/compiler/forget/src/MiddleEnd/DepGraphAnalysis.ts b/compiler/forget/src/MiddleEnd/DepGraphAnalysis.ts index 08d406782b..7eba0daa25 100644 --- a/compiler/forget/src/MiddleEnd/DepGraphAnalysis.ts +++ b/compiler/forget/src/MiddleEnd/DepGraphAnalysis.ts @@ -132,8 +132,12 @@ function populateValGraph(valGraph: DepGraph.ValGraph, irFunc: IR.Func) { const basicBlock = cfg.blocks.get(blockId)!; basicBlock.parents.forEach((parent) => { for (const dep of controlDeps) { - for (const use of parent.uses) { - valGraph.getOrCreateVertex(use.val).addDependency(dep); + for (const val of parent.defs) { + invariant( + !IR.isInputVal(val), + "No inputs should be control dependent." + ); + valGraph.getOrCreateVertex(val).addDependency(dep); } } });