@nowline/core 0.8.6 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/convert/printer.d.ts.map +1 -1
- package/dist/convert/printer.js +20 -9
- package/dist/convert/printer.js.map +1 -1
- package/dist/convert/schema.d.ts +7 -0
- package/dist/convert/schema.d.ts.map +1 -1
- package/dist/convert/schema.js +1 -1
- package/dist/convert/schema.js.map +1 -1
- package/dist/generated/ast.d.ts +134 -24
- package/dist/generated/ast.d.ts.map +1 -1
- package/dist/generated/ast.js +95 -3
- package/dist/generated/ast.js.map +1 -1
- package/dist/generated/grammar.d.ts.map +1 -1
- package/dist/generated/grammar.js +434 -148
- package/dist/generated/grammar.js.map +1 -1
- package/dist/i18n/codes.d.ts +1 -1
- package/dist/i18n/codes.d.ts.map +1 -1
- package/dist/i18n/codes.js +44 -1
- package/dist/i18n/codes.js.map +1 -1
- package/dist/i18n/index.d.ts +1 -0
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/messages.en.d.ts +107 -0
- package/dist/i18n/messages.en.d.ts.map +1 -1
- package/dist/i18n/messages.en.js +220 -1
- package/dist/i18n/messages.en.js.map +1 -1
- package/dist/i18n/messages.fr.d.ts.map +1 -1
- package/dist/i18n/messages.fr.js +250 -1
- package/dist/i18n/messages.fr.js.map +1 -1
- package/dist/i18n/wave-message-types.d.ts +238 -0
- package/dist/i18n/wave-message-types.d.ts.map +1 -0
- package/dist/i18n/wave-message-types.js +11 -0
- package/dist/i18n/wave-message-types.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +6 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +9 -0
- package/dist/internal.js.map +1 -0
- package/dist/language/ast-walk.d.ts +31 -0
- package/dist/language/ast-walk.d.ts.map +1 -0
- package/dist/language/ast-walk.js +109 -0
- package/dist/language/ast-walk.js.map +1 -0
- package/dist/language/calendar-declarations.d.ts +31 -0
- package/dist/language/calendar-declarations.d.ts.map +1 -0
- package/dist/language/calendar-declarations.js +99 -0
- package/dist/language/calendar-declarations.js.map +1 -0
- package/dist/language/include-references.d.ts +11 -0
- package/dist/language/include-references.d.ts.map +1 -0
- package/dist/language/include-references.js +45 -0
- package/dist/language/include-references.js.map +1 -0
- package/dist/language/include-resolver.d.ts +78 -1
- package/dist/language/include-resolver.d.ts.map +1 -1
- package/dist/language/include-resolver.js +190 -12
- package/dist/language/include-resolver.js.map +1 -1
- package/dist/language/include-waves.d.ts +73 -0
- package/dist/language/include-waves.d.ts.map +1 -0
- package/dist/language/include-waves.js +319 -0
- package/dist/language/include-waves.js.map +1 -0
- package/dist/language/nowline-validator.d.ts +6 -1
- package/dist/language/nowline-validator.d.ts.map +1 -1
- package/dist/language/nowline-validator.js +95 -1589
- package/dist/language/nowline-validator.js.map +1 -1
- package/dist/language/references.d.ts +14 -0
- package/dist/language/references.d.ts.map +1 -0
- package/dist/language/references.js +36 -0
- package/dist/language/references.js.map +1 -0
- package/dist/language/style-chain.d.ts +37 -0
- package/dist/language/style-chain.d.ts.map +1 -0
- package/dist/language/style-chain.js +55 -0
- package/dist/language/style-chain.js.map +1 -0
- package/dist/language/validator/calendar.d.ts +9 -0
- package/dist/language/validator/calendar.d.ts.map +1 -0
- package/dist/language/validator/calendar.js +250 -0
- package/dist/language/validator/calendar.js.map +1 -0
- package/dist/language/validator/entities.d.ts +23 -0
- package/dist/language/validator/entities.d.ts.map +1 -0
- package/dist/language/validator/entities.js +261 -0
- package/dist/language/validator/entities.js.map +1 -0
- package/dist/language/validator/properties.d.ts +18 -0
- package/dist/language/validator/properties.d.ts.map +1 -0
- package/dist/language/validator/properties.js +356 -0
- package/dist/language/validator/properties.js.map +1 -0
- package/dist/language/validator/references.d.ts +7 -0
- package/dist/language/validator/references.d.ts.map +1 -0
- package/dist/language/validator/references.js +261 -0
- package/dist/language/validator/references.js.map +1 -0
- package/dist/language/validator/structure.d.ts +16 -0
- package/dist/language/validator/structure.d.ts.map +1 -0
- package/dist/language/validator/structure.js +166 -0
- package/dist/language/validator/structure.js.map +1 -0
- package/dist/language/validator/style.d.ts +5 -0
- package/dist/language/validator/style.d.ts.map +1 -0
- package/dist/language/validator/style.js +126 -0
- package/dist/language/validator/style.js.map +1 -0
- package/dist/language/validator/support.d.ts +35 -0
- package/dist/language/validator/support.d.ts.map +1 -0
- package/dist/language/validator/support.js +49 -0
- package/dist/language/validator/support.js.map +1 -0
- package/dist/language/validator/symbols.d.ts +6 -0
- package/dist/language/validator/symbols.d.ts.map +1 -0
- package/dist/language/validator/symbols.js +131 -0
- package/dist/language/validator/symbols.js.map +1 -0
- package/dist/language/validator/tables.d.ts +34 -0
- package/dist/language/validator/tables.d.ts.map +1 -0
- package/dist/language/validator/tables.js +120 -0
- package/dist/language/validator/tables.js.map +1 -0
- package/dist/language/validator-utils.d.ts +32 -0
- package/dist/language/validator-utils.d.ts.map +1 -0
- package/dist/language/validator-utils.js +118 -0
- package/dist/language/validator-utils.js.map +1 -0
- package/dist/language/value-tables.d.ts +107 -0
- package/dist/language/value-tables.d.ts.map +1 -0
- package/dist/language/value-tables.js +240 -0
- package/dist/language/value-tables.js.map +1 -0
- package/dist/language/waves-order.d.ts +51 -0
- package/dist/language/waves-order.d.ts.map +1 -0
- package/dist/language/waves-order.js +787 -0
- package/dist/language/waves-order.js.map +1 -0
- package/dist/language/waves-plan.d.ts +45 -0
- package/dist/language/waves-plan.d.ts.map +1 -0
- package/dist/language/waves-plan.js +64 -0
- package/dist/language/waves-plan.js.map +1 -0
- package/dist/language/waves.d.ts +96 -0
- package/dist/language/waves.d.ts.map +1 -0
- package/dist/language/waves.js +575 -0
- package/dist/language/waves.js.map +1 -0
- package/dist/util/props.d.ts +27 -0
- package/dist/util/props.d.ts.map +1 -0
- package/dist/util/props.js +49 -0
- package/dist/util/props.js.map +1 -0
- package/dist/util/single-line.d.ts +14 -0
- package/dist/util/single-line.d.ts.map +1 -0
- package/dist/util/single-line.js +16 -0
- package/dist/util/single-line.js.map +1 -0
- package/package.json +7 -3
- package/src/convert/printer.ts +20 -10
- package/src/convert/schema.ts +8 -1
- package/src/generated/ast.ts +159 -27
- package/src/generated/grammar.ts +434 -148
- package/src/i18n/codes.ts +95 -2
- package/src/i18n/index.ts +1 -0
- package/src/i18n/messages.en.ts +300 -1
- package/src/i18n/messages.fr.ts +335 -1
- package/src/i18n/wave-message-types.ts +206 -0
- package/src/index.ts +33 -0
- package/src/internal.ts +9 -0
- package/src/language/ast-walk.ts +158 -0
- package/src/language/calendar-declarations.ts +141 -0
- package/src/language/include-references.ts +49 -0
- package/src/language/include-resolver.ts +284 -10
- package/src/language/include-waves.ts +419 -0
- package/src/language/nowline-validator.ts +98 -1835
- package/src/language/nowline.langium +56 -22
- package/src/language/references.ts +40 -0
- package/src/language/style-chain.ts +95 -0
- package/src/language/validator/calendar.ts +319 -0
- package/src/language/validator/entities.ts +366 -0
- package/src/language/validator/properties.ts +425 -0
- package/src/language/validator/references.ts +295 -0
- package/src/language/validator/structure.ts +206 -0
- package/src/language/validator/style.ts +149 -0
- package/src/language/validator/support.ts +84 -0
- package/src/language/validator/symbols.ts +141 -0
- package/src/language/validator/tables.ts +171 -0
- package/src/language/validator-utils.ts +123 -0
- package/src/language/value-tables.ts +260 -0
- package/src/language/waves-order.ts +879 -0
- package/src/language/waves-plan.ts +101 -0
- package/src/language/waves.ts +731 -0
- package/src/util/props.ts +59 -0
- package/src/util/single-line.ts +15 -0
|
@@ -0,0 +1,879 @@
|
|
|
1
|
+
// Wave order rules (specs/waves.md §6.3): the G set.
|
|
2
|
+
//
|
|
3
|
+
// - WV10 NL.E1103: the wave order can be realized; no member is forced to
|
|
4
|
+
// start after its own wave ends.
|
|
5
|
+
// - WV11 NL.W1100: a `before:` that can never be met.
|
|
6
|
+
// - WV12 NL.W1101: an `after:` or `before:` that layout ignores (a forward
|
|
7
|
+
// reference, or a floating milestone).
|
|
8
|
+
//
|
|
9
|
+
// The rules run over a layout scope: an ordered list of lanes that layout
|
|
10
|
+
// places together. The validator passes a file's own lanes; the include
|
|
11
|
+
// resolver passes the merged main lanes and each isolated region (§6.1), so
|
|
12
|
+
// nothing here assumes the lanes share a file. Findings keep their AST node,
|
|
13
|
+
// which maps to a file and line through `AstUtils.getDocument` and `$cstNode`.
|
|
14
|
+
|
|
15
|
+
import type { AstNode } from 'langium';
|
|
16
|
+
import type {
|
|
17
|
+
EntityProperty,
|
|
18
|
+
GroupBlock,
|
|
19
|
+
ItemDeclaration,
|
|
20
|
+
ParallelBlock,
|
|
21
|
+
SwimlaneDeclaration,
|
|
22
|
+
WaveDeclaration,
|
|
23
|
+
} from '../generated/ast.js';
|
|
24
|
+
import {
|
|
25
|
+
isGroupBlock,
|
|
26
|
+
isMilestoneDeclaration,
|
|
27
|
+
isParallelBlock,
|
|
28
|
+
isSwimlaneDeclaration,
|
|
29
|
+
} from '../generated/ast.js';
|
|
30
|
+
import type {
|
|
31
|
+
BlockRef,
|
|
32
|
+
E1103Args,
|
|
33
|
+
FlowRef,
|
|
34
|
+
WaveContainerKind,
|
|
35
|
+
} from '../i18n/wave-message-types.js';
|
|
36
|
+
import { ISO_DATE_RE, propKey } from '../util/props.js';
|
|
37
|
+
import { singleLine } from '../util/single-line.js';
|
|
38
|
+
import { trackChildren } from './ast-walk.js';
|
|
39
|
+
import { displayName, lineOf } from './validator-utils.js';
|
|
40
|
+
import { assignWaves, type WaveFinding, type WaveRefLookup } from './waves.js';
|
|
41
|
+
|
|
42
|
+
/** A layout scope for `evaluateWaveOrder`. */
|
|
43
|
+
export interface WaveOrderScope {
|
|
44
|
+
/**
|
|
45
|
+
* Lanes in the order layout places them. They may come from several
|
|
46
|
+
* files; an id reused across them resolves last-writer-wins, as in
|
|
47
|
+
* layout's shared edge maps.
|
|
48
|
+
*/
|
|
49
|
+
lanes: readonly SwimlaneDeclaration[];
|
|
50
|
+
/**
|
|
51
|
+
* Resolves an id that is not placed work (anchors, milestones) to its
|
|
52
|
+
* declaration. Used to tell floating milestones, which layout ignores,
|
|
53
|
+
* from anchors and dated milestones, which it resolves.
|
|
54
|
+
*/
|
|
55
|
+
lookup: WaveRefLookup;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Options for `evaluateWaveOrder`. */
|
|
59
|
+
export interface WaveOrderOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Leave a reference that closes an explicit `after:`/`before:` cycle to
|
|
62
|
+
* the circular-dependency check (default true). That check runs per
|
|
63
|
+
* file, so the include resolver passes false for its merged scopes: a
|
|
64
|
+
* cycle that crosses files would otherwise go unreported.
|
|
65
|
+
*/
|
|
66
|
+
suppressCycleRefs?: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type Work = ItemDeclaration | GroupBlock | ParallelBlock;
|
|
70
|
+
|
|
71
|
+
// One item, group or parallel in placement order.
|
|
72
|
+
interface Slot {
|
|
73
|
+
node: Work;
|
|
74
|
+
lane: number;
|
|
75
|
+
/** Enclosing group or parallel, or -1 at lane level. */
|
|
76
|
+
parent: number;
|
|
77
|
+
children: number[];
|
|
78
|
+
/** Previous sibling in a lane or group flow; -1 for a first child or a track. */
|
|
79
|
+
prev: number;
|
|
80
|
+
/** Tick at which layout reads the node's `after:` (its start). */
|
|
81
|
+
start: number;
|
|
82
|
+
/** Tick at which layout registers the node's id (a container: after its content). */
|
|
83
|
+
reg: number;
|
|
84
|
+
ew?: number;
|
|
85
|
+
lw?: number;
|
|
86
|
+
/** `after:` edges layout resolves to placed work. */
|
|
87
|
+
after: Array<{ from: number; prop: EntityProperty; ref: string }>;
|
|
88
|
+
/** `after:<wave>` references: constant `j`. */
|
|
89
|
+
afterWaves: Array<{ prop: EntityProperty; ref: string; j: number }>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// A term of the lower-bound system (§6.3) that feeds S(i) or E(i).
|
|
93
|
+
type Term =
|
|
94
|
+
| { kind: 'wave' | 'lead' }
|
|
95
|
+
| { kind: 'after-wave'; prop: EntityProperty; ref: string }
|
|
96
|
+
| { kind: 'parent'; from: number }
|
|
97
|
+
| { kind: 'seq'; from: number }
|
|
98
|
+
| { kind: 'after'; from: number; prop: EntityProperty; ref: string }
|
|
99
|
+
| { kind: 'start' }
|
|
100
|
+
| { kind: 'child'; from: number };
|
|
101
|
+
|
|
102
|
+
type ContainerRef = { kind: WaveContainerKind; name: string; line?: number };
|
|
103
|
+
|
|
104
|
+
// A violation's root cause, in the §6.3 preference order.
|
|
105
|
+
type Cause =
|
|
106
|
+
| { variant: 'after-wave'; owner: number; prop: EntityProperty; ref: string }
|
|
107
|
+
| { variant: 'after-item'; owner: number; prop: EntityProperty; ref: string }
|
|
108
|
+
| { variant: 'sequence'; owner: number; pred: number; ref: string | BlockRef }
|
|
109
|
+
| { variant: 'join'; owner: number; block: number; track: string };
|
|
110
|
+
|
|
111
|
+
const PREFERENCE: Cause['variant'][] = ['after-wave', 'after-item', 'sequence', 'join'];
|
|
112
|
+
|
|
113
|
+
// One NL.E1103 diagnostic and the violating items it explains.
|
|
114
|
+
interface OrderReport {
|
|
115
|
+
node: AstNode;
|
|
116
|
+
run: number[];
|
|
117
|
+
build: (run: number[]) => E1103Args;
|
|
118
|
+
/** A `sequence` run: its predecessor, and which items its flow holds. */
|
|
119
|
+
seq?: { pred: number; ref: string | BlockRef; inFlow: (i: number) => boolean };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function nameOf(node: { name?: string; title?: string }): string | undefined {
|
|
123
|
+
return node.name ?? (node.title === undefined ? undefined : singleLine(node.title));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function flowRef(node: SwimlaneDeclaration | GroupBlock | ParallelBlock): FlowRef {
|
|
127
|
+
const name = nameOf(node);
|
|
128
|
+
if (isSwimlaneDeclaration(node)) return { kind: 'swimlane', name: displayName(node) };
|
|
129
|
+
const group = isGroupBlock(node);
|
|
130
|
+
if (name) return { kind: group ? 'group' : 'parallel', name };
|
|
131
|
+
return { kind: group ? 'group-block' : 'parallel-block', line: lineOf(node) };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// How a `sequence` message names its predecessor: by id or title, or by
|
|
135
|
+
// position when it is an unnamed group or parallel. An unnamed item has no
|
|
136
|
+
// name to give.
|
|
137
|
+
function predRef(node: Work): string | BlockRef | undefined {
|
|
138
|
+
const name = nameOf(node);
|
|
139
|
+
if (name !== undefined || node.$type === 'ItemDeclaration') return name;
|
|
140
|
+
return { kind: isGroupBlock(node) ? 'group-block' : 'parallel-block', line: lineOf(node) };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// How a W1100/W1101 names the entity it is on: by id or title, or by
|
|
144
|
+
// position when it is an unnamed group or parallel.
|
|
145
|
+
function ownerOf(node: Work): { name: string; kind?: WaveContainerKind; line?: number } {
|
|
146
|
+
if (node.$type === 'ItemDeclaration' || nameOf(node) !== undefined) {
|
|
147
|
+
return { name: displayName(node) };
|
|
148
|
+
}
|
|
149
|
+
return { name: '', kind: isGroupBlock(node) ? 'group' : 'parallel', line: lineOf(node) };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function containerRef(node: GroupBlock | ParallelBlock): ContainerRef {
|
|
153
|
+
const kind = isGroupBlock(node) ? 'group' : 'parallel';
|
|
154
|
+
const name = nameOf(node);
|
|
155
|
+
return name ? { kind, name } : { kind, name: '', line: lineOf(node) };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function refValues(prop: EntityProperty): string[] {
|
|
159
|
+
return (prop.value !== undefined ? [prop.value] : prop.values).filter((v) => !!v);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function isFloatingMilestone(node: AstNode | undefined): boolean {
|
|
163
|
+
return isMilestoneDeclaration(node) && !node.properties.some((p) => propKey(p) === 'date');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The G rules (WV10-WV12) over one layout scope. `waves` is the roadmap's
|
|
168
|
+
* wave list in declaration order (`ownWaves`); with no waves there are no
|
|
169
|
+
* findings.
|
|
170
|
+
*
|
|
171
|
+
* - WV10 (NL.E1103). Lower bounds `lbS`/`lbE` per §6.3, relaxed to a fixpoint
|
|
172
|
+
* with a worklist. An item in wave k whose `lbS` reaches k is a violation.
|
|
173
|
+
* Each root cause is reported once, as `after-wave`, `after-item`,
|
|
174
|
+
* `sequence`, `join` or `chain`; a violation whose every achieving edge
|
|
175
|
+
* comes from an already explained violation is folded into that run. A
|
|
176
|
+
* `sequence` run lists the items of one wave, so it is kept per
|
|
177
|
+
* predecessor and wave.
|
|
178
|
+
* - WV11 (NL.W1100). A `before:` whose target is placed earlier, or a wave,
|
|
179
|
+
* that the barrier makes unmeetable.
|
|
180
|
+
* - WV12 (NL.W1101). An `after:` or `before:` naming work layout has not
|
|
181
|
+
* placed yet, or a floating milestone. A reference that closes an explicit
|
|
182
|
+
* `after:`/`before:` cycle is left to the circular-dependency check, unless
|
|
183
|
+
* `options.suppressCycleRefs` is false.
|
|
184
|
+
*
|
|
185
|
+
* Swimlane `after:`/`before:` are not implemented by any engine and are
|
|
186
|
+
* ignored here.
|
|
187
|
+
*/
|
|
188
|
+
export function evaluateWaveOrder(
|
|
189
|
+
scope: WaveOrderScope,
|
|
190
|
+
waves: readonly WaveDeclaration[],
|
|
191
|
+
options: WaveOrderOptions = {},
|
|
192
|
+
): WaveFinding[] {
|
|
193
|
+
if (waves.length === 0) return [];
|
|
194
|
+
const waveIds = new Map<string, number>();
|
|
195
|
+
waves.forEach((w, i) => {
|
|
196
|
+
if (w.name) waveIds.set(w.name, i + 1);
|
|
197
|
+
});
|
|
198
|
+
const waveName = (index: number): string => waves[index - 1]?.name ?? '';
|
|
199
|
+
|
|
200
|
+
const { lanes, lookup } = scope;
|
|
201
|
+
const { waveOf, leadOf } = assignWaves(lanes, waveIds);
|
|
202
|
+
|
|
203
|
+
// --- Placement walk: lanes in order, children depth first. ---
|
|
204
|
+
const slots: Slot[] = [];
|
|
205
|
+
const byId = new Map<string, number[]>(); // in registration order
|
|
206
|
+
let tick = 0;
|
|
207
|
+
const visit = (node: Work, lane: number, parent: number, prev: number): number => {
|
|
208
|
+
const i = slots.length;
|
|
209
|
+
const slot: Slot = {
|
|
210
|
+
node,
|
|
211
|
+
lane,
|
|
212
|
+
parent,
|
|
213
|
+
children: [],
|
|
214
|
+
prev,
|
|
215
|
+
start: tick++,
|
|
216
|
+
reg: -1,
|
|
217
|
+
ew: waveOf.get(node),
|
|
218
|
+
lw: leadOf.get(node),
|
|
219
|
+
after: [],
|
|
220
|
+
afterWaves: [],
|
|
221
|
+
};
|
|
222
|
+
slots.push(slot);
|
|
223
|
+
if (isGroupBlock(node) || isParallelBlock(node)) {
|
|
224
|
+
let last = -1;
|
|
225
|
+
for (const child of trackChildren(node)) {
|
|
226
|
+
last = visit(child, lane, i, isGroupBlock(node) ? last : -1);
|
|
227
|
+
slot.children.push(last);
|
|
228
|
+
}
|
|
229
|
+
slot.reg = tick++;
|
|
230
|
+
} else {
|
|
231
|
+
slot.reg = slot.start;
|
|
232
|
+
}
|
|
233
|
+
if (node.name) {
|
|
234
|
+
const list = byId.get(node.name) ?? [];
|
|
235
|
+
list.push(i);
|
|
236
|
+
byId.set(node.name, list);
|
|
237
|
+
}
|
|
238
|
+
return i;
|
|
239
|
+
};
|
|
240
|
+
lanes.forEach((lane, l) => {
|
|
241
|
+
let last = -1;
|
|
242
|
+
for (const child of trackChildren(lane)) last = visit(child, l, -1, last);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// resolve(r, v): the last node with id r that layout registered before
|
|
246
|
+
// it reads v's references.
|
|
247
|
+
const resolve = (r: string, v: number): number | undefined => {
|
|
248
|
+
const list = byId.get(r);
|
|
249
|
+
if (!list) return undefined;
|
|
250
|
+
for (let k = list.length - 1; k >= 0; k--) {
|
|
251
|
+
if (slots[list[k]].reg < slots[v].start) return list[k];
|
|
252
|
+
}
|
|
253
|
+
return undefined;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const findings: WaveFinding[] = [];
|
|
257
|
+
const onCycle =
|
|
258
|
+
(options.suppressCycleRefs ?? true) ? cycleTest(slots, lanes, lookup) : () => false;
|
|
259
|
+
|
|
260
|
+
// --- References: the after: edges layout resolves, and WV12. ---
|
|
261
|
+
for (let v = 0; v < slots.length; v++) {
|
|
262
|
+
const slot = slots[v];
|
|
263
|
+
const owner = ownerOf(slot.node);
|
|
264
|
+
for (const prop of slot.node.properties) {
|
|
265
|
+
const key = propKey(prop);
|
|
266
|
+
if (key !== 'after' && key !== 'before') continue;
|
|
267
|
+
for (const ref of refValues(prop)) {
|
|
268
|
+
if (ISO_DATE_RE.test(ref)) continue;
|
|
269
|
+
const target = resolve(ref, v);
|
|
270
|
+
const j = target === undefined ? waveIds.get(ref) : undefined;
|
|
271
|
+
if (key === 'after') {
|
|
272
|
+
if (target !== undefined) slot.after.push({ from: target, prop, ref });
|
|
273
|
+
else if (j !== undefined) slot.afterWaves.push({ prop, ref, j });
|
|
274
|
+
}
|
|
275
|
+
if (target !== undefined || j !== undefined) continue;
|
|
276
|
+
|
|
277
|
+
// WV12: work layout has not placed yet, or a floating
|
|
278
|
+
// milestone. Anchors and dated milestones resolve; an id that
|
|
279
|
+
// names nothing is the "does not resolve" error's.
|
|
280
|
+
const later = byId.get(ref)?.[0];
|
|
281
|
+
if (later === undefined && !isFloatingMilestone(lookup(ref))) continue;
|
|
282
|
+
if (onCycle(slot.node.name, key, ref)) continue;
|
|
283
|
+
// An enclosing group or parallel registers its id only once
|
|
284
|
+
// its content is placed, so layout never resolves it here.
|
|
285
|
+
let ancestor = false;
|
|
286
|
+
for (let a = slot.parent; a >= 0 && !ancestor; a = slots[a].parent) {
|
|
287
|
+
ancestor = slots[a].node.name === ref;
|
|
288
|
+
}
|
|
289
|
+
findings.push({
|
|
290
|
+
severity: 'warning',
|
|
291
|
+
code: 'NL.W1101',
|
|
292
|
+
args:
|
|
293
|
+
later === undefined
|
|
294
|
+
? { reason: 'floating-milestone', key, ref, ...owner }
|
|
295
|
+
: ancestor
|
|
296
|
+
? { reason: 'ancestor', key, ref, ...owner }
|
|
297
|
+
: slots[later].lane !== slot.lane
|
|
298
|
+
? {
|
|
299
|
+
reason: 'forward-lane',
|
|
300
|
+
key,
|
|
301
|
+
ref,
|
|
302
|
+
...owner,
|
|
303
|
+
lane: displayName(lanes[slots[later].lane]),
|
|
304
|
+
ownLane: displayName(lanes[slot.lane]),
|
|
305
|
+
}
|
|
306
|
+
: {
|
|
307
|
+
reason: 'forward-flow',
|
|
308
|
+
key,
|
|
309
|
+
ref,
|
|
310
|
+
...owner,
|
|
311
|
+
flow: flowRef(commonFlow(slots, lanes, v, later)),
|
|
312
|
+
},
|
|
313
|
+
node: prop,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// --- WV11: before: that the barrier makes unmeetable. ---
|
|
320
|
+
// maxW / minW: the largest / smallest effective wave over a subtree's items.
|
|
321
|
+
const maxW: Array<number | undefined> = new Array(slots.length);
|
|
322
|
+
const minW: Array<number | undefined> = new Array(slots.length);
|
|
323
|
+
for (let i = slots.length - 1; i >= 0; i--) {
|
|
324
|
+
const slot = slots[i];
|
|
325
|
+
if (slot.node.$type === 'ItemDeclaration') {
|
|
326
|
+
maxW[i] = slot.ew;
|
|
327
|
+
minW[i] = slot.ew;
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
for (const c of slot.children) {
|
|
331
|
+
const hi = maxW[c];
|
|
332
|
+
const lo = minW[c];
|
|
333
|
+
if (hi !== undefined) maxW[i] = Math.max(maxW[i] ?? hi, hi);
|
|
334
|
+
if (lo !== undefined) minW[i] = Math.min(minW[i] ?? lo, lo);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
for (let v = 0; v < slots.length; v++) {
|
|
338
|
+
const own = maxW[v];
|
|
339
|
+
if (own === undefined) continue; // background subtree
|
|
340
|
+
const owner = ownerOf(slots[v].node);
|
|
341
|
+
for (const prop of slots[v].node.properties) {
|
|
342
|
+
if (propKey(prop) !== 'before') continue;
|
|
343
|
+
for (const ref of refValues(prop)) {
|
|
344
|
+
if (ISO_DATE_RE.test(ref)) continue;
|
|
345
|
+
const target = resolve(ref, v);
|
|
346
|
+
if (target !== undefined) {
|
|
347
|
+
const theirs = minW[target];
|
|
348
|
+
if (theirs === undefined || own <= theirs) continue;
|
|
349
|
+
findings.push({
|
|
350
|
+
severity: 'warning',
|
|
351
|
+
code: 'NL.W1100',
|
|
352
|
+
args: {
|
|
353
|
+
reason: 'item',
|
|
354
|
+
ref,
|
|
355
|
+
...owner,
|
|
356
|
+
wave: waveName(own),
|
|
357
|
+
refWave: waveName(theirs),
|
|
358
|
+
},
|
|
359
|
+
node: prop,
|
|
360
|
+
});
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
const j = waveIds.get(ref);
|
|
364
|
+
if (j === undefined || own < j) continue;
|
|
365
|
+
findings.push({
|
|
366
|
+
severity: 'warning',
|
|
367
|
+
code: 'NL.W1100',
|
|
368
|
+
args: { reason: 'wave', ref, ...owner, wave: waveName(own) },
|
|
369
|
+
node: prop,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// --- WV10: lower bounds, relaxed to a fixpoint. ---
|
|
376
|
+
const isContainer = (i: number): boolean => slots[i].node.$type !== 'ItemDeclaration';
|
|
377
|
+
const hasParentEdge = (i: number): boolean => {
|
|
378
|
+
const { parent } = slots[i];
|
|
379
|
+
if (parent < 0) return false;
|
|
380
|
+
return isParallelBlock(slots[parent].node) || slots[parent].children[0] === i;
|
|
381
|
+
};
|
|
382
|
+
const valS = new Array<number>(slots.length).fill(0);
|
|
383
|
+
const valE = new Array<number>(slots.length).fill(0);
|
|
384
|
+
|
|
385
|
+
// Every term that feeds S(i), with its current value.
|
|
386
|
+
const termsS = (i: number): Array<{ term: Term; value: number }> => {
|
|
387
|
+
const slot = slots[i];
|
|
388
|
+
const out: Array<{ term: Term; value: number }> = [];
|
|
389
|
+
if (slot.lw !== undefined) {
|
|
390
|
+
out.push({
|
|
391
|
+
term: { kind: slot.ew !== undefined ? 'wave' : 'lead' },
|
|
392
|
+
value: slot.lw - 1,
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
for (const a of slot.afterWaves) {
|
|
396
|
+
out.push({ term: { kind: 'after-wave', prop: a.prop, ref: a.ref }, value: a.j });
|
|
397
|
+
}
|
|
398
|
+
if (hasParentEdge(i)) {
|
|
399
|
+
out.push({ term: { kind: 'parent', from: slot.parent }, value: valS[slot.parent] });
|
|
400
|
+
}
|
|
401
|
+
if (slot.prev >= 0) {
|
|
402
|
+
out.push({ term: { kind: 'seq', from: slot.prev }, value: valE[slot.prev] });
|
|
403
|
+
}
|
|
404
|
+
for (const a of slot.after) {
|
|
405
|
+
out.push({
|
|
406
|
+
term: { kind: 'after', from: a.from, prop: a.prop, ref: a.ref },
|
|
407
|
+
value: valE[a.from],
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
return out;
|
|
411
|
+
};
|
|
412
|
+
const computeE = (i: number): number => {
|
|
413
|
+
let v = valS[i];
|
|
414
|
+
for (const c of slots[i].children) v = Math.max(v, valE[c]);
|
|
415
|
+
return v;
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
// Dependents of S(i) and E(i), as worklist keys (2i for S, 2i + 1 for E).
|
|
419
|
+
const depsS: number[][] = slots.map((_, i) => [2 * i + 1]);
|
|
420
|
+
const depsE: number[][] = slots.map(() => []);
|
|
421
|
+
for (let i = 0; i < slots.length; i++) {
|
|
422
|
+
const slot = slots[i];
|
|
423
|
+
if (hasParentEdge(i)) depsS[slot.parent].push(2 * i);
|
|
424
|
+
if (slot.prev >= 0) depsE[slot.prev].push(2 * i);
|
|
425
|
+
for (const a of slot.after) depsE[a.from].push(2 * i);
|
|
426
|
+
if (slot.parent >= 0) depsE[i].push(2 * slot.parent + 1);
|
|
427
|
+
}
|
|
428
|
+
const queue: number[] = [];
|
|
429
|
+
const queued = new Array<boolean>(2 * slots.length).fill(true);
|
|
430
|
+
for (let i = 0; i < slots.length; i++) queue.push(2 * i, 2 * i + 1);
|
|
431
|
+
// Values lie in [0, n] and only grow, so this stops even on cyclic input.
|
|
432
|
+
for (let head = 0; head < queue.length; head++) {
|
|
433
|
+
const k = queue[head];
|
|
434
|
+
queued[k] = false;
|
|
435
|
+
const i = k >> 1;
|
|
436
|
+
const isE = (k & 1) === 1;
|
|
437
|
+
const next = isE ? computeE(i) : Math.max(0, ...termsS(i).map((t) => t.value));
|
|
438
|
+
if (next <= (isE ? valE[i] : valS[i])) continue;
|
|
439
|
+
if (isE) valE[i] = next;
|
|
440
|
+
else valS[i] = next;
|
|
441
|
+
for (const d of isE ? depsE[i] : depsS[i]) {
|
|
442
|
+
if (!queued[d]) {
|
|
443
|
+
queued[d] = true;
|
|
444
|
+
queue.push(d);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// --- WV10 reporting. ---
|
|
450
|
+
const achieversS = (i: number, b: number): Term[] =>
|
|
451
|
+
termsS(i)
|
|
452
|
+
.filter((t) => t.value === b)
|
|
453
|
+
.map((t) => t.term);
|
|
454
|
+
// E(C) is explained by the children that reach b; S(C) only when none
|
|
455
|
+
// does (an empty container), since the children already carry it.
|
|
456
|
+
const achieversE = (i: number, b: number): Term[] => {
|
|
457
|
+
if (!isContainer(i)) return [{ kind: 'start' }];
|
|
458
|
+
const kids: Term[] = slots[i].children
|
|
459
|
+
.filter((c) => valE[c] === b)
|
|
460
|
+
.map((c) => ({ kind: 'child', from: c }));
|
|
461
|
+
if (kids.length > 0) return isGroupBlock(slots[i].node) ? kids.reverse() : kids;
|
|
462
|
+
return valS[i] === b ? [{ kind: 'start' }] : [];
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
// The member whose own wave sets E(s) = b, reached through containment
|
|
466
|
+
// only (E(C) from a child, E(v) from S(v)), and the child of s it lies in.
|
|
467
|
+
const ownWaveOrigin = (s: number, b: number): { origin: number; via: number } | undefined => {
|
|
468
|
+
const stack: Array<{ i: number; via: number }> = [{ i: s, via: s }];
|
|
469
|
+
while (stack.length > 0) {
|
|
470
|
+
const { i, via } = stack.pop() as { i: number; via: number };
|
|
471
|
+
const terms = achieversE(i, b);
|
|
472
|
+
for (let t = terms.length - 1; t >= 0; t--) {
|
|
473
|
+
const term = terms[t];
|
|
474
|
+
if (term.kind === 'start') {
|
|
475
|
+
const ew = slots[i].ew;
|
|
476
|
+
if (ew !== undefined && ew - 1 === b) return { origin: i, via };
|
|
477
|
+
} else if (term.kind === 'child') {
|
|
478
|
+
stack.push({ i: term.from, via: i === s ? term.from : via });
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return undefined;
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// True when E(i) = b is i's own wave constant, ew(i) - 1: the condition
|
|
486
|
+
// for `after-item` and `sequence`. A container without a wave of its
|
|
487
|
+
// own may span waves, so there is no wave to name for it.
|
|
488
|
+
const ownConstant = (i: number, b: number): boolean => {
|
|
489
|
+
const ew = slots[i].ew;
|
|
490
|
+
return ew !== undefined && ew - 1 === b;
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
// The nearest work before x in its flow with a wave later than k:
|
|
494
|
+
// earlier siblings first, then those of each enclosing container.
|
|
495
|
+
const laterBefore = (x: number, k: number): number | undefined => {
|
|
496
|
+
let u = x;
|
|
497
|
+
while (slots[u].prev >= 0 || hasParentEdge(u)) {
|
|
498
|
+
const prev = slots[u].prev;
|
|
499
|
+
if (prev < 0) {
|
|
500
|
+
u = slots[u].parent;
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
const ew = slots[prev].ew;
|
|
504
|
+
if (ew !== undefined && ew > k) return prev;
|
|
505
|
+
u = prev;
|
|
506
|
+
}
|
|
507
|
+
return undefined;
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
const runOf = new Map<number, OrderReport>();
|
|
511
|
+
const reports: OrderReport[] = [];
|
|
512
|
+
const reportByKey = new Map<string, OrderReport>();
|
|
513
|
+
const propKeyOf = (owner: number, prop: EntityProperty, ref: string): string =>
|
|
514
|
+
`${owner}:${slots[owner].node.properties.indexOf(prop)}:${ref}`;
|
|
515
|
+
|
|
516
|
+
const causeOf = (x: number, b: number): Cause | undefined => {
|
|
517
|
+
const causes: Cause[] = [];
|
|
518
|
+
let u = x;
|
|
519
|
+
for (;;) {
|
|
520
|
+
const terms = achieversS(u, b);
|
|
521
|
+
for (const term of terms) {
|
|
522
|
+
if (term.kind === 'after-wave') {
|
|
523
|
+
causes.push({
|
|
524
|
+
variant: 'after-wave',
|
|
525
|
+
owner: u,
|
|
526
|
+
prop: term.prop,
|
|
527
|
+
ref: term.ref,
|
|
528
|
+
});
|
|
529
|
+
} else if (term.kind === 'after') {
|
|
530
|
+
if (ownConstant(term.from, b)) {
|
|
531
|
+
causes.push({
|
|
532
|
+
variant: 'after-item',
|
|
533
|
+
owner: u,
|
|
534
|
+
prop: term.prop,
|
|
535
|
+
ref: term.ref,
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
} else if (term.kind === 'seq') {
|
|
539
|
+
const p = term.from;
|
|
540
|
+
const pNode = slots[p].node;
|
|
541
|
+
if (isParallelBlock(pNode) && slots[p].ew === undefined) {
|
|
542
|
+
const found = ownWaveOrigin(p, b);
|
|
543
|
+
const track =
|
|
544
|
+
found &&
|
|
545
|
+
(nameOf(slots[found.via].node) ?? nameOf(slots[found.origin].node));
|
|
546
|
+
if (track) causes.push({ variant: 'join', owner: u, block: p, track });
|
|
547
|
+
} else if (ownConstant(p, b)) {
|
|
548
|
+
const ref = predRef(pNode);
|
|
549
|
+
if (ref) causes.push({ variant: 'sequence', owner: u, pred: p, ref });
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
const up = terms.find(
|
|
554
|
+
(t): t is Extract<Term, { kind: 'parent' }> => t.kind === 'parent',
|
|
555
|
+
);
|
|
556
|
+
if (!up) break;
|
|
557
|
+
u = up.from;
|
|
558
|
+
}
|
|
559
|
+
for (const variant of PREFERENCE) {
|
|
560
|
+
const found = causes.find((c) => c.variant === variant);
|
|
561
|
+
if (found) return found;
|
|
562
|
+
}
|
|
563
|
+
return undefined;
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
// Backward search over the achieving terms from S(x), stopping at
|
|
567
|
+
// explained violations. Either a path from a constant (the chain), or
|
|
568
|
+
// the first explained violation when every path goes through one.
|
|
569
|
+
const searchBack = (
|
|
570
|
+
x: number,
|
|
571
|
+
b: number,
|
|
572
|
+
): { path: number[]; origin: string } | { hit: number | undefined } => {
|
|
573
|
+
const nodes: Array<{ key: number; from: number }> = [{ key: 2 * x, from: -1 }];
|
|
574
|
+
const seen = new Set<number>([2 * x]);
|
|
575
|
+
let hit: number | undefined;
|
|
576
|
+
const push = (key: number, from: number): void => {
|
|
577
|
+
if (seen.has(key)) return;
|
|
578
|
+
seen.add(key);
|
|
579
|
+
nodes.push({ key, from });
|
|
580
|
+
};
|
|
581
|
+
for (let q = 0; q < nodes.length; q++) {
|
|
582
|
+
const i = nodes[q].key >> 1;
|
|
583
|
+
if (i !== x && runOf.has(i)) {
|
|
584
|
+
hit ??= i;
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
if ((nodes[q].key & 1) === 1) {
|
|
588
|
+
for (const term of achieversE(i, b)) {
|
|
589
|
+
if (term.kind === 'start') push(2 * i, q);
|
|
590
|
+
else if (term.kind === 'child') push(2 * term.from + 1, q);
|
|
591
|
+
}
|
|
592
|
+
continue;
|
|
593
|
+
}
|
|
594
|
+
const terms = achieversS(i, b);
|
|
595
|
+
const constant =
|
|
596
|
+
terms.find((t) => t.kind === 'wave' || t.kind === 'lead') ??
|
|
597
|
+
terms.find((t) => t.kind === 'after-wave');
|
|
598
|
+
if (constant) {
|
|
599
|
+
const path: number[] = [];
|
|
600
|
+
for (let n = q; n >= 0; n = nodes[n].from) {
|
|
601
|
+
const s = nodes[n].key >> 1;
|
|
602
|
+
if (path[path.length - 1] !== s) path.push(s);
|
|
603
|
+
}
|
|
604
|
+
const label = displayName(slots[i].node);
|
|
605
|
+
return {
|
|
606
|
+
path,
|
|
607
|
+
origin:
|
|
608
|
+
constant.kind === 'after-wave'
|
|
609
|
+
? `${label} (after:${constant.ref})`
|
|
610
|
+
: `${label} (wave "${waveName(b + 1)}")`,
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
for (const term of terms) {
|
|
614
|
+
if (term.kind === 'parent') push(2 * term.from, q);
|
|
615
|
+
else if (term.kind === 'seq' || term.kind === 'after') push(2 * term.from + 1, q);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
return { hit };
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
// The NL.E1103 report for a violation x in wave k whose root cause is
|
|
622
|
+
// `cause`.
|
|
623
|
+
const makeReport = (cause: Cause, x: number, k: number, b: number): OrderReport => {
|
|
624
|
+
const name = displayName(slots[x].node);
|
|
625
|
+
const wave = waveName(k);
|
|
626
|
+
const refWave = waveName(b + 1);
|
|
627
|
+
const owner = slots[cause.owner].node;
|
|
628
|
+
const container =
|
|
629
|
+
cause.owner === x ? undefined : containerRef(owner as GroupBlock | ParallelBlock);
|
|
630
|
+
switch (cause.variant) {
|
|
631
|
+
case 'after-wave': {
|
|
632
|
+
// The container form names the container's wave, so a
|
|
633
|
+
// container without one gets the item form, still on its
|
|
634
|
+
// after:.
|
|
635
|
+
const named = slots[cause.owner].ew === undefined ? undefined : container;
|
|
636
|
+
return {
|
|
637
|
+
node: cause.prop,
|
|
638
|
+
run: [x],
|
|
639
|
+
build: () => ({
|
|
640
|
+
reason: 'after-wave',
|
|
641
|
+
name,
|
|
642
|
+
wave,
|
|
643
|
+
refId: cause.ref,
|
|
644
|
+
...(named ? { container: named } : {}),
|
|
645
|
+
}),
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
case 'after-item':
|
|
649
|
+
return {
|
|
650
|
+
node: cause.prop,
|
|
651
|
+
run: [x],
|
|
652
|
+
build: () => ({
|
|
653
|
+
reason: 'after-item',
|
|
654
|
+
name,
|
|
655
|
+
wave,
|
|
656
|
+
refId: cause.ref,
|
|
657
|
+
ref: cause.ref,
|
|
658
|
+
refWave,
|
|
659
|
+
...(container ? { container } : {}),
|
|
660
|
+
}),
|
|
661
|
+
};
|
|
662
|
+
case 'join': {
|
|
663
|
+
const block = slots[cause.block];
|
|
664
|
+
return {
|
|
665
|
+
node: slots[x].node,
|
|
666
|
+
run: [x],
|
|
667
|
+
build: () => ({
|
|
668
|
+
reason: 'join',
|
|
669
|
+
name,
|
|
670
|
+
wave,
|
|
671
|
+
block: flowRef(block.node as ParallelBlock),
|
|
672
|
+
flow: flowRef(flowOf(slots, lanes, cause.block)),
|
|
673
|
+
track: cause.track,
|
|
674
|
+
trackWave: refWave,
|
|
675
|
+
}),
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
case 'sequence': {
|
|
679
|
+
const p = cause.pred;
|
|
680
|
+
const flowNode = slots[p].parent;
|
|
681
|
+
// List the run's items that sit in p's flow; the advice moves
|
|
682
|
+
// p below the last of them.
|
|
683
|
+
const inFlow = (i: number): boolean => {
|
|
684
|
+
if (flowNode < 0) return slots[i].lane === slots[p].lane;
|
|
685
|
+
for (let a = slots[i].parent; a >= 0; a = slots[a].parent) {
|
|
686
|
+
if (a === flowNode) return true;
|
|
687
|
+
}
|
|
688
|
+
return false;
|
|
689
|
+
};
|
|
690
|
+
return {
|
|
691
|
+
node: slots[x].node,
|
|
692
|
+
run: [x],
|
|
693
|
+
build: (run) => {
|
|
694
|
+
const listed = run.filter(inFlow);
|
|
695
|
+
return {
|
|
696
|
+
reason: 'sequence',
|
|
697
|
+
items: listed.map((i) => displayName(slots[i].node)),
|
|
698
|
+
itemWave: wave,
|
|
699
|
+
ref: cause.ref,
|
|
700
|
+
refWave: waveName(slots[p].ew ?? b + 1),
|
|
701
|
+
flow: flowRef(flowOf(slots, lanes, p)),
|
|
702
|
+
last: displayName(slots[listed[listed.length - 1]].node),
|
|
703
|
+
};
|
|
704
|
+
},
|
|
705
|
+
seq: { pred: p, ref: cause.ref, inFlow },
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
const addReport = (key: string | undefined, report: OrderReport): OrderReport => {
|
|
712
|
+
reports.push(report);
|
|
713
|
+
if (key !== undefined) reportByKey.set(key, report);
|
|
714
|
+
return report;
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
// Add violation x (wave k, bound b) to the report for `cause`, or start
|
|
718
|
+
// it. A `sequence` report is kept per predecessor and wave: its message
|
|
719
|
+
// names one wave for every item it lists. A `join` report is kept per
|
|
720
|
+
// block and wave: its message names the first affected item of a wave.
|
|
721
|
+
const joinCause = (cause: Cause, x: number, k: number, b: number): OrderReport => {
|
|
722
|
+
const key =
|
|
723
|
+
cause.variant === 'sequence'
|
|
724
|
+
? `sequence:${cause.pred}:${k}`
|
|
725
|
+
: cause.variant === 'join'
|
|
726
|
+
? `join:${cause.block}:${k}`
|
|
727
|
+
: `${cause.variant}:${propKeyOf(cause.owner, cause.prop, cause.ref)}`;
|
|
728
|
+
const report = reportByKey.get(key);
|
|
729
|
+
if (!report) return addReport(key, makeReport(cause, x, k, b));
|
|
730
|
+
report.run.push(x);
|
|
731
|
+
return report;
|
|
732
|
+
};
|
|
733
|
+
|
|
734
|
+
for (let x = 0; x < slots.length; x++) {
|
|
735
|
+
const slot = slots[x];
|
|
736
|
+
const k = slot.ew;
|
|
737
|
+
if (slot.node.$type !== 'ItemDeclaration' || k === undefined || valS[x] < k) continue;
|
|
738
|
+
const b = valS[x];
|
|
739
|
+
const cause = causeOf(x, b);
|
|
740
|
+
|
|
741
|
+
let report: OrderReport | undefined;
|
|
742
|
+
if (cause) {
|
|
743
|
+
report = joinCause(cause, x, k, b);
|
|
744
|
+
} else {
|
|
745
|
+
const back = searchBack(x, b);
|
|
746
|
+
if ('path' in back) {
|
|
747
|
+
const labels = back.path
|
|
748
|
+
.slice(1)
|
|
749
|
+
.filter((i) => !isContainer(i) || nameOf(slots[i].node) !== undefined)
|
|
750
|
+
.map((i) => displayName(slots[i].node));
|
|
751
|
+
const chain = [back.origin, ...labels.filter((l, n) => labels[n - 1] !== l)];
|
|
752
|
+
const name = displayName(slot.node);
|
|
753
|
+
const wave = waveName(k);
|
|
754
|
+
report = addReport(undefined, {
|
|
755
|
+
node: slot.node,
|
|
756
|
+
run: [x],
|
|
757
|
+
build: () => ({ reason: 'chain', name, wave, chain }),
|
|
758
|
+
});
|
|
759
|
+
} else {
|
|
760
|
+
// Cascade: fold into the run of the violation it comes from.
|
|
761
|
+
// An item a sequence run would list is listed after the
|
|
762
|
+
// nearest earlier work in its flow with a later wave (at
|
|
763
|
+
// worst the run's own predecessor), in that predecessor's run
|
|
764
|
+
// for its own wave: the message names one wave, and moving
|
|
765
|
+
// the predecessor below the run then clears what it lists.
|
|
766
|
+
const hit = back.hit === undefined ? undefined : runOf.get(back.hit);
|
|
767
|
+
const seq = hit?.seq;
|
|
768
|
+
if (seq?.inFlow(x)) {
|
|
769
|
+
const q = laterBefore(x, k);
|
|
770
|
+
const ref = q === undefined ? undefined : predRef(slots[q].node);
|
|
771
|
+
const own: Cause =
|
|
772
|
+
q !== undefined && ref !== undefined
|
|
773
|
+
? { variant: 'sequence', owner: x, pred: q, ref }
|
|
774
|
+
: { variant: 'sequence', owner: x, pred: seq.pred, ref: seq.ref };
|
|
775
|
+
report = joinCause(own, x, k, b);
|
|
776
|
+
} else {
|
|
777
|
+
report = hit;
|
|
778
|
+
report?.run.push(x);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
if (report) runOf.set(x, report);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
for (const report of reports) {
|
|
786
|
+
findings.push({
|
|
787
|
+
severity: 'error',
|
|
788
|
+
code: 'NL.E1103',
|
|
789
|
+
args: report.build(report.run),
|
|
790
|
+
node: report.node,
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
return findings;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// The flow that holds slot i: its enclosing group or parallel, or its lane.
|
|
797
|
+
function flowOf(
|
|
798
|
+
slots: readonly Slot[],
|
|
799
|
+
lanes: readonly SwimlaneDeclaration[],
|
|
800
|
+
i: number,
|
|
801
|
+
): SwimlaneDeclaration | GroupBlock | ParallelBlock {
|
|
802
|
+
const parent = slots[i].parent;
|
|
803
|
+
return parent < 0 ? lanes[slots[i].lane] : (slots[parent].node as GroupBlock | ParallelBlock);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// The innermost flow that strictly holds both a and b (same lane).
|
|
807
|
+
function commonFlow(
|
|
808
|
+
slots: readonly Slot[],
|
|
809
|
+
lanes: readonly SwimlaneDeclaration[],
|
|
810
|
+
a: number,
|
|
811
|
+
b: number,
|
|
812
|
+
): SwimlaneDeclaration | GroupBlock | ParallelBlock {
|
|
813
|
+
const holdsB = new Set<number>();
|
|
814
|
+
for (let n = slots[b].parent; n >= 0; n = slots[n].parent) holdsB.add(n);
|
|
815
|
+
for (let n = slots[a].parent; n >= 0; n = slots[n].parent) {
|
|
816
|
+
if (holdsB.has(n)) return slots[n].node as GroupBlock | ParallelBlock;
|
|
817
|
+
}
|
|
818
|
+
return lanes[slots[a].lane];
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
// True when the reference `key:ref` on the entity `id` closes an explicit
|
|
822
|
+
// after:/before: cycle, the graph `checkCircularDependencies` walks: after:r
|
|
823
|
+
// on v is the edge v -> r, before:r on v is r -> v. Lanes and the milestones
|
|
824
|
+
// the scope references take part, as they do there.
|
|
825
|
+
function cycleTest(
|
|
826
|
+
slots: readonly Slot[],
|
|
827
|
+
lanes: readonly SwimlaneDeclaration[],
|
|
828
|
+
lookup: WaveRefLookup,
|
|
829
|
+
): (id: string | undefined, key: 'after' | 'before', ref: string) => boolean {
|
|
830
|
+
const edges = new Map<string, Set<string>>();
|
|
831
|
+
const addEdge = (from: string, to: string): void => {
|
|
832
|
+
const set = edges.get(from) ?? new Set<string>();
|
|
833
|
+
set.add(to);
|
|
834
|
+
edges.set(from, set);
|
|
835
|
+
};
|
|
836
|
+
const pending: string[] = [];
|
|
837
|
+
const index = (id: string | undefined, props: readonly EntityProperty[]): void => {
|
|
838
|
+
if (!id) return;
|
|
839
|
+
for (const prop of props) {
|
|
840
|
+
const key = propKey(prop);
|
|
841
|
+
if (key !== 'after' && key !== 'before') continue;
|
|
842
|
+
for (const ref of refValues(prop)) {
|
|
843
|
+
if (ISO_DATE_RE.test(ref)) continue;
|
|
844
|
+
if (key === 'after') addEdge(id, ref);
|
|
845
|
+
else addEdge(ref, id);
|
|
846
|
+
pending.push(ref);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
for (const lane of lanes) index(lane.name, lane.properties);
|
|
851
|
+
for (const slot of slots) index(slot.node.name, slot.node.properties);
|
|
852
|
+
const seenMilestones = new Set<string>();
|
|
853
|
+
while (pending.length > 0) {
|
|
854
|
+
const ref = pending.pop() as string;
|
|
855
|
+
if (seenMilestones.has(ref)) continue;
|
|
856
|
+
seenMilestones.add(ref);
|
|
857
|
+
const decl = lookup(ref);
|
|
858
|
+
if (isMilestoneDeclaration(decl)) index(decl.name, decl.properties);
|
|
859
|
+
}
|
|
860
|
+
const reaches = (from: string, to: string): boolean => {
|
|
861
|
+
const seen = new Set<string>([from]);
|
|
862
|
+
const stack = [from];
|
|
863
|
+
while (stack.length > 0) {
|
|
864
|
+
const n = stack.pop() as string;
|
|
865
|
+
if (n === to) return true;
|
|
866
|
+
for (const next of edges.get(n) ?? []) {
|
|
867
|
+
if (!seen.has(next)) {
|
|
868
|
+
seen.add(next);
|
|
869
|
+
stack.push(next);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
return false;
|
|
874
|
+
};
|
|
875
|
+
return (id, key, ref) => {
|
|
876
|
+
if (!id) return false;
|
|
877
|
+
return key === 'after' ? reaches(ref, id) : reaches(id, ref);
|
|
878
|
+
};
|
|
879
|
+
}
|