suppressCycleWarning
This commit is contained in:
parent
4903bc5149
commit
2f34cfa588
|
@ -10,6 +10,7 @@ import * as MapSet from './mapset.js';
|
||||||
export interface ObservingGraph<ObjectId> {
|
export interface ObservingGraph<ObjectId> {
|
||||||
recordObservation(objectId: ObjectId): void;
|
recordObservation(objectId: ObjectId): void;
|
||||||
recordDamage(objectId: ObjectId): void;
|
recordDamage(objectId: ObjectId): void;
|
||||||
|
suppressCycleWarning(objectId: ObjectId): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Graph<SubjectId, ObjectId> implements ObservingGraph<ObjectId> {
|
export class Graph<SubjectId, ObjectId> implements ObservingGraph<ObjectId> {
|
||||||
|
@ -17,6 +18,7 @@ export class Graph<SubjectId, ObjectId> implements ObservingGraph<ObjectId> {
|
||||||
readonly edgesReverse: FlexMap<SubjectId, FlexSet<ObjectId>>;
|
readonly edgesReverse: FlexMap<SubjectId, FlexSet<ObjectId>>;
|
||||||
damagedNodes: FlexSet<ObjectId>;
|
damagedNodes: FlexSet<ObjectId>;
|
||||||
currentSubjectId: SubjectId | undefined;
|
currentSubjectId: SubjectId | undefined;
|
||||||
|
cyclicWarningSuppressed: FlexSet<ObjectId> | undefined;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public readonly subjectIdCanonicalizer: Canonicalizer<SubjectId>,
|
public readonly subjectIdCanonicalizer: Canonicalizer<SubjectId>,
|
||||||
|
@ -65,13 +67,26 @@ export class Graph<SubjectId, ObjectId> implements ObservingGraph<ObjectId> {
|
||||||
return Array.from(subjects);
|
return Array.from(subjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suppressCycleWarning(objectId: ObjectId): void {
|
||||||
|
if (this.cyclicWarningSuppressed === void 0) {
|
||||||
|
this.cyclicWarningSuppressed = new FlexSet(this.objectIdCanonicalizer);
|
||||||
|
}
|
||||||
|
this.cyclicWarningSuppressed.add(objectId);
|
||||||
|
}
|
||||||
|
|
||||||
repairDamage(repairNode: (subjectId: SubjectId) => void) {
|
repairDamage(repairNode: (subjectId: SubjectId) => void) {
|
||||||
let repairedThisRound = new FlexSet(this.objectIdCanonicalizer);
|
let repairedThisRound = new FlexSet(this.objectIdCanonicalizer);
|
||||||
|
let suppressed = new FlexSet(this.objectIdCanonicalizer);
|
||||||
while (true) {
|
while (true) {
|
||||||
|
if (this.cyclicWarningSuppressed !== void 0) {
|
||||||
|
suppressed = suppressed.union(this.cyclicWarningSuppressed);
|
||||||
|
this.cyclicWarningSuppressed = void 0;
|
||||||
|
}
|
||||||
|
|
||||||
let workSet = this.damagedNodes;
|
let workSet = this.damagedNodes;
|
||||||
this.damagedNodes = new FlexSet(this.objectIdCanonicalizer);
|
this.damagedNodes = new FlexSet(this.objectIdCanonicalizer);
|
||||||
|
|
||||||
const alreadyDamaged = workSet.intersect(repairedThisRound);
|
const alreadyDamaged = workSet.intersect(repairedThisRound).subtract(suppressed);
|
||||||
if (alreadyDamaged.size > 0) {
|
if (alreadyDamaged.size > 0) {
|
||||||
console.warn('Cyclic dependencies involving', this.formatCycle(alreadyDamaged));
|
console.warn('Cyclic dependencies involving', this.formatCycle(alreadyDamaged));
|
||||||
}
|
}
|
||||||
|
@ -105,6 +120,10 @@ export abstract class Cell {
|
||||||
this.__value = initial;
|
this.__value = initial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suppressCycleWarning() {
|
||||||
|
this.graph.suppressCycleWarning(this);
|
||||||
|
}
|
||||||
|
|
||||||
observe(): unknown {
|
observe(): unknown {
|
||||||
this.graph.recordObservation(this);
|
this.graph.recordObservation(this);
|
||||||
return this.__value;
|
return this.__value;
|
||||||
|
|
|
@ -153,6 +153,7 @@ export function boot(ds = Dataspace.global, debug: boolean = false, WebSocketCon
|
||||||
field best: TransportState | null = null;
|
field best: TransportState | null = null;
|
||||||
field rootPeer: Ref | null = null;
|
field rootPeer: Ref | null = null;
|
||||||
dataflow {
|
dataflow {
|
||||||
|
best.suppressCycleWarning();
|
||||||
best.value = null;
|
best.value = null;
|
||||||
for (const c of candidates.value) {
|
for (const c of candidates.value) {
|
||||||
best.value = c;
|
best.value = c;
|
||||||
|
|
Loading…
Reference in New Issue