Skip to content

Commit

Permalink
Enforce styling
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad committed Apr 20, 2024
1 parent c0b79d4 commit 34144d6
Show file tree
Hide file tree
Showing 56 changed files with 1,087 additions and 828 deletions.
76 changes: 73 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,79 @@ module.exports = {
],
"@typescript-eslint/no-unsafe-declaration-merging": "warn",
"@typescript-eslint/no-var-requires": "warn",
"semi": "error",
"array-bracket-newline": ["warn", {
"multiline": true
}],
"array-bracket-spacing": ["warn", "never"],
"array-element-newline": ["warn", "consistent"],
"arrow-spacing": "warn",
"block-spacing": ["warn", "always"],
"brace-style": ["warn", "1tbs"],
//"camelcase": ["warn"],
"comma-spacing": "warn",
"comma-dangle": ["warn", {
"functions": "never",
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline"
}],
"constructor-super": "warn",
"curly": ["warn", "multi-or-nest", "consistent"],
"eol-last": "warn",
"eqeqeq": "warn",
"func-call-spacing": ["warn", "never"],
"function-paren-newline": ["warn", "consistent"],
"implicit-arrow-linebreak": ["warn", "beside"],
"indent": ["warn", 4, {
"SwitchCase": 1
}],
"lines-between-class-members": "off",
"max-len": ["warn", {
"code": 80,
"ignoreComments": false,
"ignoreTrailingComments": false,
"ignoreUrls": true,
"ignoreStrings": false,
"ignoreTemplateLiterals": true,
"ignoreRegExpLiterals": true
}],
"no-case-declarations": "off",
"no-empty": "off",
"no-fallthrough": "off",
"no-throw-literal": "warn",
"no-trailing-spaces": "warn",
"no-undef": "off",
"no-unused-vars": "off",
"no-useless-escape": "off",
"no-multiple-empty-lines": "warn",
"no-nested-ternary": "warn",
"no-var": "warn",
"no-whitespace-before-property": "warn",
"new-parens": ["warn", "always"],
"nonblock-statement-body-position": ["warn", "below"],
"object-curly-newline": ["warn", {
"consistent": true
}],
"object-curly-spacing": ["warn", "always"],
"object-property-newline": ["warn", {
"allowMultiplePropertiesPerLine": true,
}],
"operator-linebreak": ["warn", "after"],
"padded-blocks": ["warn", {
"blocks": "never",
"classes": "always",
"switches": "never"
}],
"prefer-arrow-callback": "error",
"no-empty": "off",
}
"quotes": ["warn", "single"],
"semi": "error",
"space-before-blocks": ["warn", "always"],
"space-before-function-paren": ["warn", {
"anonymous": "always",
"named": "never",
"asyncArrow": "always"
}],
"space-in-parens": ["warn", "never"],
},
};
7 changes: 5 additions & 2 deletions src/layouter/graphlib/algorithms/components.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved.

import { DiGraph } from '../di_graph';

