mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[Fix] Control Dep Should Only Add To Defs
Control dep should only affect how things are invalidated, which are modeled as defs including declarations, writable uses to variables and expressions. Closes #633 commit-id:41bd6fe5
This commit is contained in:
@@ -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<Val>[] {
|
||||
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<Val>[] {
|
||||
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),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user