From c0c7657c370f3ca9dc04494b24cb026c2d944db6 Mon Sep 17 00:00:00 2001 From: Philipp Schaad Date: Mon, 14 Oct 2024 16:56:59 +0200 Subject: [PATCH 1/2] Fix circular class dependencies --- package.json | 2 +- src/index.ts | 96 +------------------ src/layouter/layout.ts | 45 +++++---- src/layouter/state_machine/sm_layouter.ts | 2 +- src/local_view/lview_parser.ts | 3 +- src/overlay_manager.ts | 8 +- src/overlays/avg_parallelism_overlay.ts | 9 +- src/overlays/depth_overlay.ts | 9 +- src/overlays/diff_overlay.ts | 4 +- src/overlays/generic_sdfg_overlay.ts | 7 +- src/overlays/logical_group_overlay.ts | 4 +- src/overlays/memory_location_overlay.ts | 4 +- src/overlays/memory_volume_overlay.ts | 5 +- src/overlays/operational_intensity_overlay.ts | 9 +- src/overlays/runtime_micro_seconds_overlay.ts | 4 +- ...simulated_operational_intensity_overlay.ts | 9 +- src/overlays/static_flops_overlay.ts | 9 +- src/renderer/canvas_manager.ts | 5 +- src/renderer/renderer.ts | 95 +++++++++--------- src/renderer/renderer_elements.ts | 15 ++- src/sdfg_diff_viewer.ts | 24 ++--- src/sdfv.ts | 16 ++-- src/sdfv_ui.ts | 9 +- src/types.ts | 92 ++++++++++++++++++ src/utils/bounding_box.ts | 6 +- src/utils/sdfg/dotgraph.ts | 2 +- src/utils/sdfg/json_serializer.ts | 3 +- src/utils/sdfg/memlet_trees.ts | 4 +- src/utils/sdfg/sdfg_utils.ts | 16 ++-- src/utils/sdfg/traversal.ts | 3 +- src/utils/utils.ts | 2 +- 31 files changed, 252 insertions(+), 269 deletions(-) create mode 100644 src/types.ts diff --git a/package.json b/package.json index 0a158b70..d25944cf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@spcl/sdfv", - "version": "1.3.0", + "version": "1.3.1", "description": "A standalone viewer for SDFGs", "homepage": "https://github.com/spcl/dace-webclient", "main": "out/index.js", diff --git a/src/index.ts b/src/index.ts index fbf84cd9..7385b672 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,5 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { SDFGElement } from './renderer/renderer_elements'; - export * from './overlays/memory_volume_overlay'; export * from './overlays/runtime_micro_seconds_overlay'; export * from './overlays/memory_location_overlay'; @@ -26,96 +24,4 @@ export * from './utils/utils'; export * from './overlay_manager'; export * from './sdfv'; export * from './sdfv_ui'; - -export type SymbolMap = { - [symbol: string]: number | undefined, -}; - -export type DagreGraph = dagre.graphlib.Graph; - -export type InvalidSDFGError = { - message: string | undefined, - sdfg_id: number | undefined, - state_id: number | undefined, - node_id: number | undefined, - edge_id: number | undefined, - isedge_id: number | undefined, -}; - -export interface JsonSDFGElement { - attributes?: any, - type: string, -} - -export interface JsonSDFGEdge extends JsonSDFGElement { - dst: string, - dst_connector: string | null, - src: string, - src_connector: string | null, - height: number, - width: number, - x?: number, - y?: number, -} - -export interface JsonSDFGNode extends JsonSDFGElement { - id: number, - label: string, - scope_entry: string | null, - scope_exit: string | null, -} - -export interface JsonSDFGBlock extends JsonSDFGElement { - collapsed?: boolean, - edges?: JsonSDFGEdge[], - nodes?: (JsonSDFGBlock | JsonSDFGNode)[], - id: number, - label: string, -} - -type CodeBlock = { - string_data: string, - language: string, -}; - -export interface JsonSDFGConditionalBlock extends JsonSDFGBlock { - branches: ([CodeBlock | null, JsonSDFGControlFlowRegion])[]; -} - -export interface JsonSDFGControlFlowRegion extends JsonSDFGBlock { - nodes: JsonSDFGBlock[], - edges: JsonSDFGEdge[], - start_block: number, - cfg_list_id: number, -} - -export interface JsonSDFGState extends JsonSDFGBlock { - scope_dict: any, - nodes: JsonSDFGNode[], - edges: JsonSDFGEdge[], -} - -export interface JsonSDFG extends JsonSDFGControlFlowRegion { - error: InvalidSDFGError | undefined, -} - -export type ModeButtons = { - pan: HTMLElement | null, - move: HTMLElement | null, - select: HTMLElement | null, - add_btns: HTMLElement[], -}; - -export type SDFVTooltipFunc = (container: HTMLElement) => void; - -export type Point2D = { - x: number, - y: number, -}; - -export type Size2D = { - w: number, - h: number, -}; - -export type SimpleRect = Point2D & Size2D; +export * from './types'; diff --git a/src/layouter/layout.ts b/src/layouter/layout.ts index af61cf2a..e746c3a7 100644 --- a/src/layouter/layout.ts +++ b/src/layouter/layout.ts @@ -2,42 +2,45 @@ import dagre from 'dagre'; +import { SDFVSettings } from '../utils/sdfv_settings'; +import { SMLayouter } from './state_machine/sm_layouter'; import { - AccessNode, - calculateBoundingBox, - calculateEdgeBoundingBox, - CFGListType, - check_and_redirect_edge, - ConditionalBlock, - Connector, - ControlFlowRegion, - DagreGraph, - deepCopy, - findExitForEntry, - intersectRect, - InterstateEdge, JsonSDFG, JsonSDFGBlock, - JsonSDFGConditionalBlock, JsonSDFGControlFlowRegion, JsonSDFGEdge, JsonSDFGNode, + Point2D, + Size2D, +} from '../types'; +import { + AccessNode, + ConditionalBlock, + Connector, + ControlFlowRegion, + InterstateEdge, LoopRegion, Memlet, NestedSDFG, - Point2D, ScopeNode, SDFG, - sdfg_property_to_string, SDFGElements, SDFGElementType, SDFGNode, - SDFV, - Size2D, State, -} from '..'; -import { SDFVSettings } from '../utils/sdfv_settings'; -import { SMLayouter } from './state_machine/sm_layouter'; +} from '../renderer/renderer_elements'; +import { sdfg_property_to_string } from '../utils/sdfg/display'; +import { SDFV } from '../sdfv'; +import type { CFGListType, DagreGraph } from '../renderer/renderer'; +import { + check_and_redirect_edge, + findExitForEntry, +} from '../utils/sdfg/sdfg_utils'; +import { + calculateBoundingBox, + calculateEdgeBoundingBox, +} from '../utils/bounding_box'; +import { deepCopy, intersectRect } from '../utils/utils'; type CFGBlockInfoT = { label?: string, diff --git a/src/layouter/state_machine/sm_layouter.ts b/src/layouter/state_machine/sm_layouter.ts index 0b167012..97a4a671 100644 --- a/src/layouter/state_machine/sm_layouter.ts +++ b/src/layouter/state_machine/sm_layouter.ts @@ -1,6 +1,5 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { DagreGraph } from '../..'; import * as dagre from 'dagre'; import { allBackedges } from '../graphlib/algorithms/cycles'; import { @@ -8,6 +7,7 @@ import { immediateDominators, } from '../graphlib/algorithms/dominance'; import { DiGraph } from '../graphlib/di_graph'; +import type { DagreGraph } from '../../renderer/renderer'; /* eslint-disable @typescript-eslint/no-var-requires */ const dagreOrder = require('dagre/lib/order'); diff --git a/src/local_view/lview_parser.ts b/src/local_view/lview_parser.ts index 7eb4cf54..75ad6cfe 100644 --- a/src/local_view/lview_parser.ts +++ b/src/local_view/lview_parser.ts @@ -1,7 +1,6 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. import $ from 'jquery'; -import { DagreGraph, JsonSDFG } from '..'; import { AccessNode, Edge, @@ -28,6 +27,8 @@ import { MemoryNode } from './elements/memory_node'; import { Element } from './elements/element'; import { LViewRenderer } from './lview_renderer'; import { evaluate } from 'mathjs'; +import type { DagreGraph } from '../renderer/renderer'; +import { JsonSDFG } from '../types'; export class LViewGraphParseError extends Error {} diff --git a/src/overlay_manager.ts b/src/overlay_manager.ts index a217fd85..902df7df 100644 --- a/src/overlay_manager.ts +++ b/src/overlay_manager.ts @@ -1,15 +1,15 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. import { MathNode, parse, SymbolNode } from 'mathjs'; -import { Point2D, SymbolMap } from './index'; -import { GenericSdfgOverlay } from './overlays/generic_sdfg_overlay'; -import { +import type { GenericSdfgOverlay } from './overlays/generic_sdfg_overlay'; +import type { GraphElementInfo, SDFGElementGroup, SDFGRenderer, } from './renderer/renderer'; -import { SDFGElement } from './renderer/renderer_elements'; +import type { SDFGElement } from './renderer/renderer_elements'; import { createElement } from './utils/utils'; +import { Point2D, SymbolMap } from './types'; export class SymbolResolver { diff --git a/src/overlays/avg_parallelism_overlay.ts b/src/overlays/avg_parallelism_overlay.ts index 1ebd9355..b25371a6 100644 --- a/src/overlays/avg_parallelism_overlay.ts +++ b/src/overlays/avg_parallelism_overlay.ts @@ -1,12 +1,7 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { +import type { DagreGraph, - Point2D, - SymbolMap, - getGraphElementUUID, -} from '../index'; -import { GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -19,6 +14,8 @@ import { SDFGElement, SDFGNode, } from '../renderer/renderer_elements'; +import { Point2D, SymbolMap } from '../types'; +import { getGraphElementUUID } from '../utils/sdfg/sdfg_utils'; import { getTempColorHslString } from '../utils/utils'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; diff --git a/src/overlays/depth_overlay.ts b/src/overlays/depth_overlay.ts index 7d3ebf13..43b9a0c1 100644 --- a/src/overlays/depth_overlay.ts +++ b/src/overlays/depth_overlay.ts @@ -1,12 +1,7 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { +import type { DagreGraph, - Point2D, - SymbolMap, - getGraphElementUUID, -} from '../index'; -import { GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -19,6 +14,8 @@ import { SDFGElement, SDFGNode, } from '../renderer/renderer_elements'; +import { Point2D, SymbolMap } from '../types'; +import { getGraphElementUUID } from '../utils/sdfg/sdfg_utils'; import { getTempColorHslString } from '../utils/utils'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; diff --git a/src/overlays/diff_overlay.ts b/src/overlays/diff_overlay.ts index b9f5071e..4fe3b257 100644 --- a/src/overlays/diff_overlay.ts +++ b/src/overlays/diff_overlay.ts @@ -1,7 +1,6 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { Point2D } from '../index'; -import { +import type { GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -13,6 +12,7 @@ import { ControlFlowBlock, } from '../renderer/renderer_elements'; import { DiffMap } from '../sdfg_diff_viewer'; +import { Point2D } from '../types'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; export class DiffOverlay extends GenericSdfgOverlay { diff --git a/src/overlays/generic_sdfg_overlay.ts b/src/overlays/generic_sdfg_overlay.ts index 9b509018..25c7ecaa 100644 --- a/src/overlays/generic_sdfg_overlay.ts +++ b/src/overlays/generic_sdfg_overlay.ts @@ -1,12 +1,14 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. import { log, mean, median } from 'mathjs'; -import { DagreGraph, OverlayManager, Point2D, SDFVSettings, SimpleRect, SymbolResolver } from '../index'; -import { +import type { + DagreGraph, GraphElementInfo, SDFGElementGroup, SDFGRenderer, } from '../renderer/renderer'; +import { OverlayManager, SymbolResolver } from '../overlay_manager'; +import { SDFVSettings } from '../utils/sdfv_settings'; import { ConditionalBlock, ControlFlowBlock, @@ -17,6 +19,7 @@ import { SDFGNode, State, } from '../renderer/renderer_elements'; +import { Point2D, SimpleRect } from '../types'; declare const vscode: any; diff --git a/src/overlays/logical_group_overlay.ts b/src/overlays/logical_group_overlay.ts index 07e053fc..0da209d4 100644 --- a/src/overlays/logical_group_overlay.ts +++ b/src/overlays/logical_group_overlay.ts @@ -1,7 +1,6 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { Point2D } from '../index'; -import { +import type { GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -13,6 +12,7 @@ import { ControlFlowBlock, Edge, } from '../renderer/renderer_elements'; +import { Point2D } from '../types'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; export type LogicalGroup = { diff --git a/src/overlays/memory_location_overlay.ts b/src/overlays/memory_location_overlay.ts index fe564426..cdf48257 100644 --- a/src/overlays/memory_location_overlay.ts +++ b/src/overlays/memory_location_overlay.ts @@ -1,7 +1,6 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { Point2D } from '../index'; -import { +import type { GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -11,6 +10,7 @@ import { SDFGElement, SDFGNode, } from '../renderer/renderer_elements'; +import { Point2D } from '../types'; import { KELLY_COLORS } from '../utils/utils'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; diff --git a/src/overlays/memory_volume_overlay.ts b/src/overlays/memory_volume_overlay.ts index 7bbeb17a..8c94a61f 100644 --- a/src/overlays/memory_volume_overlay.ts +++ b/src/overlays/memory_volume_overlay.ts @@ -1,7 +1,7 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { DagreGraph, Point2D, SymbolMap } from '../index'; -import { +import type { + DagreGraph, GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -15,6 +15,7 @@ import { SDFGElement, State, } from '../renderer/renderer_elements'; +import { Point2D, SymbolMap } from '../types'; import { getTempColorHslString } from '../utils/utils'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; diff --git a/src/overlays/operational_intensity_overlay.ts b/src/overlays/operational_intensity_overlay.ts index 3796d2f7..daf37fd0 100644 --- a/src/overlays/operational_intensity_overlay.ts +++ b/src/overlays/operational_intensity_overlay.ts @@ -1,12 +1,7 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { +import type { DagreGraph, - Point2D, - SymbolMap, - getGraphElementUUID, -} from '../index'; -import { GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -19,6 +14,8 @@ import { SDFGElement, SDFGNode, } from '../renderer/renderer_elements'; +import { Point2D, SymbolMap } from '../types'; +import { getGraphElementUUID } from '../utils/sdfg/sdfg_utils'; import { getTempColorHslString } from '../utils/utils'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; diff --git a/src/overlays/runtime_micro_seconds_overlay.ts b/src/overlays/runtime_micro_seconds_overlay.ts index 55570162..93245e13 100644 --- a/src/overlays/runtime_micro_seconds_overlay.ts +++ b/src/overlays/runtime_micro_seconds_overlay.ts @@ -1,13 +1,13 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { getGraphElementUUID } from '../index'; -import { SDFGRenderer } from '../renderer/renderer'; +import type { SDFGRenderer } from '../renderer/renderer'; import { ControlFlowBlock, SDFGElement, SDFGNode, } from '../renderer/renderer_elements'; import { getTempColorHslString } from '../utils/utils'; +import { getGraphElementUUID } from '../utils/sdfg/sdfg_utils'; import { GenericSdfgOverlay, OverlayType, diff --git a/src/overlays/simulated_operational_intensity_overlay.ts b/src/overlays/simulated_operational_intensity_overlay.ts index dc8a8542..407d8a2e 100644 --- a/src/overlays/simulated_operational_intensity_overlay.ts +++ b/src/overlays/simulated_operational_intensity_overlay.ts @@ -1,12 +1,7 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { +import type { DagreGraph, - Point2D, - SymbolMap, - getGraphElementUUID, -} from '../index'; -import { GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -19,6 +14,8 @@ import { SDFGElement, SDFGNode, } from '../renderer/renderer_elements'; +import { Point2D, SymbolMap } from '../types'; +import { getGraphElementUUID } from '../utils/sdfg/sdfg_utils'; import { getTempColorHslString } from '../utils/utils'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; diff --git a/src/overlays/static_flops_overlay.ts b/src/overlays/static_flops_overlay.ts index 903d1eb0..8adaa2aa 100644 --- a/src/overlays/static_flops_overlay.ts +++ b/src/overlays/static_flops_overlay.ts @@ -1,12 +1,7 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { +import type { DagreGraph, - Point2D, - SymbolMap, - getGraphElementUUID, -} from '../index'; -import { GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -19,6 +14,8 @@ import { SDFGElement, SDFGNode, } from '../renderer/renderer_elements'; +import { Point2D, SymbolMap } from '../types'; +import { getGraphElementUUID } from '../utils/sdfg/sdfg_utils'; import { getTempColorHslString } from '../utils/utils'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; diff --git a/src/renderer/canvas_manager.ts b/src/renderer/canvas_manager.ts index 7ad1b26c..541df465 100644 --- a/src/renderer/canvas_manager.ts +++ b/src/renderer/canvas_manager.ts @@ -14,8 +14,9 @@ import { getPositioningInfo, initialize_positioning_info, } from '../utils/sdfg/sdfg_utils'; -import { SDFGRenderer, CFGListType } from './renderer'; -import { DagreGraph, intersectRect, Point2D } from '../index'; +import type { SDFGRenderer, CFGListType, DagreGraph } from './renderer'; +import { Point2D } from '../types'; +import { intersectRect } from '../utils/utils'; const animation_duration = 1000; diff --git a/src/renderer/renderer.ts b/src/renderer/renderer.ts index 2f8d4b4d..f572483d 100644 --- a/src/renderer/renderer.ts +++ b/src/renderer/renderer.ts @@ -4,26 +4,6 @@ import $ from 'jquery'; import dagre from 'dagre'; import EventEmitter from 'events'; -import { - DagreGraph, - JsonSDFG, - JsonSDFGBlock, - JsonSDFGConditionalBlock, - JsonSDFGControlFlowRegion, - JsonSDFGEdge, - JsonSDFGElement, - JsonSDFGNode, - JsonSDFGState, - MemoryLocationOverlay, - MemoryVolumeOverlay, - ModeButtons, - Point2D, - SDFVTooltipFunc, - SimpleRect, - checkCompatSave, - parse_sdfg, - stringify_sdfg, -} from '../index'; import { LViewLayouter } from '../local_view/lview_layouter'; import { LViewGraphParseError, LViewParser } from '../local_view/lview_parser'; import { LViewRenderer } from '../local_view/lview_renderer'; @@ -61,6 +41,23 @@ import { import { cfgToDotGraph } from '../utils/sdfg/dotgraph'; import { layoutSDFG } from '../layouter/layout'; import { GenericSdfgOverlay } from '../overlays/generic_sdfg_overlay'; +import { + JsonSDFG, + JsonSDFGBlock, + JsonSDFGConditionalBlock, + JsonSDFGControlFlowRegion, + JsonSDFGEdge, + JsonSDFGElement, + JsonSDFGNode, + JsonSDFGState, + ModeButtons, + Point2D, + SDFVTooltipFunc, + SimpleRect, +} from '../types'; +import { MemoryLocationOverlay } from '../overlays/memory_location_overlay'; +import { MemoryVolumeOverlay } from '../overlays/memory_volume_overlay'; +import { checkCompatSave, parse_sdfg, stringify_sdfg } from '../utils/sdfg/json_serializer'; // External, non-typescript libraries which are presented as previously loaded // scripts and global javascript variables: @@ -70,6 +67,8 @@ declare const canvas2pdf: any; // Some global functions and variables which are only accessible within VSCode: declare const vscode: any | null; +export type DagreGraph = dagre.graphlib.Graph; + export type SDFGElementGroup = ( 'states' | 'nodes' | 'edges' | 'isedges' | 'connectors' | 'controlFlowRegions' | 'controlFlowBlocks' @@ -582,7 +581,7 @@ export class SDFGRenderer extends EventEmitter { // Overlays menu. if ((!this.enableMaskUI || - this.enableMaskUI.includes('overlays_menu')) && + this.enableMaskUI.includes('overlays_menu')) && !this.in_vscode) { const overlayDropdown = $('
', { class: 'dropdown', @@ -652,7 +651,7 @@ export class SDFGRenderer extends EventEmitter { role: 'group', }).appendTo(this.toolbar); if (!this.enableMaskUI || - this.enableMaskUI.includes('zoom_to_fit_all')) { + this.enableMaskUI.includes('zoom_to_fit_all')) { // Zoom to fit. $('