@tsplc/tmp-debug 0.0.0-stage → 0.6.2
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 +38 -2
- package/dist/api.js +744 -0
- package/dist/api.js.map +12 -0
- package/dist/constant.js +33 -0
- package/dist/constant.js.map +10 -0
- package/dist/explain-file.js +468 -0
- package/dist/explain-file.js.map +11 -0
- package/dist/explain.js +1310 -0
- package/dist/explain.js.map +19 -0
- package/dist/format.js +214 -0
- package/dist/format.js.map +12 -0
- package/dist/index.js +4066 -0
- package/dist/index.js.map +44 -0
- package/dist/manifest.js +240 -0
- package/dist/manifest.js.map +10 -0
- package/dist/paths.js +242 -0
- package/dist/paths.js.map +10 -0
- package/package.json +72 -4
- package/src/adapter.ts +77 -0
- package/src/api.ts +446 -0
- package/src/app-server.ts +151 -0
- package/src/build-files.ts +46 -0
- package/src/constant.ts +41 -0
- package/src/debugger.ts +237 -0
- package/src/errors.ts +13 -0
- package/src/explain-expressions.ts +484 -0
- package/src/explain-file.ts +325 -0
- package/src/explain-frames.ts +155 -0
- package/src/explain-loops.ts +151 -0
- package/src/explain-operations.ts +232 -0
- package/src/explain-tables.ts +345 -0
- package/src/explain-value.ts +203 -0
- package/src/explain-verdicts.ts +548 -0
- package/src/explain.ts +82 -0
- package/src/hardware.ts +159 -0
- package/src/http.ts +218 -0
- package/src/index.ts +44 -0
- package/src/jobs.ts +139 -0
- package/src/login-value.ts +165 -0
- package/src/login.ts +315 -0
- package/src/manifest.ts +328 -0
- package/src/opcua.ts +80 -0
- package/src/paths.ts +363 -0
- package/src/requests.ts +99 -0
- package/src/server-cursor.ts +22 -0
- package/src/shown.ts +229 -0
- package/src/telemetry.ts +125 -0
- package/src/timeline.ts +148 -0
- package/src/trace.ts +62 -0
- package/src/ui/bits.ts +48 -0
- package/src/ui/client.ts +87 -0
- package/src/ui/dom.ts +61 -0
- package/src/ui/explain-read.ts +105 -0
- package/src/ui/format.ts +261 -0
- package/src/ui/hardware.ts +425 -0
- package/src/ui/header.ts +207 -0
- package/src/ui/health.ts +64 -0
- package/src/ui/index.ts +27 -0
- package/src/ui/jobs.ts +263 -0
- package/src/ui/links.ts +59 -0
- package/src/ui/live-value.ts +85 -0
- package/src/ui/main.ts +76 -0
- package/src/ui/overview.ts +178 -0
- package/src/ui/page.ts +286 -0
- package/src/ui/pages.ts +64 -0
- package/src/ui/recent-window.ts +49 -0
- package/src/ui/recent.ts +355 -0
- package/src/ui/request-trace.ts +38 -0
- package/src/ui/requests.ts +80 -0
- package/src/ui/routes.ts +98 -0
- package/src/ui/store.ts +295 -0
- package/src/ui/success-cache.ts +11 -0
- package/src/ui/tree.ts +162 -0
- package/src/ui/variables.ts +597 -0
- package/src/ui/why-watch.ts +11 -0
- package/src/ui/why.ts +694 -0
- package/src/values.ts +170 -0
- package/src/watch.ts +32 -0
package/src/ui/why.ts
ADDED
|
@@ -0,0 +1,694 @@
|
|
|
1
|
+
import { elementaryType, nanosecondsPerMillisecond } from "@tsplc/iec";
|
|
2
|
+
import type { Forced } from "../api";
|
|
3
|
+
import {
|
|
4
|
+
type Answer,
|
|
5
|
+
type AnswerResult,
|
|
6
|
+
type ConditionResult,
|
|
7
|
+
createExplainer,
|
|
8
|
+
type Explainer,
|
|
9
|
+
type ExplainRead,
|
|
10
|
+
type Outcome,
|
|
11
|
+
type Verdict,
|
|
12
|
+
} from "../explain";
|
|
13
|
+
import type {
|
|
14
|
+
ExplainCondition,
|
|
15
|
+
ExplainExpression,
|
|
16
|
+
ExplainFile,
|
|
17
|
+
} from "../explain-file";
|
|
18
|
+
import type { DebugManifest } from "../manifest";
|
|
19
|
+
import { isPattern, typeOf } from "../paths";
|
|
20
|
+
import { findJson, getJson } from "./client";
|
|
21
|
+
import { empty, h, type View } from "./dom";
|
|
22
|
+
import { explainRead, writerIndex } from "./explain-read";
|
|
23
|
+
import { formatScalar, formatValue } from "./format";
|
|
24
|
+
import { pathLink, sourceLink } from "./links";
|
|
25
|
+
import { LiveValue } from "./live-value";
|
|
26
|
+
import type { Page } from "./pages";
|
|
27
|
+
import { href } from "./routes";
|
|
28
|
+
import type { Store, Topic } from "./store";
|
|
29
|
+
import { cacheSuccess } from "./success-cache";
|
|
30
|
+
import { maxWatched, watchList } from "./why-watch";
|
|
31
|
+
|
|
32
|
+
const forcedPollMs = 2000;
|
|
33
|
+
|
|
34
|
+
const loadFile = cacheSuccess(() => findJson("explain-file"));
|
|
35
|
+
|
|
36
|
+
const truthMark: Record<ConditionResult["truth"], string> = {
|
|
37
|
+
true: "✅",
|
|
38
|
+
false: "❌",
|
|
39
|
+
unknown: "?",
|
|
40
|
+
candidate: "◐",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const integerText = (manifest: DebugManifest, type: string, value: bigint) => {
|
|
44
|
+
const declared = typeOf(manifest, type);
|
|
45
|
+
if (declared.kind === "enum") {
|
|
46
|
+
return formatValue(manifest, type, Number(value));
|
|
47
|
+
}
|
|
48
|
+
return declared.kind === "scalar" &&
|
|
49
|
+
elementaryType(declared.iec)?.family === "duration"
|
|
50
|
+
? formatValue(manifest, type, Number(value / nanosecondsPerMillisecond))
|
|
51
|
+
: String(value);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const outcomeText = (
|
|
55
|
+
manifest: DebugManifest,
|
|
56
|
+
type: string,
|
|
57
|
+
outcome: Outcome,
|
|
58
|
+
): string => {
|
|
59
|
+
if (!outcome.known) {
|
|
60
|
+
return `? ${outcome.reason}`;
|
|
61
|
+
}
|
|
62
|
+
const { value } = outcome;
|
|
63
|
+
switch (value.kind) {
|
|
64
|
+
case "bool":
|
|
65
|
+
case "float":
|
|
66
|
+
case "text":
|
|
67
|
+
return formatScalar(value.value);
|
|
68
|
+
case "integer":
|
|
69
|
+
return integerText(manifest, type, value.value);
|
|
70
|
+
case "interval":
|
|
71
|
+
return `${value.low}…${value.high}`;
|
|
72
|
+
case "instance":
|
|
73
|
+
return value.path ?? "absent";
|
|
74
|
+
case "record":
|
|
75
|
+
case "array":
|
|
76
|
+
return "{…}";
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const assignmentOf = (file: ExplainFile, verdict: Verdict) => {
|
|
81
|
+
const assignment = file.assignments[verdict.writer.assignment];
|
|
82
|
+
if (!assignment) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`The explanation names assignment ${verdict.writer.assignment}, which this build's explain.json lacks.`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return assignment;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/** What a writer's card shows the values of, each read in the routine row `row`. */
|
|
91
|
+
const cardOf = (file: ExplainFile, verdict: Verdict) => {
|
|
92
|
+
const assignment = assignmentOf(file, verdict);
|
|
93
|
+
return {
|
|
94
|
+
conditions: verdict.conditions.map((result) => ({
|
|
95
|
+
result,
|
|
96
|
+
test:
|
|
97
|
+
result.condition.kind === "test" || result.condition.kind === "cases"
|
|
98
|
+
? result.condition.test
|
|
99
|
+
: undefined,
|
|
100
|
+
})),
|
|
101
|
+
inputs: Object.entries(assignment.block?.inputs ?? {}),
|
|
102
|
+
value: assignment.value,
|
|
103
|
+
row: assignment.routine,
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/** "Why does this variable have this value?": its writers, their conditions and the values they read. */
|
|
108
|
+
export const whyView = (
|
|
109
|
+
store: Store,
|
|
110
|
+
page: Page,
|
|
111
|
+
{ path = "", trail = [] }: { path?: string; trail?: readonly string[] },
|
|
112
|
+
): View => {
|
|
113
|
+
const element = h("section", { class: "why" });
|
|
114
|
+
const node = path ? store.tree.resolve(path) : undefined;
|
|
115
|
+
if (!node || node.constant) {
|
|
116
|
+
element.append(
|
|
117
|
+
h("h1", {}, "Why?"),
|
|
118
|
+
empty(
|
|
119
|
+
path
|
|
120
|
+
? `${path} isn't a stored value this build can explain.`
|
|
121
|
+
: "Pick a variable on the Variables page and choose Why?",
|
|
122
|
+
),
|
|
123
|
+
);
|
|
124
|
+
return { element, update: () => {} };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const { manifest } = store;
|
|
128
|
+
const live = new LiveValue(store, node);
|
|
129
|
+
const answerBox = h("div", { class: "panel why-answer" });
|
|
130
|
+
const writersBox = h("div", { class: "why-writers" });
|
|
131
|
+
const notes = h("p", { class: "hint" });
|
|
132
|
+
const needed = new Set<string>();
|
|
133
|
+
const clocks = manifest.tasks.flatMap((task) =>
|
|
134
|
+
task.clock ? [task.name] : [],
|
|
135
|
+
);
|
|
136
|
+
const slot = writerIndex(manifest, path);
|
|
137
|
+
const show = (jobs: number[]) =>
|
|
138
|
+
page.show({
|
|
139
|
+
watch: watchList(path, needed).watched,
|
|
140
|
+
jobs,
|
|
141
|
+
clocks,
|
|
142
|
+
slots: slot === undefined ? [] : [slot],
|
|
143
|
+
});
|
|
144
|
+
let render = () => {};
|
|
145
|
+
|
|
146
|
+
element.append(
|
|
147
|
+
h(
|
|
148
|
+
"nav",
|
|
149
|
+
{ class: "trail" },
|
|
150
|
+
...trail.flatMap((step, index) => [
|
|
151
|
+
h(
|
|
152
|
+
"a",
|
|
153
|
+
{
|
|
154
|
+
href: href({
|
|
155
|
+
route: "why",
|
|
156
|
+
path: step,
|
|
157
|
+
trail: trail.slice(0, index),
|
|
158
|
+
}),
|
|
159
|
+
},
|
|
160
|
+
step,
|
|
161
|
+
),
|
|
162
|
+
" › ",
|
|
163
|
+
]),
|
|
164
|
+
h("b", {}, path),
|
|
165
|
+
),
|
|
166
|
+
h("h1", {}, pathLink(path), " ", live.value, " ", live.meta),
|
|
167
|
+
answerBox,
|
|
168
|
+
notes,
|
|
169
|
+
writersBox,
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const explain = (explainer: Explainer) => {
|
|
173
|
+
const jobs = explainer.file.routines.flatMap((routine) =>
|
|
174
|
+
routine.job === null ? [] : [routine.job],
|
|
175
|
+
);
|
|
176
|
+
let forced: Forced | null = null;
|
|
177
|
+
render = () => {
|
|
178
|
+
const read = explainRead({
|
|
179
|
+
manifest,
|
|
180
|
+
samples: store.samples,
|
|
181
|
+
jobs: store.jobs,
|
|
182
|
+
forced: forced?.forced ?? null,
|
|
183
|
+
target: path,
|
|
184
|
+
});
|
|
185
|
+
const result = explainer.answer(explainer.explain(path), node.type, read);
|
|
186
|
+
const before = needed.size;
|
|
187
|
+
for (const shown of [...result.needs, ...shownPaths(explainer, result)]) {
|
|
188
|
+
needed.add(shown);
|
|
189
|
+
}
|
|
190
|
+
if (needed.size !== before) {
|
|
191
|
+
show(jobs);
|
|
192
|
+
}
|
|
193
|
+
answerBox.replaceChildren(
|
|
194
|
+
...answerView(store, explainer, result, node.type, trail),
|
|
195
|
+
);
|
|
196
|
+
writersBox.replaceChildren(
|
|
197
|
+
h("h2", {}, `Writers (${result.verdicts.length})`),
|
|
198
|
+
...(result.verdicts.length
|
|
199
|
+
? orderedVerdicts(result).map((verdict) =>
|
|
200
|
+
verdictView(store, explainer, verdict, read, {
|
|
201
|
+
target: path,
|
|
202
|
+
type: node.type,
|
|
203
|
+
trail,
|
|
204
|
+
}),
|
|
205
|
+
)
|
|
206
|
+
: [empty("No statement in the program writes it.")]),
|
|
207
|
+
);
|
|
208
|
+
const { unread } = watchList(path, needed);
|
|
209
|
+
const own = store.samples.get(path);
|
|
210
|
+
notes.textContent = [
|
|
211
|
+
unread.length
|
|
212
|
+
? `Not read: too many values (${unread.length} more than ${maxWatched}).`
|
|
213
|
+
: "",
|
|
214
|
+
own && own.read === undefined
|
|
215
|
+
? "Values not read together: every answer is an estimate."
|
|
216
|
+
: "",
|
|
217
|
+
]
|
|
218
|
+
.filter(Boolean)
|
|
219
|
+
.join(" ");
|
|
220
|
+
};
|
|
221
|
+
show(jobs);
|
|
222
|
+
render();
|
|
223
|
+
page.poll(async () => {
|
|
224
|
+
forced = await getJson("forced");
|
|
225
|
+
render();
|
|
226
|
+
}, forcedPollMs);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
show([]);
|
|
230
|
+
loadFile()
|
|
231
|
+
.then((file) => {
|
|
232
|
+
if (file) {
|
|
233
|
+
explain(createExplainer(manifest, file));
|
|
234
|
+
} else {
|
|
235
|
+
answerBox.replaceChildren(
|
|
236
|
+
empty("This build has no explanations: rebuild with this compiler."),
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
})
|
|
240
|
+
.catch((error: unknown) => store.reportError(error));
|
|
241
|
+
|
|
242
|
+
const topics: Topic[] = ["samples", "jobs", "clock", "session"];
|
|
243
|
+
return {
|
|
244
|
+
element,
|
|
245
|
+
update: (changed) => {
|
|
246
|
+
live.update();
|
|
247
|
+
if (topics.some((topic) => changed.has(topic))) {
|
|
248
|
+
render();
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
/** The stored values the writer cards show: what their conditions, values and block inputs read. */
|
|
255
|
+
const shownPaths = (explainer: Explainer, result: AnswerResult): string[] =>
|
|
256
|
+
result.verdicts.flatMap((verdict) => {
|
|
257
|
+
const { file } = explainer;
|
|
258
|
+
const card = cardOf(file, verdict);
|
|
259
|
+
const roots = [
|
|
260
|
+
...card.conditions.flatMap(({ result, test }) =>
|
|
261
|
+
test === undefined ? [] : [{ expression: test, row: result.row }],
|
|
262
|
+
),
|
|
263
|
+
...card.inputs.map(([, expression]) => ({ expression, row: card.row })),
|
|
264
|
+
...(card.value === null
|
|
265
|
+
? []
|
|
266
|
+
: [{ expression: card.value, row: card.row }]),
|
|
267
|
+
];
|
|
268
|
+
return roots.flatMap(({ expression, row }) =>
|
|
269
|
+
[...leavesOf(file, expression, row)].flatMap((leaf) => {
|
|
270
|
+
const path = leafPath(explainer, leaf, row);
|
|
271
|
+
return path && !isPattern(path) ? [path] : [];
|
|
272
|
+
}),
|
|
273
|
+
);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
/** The stored path a read or pattern names in its routine row, or nothing for other expressions. */
|
|
277
|
+
const leafPath = (
|
|
278
|
+
explainer: Explainer,
|
|
279
|
+
leaf: number,
|
|
280
|
+
row: number,
|
|
281
|
+
): string | undefined => {
|
|
282
|
+
const node = explainer.file.expressions[leaf];
|
|
283
|
+
if (node?.kind === "reference") {
|
|
284
|
+
return leafPath(explainer, node.operand, row);
|
|
285
|
+
}
|
|
286
|
+
return node && (node.kind === "read" || node.kind === "pattern")
|
|
287
|
+
? explainer.pathAt(row, node.path)
|
|
288
|
+
: undefined;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const orderedVerdicts = (result: AnswerResult): Verdict[] => {
|
|
292
|
+
const answered =
|
|
293
|
+
result.answer.kind === "set" ? result.answer.writer : undefined;
|
|
294
|
+
const rank = { runs: 0, unknown: 1, candidate: 2, blocked: 3 } as const;
|
|
295
|
+
return [...result.verdicts].sort((a, b) => {
|
|
296
|
+
if (a === answered) {
|
|
297
|
+
return -1;
|
|
298
|
+
}
|
|
299
|
+
if (b === answered) {
|
|
300
|
+
return 1;
|
|
301
|
+
}
|
|
302
|
+
return rank[a.state] - rank[b.state];
|
|
303
|
+
});
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
/** A statement's source text and a link to it; code the compiler made has neither. */
|
|
307
|
+
const siteOf = (store: Store, file: ExplainFile, site: number | null) => {
|
|
308
|
+
const found = site === null ? undefined : file.sites[site];
|
|
309
|
+
const text =
|
|
310
|
+
found === undefined || found.text === null
|
|
311
|
+
? undefined
|
|
312
|
+
: file.texts[found.text];
|
|
313
|
+
return {
|
|
314
|
+
text: text ?? "generated code",
|
|
315
|
+
link: found && sourceLink(store, found.range),
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const answerView = (
|
|
320
|
+
store: Store,
|
|
321
|
+
explainer: Explainer,
|
|
322
|
+
result: AnswerResult,
|
|
323
|
+
type: string,
|
|
324
|
+
trail: readonly string[],
|
|
325
|
+
): Node[] => {
|
|
326
|
+
const answer: Answer = result.answer;
|
|
327
|
+
const badges = [
|
|
328
|
+
...(result.hmiControl
|
|
329
|
+
? [
|
|
330
|
+
h(
|
|
331
|
+
"span",
|
|
332
|
+
{ class: "badge h-stale", title: "The HMI writes it" },
|
|
333
|
+
`HMI: ${result.hmiControl}`,
|
|
334
|
+
),
|
|
335
|
+
]
|
|
336
|
+
: []),
|
|
337
|
+
...(result.retained
|
|
338
|
+
? [
|
|
339
|
+
h(
|
|
340
|
+
"span",
|
|
341
|
+
{ class: "badge h-unknown", title: "Kept across restarts" },
|
|
342
|
+
"retained",
|
|
343
|
+
),
|
|
344
|
+
]
|
|
345
|
+
: []),
|
|
346
|
+
...(result.writerTasks.length
|
|
347
|
+
? [
|
|
348
|
+
h(
|
|
349
|
+
"span",
|
|
350
|
+
{
|
|
351
|
+
class: "badge h-stale",
|
|
352
|
+
title: `Written by ${result.writerTasks.join(", ")}`,
|
|
353
|
+
},
|
|
354
|
+
"also written by another task",
|
|
355
|
+
),
|
|
356
|
+
]
|
|
357
|
+
: []),
|
|
358
|
+
...(result.clientWritable
|
|
359
|
+
? [
|
|
360
|
+
h(
|
|
361
|
+
"span",
|
|
362
|
+
{
|
|
363
|
+
class: "badge h-stale",
|
|
364
|
+
title: "A client such as the HMI may write it",
|
|
365
|
+
},
|
|
366
|
+
"clients can write",
|
|
367
|
+
),
|
|
368
|
+
]
|
|
369
|
+
: []),
|
|
370
|
+
];
|
|
371
|
+
const writerText = (verdict: Verdict) => {
|
|
372
|
+
const site = siteOf(
|
|
373
|
+
store,
|
|
374
|
+
explainer.file,
|
|
375
|
+
assignmentOf(explainer.file, verdict).site,
|
|
376
|
+
);
|
|
377
|
+
return site.link ?? h("code", {}, site.text);
|
|
378
|
+
};
|
|
379
|
+
const sentence = (): (Node | string)[] => {
|
|
380
|
+
switch (answer.kind) {
|
|
381
|
+
case "exact":
|
|
382
|
+
return answer.writer
|
|
383
|
+
? [
|
|
384
|
+
"Last written at ",
|
|
385
|
+
writerText(answer.writer),
|
|
386
|
+
", as the controller recorded it.",
|
|
387
|
+
]
|
|
388
|
+
: [
|
|
389
|
+
"Not written since the controller started: it holds its initial value.",
|
|
390
|
+
];
|
|
391
|
+
case "forced":
|
|
392
|
+
return [
|
|
393
|
+
h("b", { class: "err" }, "Forced on the controller"),
|
|
394
|
+
` (now ${outcomeText(store.manifest, type, answer.value)}).`,
|
|
395
|
+
];
|
|
396
|
+
case "input":
|
|
397
|
+
return [
|
|
398
|
+
"Hardware input: ",
|
|
399
|
+
h("b", {}, answer.io.device ?? "I/O"),
|
|
400
|
+
answer.io.channel ? ` / ${answer.io.channel}` : "",
|
|
401
|
+
answer.io.address ? ` (${answer.io.address})` : "",
|
|
402
|
+
answer.io.inverted ? ", inverted" : "",
|
|
403
|
+
".",
|
|
404
|
+
];
|
|
405
|
+
case "set":
|
|
406
|
+
return [
|
|
407
|
+
answer.estimate.length ? "Probably set at " : "Set this scan at ",
|
|
408
|
+
writerText(answer.writer),
|
|
409
|
+
...(answer.unless.length
|
|
410
|
+
? [
|
|
411
|
+
", unless ",
|
|
412
|
+
...answer.unless.flatMap((item, index) => [
|
|
413
|
+
index ? " or " : "",
|
|
414
|
+
writerText(item),
|
|
415
|
+
]),
|
|
416
|
+
" ran",
|
|
417
|
+
]
|
|
418
|
+
: []),
|
|
419
|
+
".",
|
|
420
|
+
];
|
|
421
|
+
case "held":
|
|
422
|
+
return [
|
|
423
|
+
"Not written in the latest scan: it keeps a value set earlier",
|
|
424
|
+
...(answer.writers.length
|
|
425
|
+
? [
|
|
426
|
+
", by ",
|
|
427
|
+
...answer.writers.flatMap((item, index) => [
|
|
428
|
+
index ? " or " : "",
|
|
429
|
+
writerText(item),
|
|
430
|
+
]),
|
|
431
|
+
]
|
|
432
|
+
: []),
|
|
433
|
+
".",
|
|
434
|
+
];
|
|
435
|
+
case "changed":
|
|
436
|
+
return ["The values changed between reads; waiting for a newer one."];
|
|
437
|
+
case "unknown":
|
|
438
|
+
return [
|
|
439
|
+
"Can't tell which statement set it: ",
|
|
440
|
+
answer.reasons.join("; ") || "some conditions are unknown",
|
|
441
|
+
".",
|
|
442
|
+
];
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
const estimate = "estimate" in answer ? answer.estimate : [];
|
|
446
|
+
const hint = result.hint.length
|
|
447
|
+
? [
|
|
448
|
+
h(
|
|
449
|
+
"p",
|
|
450
|
+
{ class: "hint" },
|
|
451
|
+
"The controller's record of its last writer, which may miss some writes: ",
|
|
452
|
+
...result.hint.flatMap((item, index) => [
|
|
453
|
+
index ? " or " : "",
|
|
454
|
+
writerText(item),
|
|
455
|
+
]),
|
|
456
|
+
".",
|
|
457
|
+
),
|
|
458
|
+
]
|
|
459
|
+
: [];
|
|
460
|
+
return [
|
|
461
|
+
h("p", { class: "why-sentence" }, ...sentence()),
|
|
462
|
+
...(estimate.length
|
|
463
|
+
? [h("p", { class: "hint" }, `Estimate: ${estimate.join("; ")}.`)]
|
|
464
|
+
: []),
|
|
465
|
+
...hint,
|
|
466
|
+
...(badges.length ? [h("div", { class: "chips" }, ...badges)] : []),
|
|
467
|
+
...(trail.length
|
|
468
|
+
? []
|
|
469
|
+
: [
|
|
470
|
+
h(
|
|
471
|
+
"p",
|
|
472
|
+
{ class: "hint" },
|
|
473
|
+
"Click a value below to see why it has its value.",
|
|
474
|
+
),
|
|
475
|
+
]),
|
|
476
|
+
];
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
const operandsOf = (
|
|
480
|
+
file: ExplainFile,
|
|
481
|
+
node: ExplainExpression,
|
|
482
|
+
row: number,
|
|
483
|
+
): readonly number[] => {
|
|
484
|
+
switch (node.kind) {
|
|
485
|
+
case "pattern":
|
|
486
|
+
return node.indexes;
|
|
487
|
+
case "unary":
|
|
488
|
+
case "convert":
|
|
489
|
+
return [node.operand];
|
|
490
|
+
case "binary":
|
|
491
|
+
case "logical":
|
|
492
|
+
return [node.left, node.right];
|
|
493
|
+
case "select":
|
|
494
|
+
return [node.condition, node.then, node.else];
|
|
495
|
+
case "record":
|
|
496
|
+
return Object.values(node.fields);
|
|
497
|
+
case "array":
|
|
498
|
+
return node.items;
|
|
499
|
+
case "opaque":
|
|
500
|
+
return node.reads;
|
|
501
|
+
case "call": {
|
|
502
|
+
const call = file.routines[row]?.calls[node.call];
|
|
503
|
+
return call === undefined ? [] : (file.calls[call]?.arguments ?? []);
|
|
504
|
+
}
|
|
505
|
+
case "read":
|
|
506
|
+
case "constant":
|
|
507
|
+
case "local":
|
|
508
|
+
case "parameter":
|
|
509
|
+
case "clock":
|
|
510
|
+
case "reference":
|
|
511
|
+
return [];
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
/** The stored values an expression reads, for chips. */
|
|
516
|
+
const leavesOf = (
|
|
517
|
+
file: ExplainFile,
|
|
518
|
+
index: number,
|
|
519
|
+
row: number,
|
|
520
|
+
found = new Set<number>(),
|
|
521
|
+
): Set<number> => {
|
|
522
|
+
const node = file.expressions[index];
|
|
523
|
+
if (!node || found.has(index)) {
|
|
524
|
+
return found;
|
|
525
|
+
}
|
|
526
|
+
// A reference is shown as the object it holds, so it is the leaf rather than its id.
|
|
527
|
+
if (
|
|
528
|
+
node.kind === "read" ||
|
|
529
|
+
node.kind === "pattern" ||
|
|
530
|
+
node.kind === "reference"
|
|
531
|
+
) {
|
|
532
|
+
found.add(index);
|
|
533
|
+
}
|
|
534
|
+
if (node.kind === "reference") {
|
|
535
|
+
return found;
|
|
536
|
+
}
|
|
537
|
+
for (const operand of operandsOf(file, node, row)) {
|
|
538
|
+
leavesOf(file, operand, row, found);
|
|
539
|
+
}
|
|
540
|
+
return found;
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
const conditionWords = (
|
|
544
|
+
manifest: DebugManifest,
|
|
545
|
+
file: ExplainFile,
|
|
546
|
+
condition: ExplainCondition,
|
|
547
|
+
row: number,
|
|
548
|
+
): string => {
|
|
549
|
+
const job = manifest.jobs.find((item) => item.id === file.routines[row]?.job);
|
|
550
|
+
const text = (index: number | null) =>
|
|
551
|
+
index === null ? "a condition" : (file.texts[index] ?? "a condition");
|
|
552
|
+
switch (condition.kind) {
|
|
553
|
+
case "test":
|
|
554
|
+
return condition.holds
|
|
555
|
+
? text(condition.text)
|
|
556
|
+
: `not (${text(condition.text)})`;
|
|
557
|
+
case "cases":
|
|
558
|
+
return `${text(condition.text)} ${condition.member ? "is one of" : "is none of"} ${condition.values.map(String).join(", ")}`;
|
|
559
|
+
case "exits":
|
|
560
|
+
return "no earlier return or break happened";
|
|
561
|
+
case "loop":
|
|
562
|
+
return "an iteration of the loop runs it";
|
|
563
|
+
case "loopReturns":
|
|
564
|
+
return "no iteration of the loop returned";
|
|
565
|
+
case "job": {
|
|
566
|
+
const step = job?.steps.find((item) => item.step === condition.step);
|
|
567
|
+
return `job ${job?.name ?? ""} is at ${step?.text ?? `step ${condition.step}`}`;
|
|
568
|
+
}
|
|
569
|
+
case "jobBusy":
|
|
570
|
+
return `job ${job?.name ?? ""} is running`;
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
const verdictView = (
|
|
575
|
+
store: Store,
|
|
576
|
+
explainer: Explainer,
|
|
577
|
+
verdict: Verdict,
|
|
578
|
+
read: ExplainRead,
|
|
579
|
+
{
|
|
580
|
+
target,
|
|
581
|
+
type: targetType,
|
|
582
|
+
trail,
|
|
583
|
+
}: { target: string; type: string; trail: readonly string[] },
|
|
584
|
+
) => {
|
|
585
|
+
const { file } = explainer;
|
|
586
|
+
const { manifest } = store;
|
|
587
|
+
const assignment = assignmentOf(file, verdict);
|
|
588
|
+
const card = cardOf(file, verdict);
|
|
589
|
+
const site = siteOf(store, file, assignment.site);
|
|
590
|
+
const via = assignment.via.map((call) =>
|
|
591
|
+
siteOf(store, file, file.calls[call]?.site ?? null),
|
|
592
|
+
);
|
|
593
|
+
const expressionType = (expression: number) => {
|
|
594
|
+
const node = file.expressions[expression];
|
|
595
|
+
return node && "type" in node ? node.type : "";
|
|
596
|
+
};
|
|
597
|
+
const chip = (expression: number, row: number) => {
|
|
598
|
+
const leaf = leafPath(explainer, expression, row) ?? "";
|
|
599
|
+
const outcome = explainer.evaluate(expression, verdict.chain, read, row);
|
|
600
|
+
return h(
|
|
601
|
+
"span",
|
|
602
|
+
{
|
|
603
|
+
class: `chip${outcome.estimate.length ? " unstable" : ""}`,
|
|
604
|
+
title: outcome.estimate.join("; "),
|
|
605
|
+
},
|
|
606
|
+
leaf && !isPattern(leaf)
|
|
607
|
+
? h(
|
|
608
|
+
"a",
|
|
609
|
+
{
|
|
610
|
+
href: href({
|
|
611
|
+
route: "why",
|
|
612
|
+
path: leaf,
|
|
613
|
+
trail: [...trail, target],
|
|
614
|
+
}),
|
|
615
|
+
},
|
|
616
|
+
leaf,
|
|
617
|
+
)
|
|
618
|
+
: leaf,
|
|
619
|
+
" ",
|
|
620
|
+
h("b", {}, outcomeText(manifest, expressionType(expression), outcome)),
|
|
621
|
+
);
|
|
622
|
+
};
|
|
623
|
+
const chips = (expression: number, row: number) =>
|
|
624
|
+
[...leavesOf(file, expression, row)].map((leaf) => chip(leaf, row));
|
|
625
|
+
const conditions = card.conditions.map(({ result, test }) => {
|
|
626
|
+
const leaves = test === undefined ? [] : chips(test, result.row);
|
|
627
|
+
return h(
|
|
628
|
+
"li",
|
|
629
|
+
{},
|
|
630
|
+
h("span", { class: "mark" }, truthMark[result.truth]),
|
|
631
|
+
" ",
|
|
632
|
+
conditionWords(manifest, file, result.condition, result.row),
|
|
633
|
+
result.reasons.length
|
|
634
|
+
? h("span", { class: "dim" }, ` — ${result.reasons.join("; ")}`)
|
|
635
|
+
: "",
|
|
636
|
+
leaves.length ? h("div", { class: "chips" }, ...leaves) : "",
|
|
637
|
+
);
|
|
638
|
+
});
|
|
639
|
+
const inputs = card.inputs.map(([name, input]) =>
|
|
640
|
+
h(
|
|
641
|
+
"div",
|
|
642
|
+
{ class: "chips" },
|
|
643
|
+
h("span", { class: "dim" }, `${name} =`),
|
|
644
|
+
h(
|
|
645
|
+
"b",
|
|
646
|
+
{},
|
|
647
|
+
outcomeText(
|
|
648
|
+
manifest,
|
|
649
|
+
expressionType(input),
|
|
650
|
+
explainer.evaluate(input, verdict.chain, read, card.row),
|
|
651
|
+
),
|
|
652
|
+
),
|
|
653
|
+
...chips(input, card.row),
|
|
654
|
+
),
|
|
655
|
+
);
|
|
656
|
+
const valueChips = card.value === null ? [] : chips(card.value, card.row);
|
|
657
|
+
return h(
|
|
658
|
+
"div",
|
|
659
|
+
{ class: `panel why-writer v-${verdict.state}` },
|
|
660
|
+
h(
|
|
661
|
+
"div",
|
|
662
|
+
{},
|
|
663
|
+
h("span", { class: `badge v-${verdict.state}` }, verdict.state),
|
|
664
|
+
" ",
|
|
665
|
+
h("code", {}, site.text),
|
|
666
|
+
" ",
|
|
667
|
+
site.link,
|
|
668
|
+
...via.map((call) =>
|
|
669
|
+
h("span", { class: "dim" }, ` via ${call.text} at `, call.link),
|
|
670
|
+
),
|
|
671
|
+
),
|
|
672
|
+
verdict.value
|
|
673
|
+
? h(
|
|
674
|
+
"p",
|
|
675
|
+
{ class: "dim" },
|
|
676
|
+
"writes ",
|
|
677
|
+
h("b", {}, outcomeText(manifest, targetType, verdict.value)),
|
|
678
|
+
)
|
|
679
|
+
: "",
|
|
680
|
+
h("ul", { class: "why-conditions" }, ...conditions),
|
|
681
|
+
...inputs,
|
|
682
|
+
valueChips.length
|
|
683
|
+
? h(
|
|
684
|
+
"div",
|
|
685
|
+
{ class: "chips" },
|
|
686
|
+
h("span", { class: "dim" }, "reads"),
|
|
687
|
+
...valueChips,
|
|
688
|
+
)
|
|
689
|
+
: "",
|
|
690
|
+
verdict.estimate.length
|
|
691
|
+
? h("p", { class: "hint" }, `Estimate: ${verdict.estimate.join("; ")}.`)
|
|
692
|
+
: "",
|
|
693
|
+
);
|
|
694
|
+
};
|