typesea 0.1.0 → 0.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.
- package/CHANGELOG.md +85 -6
- package/README.md +143 -28
- package/dist/adapters/index.d.ts +50 -8
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +169 -48
- package/dist/aot/index.d.ts +19 -3
- package/dist/aot/index.d.ts.map +1 -1
- package/dist/aot/index.js +115 -17
- package/dist/async/index.d.ts +28 -56
- package/dist/async/index.d.ts.map +1 -1
- package/dist/async/index.js +94 -37
- package/dist/builders/composite.d.ts +43 -9
- package/dist/builders/composite.d.ts.map +1 -1
- package/dist/builders/composite.js +100 -17
- package/dist/builders/index.d.ts +8 -5
- package/dist/builders/index.d.ts.map +1 -1
- package/dist/builders/index.js +7 -4
- package/dist/builders/modifier.d.ts +36 -5
- package/dist/builders/modifier.d.ts.map +1 -1
- package/dist/builders/modifier.js +52 -5
- package/dist/builders/object/guard.d.ts +72 -24
- package/dist/builders/object/guard.d.ts.map +1 -1
- package/dist/builders/object/guard.js +139 -29
- package/dist/builders/object/index.d.ts +4 -2
- package/dist/builders/object/index.d.ts.map +1 -1
- package/dist/builders/object/index.js +3 -1
- package/dist/builders/object/schema.d.ts +88 -11
- package/dist/builders/object/schema.d.ts.map +1 -1
- package/dist/builders/object/schema.js +290 -23
- package/dist/builders/object/types.d.ts +20 -31
- package/dist/builders/object/types.d.ts.map +1 -1
- package/dist/builders/object/types.js +2 -0
- package/dist/builders/runtime.d.ts +40 -0
- package/dist/builders/runtime.d.ts.map +1 -0
- package/dist/builders/runtime.js +150 -0
- package/dist/builders/scalar.d.ts +49 -9
- package/dist/builders/scalar.d.ts.map +1 -1
- package/dist/builders/scalar.js +87 -9
- package/dist/builders/table.d.ts +35 -5
- package/dist/builders/table.d.ts.map +1 -1
- package/dist/builders/table.js +35 -5
- package/dist/builders/types.d.ts +20 -4
- package/dist/builders/types.d.ts.map +1 -1
- package/dist/builders/types.js +2 -0
- package/dist/compile/check-composite.d.ts +25 -2
- package/dist/compile/check-composite.d.ts.map +1 -1
- package/dist/compile/check-composite.js +699 -27
- package/dist/compile/check-scalar.d.ts +88 -0
- package/dist/compile/check-scalar.d.ts.map +1 -1
- package/dist/compile/check-scalar.js +570 -3
- package/dist/compile/check.d.ts +12 -0
- package/dist/compile/check.d.ts.map +1 -1
- package/dist/compile/check.js +62 -3
- package/dist/compile/context.d.ts +47 -9
- package/dist/compile/context.d.ts.map +1 -1
- package/dist/compile/context.js +53 -8
- package/dist/compile/first.d.ts +26 -0
- package/dist/compile/first.d.ts.map +1 -0
- package/dist/compile/first.js +850 -0
- package/dist/compile/graph-predicate.d.ts +4 -2
- package/dist/compile/graph-predicate.d.ts.map +1 -1
- package/dist/compile/graph-predicate.js +2272 -165
- package/dist/compile/guard.d.ts +16 -24
- package/dist/compile/guard.d.ts.map +1 -1
- package/dist/compile/guard.js +202 -72
- package/dist/compile/index.d.ts +3 -1
- package/dist/compile/index.d.ts.map +1 -1
- package/dist/compile/index.js +2 -0
- package/dist/compile/issue.d.ts +110 -0
- package/dist/compile/issue.d.ts.map +1 -1
- package/dist/compile/issue.js +184 -1
- package/dist/compile/names.d.ts +12 -2
- package/dist/compile/names.d.ts.map +1 -1
- package/dist/compile/names.js +19 -3
- package/dist/compile/predicate.d.ts +24 -0
- package/dist/compile/predicate.d.ts.map +1 -1
- package/dist/compile/predicate.js +287 -10
- package/dist/compile/runtime.d.ts +100 -13
- package/dist/compile/runtime.d.ts.map +1 -1
- package/dist/compile/runtime.js +56 -6
- package/dist/compile/source.d.ts +10 -2
- package/dist/compile/source.d.ts.map +1 -1
- package/dist/compile/source.js +385 -26
- package/dist/compile/types.d.ts +22 -0
- package/dist/compile/types.d.ts.map +1 -1
- package/dist/compile/types.js +2 -0
- package/dist/decoder/index.d.ts +92 -46
- package/dist/decoder/index.d.ts.map +1 -1
- package/dist/decoder/index.js +266 -39
- package/dist/evaluate/check-composite.d.ts +111 -2
- package/dist/evaluate/check-composite.d.ts.map +1 -1
- package/dist/evaluate/check-composite.js +343 -8
- package/dist/evaluate/check-scalar.d.ts +25 -0
- package/dist/evaluate/check-scalar.d.ts.map +1 -1
- package/dist/evaluate/check-scalar.js +124 -3
- package/dist/evaluate/check.d.ts +7 -0
- package/dist/evaluate/check.d.ts.map +1 -1
- package/dist/evaluate/check.js +62 -4
- package/dist/evaluate/index.d.ts +2 -0
- package/dist/evaluate/index.d.ts.map +1 -1
- package/dist/evaluate/index.js +2 -0
- package/dist/evaluate/issue.d.ts +11 -1
- package/dist/evaluate/issue.d.ts.map +1 -1
- package/dist/evaluate/issue.js +15 -1
- package/dist/evaluate/predicate.d.ts +16 -5
- package/dist/evaluate/predicate.d.ts.map +1 -1
- package/dist/evaluate/predicate.js +20 -5
- package/dist/evaluate/shared.d.ts +78 -13
- package/dist/evaluate/shared.d.ts.map +1 -1
- package/dist/evaluate/shared.js +101 -8
- package/dist/evaluate/state.d.ts +35 -13
- package/dist/evaluate/state.d.ts.map +1 -1
- package/dist/evaluate/state.js +35 -2
- package/dist/guard/array.d.ts +48 -0
- package/dist/guard/array.d.ts.map +1 -0
- package/dist/guard/array.js +84 -0
- package/dist/guard/base.d.ts +111 -31
- package/dist/guard/base.d.ts.map +1 -1
- package/dist/guard/base.js +165 -32
- package/dist/guard/date.d.ts +34 -0
- package/dist/guard/date.d.ts.map +1 -0
- package/dist/guard/date.js +60 -0
- package/dist/guard/error.d.ts +10 -5
- package/dist/guard/error.d.ts.map +1 -1
- package/dist/guard/error.js +10 -5
- package/dist/guard/index.d.ts +4 -0
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +4 -0
- package/dist/guard/number.d.ts +86 -11
- package/dist/guard/number.d.ts.map +1 -1
- package/dist/guard/number.js +159 -11
- package/dist/guard/props.d.ts +27 -3
- package/dist/guard/props.d.ts.map +1 -1
- package/dist/guard/props.js +27 -3
- package/dist/guard/read.d.ts +115 -10
- package/dist/guard/read.d.ts.map +1 -1
- package/dist/guard/read.js +185 -10
- package/dist/guard/registry.d.ts +12 -2
- package/dist/guard/registry.d.ts.map +1 -1
- package/dist/guard/registry.js +15 -3
- package/dist/guard/string.d.ts +115 -13
- package/dist/guard/string.d.ts.map +1 -1
- package/dist/guard/string.js +250 -13
- package/dist/guard/types.d.ts +110 -40
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/guard/types.js +2 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/internal/index.d.ts +42 -6
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +51 -8
- package/dist/ir/builder.d.ts +17 -127
- package/dist/ir/builder.d.ts.map +1 -1
- package/dist/ir/builder.js +80 -137
- package/dist/ir/freeze.d.ts +4 -0
- package/dist/ir/freeze.d.ts.map +1 -1
- package/dist/ir/freeze.js +66 -0
- package/dist/ir/index.d.ts +3 -1
- package/dist/ir/index.d.ts.map +1 -1
- package/dist/ir/index.js +2 -0
- package/dist/ir/regexp.d.ts +2 -0
- package/dist/ir/regexp.d.ts.map +1 -1
- package/dist/ir/regexp.js +2 -0
- package/dist/ir/types.d.ts +94 -56
- package/dist/ir/types.d.ts.map +1 -1
- package/dist/ir/types.js +2 -0
- package/dist/ir/validate.d.ts +8 -1
- package/dist/ir/validate.d.ts.map +1 -1
- package/dist/ir/validate.js +511 -61
- package/dist/issue/index.d.ts +42 -10
- package/dist/issue/index.d.ts.map +1 -1
- package/dist/issue/index.js +65 -11
- package/dist/json-schema/emit-combinator.d.ts +44 -4
- package/dist/json-schema/emit-combinator.d.ts.map +1 -1
- package/dist/json-schema/emit-combinator.js +44 -4
- package/dist/json-schema/emit-composite.d.ts +16 -2
- package/dist/json-schema/emit-composite.d.ts.map +1 -1
- package/dist/json-schema/emit-composite.js +81 -13
- package/dist/json-schema/emit-scalar.d.ts +26 -3
- package/dist/json-schema/emit-scalar.d.ts.map +1 -1
- package/dist/json-schema/emit-scalar.js +124 -10
- package/dist/json-schema/emit-types.d.ts +11 -1
- package/dist/json-schema/emit-types.d.ts.map +1 -1
- package/dist/json-schema/emit-types.js +2 -0
- package/dist/json-schema/emit.d.ts +12 -1
- package/dist/json-schema/emit.d.ts.map +1 -1
- package/dist/json-schema/emit.js +23 -3
- package/dist/json-schema/freeze.d.ts +13 -2
- package/dist/json-schema/freeze.d.ts.map +1 -1
- package/dist/json-schema/freeze.js +41 -8
- package/dist/json-schema/index.d.ts +16 -2
- package/dist/json-schema/index.d.ts.map +1 -1
- package/dist/json-schema/index.js +23 -3
- package/dist/json-schema/issue.d.ts +4 -1
- package/dist/json-schema/issue.d.ts.map +1 -1
- package/dist/json-schema/issue.js +4 -1
- package/dist/json-schema/read.d.ts +24 -3
- package/dist/json-schema/read.d.ts.map +1 -1
- package/dist/json-schema/read.js +59 -12
- package/dist/json-schema/types.d.ts +45 -16
- package/dist/json-schema/types.d.ts.map +1 -1
- package/dist/json-schema/types.js +2 -0
- package/dist/kind/index.d.ts +40 -28
- package/dist/kind/index.d.ts.map +1 -1
- package/dist/kind/index.js +41 -13
- package/dist/lower/index.d.ts +6 -1
- package/dist/lower/index.d.ts.map +1 -1
- package/dist/lower/index.js +462 -46
- package/dist/message/index.d.ts +64 -10
- package/dist/message/index.d.ts.map +1 -1
- package/dist/message/index.js +155 -17
- package/dist/optimize/algebraic.d.ts +54 -0
- package/dist/optimize/algebraic.d.ts.map +1 -0
- package/dist/optimize/algebraic.js +314 -0
- package/dist/optimize/compact.d.ts +8 -1
- package/dist/optimize/compact.d.ts.map +1 -1
- package/dist/optimize/compact.js +13 -2
- package/dist/optimize/domain.d.ts +16 -0
- package/dist/optimize/domain.d.ts.map +1 -0
- package/dist/optimize/domain.js +619 -0
- package/dist/optimize/fold-boolean.d.ts +17 -2
- package/dist/optimize/fold-boolean.d.ts.map +1 -1
- package/dist/optimize/fold-boolean.js +59 -14
- package/dist/optimize/fold-common.d.ts +43 -8
- package/dist/optimize/fold-common.d.ts.map +1 -1
- package/dist/optimize/fold-common.js +37 -6
- package/dist/optimize/fold-constraints.d.ts +33 -0
- package/dist/optimize/fold-constraints.d.ts.map +1 -0
- package/dist/optimize/fold-constraints.js +484 -0
- package/dist/optimize/fold-scalar.d.ts +98 -13
- package/dist/optimize/fold-scalar.d.ts.map +1 -1
- package/dist/optimize/fold-scalar.js +98 -13
- package/dist/optimize/fold.d.ts +8 -1
- package/dist/optimize/fold.d.ts.map +1 -1
- package/dist/optimize/fold.js +22 -2
- package/dist/optimize/index.d.ts +9 -1
- package/dist/optimize/index.d.ts.map +1 -1
- package/dist/optimize/index.js +18 -3
- package/dist/optimize/map-node.d.ts +3 -1
- package/dist/optimize/map-node.d.ts.map +1 -1
- package/dist/optimize/map-node.js +48 -3
- package/dist/optimize/peephole.d.ts +16 -0
- package/dist/optimize/peephole.d.ts.map +1 -0
- package/dist/optimize/peephole.js +254 -0
- package/dist/optimize/remap.d.ts +2 -0
- package/dist/optimize/remap.d.ts.map +1 -1
- package/dist/optimize/remap.js +2 -0
- package/dist/optimize/rewrite.d.ts +13 -8
- package/dist/optimize/rewrite.d.ts.map +1 -1
- package/dist/optimize/rewrite.js +13 -8
- package/dist/plan/cache.d.ts +9 -3
- package/dist/plan/cache.d.ts.map +1 -1
- package/dist/plan/cache.js +34 -6
- package/dist/plan/index.d.ts +2 -0
- package/dist/plan/index.d.ts.map +1 -1
- package/dist/plan/index.js +2 -0
- package/dist/plan/predicate.d.ts +2 -0
- package/dist/plan/predicate.d.ts.map +1 -1
- package/dist/plan/predicate.js +298 -29
- package/dist/plan/schema-predicate.d.ts +6 -0
- package/dist/plan/schema-predicate.d.ts.map +1 -1
- package/dist/plan/schema-predicate.js +382 -19
- package/dist/plan/types.d.ts +2 -0
- package/dist/plan/types.d.ts.map +1 -1
- package/dist/plan/types.js +2 -0
- package/dist/result/index.d.ts +19 -5
- package/dist/result/index.d.ts.map +1 -1
- package/dist/result/index.js +10 -2
- package/dist/schema/common.d.ts +69 -6
- package/dist/schema/common.d.ts.map +1 -1
- package/dist/schema/common.js +104 -10
- package/dist/schema/freeze.d.ts +4 -0
- package/dist/schema/freeze.d.ts.map +1 -1
- package/dist/schema/freeze.js +40 -0
- package/dist/schema/index.d.ts +5 -2
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +4 -1
- package/dist/schema/lazy.d.ts +4 -0
- package/dist/schema/lazy.d.ts.map +1 -1
- package/dist/schema/lazy.js +4 -0
- package/dist/schema/literal.d.ts +7 -1
- package/dist/schema/literal.d.ts.map +1 -1
- package/dist/schema/literal.js +7 -1
- package/dist/schema/types.d.ts +109 -100
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/types.js +13 -2
- package/dist/schema/undefined.d.ts +17 -0
- package/dist/schema/undefined.d.ts.map +1 -0
- package/dist/schema/undefined.js +77 -0
- package/dist/schema/validate.d.ts +8 -1
- package/dist/schema/validate.d.ts.map +1 -1
- package/dist/schema/validate.js +255 -57
- package/docs/api.md +128 -8
- package/docs/assets/benchmark-headline.svg +163 -0
- package/docs/engine-notes.md +62 -15
- package/docs/index.html +1340 -702
- package/docs/ko/api.md +375 -0
- package/docs/ko/engine-notes.md +156 -0
- package/docs/ko/readme.md +378 -0
- package/package.json +66 -65
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file fold-boolean.ts
|
|
3
3
|
* @brief Constant folding for boolean fold nodes.
|
|
4
|
+
* @details Optimizer helpers preserve graph equivalence while shrinking redundant nodes
|
|
5
|
+
* before code generation consumes the graph.
|
|
4
6
|
*/
|
|
5
7
|
import { ensureConst, keep, readConst, replace } from "./fold-common.js";
|
|
8
|
+
import { flattenBooleanValues, simplifyAndValues, simplifyOrValues } from "./algebraic.js";
|
|
9
|
+
import { canonicalizeAndValues, canonicalizeOrValues } from "./fold-constraints.js";
|
|
6
10
|
/**
|
|
7
|
-
* @brief fold and.
|
|
11
|
+
* @brief Simplify an `And` fold node using boolean identities and constraints.
|
|
12
|
+
* @details False annihilates the whole conjunction, true disappears, nested
|
|
13
|
+
* conjunctions are flattened, and scalar constraints are canonicalized after
|
|
14
|
+
* algebraic simplification.
|
|
15
|
+
* @param node Boolean fold node to simplify.
|
|
16
|
+
* @param nodes Mutable graph node table for constant interning.
|
|
17
|
+
* @param aliases Mutable alias table updated when a constant is inserted.
|
|
18
|
+
* @returns Fold result for the conjunction.
|
|
8
19
|
*/
|
|
9
20
|
export function foldAnd(node, nodes, aliases) {
|
|
10
21
|
const values = [];
|
|
11
|
-
|
|
12
|
-
|
|
22
|
+
const flattened = flattenBooleanValues(node.values, nodes, node.tag);
|
|
23
|
+
for (let index = 0; index < flattened.length; index += 1) {
|
|
24
|
+
const value = flattened[index];
|
|
13
25
|
if (value === undefined) {
|
|
14
26
|
continue;
|
|
15
27
|
}
|
|
@@ -25,8 +37,23 @@ export function foldAnd(node, nodes, aliases) {
|
|
|
25
37
|
if (values.length === 0) {
|
|
26
38
|
return replace(node, ensureConst(nodes, aliases, true));
|
|
27
39
|
}
|
|
28
|
-
|
|
29
|
-
|
|
40
|
+
const algebraic = simplifyAndValues(values, nodes);
|
|
41
|
+
if (algebraic.contradiction) {
|
|
42
|
+
return replace(node, ensureConst(nodes, aliases, false));
|
|
43
|
+
}
|
|
44
|
+
if (algebraic.values.length === 0) {
|
|
45
|
+
return replace(node, ensureConst(nodes, aliases, true));
|
|
46
|
+
}
|
|
47
|
+
const canonical = canonicalizeAndValues(algebraic.values, nodes);
|
|
48
|
+
if (canonical.contradiction) {
|
|
49
|
+
return replace(node, ensureConst(nodes, aliases, false));
|
|
50
|
+
}
|
|
51
|
+
const canonicalValues = canonical.values;
|
|
52
|
+
if (canonicalValues.length === 0) {
|
|
53
|
+
return replace(node, ensureConst(nodes, aliases, true));
|
|
54
|
+
}
|
|
55
|
+
if (canonicalValues.length === 1) {
|
|
56
|
+
const only = canonicalValues[0];
|
|
30
57
|
if (only !== undefined) {
|
|
31
58
|
return replace(node, only);
|
|
32
59
|
}
|
|
@@ -34,17 +61,24 @@ export function foldAnd(node, nodes, aliases) {
|
|
|
34
61
|
return keep({
|
|
35
62
|
id: node.id,
|
|
36
63
|
tag: node.tag,
|
|
37
|
-
deps:
|
|
38
|
-
values
|
|
64
|
+
deps: canonicalValues,
|
|
65
|
+
values: canonicalValues
|
|
39
66
|
});
|
|
40
67
|
}
|
|
41
68
|
/**
|
|
42
|
-
* @brief fold
|
|
69
|
+
* @brief Simplify an `Or` fold node using boolean identities and tautologies.
|
|
70
|
+
* @details True satisfies the whole disjunction, false disappears, nested
|
|
71
|
+
* disjunctions are flattened, and duplicate surviving arms are removed.
|
|
72
|
+
* @param node Boolean fold node to simplify.
|
|
73
|
+
* @param nodes Mutable graph node table for constant interning.
|
|
74
|
+
* @param aliases Mutable alias table updated when a constant is inserted.
|
|
75
|
+
* @returns Fold result for the disjunction.
|
|
43
76
|
*/
|
|
44
77
|
export function foldOr(node, nodes, aliases) {
|
|
45
78
|
const values = [];
|
|
46
|
-
|
|
47
|
-
|
|
79
|
+
const flattened = flattenBooleanValues(node.values, nodes, node.tag);
|
|
80
|
+
for (let index = 0; index < flattened.length; index += 1) {
|
|
81
|
+
const value = flattened[index];
|
|
48
82
|
if (value === undefined) {
|
|
49
83
|
continue;
|
|
50
84
|
}
|
|
@@ -60,8 +94,19 @@ export function foldOr(node, nodes, aliases) {
|
|
|
60
94
|
if (values.length === 0) {
|
|
61
95
|
return replace(node, ensureConst(nodes, aliases, false));
|
|
62
96
|
}
|
|
63
|
-
|
|
64
|
-
|
|
97
|
+
const algebraic = simplifyOrValues(values, nodes);
|
|
98
|
+
if (algebraic.tautology) {
|
|
99
|
+
return replace(node, ensureConst(nodes, aliases, true));
|
|
100
|
+
}
|
|
101
|
+
if (algebraic.values.length === 0) {
|
|
102
|
+
return replace(node, ensureConst(nodes, aliases, false));
|
|
103
|
+
}
|
|
104
|
+
const canonicalValues = canonicalizeOrValues(algebraic.values);
|
|
105
|
+
if (canonicalValues.length === 0) {
|
|
106
|
+
return replace(node, ensureConst(nodes, aliases, false));
|
|
107
|
+
}
|
|
108
|
+
if (canonicalValues.length === 1) {
|
|
109
|
+
const only = canonicalValues[0];
|
|
65
110
|
if (only !== undefined) {
|
|
66
111
|
return replace(node, only);
|
|
67
112
|
}
|
|
@@ -69,7 +114,7 @@ export function foldOr(node, nodes, aliases) {
|
|
|
69
114
|
return keep({
|
|
70
115
|
id: node.id,
|
|
71
116
|
tag: node.tag,
|
|
72
|
-
deps:
|
|
73
|
-
values
|
|
117
|
+
deps: canonicalValues,
|
|
118
|
+
values: canonicalValues
|
|
74
119
|
});
|
|
75
120
|
}
|
|
@@ -1,45 +1,80 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file fold-common.ts
|
|
3
3
|
* @brief Shared constant-folding helpers.
|
|
4
|
+
* @details Optimizer helpers preserve graph equivalence while shrinking redundant nodes
|
|
5
|
+
* before code generation consumes the graph.
|
|
4
6
|
*/
|
|
5
7
|
import type { GraphNode, NodeId } from "../ir/index.js";
|
|
6
8
|
import type { LiteralValue } from "../schema/index.js";
|
|
7
9
|
/**
|
|
8
|
-
* @brief
|
|
10
|
+
* @brief Result of probing a node slot for a constant value.
|
|
11
|
+
* @details `found` is separate from `value` because `undefined` is itself a
|
|
12
|
+
* valid literal constant in the graph.
|
|
9
13
|
*/
|
|
10
14
|
export interface ConstRead {
|
|
11
15
|
readonly found: boolean;
|
|
12
16
|
readonly value: LiteralValue | undefined;
|
|
13
17
|
}
|
|
14
18
|
/**
|
|
15
|
-
* @brief
|
|
19
|
+
* @brief Node rewrite result returned by scalar folding helpers.
|
|
20
|
+
* @details The node carries the possibly edited payload while `replacement`
|
|
21
|
+
* records aliasing information for later dependency rewrites.
|
|
16
22
|
*/
|
|
17
23
|
export interface FoldResult {
|
|
18
24
|
readonly node: GraphNode;
|
|
19
25
|
readonly replacement: NodeId | undefined;
|
|
20
26
|
}
|
|
21
27
|
/**
|
|
22
|
-
* @brief
|
|
28
|
+
* @brief Reuse or append a constant node for a literal value.
|
|
29
|
+
* @details Constants are interned with `Object.is` so NaN, -0, and undefined
|
|
30
|
+
* keep JavaScript literal identity semantics. The alias table is updated
|
|
31
|
+
* immediately because later folders may depend on the new node id.
|
|
32
|
+
* @param nodes Mutable graph node table for the folding pass.
|
|
33
|
+
* @param aliases Mutable node alias table kept in step with `nodes`.
|
|
34
|
+
* @param value Literal value that must exist in the graph.
|
|
35
|
+
* @returns Node id of the existing or newly appended constant.
|
|
23
36
|
*/
|
|
24
37
|
export declare function ensureConst(nodes: GraphNode[], aliases: NodeId[], value: LiteralValue): NodeId;
|
|
25
38
|
/**
|
|
26
|
-
* @brief
|
|
39
|
+
* @brief Probe a node id for an IR constant without conflating misses.
|
|
40
|
+
* @details Optimizer helpers preserve graph equivalence while shrinking redundant nodes
|
|
41
|
+
* before code generation consumes the graph.
|
|
42
|
+
* @param nodes Graph node table being optimized.
|
|
43
|
+
* @param id Node id to inspect.
|
|
44
|
+
* @returns Const probe result with an explicit found bit.
|
|
27
45
|
*/
|
|
28
46
|
export declare function readConst(nodes: readonly GraphNode[], id: NodeId): ConstRead;
|
|
29
47
|
/**
|
|
30
|
-
* @brief
|
|
48
|
+
* @brief Return a fold result that keeps the node in place.
|
|
49
|
+
* @details Optimizer helpers preserve graph equivalence while shrinking redundant nodes
|
|
50
|
+
* before code generation consumes the graph.
|
|
51
|
+
* @param node Node after local payload edits.
|
|
52
|
+
* @returns Fold result without an alias replacement.
|
|
31
53
|
*/
|
|
32
54
|
export declare function keep(node: GraphNode): FoldResult;
|
|
33
55
|
/**
|
|
34
|
-
* @brief
|
|
56
|
+
* @brief Return a fold result that aliases this node to another node id.
|
|
57
|
+
* @details Optimizer helpers preserve graph equivalence while shrinking redundant nodes
|
|
58
|
+
* before code generation consumes the graph.
|
|
59
|
+
* @param node Original node retained for pass bookkeeping.
|
|
60
|
+
* @param replacement Node id that should replace references to `node`.
|
|
61
|
+
* @returns Fold result carrying the alias replacement.
|
|
35
62
|
*/
|
|
36
63
|
export declare function replace(node: GraphNode, replacement: NodeId): FoldResult;
|
|
37
64
|
/**
|
|
38
|
-
* @brief is finite number.
|
|
65
|
+
* @brief Check whether a value is a finite JavaScript number.
|
|
66
|
+
* @details Numeric bound folding excludes NaN and infinities because order
|
|
67
|
+
* comparisons against those values do not form useful closed validation ranges.
|
|
68
|
+
* @param value Candidate literal value.
|
|
69
|
+
* @returns True when the value is a finite number.
|
|
39
70
|
*/
|
|
40
71
|
export declare function isFiniteNumber(value: unknown): boolean;
|
|
41
72
|
/**
|
|
42
|
-
* @brief is
|
|
73
|
+
* @brief Check whether a value is an object-like record for fold metadata.
|
|
74
|
+
* @details Arrays are excluded because optimizer metadata objects use named
|
|
75
|
+
* fields, and accepting arrays would hide malformed pass state.
|
|
76
|
+
* @param value Candidate metadata value.
|
|
77
|
+
* @returns True when the value is a non-array object.
|
|
43
78
|
*/
|
|
44
79
|
export declare function isPlainRecord(value: unknown): boolean;
|
|
45
80
|
//# sourceMappingURL=fold-common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fold-common.d.ts","sourceRoot":"","sources":["../../src/optimize/fold-common.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"fold-common.d.ts","sourceRoot":"","sources":["../../src/optimize/fold-common.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,SAAS,CAAC;CAC5C;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5C;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACvB,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,EACjB,KAAK,EAAE,YAAY,GACpB,MAAM,CAgBR;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,CAY5E;AAED;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,SAAS,GAAG,UAAU,CAKhD;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,UAAU,CAKxE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEtD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAErD"}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file fold-common.ts
|
|
3
3
|
* @brief Shared constant-folding helpers.
|
|
4
|
+
* @details Optimizer helpers preserve graph equivalence while shrinking redundant nodes
|
|
5
|
+
* before code generation consumes the graph.
|
|
4
6
|
*/
|
|
5
7
|
import { NodeTag } from "../kind/index.js";
|
|
6
8
|
/**
|
|
7
|
-
* @brief
|
|
9
|
+
* @brief Reuse or append a constant node for a literal value.
|
|
10
|
+
* @details Constants are interned with `Object.is` so NaN, -0, and undefined
|
|
11
|
+
* keep JavaScript literal identity semantics. The alias table is updated
|
|
12
|
+
* immediately because later folders may depend on the new node id.
|
|
13
|
+
* @param nodes Mutable graph node table for the folding pass.
|
|
14
|
+
* @param aliases Mutable node alias table kept in step with `nodes`.
|
|
15
|
+
* @param value Literal value that must exist in the graph.
|
|
16
|
+
* @returns Node id of the existing or newly appended constant.
|
|
8
17
|
*/
|
|
9
18
|
export function ensureConst(nodes, aliases, value) {
|
|
10
19
|
for (let index = 0; index < nodes.length; index += 1) {
|
|
@@ -24,7 +33,12 @@ export function ensureConst(nodes, aliases, value) {
|
|
|
24
33
|
return id;
|
|
25
34
|
}
|
|
26
35
|
/**
|
|
27
|
-
* @brief
|
|
36
|
+
* @brief Probe a node id for an IR constant without conflating misses.
|
|
37
|
+
* @details Optimizer helpers preserve graph equivalence while shrinking redundant nodes
|
|
38
|
+
* before code generation consumes the graph.
|
|
39
|
+
* @param nodes Graph node table being optimized.
|
|
40
|
+
* @param id Node id to inspect.
|
|
41
|
+
* @returns Const probe result with an explicit found bit.
|
|
28
42
|
*/
|
|
29
43
|
export function readConst(nodes, id) {
|
|
30
44
|
const node = nodes[id];
|
|
@@ -40,7 +54,11 @@ export function readConst(nodes, id) {
|
|
|
40
54
|
};
|
|
41
55
|
}
|
|
42
56
|
/**
|
|
43
|
-
* @brief
|
|
57
|
+
* @brief Return a fold result that keeps the node in place.
|
|
58
|
+
* @details Optimizer helpers preserve graph equivalence while shrinking redundant nodes
|
|
59
|
+
* before code generation consumes the graph.
|
|
60
|
+
* @param node Node after local payload edits.
|
|
61
|
+
* @returns Fold result without an alias replacement.
|
|
44
62
|
*/
|
|
45
63
|
export function keep(node) {
|
|
46
64
|
return {
|
|
@@ -49,7 +67,12 @@ export function keep(node) {
|
|
|
49
67
|
};
|
|
50
68
|
}
|
|
51
69
|
/**
|
|
52
|
-
* @brief
|
|
70
|
+
* @brief Return a fold result that aliases this node to another node id.
|
|
71
|
+
* @details Optimizer helpers preserve graph equivalence while shrinking redundant nodes
|
|
72
|
+
* before code generation consumes the graph.
|
|
73
|
+
* @param node Original node retained for pass bookkeeping.
|
|
74
|
+
* @param replacement Node id that should replace references to `node`.
|
|
75
|
+
* @returns Fold result carrying the alias replacement.
|
|
53
76
|
*/
|
|
54
77
|
export function replace(node, replacement) {
|
|
55
78
|
return {
|
|
@@ -58,13 +81,21 @@ export function replace(node, replacement) {
|
|
|
58
81
|
};
|
|
59
82
|
}
|
|
60
83
|
/**
|
|
61
|
-
* @brief is finite number.
|
|
84
|
+
* @brief Check whether a value is a finite JavaScript number.
|
|
85
|
+
* @details Numeric bound folding excludes NaN and infinities because order
|
|
86
|
+
* comparisons against those values do not form useful closed validation ranges.
|
|
87
|
+
* @param value Candidate literal value.
|
|
88
|
+
* @returns True when the value is a finite number.
|
|
62
89
|
*/
|
|
63
90
|
export function isFiniteNumber(value) {
|
|
64
91
|
return typeof value === "number" && Number.isFinite(value);
|
|
65
92
|
}
|
|
66
93
|
/**
|
|
67
|
-
* @brief is
|
|
94
|
+
* @brief Check whether a value is an object-like record for fold metadata.
|
|
95
|
+
* @details Arrays are excluded because optimizer metadata objects use named
|
|
96
|
+
* fields, and accepting arrays would hide malformed pass state.
|
|
97
|
+
* @param value Candidate metadata value.
|
|
98
|
+
* @returns True when the value is a non-array object.
|
|
68
99
|
*/
|
|
69
100
|
export function isPlainRecord(value) {
|
|
70
101
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file fold-constraints.ts
|
|
3
|
+
* @brief Boolean constraint canonicalization for pure predicate runs.
|
|
4
|
+
* @details Optimizer helpers preserve graph equivalence while shrinking redundant nodes
|
|
5
|
+
* before code generation consumes the graph.
|
|
6
|
+
*/
|
|
7
|
+
import type { GraphNode, NodeId } from "../ir/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* @brief Canonicalized input list for a boolean fold node.
|
|
10
|
+
* @details Contradictions are represented separately from an empty value list so
|
|
11
|
+
* callers can distinguish a provably false conjunction from a fold that simply
|
|
12
|
+
* had no surviving children.
|
|
13
|
+
*/
|
|
14
|
+
export interface ConstraintFold {
|
|
15
|
+
readonly contradiction: boolean;
|
|
16
|
+
readonly values: readonly NodeId[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @brief canonicalize and values.
|
|
20
|
+
* @details Removes duplicate predicates and dominated scalar bounds while keeping
|
|
21
|
+
* the first observable execution order intact. Only the pure prefix may collapse
|
|
22
|
+
* the whole conjunction to `false`.
|
|
23
|
+
* @returns Canonical node id vector or a contradiction marker.
|
|
24
|
+
*/
|
|
25
|
+
export declare function canonicalizeAndValues(values: readonly NodeId[], nodes: readonly GraphNode[]): ConstraintFold;
|
|
26
|
+
/**
|
|
27
|
+
* @brief canonicalize or values.
|
|
28
|
+
* @details Removes repeated node ids. Repeated ids are already memoized by graph
|
|
29
|
+
* execution, so this only shrinks emitted boolean expressions.
|
|
30
|
+
* @returns Canonical node id vector.
|
|
31
|
+
*/
|
|
32
|
+
export declare function canonicalizeOrValues(values: readonly NodeId[]): readonly NodeId[];
|
|
33
|
+
//# sourceMappingURL=fold-constraints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fold-constraints.d.ts","sourceRoot":"","sources":["../../src/optimize/fold-constraints.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EACR,SAAS,EACT,MAAM,EACT,MAAM,gBAAgB,CAAC;AAGxB;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAoED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACjC,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,KAAK,EAAE,SAAS,SAAS,EAAE,GAC5B,cAAc,CA6BhB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE,CAYjF"}
|