@procedures/compiler 0.0.0-stage → 0.2.3

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 (174) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +254 -2
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/checks.d.ts +24 -0
  5. package/dist/checks.d.ts.map +1 -0
  6. package/dist/checks.js +123 -0
  7. package/dist/checks.js.map +1 -0
  8. package/dist/codegen-closure.d.ts +19 -0
  9. package/dist/codegen-closure.d.ts.map +1 -0
  10. package/dist/codegen-closure.js +200 -0
  11. package/dist/codegen-closure.js.map +1 -0
  12. package/dist/codegen-text.d.ts +44 -0
  13. package/dist/codegen-text.d.ts.map +1 -0
  14. package/dist/codegen-text.js +360 -0
  15. package/dist/codegen-text.js.map +1 -0
  16. package/dist/diagnostics.d.ts +67 -0
  17. package/dist/diagnostics.d.ts.map +1 -0
  18. package/dist/diagnostics.js +38 -0
  19. package/dist/diagnostics.js.map +1 -0
  20. package/dist/effects.d.ts +63 -0
  21. package/dist/effects.d.ts.map +1 -0
  22. package/dist/effects.js +185 -0
  23. package/dist/effects.js.map +1 -0
  24. package/dist/explain.d.ts +58 -0
  25. package/dist/explain.d.ts.map +1 -0
  26. package/dist/explain.js +144 -0
  27. package/dist/explain.js.map +1 -0
  28. package/dist/facts.d.ts +66 -0
  29. package/dist/facts.d.ts.map +1 -0
  30. package/dist/facts.js +102 -0
  31. package/dist/facts.js.map +1 -0
  32. package/dist/fold.d.ts +27 -0
  33. package/dist/fold.d.ts.map +1 -0
  34. package/dist/fold.js +128 -0
  35. package/dist/fold.js.map +1 -0
  36. package/dist/index.d.ts +35 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +22 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/interceptor.d.ts +51 -0
  41. package/dist/interceptor.d.ts.map +1 -0
  42. package/dist/interceptor.js +116 -0
  43. package/dist/interceptor.js.map +1 -0
  44. package/dist/ir.d.ts +240 -0
  45. package/dist/ir.d.ts.map +1 -0
  46. package/dist/ir.js +74 -0
  47. package/dist/ir.js.map +1 -0
  48. package/dist/mermaid.d.ts +53 -0
  49. package/dist/mermaid.d.ts.map +1 -0
  50. package/dist/mermaid.js +423 -0
  51. package/dist/mermaid.js.map +1 -0
  52. package/dist/module.d.ts +20 -0
  53. package/dist/module.d.ts.map +1 -0
  54. package/dist/module.js +124 -0
  55. package/dist/module.js.map +1 -0
  56. package/dist/normalize.d.ts +43 -0
  57. package/dist/normalize.d.ts.map +1 -0
  58. package/dist/normalize.js +529 -0
  59. package/dist/normalize.js.map +1 -0
  60. package/dist/openrpc.d.ts +63 -0
  61. package/dist/openrpc.d.ts.map +1 -0
  62. package/dist/openrpc.js +57 -0
  63. package/dist/openrpc.js.map +1 -0
  64. package/dist/print.d.ts +8 -0
  65. package/dist/print.d.ts.map +1 -0
  66. package/dist/print.js +148 -0
  67. package/dist/print.js.map +1 -0
  68. package/dist/procedures/program/check.d.ts +14 -0
  69. package/dist/procedures/program/check.d.ts.map +1 -0
  70. package/dist/procedures/program/check.js +30 -0
  71. package/dist/procedures/program/check.js.map +1 -0
  72. package/dist/procedures/program/compile.d.ts +14 -0
  73. package/dist/procedures/program/compile.d.ts.map +1 -0
  74. package/dist/procedures/program/compile.js +35 -0
  75. package/dist/procedures/program/compile.js.map +1 -0
  76. package/dist/procedures/program/diagram.d.ts +14 -0
  77. package/dist/procedures/program/diagram.d.ts.map +1 -0
  78. package/dist/procedures/program/diagram.js +23 -0
  79. package/dist/procedures/program/diagram.js.map +1 -0
  80. package/dist/procedures/program/effects-output.d.ts +8 -0
  81. package/dist/procedures/program/effects-output.d.ts.map +1 -0
  82. package/dist/procedures/program/effects-output.js +13 -0
  83. package/dist/procedures/program/effects-output.js.map +1 -0
  84. package/dist/procedures/program/explain.d.ts +14 -0
  85. package/dist/procedures/program/explain.d.ts.map +1 -0
  86. package/dist/procedures/program/explain.js +43 -0
  87. package/dist/procedures/program/explain.js.map +1 -0
  88. package/dist/procedures/program/index.d.ts +5 -0
  89. package/dist/procedures/program/index.d.ts.map +1 -0
  90. package/dist/procedures/program/index.js +5 -0
  91. package/dist/procedures/program/index.js.map +1 -0
  92. package/dist/procedures/sdk/index.d.ts +3 -0
  93. package/dist/procedures/sdk/index.d.ts.map +1 -0
  94. package/dist/procedures/sdk/index.js +3 -0
  95. package/dist/procedures/sdk/index.js.map +1 -0
  96. package/dist/procedures/sdk/manifest.d.ts +11 -0
  97. package/dist/procedures/sdk/manifest.d.ts.map +1 -0
  98. package/dist/procedures/sdk/manifest.js +15 -0
  99. package/dist/procedures/sdk/manifest.js.map +1 -0
  100. package/dist/procedures/sdk/openrpc.d.ts +11 -0
  101. package/dist/procedures/sdk/openrpc.d.ts.map +1 -0
  102. package/dist/procedures/sdk/openrpc.js +13 -0
  103. package/dist/procedures/sdk/openrpc.js.map +1 -0
  104. package/dist/procedures/sdk/typescript.d.ts +11 -0
  105. package/dist/procedures/sdk/typescript.d.ts.map +1 -0
  106. package/dist/procedures/sdk/typescript.js +14 -0
  107. package/dist/procedures/sdk/typescript.js.map +1 -0
  108. package/dist/program.d.ts +84 -0
  109. package/dist/program.d.ts.map +1 -0
  110. package/dist/program.js +108 -0
  111. package/dist/program.js.map +1 -0
  112. package/dist/refs.d.ts +9 -0
  113. package/dist/refs.d.ts.map +1 -0
  114. package/dist/refs.js +9 -0
  115. package/dist/refs.js.map +1 -0
  116. package/dist/register.d.ts +6 -0
  117. package/dist/register.d.ts.map +1 -0
  118. package/dist/register.js +8 -0
  119. package/dist/register.js.map +1 -0
  120. package/dist/runtime.d.ts +68 -0
  121. package/dist/runtime.d.ts.map +1 -0
  122. package/dist/runtime.js +138 -0
  123. package/dist/runtime.js.map +1 -0
  124. package/dist/schema.d.ts +41 -0
  125. package/dist/schema.d.ts.map +1 -0
  126. package/dist/schema.js +325 -0
  127. package/dist/schema.js.map +1 -0
  128. package/dist/scopes.d.ts +25 -0
  129. package/dist/scopes.d.ts.map +1 -0
  130. package/dist/scopes.js +202 -0
  131. package/dist/scopes.js.map +1 -0
  132. package/dist/types.d.ts +129 -0
  133. package/dist/types.d.ts.map +1 -0
  134. package/dist/types.js +157 -0
  135. package/dist/types.js.map +1 -0
  136. package/dist/typescript-sdk.d.ts +34 -0
  137. package/dist/typescript-sdk.d.ts.map +1 -0
  138. package/dist/typescript-sdk.js +231 -0
  139. package/dist/typescript-sdk.js.map +1 -0
  140. package/package.json +83 -3
  141. package/src/checks.ts +128 -0
  142. package/src/codegen-closure.ts +224 -0
  143. package/src/codegen-text.ts +396 -0
  144. package/src/diagnostics.ts +98 -0
  145. package/src/effects.ts +231 -0
  146. package/src/explain.ts +194 -0
  147. package/src/facts.ts +161 -0
  148. package/src/fold.ts +136 -0
  149. package/src/index.ts +35 -0
  150. package/src/interceptor.ts +149 -0
  151. package/src/ir.ts +330 -0
  152. package/src/mermaid.ts +460 -0
  153. package/src/module.ts +171 -0
  154. package/src/normalize.ts +694 -0
  155. package/src/openrpc.ts +104 -0
  156. package/src/print.ts +143 -0
  157. package/src/procedures/program/check.ts +31 -0
  158. package/src/procedures/program/compile.ts +36 -0
  159. package/src/procedures/program/diagram.ts +25 -0
  160. package/src/procedures/program/effects-output.ts +16 -0
  161. package/src/procedures/program/explain.ts +46 -0
  162. package/src/procedures/program/index.ts +4 -0
  163. package/src/procedures/sdk/index.ts +2 -0
  164. package/src/procedures/sdk/manifest.ts +17 -0
  165. package/src/procedures/sdk/openrpc.ts +16 -0
  166. package/src/procedures/sdk/typescript.ts +17 -0
  167. package/src/program.ts +181 -0
  168. package/src/refs.ts +9 -0
  169. package/src/register.ts +10 -0
  170. package/src/runtime.ts +188 -0
  171. package/src/schema.ts +318 -0
  172. package/src/scopes.ts +196 -0
  173. package/src/types.ts +318 -0
  174. package/src/typescript-sdk.ts +282 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codegen-text.js","sourceRoot":"","sources":["../src/codegen-text.ts"],"names":[],"mappings":"A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P,wBAAwB;YAC1B,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;AACjG,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * The diagnostics of the compiler: each problem that a pass finds, with the JSON pointer of its
