@stateward/core 1.2.1 → 1.3.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.
Files changed (75) hide show
  1. package/dist/analyses.d.ts +37 -0
  2. package/dist/analyses.js +57 -0
  3. package/dist/backend/program-record.d.ts +7 -0
  4. package/dist/backend/typescript6.d.ts +35 -32
  5. package/dist/backend/typescript6.js +3804 -163
  6. package/dist/baseline.d.ts +1 -1
  7. package/dist/baseline.js +14 -10
  8. package/dist/cache.d.ts +89 -5
  9. package/dist/cache.js +271 -40
  10. package/dist/checker.d.ts +11 -1
  11. package/dist/checker.js +32 -2
  12. package/dist/class-id.d.ts +34 -0
  13. package/dist/class-id.js +93 -0
  14. package/dist/code-text.d.ts +8 -0
  15. package/dist/code-text.js +66 -0
  16. package/dist/config-file.js +7 -5
  17. package/dist/config.d.ts +10 -2
  18. package/dist/config.js +541 -49
  19. package/dist/define.d.ts +8 -2
  20. package/dist/disk-cache.d.ts +2 -0
  21. package/dist/disk-cache.js +77 -11
  22. package/dist/engine.d.ts +51 -1
  23. package/dist/engine.js +517 -42
  24. package/dist/fact-lines.d.ts +31 -0
  25. package/dist/fact-lines.js +197 -0
  26. package/dist/facts-versions.d.ts +27 -0
  27. package/dist/facts-versions.js +99 -0
  28. package/dist/fixes.js +9 -4
  29. package/dist/guarantees.d.ts +63 -11
  30. package/dist/guarantees.js +151 -21
  31. package/dist/ignores.d.ts +11 -0
  32. package/dist/ignores.js +74 -27
  33. package/dist/implementation.d.ts +0 -6
  34. package/dist/implementation.js +0 -17
  35. package/dist/index.d.ts +10 -9
  36. package/dist/index.js +14 -7
  37. package/dist/internal.d.ts +9 -5
  38. package/dist/internal.js +6 -3
  39. package/dist/lazy.d.ts +8 -1
  40. package/dist/lazy.js +27 -2
  41. package/dist/ledger.d.ts +77 -0
  42. package/dist/ledger.js +423 -0
  43. package/dist/off-by-default.d.ts +13 -0
  44. package/dist/off-by-default.js +15 -0
  45. package/dist/options.d.ts +21 -5
  46. package/dist/options.js +22 -7
  47. package/dist/package-facts.d.ts +211 -17
  48. package/dist/package-facts.js +520 -38
  49. package/dist/plan.d.ts +1 -1
  50. package/dist/plan.js +7 -2
  51. package/dist/release.d.ts +12 -21
  52. package/dist/release.js +28 -38
  53. package/dist/renamed.d.ts +22 -3
  54. package/dist/renamed.js +50 -16
  55. package/dist/rollout.js +7 -4
  56. package/dist/safe-calls.d.ts +26 -0
  57. package/dist/safe-calls.js +345 -0
  58. package/dist/severity.d.ts +1 -1
  59. package/dist/severity.js +17 -3
  60. package/dist/stated.d.ts +37 -0
  61. package/dist/stated.js +123 -0
  62. package/dist/test-runner.d.ts +18 -0
  63. package/dist/test-runner.js +483 -0
  64. package/dist/testing-tsc.d.ts +16 -0
  65. package/dist/testing-tsc.js +86 -0
  66. package/dist/testing.d.ts +5 -4
  67. package/dist/testing.js +6 -6
  68. package/dist/timing.d.ts +15 -0
  69. package/dist/timing.js +41 -2
  70. package/dist/types.d.ts +1068 -16
  71. package/dist/unread.d.ts +90 -0
  72. package/dist/unread.js +405 -0
  73. package/dist/vocabulary.d.ts +1 -1
  74. package/dist/vocabulary.js +1 -1
  75. package/package.json +4 -2
