@thi.ng/shader-ast-optimize 0.4.15 → 0.4.17

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-05-08T18:24:32Z
3
+ - **Last updated**: 2024-06-29T09:28:36Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [0.4.16](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-optimize@0.4.16) (2024-06-21)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
17
+
12
18
  ### [0.4.12](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-optimize@0.4.12) (2024-04-20)
13
19
 
14
20
  #### ♻️ Refactoring
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 189 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -138,7 +138,7 @@ For Node.js REPL:
138
138
  const opt = await import("@thi.ng/shader-ast-optimize");
139
139
  ```
140
140
 
141
- Package sizes (brotli'd, pre-treeshake): ESM: 1.24 KB
141
+ Package sizes (brotli'd, pre-treeshake): ESM: 1.26 KB
142
142
 
143
143
  ## Dependencies
144
144
 
@@ -29,7 +29,7 @@ import {
29
29
  } from "@thi.ng/shader-ast/ast/lit";
30
30
  import { allChildren, walk } from "@thi.ng/shader-ast/ast/scope";
31
31
  import { LOGGER } from "@thi.ng/shader-ast/logger";
32
- const replaceNode = (node, next) => {
32
+ const __replaceNode = (node, next) => {
33
33
  if (LOGGER.level <= LogLevel.DEBUG) {
34
34
  LOGGER.debug(`replacing AST node:`);
35
35
  LOGGER.debug(" old: " + JSON.stringify(node));
@@ -41,15 +41,15 @@ const replaceNode = (node, next) => {
41
41
  Object.assign(node, next);
42
42
  return true;
43
43
  };
44
- const replaceNumericNode = (node, res) => {
44
+ const __replaceNumericNode = (node, res) => {
45
45
  node.type === "int" && (res |= 0);
46
46
  node.type === "uint" && (res >>>= 0);
47
- return replaceNode(node, lit(node.type, res));
47
+ return __replaceNode(node, lit(node.type, res));
48
48
  };
49
- const replaceBooleanNode = (node, res) => replaceNode(node, bool(res));
50
- const replaceWithConst = (node, ref, n) => replaceNode(node, matchingPrimFor(ref, n));
51
- const maybeFoldMath = (op, l, r) => op === "+" ? l + r : op === "-" ? l - r : op === "*" ? l * r : op === "/" ? r != 0 ? l / r : illegalArgs(`division by zero: ${l}/${r}`) : void 0;
52
- const maybeFoldCompare = (op, l, r) => op === "==" ? l === r : op === "!=" ? l !== r : op === "<" ? l < r : op === "<=" ? l <= r : op === ">=" ? l >= r : op === ">" ? l > r : void 0;
49
+ const __replaceBooleanNode = (node, res) => __replaceNode(node, bool(res));
50
+ const __replaceWithConst = (node, ref, n) => __replaceNode(node, matchingPrimFor(ref, n));
51
+ const __maybeFoldMath = (op, l, r) => op === "+" ? l + r : op === "-" ? l - r : op === "*" ? l * r : op === "/" ? r != 0 ? l / r : illegalArgs(`division by zero: ${l}/${r}`) : void 0;
52
+ const __maybeFoldCompare = (op, l, r) => op === "==" ? l === r : op === "!=" ? l !== r : op === "<" ? l < r : op === "<=" ? l <= r : op === ">=" ? l >= r : op === ">" ? l > r : void 0;
53
53
  const COMPS = { x: 0, y: 1, z: 2, w: 3 };
54
54
  const BUILTINS = {
55
55
  abs: ([a]) => Math.abs(a),
@@ -86,7 +86,7 @@ const foldNode = defmulti(
86
86
  const $node = node;
87
87
  if ($node.op == "-" && isLitNumericConst($node.val)) {
88
88
  $node.val.val *= -1;
89
- return replaceNode(node, $node.val);
89
+ return __replaceNode(node, $node.val);
90
90
  }
91
91
  },
92
92
  op2: (node) => {
@@ -97,28 +97,28 @@ const foldNode = defmulti(
97
97
  const isNumL = isLitNumericConst(l);
98
98
  const isNumR = isLitNumericConst(r);
99
99
  if (isNumL && isNumR) {
100
- const num = maybeFoldMath(op, l.val, r.val);
101
- if (num !== void 0) return replaceNumericNode(node, num);
102
- const bool2 = maybeFoldCompare(op, l.val, r.val);
103
- if (bool2 !== void 0) return replaceBooleanNode(node, bool2);
100
+ const num = __maybeFoldMath(op, l.val, r.val);
101
+ if (num !== void 0) return __replaceNumericNode(node, num);
102
+ const bool2 = __maybeFoldCompare(op, l.val, r.val);
103
+ if (bool2 !== void 0) return __replaceBooleanNode(node, bool2);
104
104
  } else if (op === "*") {
105
105
  if (isNumL && l.val === 0)
106
- return replaceWithConst(node, r, FLOAT0);
106
+ return __replaceWithConst(node, r, FLOAT0);
107
107
  if (isNumR && r.val === 0)
108
- return replaceWithConst(node, l, FLOAT0);
109
- if (isNumL && l.val === 1) return replaceNode(node, r);
110
- if (isNumR && r.val === 1) return replaceNode(node, l);
108
+ return __replaceWithConst(node, l, FLOAT0);
109
+ if (isNumL && l.val === 1) return __replaceNode(node, r);
110
+ if (isNumR && r.val === 1) return __replaceNode(node, l);
111
111
  } else if (op === "/") {
112
112
  if (isNumL && l.val === 0)
113
- return replaceWithConst(node, r, FLOAT0);
113
+ return __replaceWithConst(node, r, FLOAT0);
114
114
  if (isNumR && r.val === 0) illegalArgs("division by zero");
115
- if (isNumR && r.val === 1) return replaceNode(node, l);
115
+ if (isNumR && r.val === 1) return __replaceNode(node, l);
116
116
  } else if (op === "+") {
117
- if (isNumL && l.val === 0) return replaceNode(node, r);
118
- if (isNumR && r.val === 0) return replaceNode(node, l);
117
+ if (isNumL && l.val === 0) return __replaceNode(node, r);
118
+ if (isNumR && r.val === 0) return __replaceNode(node, l);
119
119
  } else if (op === "-") {
120
- if (isNumL && l.val === 0) return replaceNode(node, neg(r));
121
- if (isNumR && r.val === 0) return replaceNode(node, l);
120
+ if (isNumL && l.val === 0) return __replaceNode(node, neg(r));
121
+ if (isNumR && r.val === 0) return __replaceNode(node, l);
122
122
  }
123
123
  },
124
124
  call_i: (node) => {
@@ -126,7 +126,7 @@ const foldNode = defmulti(
126
126
  if ($node.args.every((x) => isLitNumericConst(x))) {
127
127
  const op = BUILTINS[$node.id];
128
128
  if (op !== void 0) {
129
- return replaceNumericNode(
129
+ return __replaceNumericNode(
130
130
  node,
131
131
  op($node.args.map((x) => x.val))
132
132
  );
@@ -139,13 +139,13 @@ const foldNode = defmulti(
139
139
  const $node = node;
140
140
  if (isLitNumericConst($node.val)) {
141
141
  if (isFloat($node.val)) {
142
- return replaceNode(node, float($node.val.val));
142
+ return __replaceNode(node, float($node.val.val));
143
143
  }
144
144
  if (isInt($node.val)) {
145
- return replaceNode(node, int($node.val.val));
145
+ return __replaceNode(node, int($node.val.val));
146
146
  }
147
147
  if (isUint($node.val)) {
148
- return replaceNode(node, uint($node.val.val));
148
+ return __replaceNode(node, uint($node.val.val));
149
149
  }
150
150
  }
151
151
  },
@@ -154,7 +154,7 @@ const foldNode = defmulti(
154
154
  const val = $node.val;
155
155
  if (isLitVecConst(val)) {
156
156
  if (isFloat(node)) {
157
- return replaceNode(
157
+ return __replaceNode(
158
158
  node,
159
159
  float(val.val[COMPS[$node.id]])
160
160
  );
@@ -171,19 +171,19 @@ const foldBuiltin = defmulti(
171
171
  exp2: (node) => {
172
172
  const a = node.args[0];
173
173
  if (isLitNumOrVecConst(a, 0)) {
174
- return replaceWithConst(node, a, FLOAT1);
174
+ return __replaceWithConst(node, a, FLOAT1);
175
175
  }
176
176
  if (isLitNumOrVecConst(a, 1)) {
177
- return replaceWithConst(node, a, FLOAT2);
177
+ return __replaceWithConst(node, a, FLOAT2);
178
178
  }
179
179
  },
180
180
  pow: (node) => {
181
181
  const [a, b] = node.args;
182
182
  if (isLitNumOrVecConst(b, 0)) {
183
- return replaceWithConst(node, a, FLOAT1);
183
+ return __replaceWithConst(node, a, FLOAT1);
184
184
  }
185
185
  if (isLitNumOrVecConst(b, 1)) {
186
- return replaceNode(node, a);
186
+ return __replaceNode(node, a);
187
187
  }
188
188
  }
189
189
  }
package/defoptimized.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import type { FnBody0 } from "@thi.ng/shader-ast";
2
+ import { defMain } from "@thi.ng/shader-ast/ast/function";
2
3
  /**
3
4
  * Same as [defMain()](), but applies optimizations (e.g.
4
5
  * {@link constantFolding}) to the given function body.
5
6
  *
6
7
  * @param fn
7
8
  */
8
- export declare const defOptimized: (fn: FnBody0) => import("@thi.ng/shader-ast").TaggedFn0<"void">;
9
+ export declare const defOptimized: (fn: FnBody0) => ReturnType<typeof defMain>;
9
10
  //# sourceMappingURL=defoptimized.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/shader-ast-optimize",
3
- "version": "0.4.15",
3
+ "version": "0.4.17",
4
4
  "description": "Shader AST code optimization passes/strategies",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast-optimize#readme",
13
+ "homepage": "https://thi.ng/shader-ast-optimize",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -36,18 +36,18 @@
36
36
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.11.2",
40
- "@thi.ng/defmulti": "^3.0.39",
41
- "@thi.ng/errors": "^2.5.7",
42
- "@thi.ng/logger": "^3.0.12",
43
- "@thi.ng/math": "^5.10.13",
44
- "@thi.ng/shader-ast": "^0.15.15"
39
+ "@thi.ng/api": "^8.11.4",
40
+ "@thi.ng/defmulti": "^3.0.41",
41
+ "@thi.ng/errors": "^2.5.9",
42
+ "@thi.ng/logger": "^3.0.14",
43
+ "@thi.ng/math": "^5.11.1",
44
+ "@thi.ng/shader-ast": "^0.15.17"
45
45
  },
46
46
  "devDependencies": {
47
- "@microsoft/api-extractor": "^7.43.2",
48
- "esbuild": "^0.21.1",
47
+ "@microsoft/api-extractor": "^7.47.0",
48
+ "esbuild": "^0.21.5",
49
49
  "typedoc": "^0.25.13",
50
- "typescript": "^5.4.5"
50
+ "typescript": "^5.5.2"
51
51
  },
52
52
  "keywords": [
53
53
  "typescript"
@@ -82,5 +82,5 @@
82
82
  "parent": "@thi.ng/shader-ast",
83
83
  "year": 2019
84
84
  },
85
- "gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
85
+ "gitHead": "7b950c112fba0b2e7c450765b15624c3382f1354\n"
86
86
  }