From 2f34cfa5884cddde8aca37f57bedab56557ac45f Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sun, 3 Dec 2023 23:05:49 +0100 Subject: [PATCH] suppressCycleWarning --- packages/core/src/runtime/dataflow.ts | 21 ++++++++++++++++++++- packages/ws-relay/src/index.ts | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/core/src/runtime/dataflow.ts b/packages/core/src/runtime/dataflow.ts index 5176bce..db2447d 100644 --- a/packages/core/src/runtime/dataflow.ts +++ b/packages/core/src/runtime/dataflow.ts @@ -10,6 +10,7 @@ import * as MapSet from './mapset.js'; export interface ObservingGraph { recordObservation(objectId: ObjectId): void; recordDamage(objectId: ObjectId): void; + suppressCycleWarning(objectId: ObjectId): void; } export class Graph implements ObservingGraph { @@ -17,6 +18,7 @@ export class Graph implements ObservingGraph { readonly edgesReverse: FlexMap>; damagedNodes: FlexSet; currentSubjectId: SubjectId | undefined; + cyclicWarningSuppressed: FlexSet | undefined; constructor( public readonly subjectIdCanonicalizer: Canonicalizer, @@ -65,13 +67,26 @@ export class Graph implements ObservingGraph { 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) { let repairedThisRound = new FlexSet(this.objectIdCanonicalizer); + let suppressed = new FlexSet(this.objectIdCanonicalizer); while (true) { + if (this.cyclicWarningSuppressed !== void 0) { + suppressed = suppressed.union(this.cyclicWarningSuppressed); + this.cyclicWarningSuppressed = void 0; + } + let workSet = this.damagedNodes; this.damagedNodes = new FlexSet(this.objectIdCanonicalizer); - const alreadyDamaged = workSet.intersect(repairedThisRound); + const alreadyDamaged = workSet.intersect(repairedThisRound).subtract(suppressed); if (alreadyDamaged.size > 0) { console.warn('Cyclic dependencies involving', this.formatCycle(alreadyDamaged)); } @@ -105,6 +120,10 @@ export abstract class Cell { this.__value = initial; } + suppressCycleWarning() { + this.graph.suppressCycleWarning(this); + } + observe(): unknown { this.graph.recordObservation(this); return this.__value; diff --git a/packages/ws-relay/src/index.ts b/packages/ws-relay/src/index.ts index 95b6b3f..420ad83 100644 --- a/packages/ws-relay/src/index.ts +++ b/packages/ws-relay/src/index.ts @@ -153,6 +153,7 @@ export function boot(ds = Dataspace.global, debug: boolean = false, WebSocketCon field best: TransportState | null = null; field rootPeer: Ref | null = null; dataflow { + best.suppressCycleWarning(); best.value = null; for (const c of candidates.value) { best.value = c;