package/dist/timing.d.ts CHANGED
@@ -20,6 +20,12 @@ export type RuleCost = {
20
20
  * triggers first, which later questions of any rule then reuse.
21
21
  */
22
22
  readonly typeMs: number;
23
+ /**
24
+ * Of `typeMs`, the first answer to each question (a method asked about the same node, symbol or
25
+ * value): the shared type checking, which later questions of any rule reuse. The rest of `ms` is
26
+ * the rule's own work.
27
+ */
28
+ readonly firstTypeMs: number;
23
29
  /** Files the rule ran on (not counting results reused from the cache). */
24
30
  readonly files: number;
25
31
  /**
@@ -48,8 +54,15 @@ export type RunTiming = {
48
54
  readonly programMs: number;
49
55
  /** Of the rules' time, inside type questions: the type checking the rules ask for. */
50
56
  readonly typeMs: number;
57
+ /** Of `typeMs`, the first answer to each question: the shared type checking (`RuleCost.firstTypeMs`). */
58
+ readonly firstTypeMs: number;
51
59
  /** Dependency fingerprints for the results cache. */
52
60
  readonly fingerprintMs: number;
61
+ /**
62
+ * The reference ledger: every reference to each stated declaration, in the files whose ledger is
63
+ * not in the cache (its type questions included).
64
+ */
65
+ readonly ledgerMs: number;
53
66
  /** Everything else: syntax and import findings, ignore comments, sorting, the cache. */
54
67
  readonly otherMs: number;
55
68
  /** The second pass's time (not part of the check's result), when there was one. */
@@ -61,6 +74,8 @@ export type TimingRecorder = {
61
74
  /** The time of building programs, added to `programMs`. */
62
75
  program(ms: number): void;
63
76
  fingerprint(ms: number): void;
77
+ /** The time of the reference ledger on one file, added to `ledgerMs`. */
78
+ ledger(ms: number): void;
64
79
  /** Runs `run` as `ruleId`'s file side on one file and records its cost. */
65
80
  fileSide<T>(ruleId: string, kind: "file" | "project", run: () => T): T;
66
81
  /** Counts one result of `ruleId` reused from the cache. */
package/dist/timing.js CHANGED
@@ -5,9 +5,36 @@ export function createTimingRecorder({ secondPass = false, } = {}) {
5
5
  let started = performance.now();
6
6
  let programMs = 0;
7
7
  let fingerprintMs = 0;
8
+ let ledgerMs = 0;
8
9
  /** The type time of the rule that is running; undefined between rules. */
9
10
  let current;
10
11
  const wrapped = new WeakMap();
12
+ /** The questions asked so far, by their first argument, then the method: a second ask is not first. */
13
+ const askedOn = new WeakMap();
14
+ const askedBy = new Map();
15
+ /** Whether this is the first time `method` is asked about `subject` in the run; notes it. */
16
+ const firstAsk = (method, subject) => {
17
+ let methods;
18
+ if (typeof subject === "object" && subject !== null) {
19
+ methods = askedOn.get(subject);
20
+ if (methods === undefined) {
21
+ methods = new Set();
22
+ askedOn.set(subject, methods);
23
+ }
24
+ }
25
+ else {
26
+ const key = `${typeof subject}:${String(subject)}`;
27
+ methods = askedBy.get(key);
28
+ if (methods === undefined) {
29
+ methods = new Set();
30
+ askedBy.set(key, methods);
31
+ }
32
+ }
33
+ if (methods.has(method))
34
+ return false;
35
+ methods.add(method);
36
+ return true;
37
+ };
11
38
  const costOf = (ruleId, kind) => {
12
39
  let found = rules.get(ruleId);
13
40
  if (found === undefined) {
@@ -19,6 +46,7 @@ export function createTimingRecorder({ secondPass = false, } = {}) {
19
46
  fileMs: 0,
20
47
  projectMs: 0,
21
48
  typeMs: 0,
49
+ firstTypeMs: 0,
22
50
  files: 0,
23
51
  reused: 0,
24
52
  allocatedBytes: 0,
@@ -55,6 +83,9 @@ export function createTimingRecorder({ secondPass = false, } = {}) {
55
83
  fingerprint(ms) {
56
84
  fingerprintMs += ms;
57
85
  },
86
+ ledger(ms) {
87
+ ledgerMs += ms;
88
+ },
58
89
  fileSide(ruleId, kind, run) {
59
90
  const cost = costOf(ruleId, kind);
60
91
  cost.files += 1;
@@ -90,13 +121,18 @@ export function createTimingRecorder({ secondPass = false, } = {}) {
90
121
  }
91
122
  // A question asked inside another (none today) is counted once, by the outer one.
92
123
  current = undefined;
124
+ // The second pass asks everything again: only the check's first asks are shared.
125
+ const first = typeSide === "typeMs" && firstAsk(key, args[0]);
93
126
  const at = performance.now();
94
127
  try {
95
128
  const answer = Reflect.apply(value, target, args);
96
129
  return answer;
97
130
  }
98
131
  finally {
99
- cost[typeSide] += performance.now() - at;
132
+ const spent = performance.now() - at;
133
+ cost[typeSide] += spent;
134
+ if (first)
135
+ cost.firstTypeMs += spent;
100
136
  current = cost;
101
137
  }
102
138
  };
@@ -124,14 +160,17 @@ export function createTimingRecorder({ secondPass = false, } = {}) {
124
160
  const ruleMs = costs.reduce((sum, cost) => sum + cost.ms, 0);
125
161
  const warmMs = costs.reduce((sum, cost) => sum + (cost.warmMs ?? 0), 0);
126
162
  const typeMs = costs.reduce((sum, cost) => sum + cost.typeMs, 0);
163
+ const firstTypeMs = costs.reduce((sum, cost) => sum + cost.firstTypeMs, 0);
127
164
  // The second pass is not part of the check: the total is what the check alone took.
128
165
  const totalMs = elapsed - warmMs;
129
166
  return {
130
167
  totalMs,
131
168
  programMs,
132
169
  typeMs,
170
+ firstTypeMs,
133
171
  fingerprintMs,
134
- otherMs: Math.max(0, totalMs - programMs - fingerprintMs - ruleMs),
172
+ ledgerMs,
173
+ otherMs: Math.max(0, totalMs - programMs - fingerprintMs - ledgerMs - ruleMs),
135
174
  secondPassMs: secondPass ? warmMs : undefined,
136
175
  rules: costs,
137
176
  };