3
+ * source in the program.
4
+ */
5
+ /** The severity of a diagnostic. An error makes `ok` false: the host does not start the program. */
6
+ export type Severity = "error" | "warning" | "info";
7
+ /** The codes of the diagnostics. */
8
+ export type DiagnosticCode =
9
+ /** The program is not a call: `client.exec()` starts only a call. */
10
+ "root-not-call"
11
+ /** A `$proc` path is empty, or it has a segment that is not a string. */
12
+ | "invalid-path"
13
+ /** No procedure has the path. */
14
+ | "unknown-procedure"
15
+ /** The host does not expose the procedure, so a data-driven procedure cannot call it. */
16
+ | "not-exposed"
17
+ /** The capability refuses the call: its effects, or a destructive procedure. */
18
+ | "capability-refused"
19
+ /** The compiler cannot see what a call runs, so it does not know its effects. */
20
+ | "effects-unknown"
21
+ /** A `$ref` reads a name that no scope has. */
22
+ | "unknown-name"
23
+ /** A `$ref` reads the name of a later step of a chain. */
24
+ | "use-before-definition"
25
+ /** A `$ref` is outside each scope, so it is data. */
26
+ | "unscoped-ref"
27
+ /** The input does not agree with the JSON Schema of the procedure. */
28
+ | "input-schema"
29
+ /** The input of a control-flow procedure does not agree with its schema. */
30
+ | "invalid-control-flow"
31
+ /** The `fn` of `client.map` or `client.reduce` is not one call. */
32
+ | "fn-not-call"
33
+ /** The calls nest deeper than the hydration limit of 10 levels. */
34
+ | "depth-limit"
35
+ /** Plain data nests deeper than 1000 levels. */
36
+ | "data-depth"
37
+ /** An input contains itself. */
38
+ | "cyclic-input"
39
+ /** A `$never` call is data in a position where a call usually runs. */
40
+ | "never-trap"
41
+ /** A call waits for its runner (`$parent` or a context name), so hydration keeps it as data. */
42
+ | "deferred-call"
43
+ /** A `$name` on a call that is not a chain step: no `$ref` can read it. */
44
+ | "name-not-bound"
45
+ /** Two steps of one chain have the same `$name`. */
46
+ | "duplicate-name"
47
+ /** Control flow adds `cwd` or `node` to an input that is not an object, so the input is lost. */
48
+ | "input-replaced"
49
+ /** An array of calls runs as one `client.chain`: its value is `{ results, final }`. */
50
+ | "implicit-chain"
51
+ /** A literal of the program has no source text (a function, a class instance). */
52
+ | "not-serializable"
53
+ /** The program nests so deep that a JavaScript parser can refuse its source text. */
54
+ | "text-depth";
55
+ /** One problem that the compiler found. */
56
+ export interface Diagnostic {
57
+ readonly severity: Severity;
58
+ readonly code: DiagnosticCode;
59
+ readonly message: string;
60
+ /** The JSON pointer (RFC 6901) of the part of the program. The empty string is the root. */
61
+ readonly pointer: string;
62
+ }
63
+ /** True when the list has an error. */
64
+ export declare function hasErrors(diagnostics: readonly Diagnostic[]): boolean;
65
+ /** The diagnostics in the order of their pointers, then the errors first. The same problem at the same place is one diagnostic. */
66
+ export declare function sortDiagnostics(diagnostics: readonly Diagnostic[]): Diagnostic[];
67
+ //# sourceMappingURL=diagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,oGAAoG;AACpG,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAEpD,oCAAoC;AACpC,MAAM,MAAM,cAAc;AACxB,qEAAqE;AACnE,eAAe;AACjB,yEAAyE;GACvE,cAAc;AAChB,iCAAiC;GAC/B,mBAAmB;AACrB,yFAAyF;GACvF,aAAa;AACf,gFAAgF;GAC9E,oBAAoB;AACtB,iFAAiF;GAC/E,iBAAiB;AACnB,+CAA+C;GAC7C,cAAc;AAChB,0DAA0D;GACxD,uBAAuB;AACzB,qDAAqD;GACnD,cAAc;AAChB,sEAAsE;GACpE,cAAc;AAChB,4EAA4E;GAC1E,sBAAsB;AACxB,mEAAmE;GACjE,aAAa;AACf,mEAAmE;GACjE,aAAa;AACf,gDAAgD;GAC9C,YAAY;AACd,gCAAgC;GAC9B,cAAc;AAChB,uEAAuE;GACrE,YAAY;AACd,gGAAgG;GAC9F,eAAe;AACjB,2EAA2E;GACzE,gBAAgB;AAClB,oDAAoD;GAClD,gBAAgB;AAClB,iGAAiG;GAC/F,gBAAgB;AAClB,uFAAuF;GACrF,gBAAgB;AAClB,kFAAkF;GAChF,kBAAkB;AACpB,qFAAqF;GACnF,YAAY,CAAC;AAEjB,2CAA2C;AAC3C,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,4FAA4F;IAC5F,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,uCAAuC;AACvC,wBAAgB,SAAS,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,GAAG,OAAO,CAErE;AAED,mIAAmI;AACnI,wBAAgB,eAAe,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,EAAE,CAUhF"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The diagnostics of the compiler: each problem that a pass finds, with the JSON pointer of its
3
+ * source in the program.
4
+ */
5
+ /** True when the list has an error. */
6
+ export function hasErrors(diagnostics) {
7
+ return diagnostics.some((diagnostic) => diagnostic.severity === "error");
8
+ }
9
+ /** The diagnostics in the order of their pointers, then the errors first. The same problem at the same place is one diagnostic. */
10
+ export function sortDiagnostics(diagnostics) {
11
+ const rank = { error: 0, warning: 1, info: 2 };
12
+ const seen = new Set();
13
+ const unique = diagnostics.filter((diagnostic) => {
14
+ const key = `${diagnostic.pointer}\u0000${diagnostic.code}\u0000${diagnostic.message}`;
15
+ if (seen.has(key))
16
+ return false;
17
+ seen.add(key);
18
+ return true;
19
+ });
20
+ return unique.sort((a, b) => comparePointers(a.pointer, b.pointer) || rank[a.severity] - rank[b.severity]);
21
+ }
22
+ /** The order of two pointers: the segments one by one, and a number segment as a number. */
23
+ function comparePointers(a, b) {
24
+ const left = a.split("/");
25
+ const right = b.split("/");
26
+ for (let index = 0; index < Math.min(left.length, right.length); index++) {
27
+ const x = left[index];
28
+ const y = right[index];
29
+ if (x === y)
30
+ continue;
31
+ const numbers = /^\d+$/.test(x) && /^\d+$/.test(y);
32
+ if (numbers)
33
+ return Number(x) - Number(y);
34
+ return x < y ? -1 : 1;
35
+ }
36
+ return left.length - right.length;
37
+ }
38
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA+DH,uCAAuC;AACvC,MAAM,UAAU,SAAS,CAAC,WAAkC;IAC1D,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;AAC3E,CAAC;AAED,mIAAmI;AACnI,MAAM,UAAU,eAAe,CAAC,WAAkC;IAChE,MAAM,IAAI,GAA6B,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;IACzE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;QAC/C,MAAM,GAAG,GAAG,GAAG,UAAU,CAAC,OAAO,SAAS,UAAU,CAAC,IAAI,SAAS,UAAU,CAAC,OAAO,EAAE,CAAC;QACvF,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QAChC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACd,OAAO,IAAI,CAAC;IACd,C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of each call that can start. A sequence and the
5
+ * branches give the union. A call that does not declare its effects, or whose program the
6
+ * compiler cannot see, makes the effects unknown: the check fails closed.
7
+ * - `must` is the lower bound: the effects of each run in which no call fails. A sequence gives
8
+ * the union. Two branches give the condition and the intersection of the branches. A part
9
+ * that can start zero times (a later operand of `and`, the `fn` of `map`) gives nothing.
10
+ */
11
+ import { type Effects, type ProcedureEntry, type ProcedurePath } from "@procedures/client/browser";
12
+ import type { IRNode, Pointer } from "./ir.js";
13
+ import type { ProcedureFacts } from "./facts.js";
14
+ /** The upper bound of the effects. An undefined list: the compiler does not know it. */
15
+ export interface MayEffects {
16
+ readonly reads: ReadonlySet<string> | undefined;
17
+ readonly writes: ReadonlySet<string> | undefined;
18
+ /** True: a call can delete or overwrite data. */
19
+ readonly destructive: boolean;
20
+ /** True: each call that writes is idempotent. */
21
+ readonly idempotent: boolean;
22
+ }
23
+ /** The lower bound of the effects. */
24
+ export interface MustEffects {
25
+ readonly reads: ReadonlySet<string>;
26
+ readonly writes: ReadonlySet<string>;
27
+ }
28
+ /** The effects of a node. */
29
+ export interface EffectSummary {
30
+ readonly may: MayEffects;
31
+ readonly must: MustEffects;
32
+ }
33
+ /** The effects of a part that does nothing. */
34
+ export declare const NO_EFFECTS: EffectSummary;
35
+ /** The effects of a part that the compiler does not know. */
36
+ export declare const UNKNOWN_EFFECTS: EffectSummary;
37
+ /** The effects of two parts that both start, one after the other. */
38
+ export declare function sequence(...parts: EffectSummary[]): EffectSummary;
39
+ /** The effects of a part that can start zero times. */
40
+ export declare function optional(part: EffectSummary): EffectSummary;
41
+ /** The effects of one of two parts. */
42
+ export declare function either(a: EffectSummary, b: EffectSummary): EffectSummary;
43
+ /** The effects that an entry declares. Absent effects, or an absent list, are unknown. */
44
+ export declare function declaredEffects(entry: ProcedureEntry | undefined): EffectSummary;
45
+ /** True when the effects are not fully known. */
46
+ export declare function isUnknown(summary: EffectSummary): boolean;
47
+ /** The effects as the `Effects` of a manifest: an unknown list is absent. */
48
+ export declare function toEffects(may: MayEffects): Effects;
49
+ /** The result of the pass. */
50
+ export interface EffectsAnalysis {
51
+ readonly program: EffectSummary;
52
+ /** The effects of each node. */
53
+ readonly byNode: ReadonlyMap<IRNode, EffectSummary>;
54
+ /** The effects of the program that each data-driven call runs (its body), when the compiler knows them. */
55
+ readonly nested: ReadonlyMap<IRNode, EffectSummary>;
56
+ /** The pointers of the calls whose effects the compiler does not know. */
57
+ readonly unknownAt: readonly Pointer[];
58
+ }
59
+ /** The effects of the body of a defined procedure, or undefined when the compiler cannot see it. */
60
+ export type BodyEffects = (path: ProcedurePath) => EffectSummary | undefined;
61
+ /** This function infers the effects of each node and of the program. */
62
+ export declare function inferEffects(root: IRNode, facts: ProcedureFacts, bodyEffects: BodyEffects): EffectsAnalysis;
63
+ //# sourceMappingURL=effects.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effects.d.ts","sourceRoot":"","sources":["../src/effects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAA6B,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC9H,OAAO,KAAK,EAAyB,MAAM,EAAa,OAAO,EAAE,MAAM,SAAS,CAAC;AACjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,wFAAwF;AACxF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAChD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACjD,iDAAiD;IACjD,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,iDAAiD;IACjD,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B;AAED,sCAAsC;AACtC,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAA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,IAAI,EAAE,aAAa,KAAK,aAAa,GAAG,SAAS,CAAC;AAE7E,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,GAAG,eAAe,CA6F3G"}
@@ -0,0 +1,185 @@
1
+ /**
2
+ * The effects pass: the effects of the whole program, from the bottom up.
3
+ *
4
+ * - `may` is the upper bound: the effects of each call that can start. A sequence and the
5
+ * branches give the union. A call that does not declare its effects, or whose program the
6
+ * compiler cannot see, makes the effects unknown: the check fails closed.
7
+ * - `must` is the lower bound: the effects of each run in which no call fails. A sequence gives
8
+ * the union. Two branches give the condition and the intersection of the branches. A part
9
+ * that can start zero times (a later operand of `and`, the `fn` of `map`) gives nothing.
10
+ */
11
+ import { isDestructive, isReadOnly } from "@procedures/client/browser";
12
+ const EMPTY_SET = new Set();
13
+ /** The effects of a part that does nothing. */
14
+ export const NO_EFFECTS = {
15
+ may: { reads: EMPTY_SET, writes: EMPTY_SET, destructive: false, idempotent: true },
16
+ must: { reads: EMPTY_SET, writes: EMPTY_SET },
17
+ };
18
+ /** The effects of a part that the compiler does not know. */
19
+ export const UNKNOWN_EFFECTS = {
20
+ may: { reads: undefined, writes: undefined, destructive: true, idempotent: false },
21
+ must: { reads: EMPTY_SET, writes: EMPTY_SET },
22
+ };
23
+ function union(a, b) {
24
+ if (!a || !b)
25
+ return undefined;
26
+ if (a.size === 0)
27
+ return b;
28
+ if (b.size === 0)
29
+ return a;
30
+ return new Set([...a, ...b]);
31
+ }
32
+ function unionMust(a, b) {
33
+ return union(a, b) ?? EMPTY_SET;
34
+ }
35
+ /** The effects of two parts that both start, one after the other. */
36
+ export function sequence(...parts) {
37
+ return parts.reduce((a, b) => ({
38
+ may: {
39
+ reads: union(a.may.reads, b.may.reads),
40
+ writes: union(a.may.writes, b.may.writes),
41
+ destructive: a.may.destructive || b.may.destructive,
42
+ idempotent: a.may.idempotent && b.may.idempotent,
43
+ },
44
+ must: { reads: unionMust(a.must.reads, b.must.reads), writes: unionMust(a.must.writes, b.must.writes) },
45
+ }), NO_EFFECTS);
46
+ }
47
+ /** The effects of a part that can start zero times. */
48
+ export function optional(part) {
49
+ return { may: part.may, must: NO_EFFECTS.must };
50
+ }
51
+ /** The effects of one of two parts. */
52
+ export function either(a, b) {
53
+ const intersect = (x, y) => new Set([...x].filter((name) => y.has(name)));
54
+ return {
55
+ may: sequence(a, b).may,
56
+ must: { reads: intersect(a.must.reads, b.must.reads), writes: intersect(a.must.writes, b.must.writes) },
57
+ };
58
+ }
59
+ /** The effects that an entry declares. Absent effects, or an absent list, are unknown. */
60
+ export function declaredEffects(entry) {
61
+ const effects = entry?.effects;
62
+ if (!effects)
63
+ return UNKNOWN_EFFECTS;
64
+ return {
65
+ may: {
66
+ reads: effects.reads ? new Set(effects.reads) : undefined,
67
+ writes: effects.writes ? new Set(effects.writes) : undefined,
68
+ destructive: isDestructive(effects),
69
+ idempotent: isReadOnly(effects) || effects.idempotent === true,
70
+ },
71
+ must: { reads: new Set(effects.reads ?? []), writes: new Set(effects.writes ?? []) },
72
+ };
73
+ }
74
+ /** True when the effects are not fully known. */
75
+ export function isUnknown(summary) {
76
+ return summary.may.reads === undefined || summary.may.writes === undefined;
77
+ }
78
+ /** The effects as the `Effects` of a manifest: an unknown list is absent. */
79
+ export function toEffects(may) {
80
+ return {
81
+ ...(may.reads ? { reads: [...may.reads].sort() } : {}),
82
+ ...(may.writes ? { writes: [...may.writes].sort() } : {}),
83
+ destructive: may.destructive,
84
+ idempotent: may.idempotent,
85
+ };
86
+ }
87
+ /** This function infers the effects of each node and of the program. */
88
+ export function inferEffects(root, facts, bodyEffects) {
89
+ const byNode = new Map();
90
+ const nested = new Map();
91
+ const unknownAt = [];
92
+ const items = (spec) => spec.kind === "list"
93
+ ? { summary: sequence(...spec.items.map(infer)), nonEmpty: spec.items.length > 0 }
94
+ : { summary: infer(spec.value), nonEmpty: false };
95
+ /** The effects of what a data-driven procedure runs. */
96
+ const inner = (node, entry) => {
97
+ if (node.kind === "dynamic") {
98
+ if (node.model)
99
+ return infer(node.model);
100
+ if (node.reason === "invalid-control-flow")
101
+ return NO_EFFECTS;
102
+ if (node.reason === "raw-input" && entry && !entry.dataDriven)
103
+ return NO_EFFECTS;
104
+ // procedure.define runs nothing now: the body runs when the new procedure starts
105
+ if (node.key === "procedure.define" && entry?.dataDriven)
106
+ return NO_EFFECTS;
107
+ }
108
+ if (entry && !entry.dataDriven)
109
+ return NO_EFFECTS;
110
+ if (entry) {
111
+ const body = bodyEffects(node.path);
112
+ if (body)
113
+ return body;
114
+ }
115
+ return UNKNOWN_EFFECTS;
116
+ };
117
+ const infer = (node) => {
118
+ let summary;
119
+ switch (node.kind) {
120
+ case "literal":
121
+ case "reference":
122
+ case "fail":
123
+ summary = NO_EFFECTS;
124
+ break;
125
+ case "object":
126
+ summary = sequence(...node.entries.map((entry) => infer(entry.value)));
127
+ break;
128
+ case "array":
129
+ summary = sequence(...node.items.map(infer));
130
+ break;
131
+ case "deferred":
132
+ summary = infer(node.input);
133
+ break;
134
+ case "call":
135
+ case "dynamic": {
136
+ const entry = facts.entry(node.path);
137
+ const runs = inner(node, entry);
138
+ if (runs !== NO_EFFECTS)
139
+ nested.set(node, runs);
140
+ summary = sequence(infer(node.input), declaredEffects(entry), runs);
141
+ if (isUnknown(declaredEffects(entry)) || isUnknown(runs))
142
+ unknownAt.push(node.pointer);
143
+ break;
144
+ }
145
+ case "chain":
146
+ summary = sequence(declaredEffects(facts.entry(node.path)), ...(node.initialInput ? [infer(node.initialInput)] : []), ...node.steps.map((step) => infer(step.node)));
147
+ break;
148
+ case "parallel":
149
+ summary = sequence(declaredEffects(facts.entry(node.path)), ...node.tasks.map(infer));
150
+ break;
151
+ case "conditional": {
152
+ const thenEffects = node.then ? infer(node.then) : NO_EFFECTS;
153
+ const elseEffects = node.else ? infer(node.else) : NO_EFFECTS;
154
+ summary = sequence(declaredEffects(facts.entry(node.path)), infer(node.condition), either(thenEffects, elseEffects));
155
+ break;
156
+ }
157
+ case "try":
158
+ summary = sequence(declaredEffects(facts.entry(node.path)), infer(node.try), optional(infer(node.catch)));
159
+ break;
160
+ case "and":
161
+ case "or": {
162
+ const [first, ...rest] = node.values.map(infer);
163
+ summary = sequence(declaredEffects(facts.entry(node.path)), ...(first ? [first] : []), ...rest.map(optional));
164
+ break;
165
+ }
166
+ case "map": {
167
+ const { summary: itemEffects, nonEmpty } = items(node.items);
168
+ const fn = node.fn ? infer(node.fn) : NO_EFFECTS;
169
+ summary = sequence(declaredEffects(facts.entry(node.path)), itemEffects, nonEmpty ? fn : optional(fn));
170
+ break;
171
+ }
172
+ case "reduce": {
173
+ const itemPart = node.items ? items(node.items) : { summary: NO_EFFECTS, nonEmpty: false };
174
+ const fn = node.fn ? infer(node.fn) : NO_EFFECTS;
175
+ summary = sequence(declaredEffects(facts.entry(node.path)), itemPart.summary, infer(node.initial), itemPart.nonEmpty ? fn : optional(fn));
176
+ break;
177
+ }
178
+ }
179
+ byNode.set(node, summary);
180
+ return summary;
181
+ };
182
+ const program = infer(root);
183
+ return { program, byNode, nested, unknownAt };
184
+ }
185
+ //# sourceMappingURL=effects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effects.js","sourceRoot":"","sources":["../src/effects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAyD,MAAM,4BAA4B,CAAC;AA0B9H,MAAM,SAAS,GAAwB,IAAI,GAAG,EAAE,CAAC;AAEjD,+CAA+C;AAC/C,MAAM,CAAC,MAAM,UAAU,GAAkB;IACvC,GAAG,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE;IAClF,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE;CAC9C,CAAC;AAEF,6DAA6D;AA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C,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;gBAC3F,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;gBACjD,OAAO,GAAG,QAAQ,CAAC,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC1I,MAAM;YACR,CAAC;QACH,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC1B,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;IAEF,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAChD,CAAC"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * The explanation of a program (roadmap R23): the check and `explainInvocation()` of the client
3
+ * in one result.
4
+ *
5
+ * The result has the effects of the program, each call with its declared effects, the answer of
6
+ * the capability for the call, and the diagnostics. A short text in plain words tells the same.
7
+ * An application can show the text to a user before the user starts the program.
8
+ */
9
+ import { type CapabilityRefusalReason, type Effects, type ProcedurePath } from "@procedures/client/browser";
10
+ import { type Pointer } from "./ir.js";
11
+ import { type CheckOptions, type MustEffects } from "./program.js";
12
+ import type { Diagnostic } from "./diagnostics.js";
13
+ /** The kind of a call: a call of a procedure, a control-flow call or a dynamic call. */
14
+ export type CallKind = "call" | "control" | "dynamic";
15
+ /** The explanation of one call of a program. */
16
+ export interface CallExplanation {
17
+ /** The key of the procedure: its path with dots. */
18
+ readonly key: string;
19
+ readonly path: ProcedurePath;
20
+ /** The JSON pointer of the call in the program. */
21
+ readonly pointer: Pointer;
22
+ readonly kind: CallKind;
23
+ /** The effects that the procedure declares. Absent: the procedure does not declare its effects. */
24
+ readonly effects?: Effects | undefined;
25
+ /** True when the host has a procedure at the path. */
26
+ readonly known: boolean;
27
+ /** True when the host has the procedure and its expose rule lets a program call it. */
28
+ readonly exposed: boolean;
29
+ /** True when the capability permits the call (`explainInvocation()` of the client). */
30
+ readonly permitted: boolean;
31
+ /** The reason of a refusal, or `not-found` for a path without a procedure. */
32
+ readonly reason?: CapabilityRefusalReason | "not-found" | undefined;
33
+ /** The answer of `explainInvocation()` in words. */
34
+ readonly message: string;
35
+ }
36
+ /** The result of `explainProgram()`. */
37
+ export interface ProgramExplanation {
38
+ /** True when no diagnostic is an error. A host starts the program only then. */
39
+ readonly ok: boolean;
40
+ /** The effects that a run can have (the upper bound). An absent `reads` or `writes`: not known. */
41
+ readonly effects: Effects;
42
+ /** The effects of each run in which no call fails (the lower bound). */
43
+ readonly mustEffects: MustEffects;
44
+ /** The calls of the program, in the order of the tree: a call comes before the calls of its input. */
45
+ readonly calls: CallExplanation[];
46
+ /** The problems that the check found, in the order of the program. */
47
+ readonly diagnostics: Diagnostic[];
48
+ /** The hash of the manifest that the check used. */
49
+ readonly registryHash: string;
50
+ /** The explanation in short sentences of plain words. */
51
+ readonly summary: string;
52
+ }
53
+ /**
54
+ * This function explains a program before it starts. It checks the program, and it asks
55
+ * `explainInvocation()` of the client about each call. No call of the program starts.
56
+ */
57
+ export declare function explainProgram(program: unknown, options: CheckOptions): ProgramExplanation;
58
+ //# sourceMappingURL=explain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"explain.d.ts","sourceRoot":"","sources":["../src/explain.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAI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G;IACtG,QAAQ,CAAC,KAAK,EAAE,eAAe,EAAE,CAAC;IAClC,sEAAsE;IACtE,QAAQ,CAAC,WAAW,EAAE,UAAU,EAAE,CAAC;IACnC,oDAAoD;IACpD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,yDAAyD;IACzD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAsFD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,GAAG,kBAAkB,CAuC1F"}
@@ -0,0 +1,144 @@
1
+ /**
2
+ * The explanation of a program (roadmap R23): the check and `explainInvocation()` of the client
3
+ * in one result.
4
+ *
5
+ * The result has the effects of the program, each call with its declared effects, the answer of
6
+ * the capability for the call, and the diagnostics. A short text in plain words tells the same.
7
+ * An application can show the text to a user before the user starts the program.
8
+ */
9
+ import { explainInvocation, } from "@procedures/client/browser";
10
+ import { isCallLike, walk } from "./ir.js";
11
+ import { isStringPath, withDefinitions } from "./facts.js";
12
+ import { findDefinitions } from "./normalize.js";
13
+ import { baseFacts, checkProgram } from "./program.js";
14
+ /** A capability without its deadline: the static check does not know the time of the run. */
15
+ function withoutDeadline(capability) {
16
+ if (!capability || capability.deadline === undefined)
17
+ return capability;
18
+ const { deadline: _deadline, ...rest } = capability;
19
+ return rest;
20
+ }
21
+ /** A registry for `explainInvocation()` that has a procedure with the declared effects for each known path. */
22
+ function registryOf(facts) {
23
+ return {
24
+ get: (path) => {
25
+ const entry = facts.entry(path);
26
+ return entry ? { path, metadata: entry.effects ? { effects: entry.effects } : {} } : undefined;
27
+ },
28
+ };
29
+ }
30
+ function kindOf(node) {
31
+ return node.kind === "call" ? "call" : node.kind === "dynamic" ? "dynamic" : "control";
32
+ }
33
+ /** A list in words: "a", "a and b", "a, b and c". */
34
+ function listText(items) {
35
+ if (items.length <= 1)
36
+ return items.join("");
37
+ return `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
38
+ }
39
+ function count(value, noun) {
40
+ return `${value} ${noun}${value === 1 ? "" : "s"}`;
41
+ }
42
+ /** Each call of a list with its place, at most three, and the number of the others. */
43
+ function callsText(calls) {
44
+ const shown = calls.slice(0, 3).map((call) => `${call.key} at ${call.pointer === "" ? "the root" : call.pointer}`);
45
+ return calls.length > 3 ? `${shown.join(", ")} and ${calls.length - 3} more` : listText(shown);
46
+ }
47
+ /** The sentences of the effects. */
48
+ function effectsText(effects, must) {
49
+ const sentences = [];
50
+ const names = (list) => (list.length === 0 ? "nothing" : listText(list));
51
+ if (effects.reads && effects.writes) {
52
+ const reads = effects.reads.length === 0 ? "reads nothing" : `can read ${names(effects.reads)}`;
53
+ const writes = effects.writes.length === 0 ? "changes nothing" : `can change ${names(effects.writes)}`;
54
+ sentences.push(`The program ${reads} and ${writes}.`);
55
+ }
56
+ else if (effects.reads) {
57
+ sentences.push(`The program ${effects.reads.length === 0 ? "reads nothing" : `can read ${names(effects.reads)}`}. The compiler does not know what it changes.`);
58
+ }
59
+ else if (effects.writes) {
60
+ sentences.push(`The compiler does not know what the program reads. It ${effects.writes.length === 0 ? "changes nothing" : `can change ${names(effects.writes)}`}.`);
61
+ }
62
+ else {
63
+ sentences.push("The compiler does not know the effects of the program: a call does not declare them, or it runs a program that the compiler cannot see.");
64
+ }
65
+ if (effects.writes && effects.writes.length > 0 && effects.destructive)
66
+ sentences.push("A call can delete or overwrite data.");
67
+ if (must.reads.length > 0 || must.writes.length > 0) {
68
+ const parts = [...(must.reads.length > 0 ? [`reads ${names(must.reads)}`] : []), ...(must.writes.length > 0 ? [`changes ${names(must.writes)}`] : [])];
69
+ sentences.push(`Each run in which no call fails ${parts.join(" and ")}.`);
70
+ }
71
+ return sentences;
72
+ }
73
+ /** The text of the explanation, in short sentences. */
74
+ function summaryOf(explanation) {
75
+ const { calls, diagnostics } = explanation;
76
+ const sentences = [];
77
+ const keys = new Set(calls.map((call) => call.key));
78
+ sentences.push(`The program has ${count(calls.length, "call")} of ${count(keys.size, "procedure")}.`);
79
+ sentences.push(...effectsText(explanation.effects, explanation.mustEffects));
80
+ const unknown = calls.filter((call) => !call.known);
81
+ if (unknown.length > 0)
82
+ sentences.push(`The host has no procedure for ${count(unknown.length, "call")}: ${callsText(unknown)}.`);
83
+ const hidden = calls.filter((call) => call.known && !call.exposed);
84
+ if (hidden.length > 0)
85
+ sentences.push(`The host does not expose ${count(hidden.length, "call")}: ${callsText(hidden)}.`);
86
+ const refused = calls.filter((call) => call.known && !call.permitted);
87
+ if (refused.length > 0)
88
+ sentences.push(`The capability refuses ${count(refused.length, "call")}: ${callsText(refused)}.`);
89
+ const errors = diagnostics.filter((diagnostic) => diagnostic.severity === "error").length;
90
+ const warnings = diagnostics.filter((diagnostic) => diagnostic.severity === "warning").length;
91
+ sentences.push(errors === 0
92
+ ? "The check found no error, so the host can start the program."
93
+ : `The check found ${count(errors, "error")}, so the host does not start the program.`);
94
+ if (warnings > 0)
95
+ sentences.push(`The check also found ${count(warnings, "warning")}.`);
96
+ return sentences.join(" ");
97
+ }
98
+ /**
99
+ * This function explains a program before it starts. It checks the program, and it asks
100
+ * `explainInvocation()` of the client about each call. No call of the program starts.
101
+ */
102
+ export function explainProgram(program, options) {
103
+ const base = baseFacts(options);
104
+ const facts = withDefinitions(base, findDefinitions(program));
105
+ const result = checkProgram(program, { ...options, facts: base });
106
+ const capability = withoutDeadline(options.capability);
107
+ const registry = registryOf(facts);
108
+ const calls = [];
109
+ const visit = (node) => {
110
+ if (!isCallLike(node))
111
+ return;
112
+ const path = node.path;
113
+ if (isStringPath(path) && path.length > 0 && path.every((segment) => segment.length > 0)) {
114
+ const entry = facts.entry(path);
115
+ const answer = explainInvocation(path, capability, registry);
116
+ calls.push({
117
+ key: node.key,
118
+ path: [...path],
119
+ pointer: node.pointer,
120
+ kind: kindOf(node),
121
+ ...(entry?.effects ? { effects: entry.effects } : {}),
122
+ known: entry !== undefined,
123
+ exposed: entry !== undefined && facts.exposed(path),
124
+ permitted: answer.permitted,
125
+ ...(answer.reason !== undefined ? { reason: answer.reason } : {}),
126
+ message: answer.message,
127
+ });
128
+ }
129
+ // The program that a dynamic call runs, when the compiler can see it (client.eval of a literal path)
130
+ if (node.kind === "dynamic" && node.model)
131
+ walk(node.model, visit);
132
+ };
133
+ walk(result.ir.root, visit);
134
+ const explanation = {
135
+ ok: result.ok,
136
+ effects: result.effects,
137
+ mustEffects: result.mustEffects,
138
+ calls,
139
+ diagnostics: result.diagnostics,
140
+ registryHash: result.registryHash,
141
+ };
142
+ return { ...explanation, summary: summaryOf(explanation) };
143
+ }
144
+ //# sourceMappingURL=explain.js.map