export function* stronglyConnectedComponents(
Expand Down Expand Up @@ -33,14 +35,15 @@ export function* stronglyConnectedComponents(
lowlink.set(v, preorder.get(v)!);
for (const w of g.neighborsIter(v)) {
if (!sccFound.has(w)) {
if (preorder.get(w)! > preorder.get(v)!)
if (preorder.get(w)! > preorder.get(v)!) {
lowlink.set(v, Math.min(
lowlink.get(v)!, lowlink.get(w)!
));
else
} else {
lowlink.set(v, Math.min(
lowlink.get(v)!, preorder.get(w)!
));
}
}
}
queue.pop();
Expand Down
11 changes: 8 additions & 3 deletions src/layouter/graphlib/algorithms/cycles.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved.

import { DiGraph } from '../di_graph';
import { stronglyConnectedComponents } from './components';

Expand Down Expand Up @@ -34,7 +36,6 @@ export class NodeCycle<NodeT> {
export function* simpleCycles(
g: DiGraph<unknown, unknown>
): Generator<[string[], [string, string][]]> {

function _unblock(
thisnode: string, blocked: Set<string>, B: Map<string, Set<string>>
): void {
Expand All @@ -54,9 +55,10 @@ export function* simpleCycles(

const subGraph = g.copy();
const sccs: Set<string>[] = [];
for (const scc of stronglyConnectedComponents(subGraph))
for (const scc of stronglyConnectedComponents(subGraph)) {
if (scc.size > 1)
sccs.push(scc);
}

for (const node of subGraph.nodes()) {
const selfEdge: [string, string] = [node, node];
Expand All @@ -79,7 +81,10 @@ export function* simpleCycles(
blocked.add(startNode);
const B = new Map<string, Set<string>>();
const stack: [string, string[]][] = [
[startNode, sccGraph.neighbors(startNode)]
[
startNode,
sccGraph.neighbors(startNode),
],
];

while (stack.length > 0) {
Expand Down
2 changes: 2 additions & 0 deletions src/layouter/graphlib/algorithms/dominance.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved.

import { DiGraph } from '../di_graph';
import { dfsPostorderNodes } from './traversal';

Expand Down
8 changes: 7 additions & 1 deletion src/layouter/graphlib/algorithms/traversal.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved.

import { DiGraph } from '../di_graph';

export function* dfsLabeledEdges(
Expand All @@ -19,7 +21,11 @@ export function* dfsLabeledEdges(
yield [start, start, 'forward'];
visited.add(start);
const stack: [string, number, string[]][] = [
[start, depthLimit, graph.successors(start)]
[
start,
depthLimit,
graph.successors(start),
],
];

while (stack.length) {
Expand Down
20 changes: 12 additions & 8 deletions src/layouter/graphlib/di_graph.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved.

import { Graph } from './graph';

export class DiGraph<NodeT, EdgeT> extends Graph<NodeT, EdgeT> {

private pred: Map<string, Map<string, EdgeT | null>> = new Map();
private succ: Map<string, Map<string, EdgeT | null>> = new Map();

public constructor(
name: string = '',
) {
public constructor(name: string = '') {
super(name);
}

Expand Down Expand Up @@ -58,9 +58,10 @@ export class DiGraph<NodeT, EdgeT> extends Graph<NodeT, EdgeT> {
}

public* edgesIter(): Generator<[string, string]> {
for (const [u, neighbors] of this.succ)
for (const [u, neighbors] of this.succ) {
for (const v of neighbors.keys())
yield [u, v];
}
}

public hasEdge(u: string, v: string): boolean {
Expand All @@ -71,9 +72,10 @@ export class DiGraph<NodeT, EdgeT> extends Graph<NodeT, EdgeT> {
id: string, ignoreEdges: [string, string][]
): Generator<string> {
const ignoredTargets = new Set<string>();
for (const ie of ignoreEdges)
if (ie[0] == id)
for (const ie of ignoreEdges) {
if (ie[0] === id)
ignoredTargets.add(ie[1]);
}
for (const v of this.succ.get(id)?.keys() ?? []) {
if (!ignoredTargets.has(v))
yield v;
Expand Down Expand Up @@ -131,19 +133,21 @@ export class DiGraph<NodeT, EdgeT> extends Graph<NodeT, EdgeT> {
}

public* sourcesIter(): Generator<string> {
for (const [id, neighbors] of this.pred)
for (const [id, neighbors] of this.pred) {
if (neighbors.size === 0)
yield id;
}
}

public sinks(): string[] {
return Array.from(this.sinksIter());
}

public* sinksIter(): Generator<string> {
for (const [id, neighbors] of this.succ)
for (const [id, neighbors] of this.succ) {
if (neighbors.size === 0)
yield id;
}
}

public clear(): void {
Expand Down
12 changes: 8 additions & 4 deletions src/layouter/graphlib/graph.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved.

import { GraphI } from './graph_types';

export class Graph<NodeT, EdgeT> implements GraphI<NodeT, EdgeT> {
Expand All @@ -6,7 +8,7 @@ export class Graph<NodeT, EdgeT> implements GraphI<NodeT, EdgeT> {
protected adjacencyList: Map<string, Map<string, EdgeT | null>> = new Map();

public constructor(
public name: string = '',
public name: string = ''
) {
return;
}
Expand Down Expand Up @@ -118,9 +120,10 @@ export class Graph<NodeT, EdgeT> implements GraphI<NodeT, EdgeT> {
public* edgesIter(): Generator<[string, string]> {
const taken = new Set<[string, string]>();
for (const [src, adj] of this.adjacencyList.entries()) {
for (const dst of adj.keys())
for (const dst of adj.keys()) {
if (!taken.has([dst, src]) && !taken.has([src, dst]))
yield [src, dst];
}
}
}

Expand All @@ -136,11 +139,12 @@ export class Graph<NodeT, EdgeT> implements GraphI<NodeT, EdgeT> {

public* adjListIter(): Generator<string | [string, string]> {
for (const [src, adj] of this.adjacencyList.entries()) {
if (adj.size)
if (adj.size) {
for (const dst of adj)
yield [src, dst[0]];
else
} else {
yield src;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/layouter/graphlib/graph_types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved.

export interface GraphI<NodeT, EdgeT> {

get(id: string): NodeT | null;
Expand Down
22 changes: 15 additions & 7 deletions src/layouter/state_machine/sm_layouter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +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';
Expand All @@ -7,6 +9,7 @@ import {
} from '../graphlib/algorithms/dominance';
import { DiGraph } from '../graphlib/di_graph';

/* eslint-disable @typescript-eslint/no-var-requires */
const dagreOrder = require('dagre/lib/order');

const ARTIFICIAL_START = '__smlayouter_artifical_start';
Expand Down Expand Up @@ -220,7 +223,7 @@ export class SMLayouter {
* Add a 'lane' to the left of the laid out graph where all back-edges
* are routed upwards in the vertical layout. Ensures that the number
* of crossings is reduced to a minimum.
*
*
* Note: This operates in-place on the layout graph.
* @see {@link SMLayouter.doRanking}
* @see {@link SMLayouter.normalizeEdges}
Expand Down Expand Up @@ -268,11 +271,12 @@ export class SMLayouter {
if (!routedEdges.has(edgeData))
unrouted.add(edgeData);
}
if (unrouted.size > 0)
if (unrouted.size > 0) {
console.warn(
'The following edges were not routed:',
unrouted
);
}
}

private propagate(
Expand Down Expand Up @@ -312,9 +316,10 @@ export class SMLayouter {
scopes.push([ScopeType.BRANCH, rank, mergeNodeRank]);
}

for (const s of successors)
for (const s of successors) {
if (s !== mergeNode)
q.push([s, rank + 1]);
}
}
}

Expand All @@ -323,12 +328,14 @@ export class SMLayouter {
oNode: string
): void {
let exitCandidates = new Set<string>();
for (const n of successors)
for (const n of successors) {
if (n !== oNode && !this.allDom.get(n)?.has(oNode))
exitCandidates.add(n);
for (const n of this.graph.successorsIter(oNode))
}
for (const n of this.graph.successorsIter(oNode)) {
if (n !== node)
exitCandidates.add(n);
}

if (exitCandidates.size < 1) {
throw new Error('No exit candidates found.');
Expand Down Expand Up @@ -405,11 +412,12 @@ export class SMLayouter {
const successors: string[] = [];
for (const s of this.graph.successorsIter(node)) {
let foundAsBackedge = false;
for (const sBe of this.backedgesCombined)
for (const sBe of this.backedgesCombined) {
if (sBe[1] === s && sBe[0] === node) {
foundAsBackedge = true;
break;
}
}
if (!foundAsBackedge)
successors.push(s);
}
Expand Down Expand Up @@ -522,7 +530,7 @@ export class SMLayouter {

// If the edge spans only one rank or is within the same rank,
// nothing needs to be done.
if (srcRank === dstRank - 1 || srcRank == dstRank)
if (srcRank === dstRank - 1 || srcRank === dstRank)
continue;

// We also don't want to handle back edges here.
Expand Down
Loading

0 comments on commit 34144d6

Please sign in to comment.