From f091817c9a78b3df5cf626b8a2577daba9987500 Mon Sep 17 00:00:00 2001 From: Ahmed Alshaybani Date: Thu, 5 Nov 2026 23:05:41 +0100 Subject: [PATCH 1/2] Expand each region once during static reachability checks --- lib/static-reachability.ts | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/static-reachability.ts b/lib/static-reachability.ts index 91583446..c98d3097 100644 --- a/lib/static-reachability.ts +++ b/lib/static-reachability.ts @@ -122,31 +122,27 @@ const hasStaticReachabilityPath = ( return false } - const queue: Array<{ portId: PortId; nextRegionId: RegionId }> = [ - { - portId: startPortId, - nextRegionId: startRegionId, - }, - ] + const queue: RegionId[] = [startRegionId] + const seenRegions = new Set(queue) const seenHops = new Set([ startPortId * topology.regionCount + startRegionId, ]) for (let queueIndex = 0; queueIndex < queue.length; queueIndex++) { - const currentCandidate = queue[queueIndex]! + const currentRegionId = queue[queueIndex]! if ( isRegionBlockedForStaticReachability( problem, routeNetId, - currentCandidate.nextRegionId, + currentRegionId, ) ) { continue } for (const neighborPortId of topology.regionIncidentPorts[ - currentCandidate.nextRegionId + currentRegionId ] ?? []) { const assignedNetId = portAssignment[neighborPortId] @@ -165,9 +161,6 @@ const hasStaticReachabilityPath = ( } return true } - if (neighborPortId === currentCandidate.portId) { - continue - } if (assignedNetId !== -1 && assignedNetId !== routeNetId) { continue } @@ -177,7 +170,7 @@ const hasStaticReachabilityPath = ( const incidentRegions = topology.incidentPortRegion[neighborPortId] ?? [] const nextRegionId = - incidentRegions[0] === currentCandidate.nextRegionId + incidentRegions[0] === currentRegionId ? incidentRegions[1] : incidentRegions[0] @@ -197,10 +190,10 @@ const hasStaticReachabilityPath = ( } seenHops.add(hopId) - queue.push({ - portId: neighborPortId, - nextRegionId, - }) + if (!seenRegions.has(nextRegionId)) { + seenRegions.add(nextRegionId) + queue.push(nextRegionId) + } } } From f21e8c7937d416d98180586711decd2468fc2611 Mon Sep 17 00:00:00 2001 From: Ahmed Alshaybani Date: Thu, 5 Nov 2026 23:08:51 +0100 Subject: [PATCH 2/2] Keep bounded reachability behavior unchanged --- lib/static-reachability.ts | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/static-reachability.ts b/lib/static-reachability.ts index c98d3097..42e3aec8 100644 --- a/lib/static-reachability.ts +++ b/lib/static-reachability.ts @@ -122,27 +122,38 @@ const hasStaticReachabilityPath = ( return false } - const queue: RegionId[] = [startRegionId] - const seenRegions = new Set(queue) + const queue: Array<{ portId: PortId; nextRegionId: RegionId }> = [ + { + portId: startPortId, + nextRegionId: startRegionId, + }, + ] const seenHops = new Set([ startPortId * topology.regionCount + startRegionId, ]) + const expandedRegions = new Set() for (let queueIndex = 0; queueIndex < queue.length; queueIndex++) { - const currentRegionId = queue[queueIndex]! + const currentCandidate = queue[queueIndex]! + if (maxPrecheckHops === Number.POSITIVE_INFINITY) { + if (expandedRegions.has(currentCandidate.nextRegionId)) { + continue + } + expandedRegions.add(currentCandidate.nextRegionId) + } if ( isRegionBlockedForStaticReachability( problem, routeNetId, - currentRegionId, + currentCandidate.nextRegionId, ) ) { continue } for (const neighborPortId of topology.regionIncidentPorts[ - currentRegionId + currentCandidate.nextRegionId ] ?? []) { const assignedNetId = portAssignment[neighborPortId] @@ -161,6 +172,9 @@ const hasStaticReachabilityPath = ( } return true } + if (neighborPortId === currentCandidate.portId) { + continue + } if (assignedNetId !== -1 && assignedNetId !== routeNetId) { continue } @@ -170,7 +184,7 @@ const hasStaticReachabilityPath = ( const incidentRegions = topology.incidentPortRegion[neighborPortId] ?? [] const nextRegionId = - incidentRegions[0] === currentRegionId + incidentRegions[0] === currentCandidate.nextRegionId ? incidentRegions[1] : incidentRegions[0] @@ -190,10 +204,10 @@ const hasStaticReachabilityPath = ( } seenHops.add(hopId) - if (!seenRegions.has(nextRegionId)) { - seenRegions.add(nextRegionId) - queue.push(nextRegionId) - } + queue.push({ + portId: neighborPortId, + nextRegionId, + }) } }