Repository navigation
feat: std.typeOf - #2529
feat: std.typeOf#2529
Conversation
|
pkg.pr.new packages benchmark commit |
Bundle size comparison (
|
| 🟢 Decreased | ➖ Unchanged | 🔴 Increased (max 0.96%) | ❔ Unknown |
|---|---|---|---|
| 0 | 346 | 3 | 3 |
import * as ... in PR vs import * as ... in target (did bundle size increase?):
| Test | tsdown |
|---|---|
| STATIC_std.ts | 111.79 kB ( |
| d_abstractFloat.ts | 20.08 kB |
| d_abstractInt.ts | 20.08 kB |
| std_typeOf.ts | 21.99 kB |
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.
Resolution Time Benchmark---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.55, 1.14, 2.26, 3.67, 4.38, 7.62, 13.31, 15.53]
line [0.50, 1.01, 2.27, 3.55, 4.14, 7.67, 14.00, 14.13]
line [0.52, 0.99, 2.21, 3.32, 4.12, 6.50, 13.59, 14.92]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.14, 0.25, 0.35, 0.41, 0.65, 0.63, 0.75, 0.84]
line [0.18, 0.31, 0.40, 0.49, 0.71, 0.68, 0.81, 0.89]
line [0.18, 0.29, 0.40, 0.46, 0.64, 0.56, 0.70, 0.81]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.57, 1.36, 2.20, 4.02, 7.62, 15.44, 31.57, 67.10]
line [0.44, 1.37, 2.32, 4.46, 6.70, 14.74, 33.16, 63.66]
line [0.53, 1.27, 2.45, 4.32, 7.33, 14.56, 32.28, 64.12]
|
994488e to
cfc9d78
Compare
3dce44a to
f60069f
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The matcher can hang for valid regular expressions, and typeOf is not correctly marked or named internally.
3 open findings
What changed in this PR
Adds std.typeOf for compile-time shader type introspection.
Changes:
- Implements and exports
std.typeOf. - Adds scalar, assertion, and error-path tests.
- Adds a reusable match-count matcher.
| File | Description |
|---|---|
packages/typegpu/src/std/typeOf.ts |
Implements type introspection. |
packages/typegpu/src/std/index.ts |
Exports typeOf. |
packages/typegpu/tests/std/typeOf.test.ts |
Tests the new API. |
packages/typegpu-testing-utility/src/index.ts |
Adds toMatchNTimes. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
ℹ️ No critical issues — two rough edges worth a look.
Reviewed changes
- New
std.typeOf(packages/typegpu/src/std/typeOf.ts): compile-time introspection returning the WGSL type of an expression as a comptime-known value; returns UnknownData forUnknownData/AutoStructtypes and throws when called from JS/comptime. stdbarrel export (packages/typegpu/src/std/index.ts): re-exportstypeOf.- Tests (
packages/typegpu/tests/std/typeOf.test.ts): scalar type resolution, a comptime assertion helper distinguishing f32/i32, and JS/comptimethrow behavior. toMatchNTimesmatcher (packages/typegpu-testing-utility/src/index.ts): new global vitest matcher plusMatcherstype augmentation.
ℹ️ New public API isn't documented
std.typeOf is in the same family as std.isBeingTranspiled / std.getShaderStage / std.getTargetShaderLanguage, which are covered in the "Resolution environment" section of apps/typegpu-docs/src/content/docs/apis/utils.mdx. Adding a short entry there (including the "result can't be stored in a variable" restriction below) would make the new function discoverable and avoid the confusing error new users will otherwise hit.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
5d1bbac to
9c816dc
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Documented
std.typeOfin the "Resolution environment" section ofapps/typegpu-docs/src/content/docs/apis/utils.mdx, including the "consume immediately / cannot be stored in a variable" restriction. - Hardened
toMatchNTimes(packages/typegpu-testing-utility/src/index.ts): builds a fresh global regex and counts withmatchAll, so a non-global or empty-matching pattern can no longer loop forever and the caller'slastIndexis left untouched. - Marked
typeOfinternal correctly (packages/typegpu/src/std/typeOf.ts):$internalnow uses{ value: true }soisMarkedInternalrecognizes it, the callable registers its name viasetName, and the JSDoc documents the no-storage restriction.
All prior review feedback (Copilot's regex-hang, internal-marker, and metadata-naming findings, plus the earlier docs request) is addressed by these commits.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
We don't cache array types, so it is currently impossible to compare against them
const inspect = tgpu.comptime((t: unknown) => {
return tgpu['~unstable'].rawCodeSnippet(`// type = ${t}`, d.Void);
});
test('std.typeof of an arrayExpression', () => {
const fn = () => {
'use gpu';
inspect(std.typeOf([1, 2, 3])).$;
const t = std.typeOf([1, 2, 3]) === d.arrayOf(d.i32, 3);
};
expect(tgpu.resolve([fn])).toMatchInlineSnapshot(`
"fn fn_1() {
// type = arrayOf(i32, 3);
const t = false;
}"
`);
});There was a problem hiding this comment.
That's true, though it would be possible if we made deepEqual callable at comptime.
9c816dc to
3f7ebff
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Added
std.typeOftests (packages/typegpu/tests/std/typeOf.test.ts): constant folding (std.typeOf(0) === abstractInt), struct types (std.typeOf(Schema()) === Schema),UnknownDataresolution for strings / functions / schema-methods (=== undefinedfolds totrue), and the "assigned to a variable throws" error path. - Fixed an
occurrencestypo in thetoMatchNTimesmatcher (packages/typegpu-testing-utility/src/index.ts).
The new tests pass locally (pnpm vitest run --project='!browser' packages/typegpu/tests/std/typeOf.test.ts — 7 passed) and oxfmt --check / oxlint --max-warnings=0 are clean on the touched files. These commits respond to the human reviewer's typo and "free tests" requests; the outstanding reviewer threads are informational questions left to that reviewer.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
3f7ebff to
64b1bf6
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Narrowed the
std.typeOftype filter (packages/typegpu/src/std/typeOf.ts): replaced thetype === UnknownData || type instanceof AutoStructexclusion with the canonicalisData(type)predicate, so every internal type (notablyEntryInputRouter) now resolves toundefinedinstead of leaking a non-public schema. - Added coverage for internal input types (
packages/typegpu/tests/std/typeOf.test.ts): new tests assertstd.typeOfof an AutoStruct (render-pipeline fragment input) and of anEntryInputRouter(tgpu.fragmentFninput) both returnundefined.
Both prior Pullfrog threads (toMatchNTimes hang, JSDoc storage restriction) remain resolved, and the new commit addresses the human reviewer's internal-leak concern. Tests pass locally (pnpm vitest run --project='!browser' packages/typegpu/tests/std/typeOf.test.ts — 9 passed) and oxfmt --check / oxlint --max-warnings=0 are clean on the touched files.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
64b1bf6 to
92061ca
Compare
7734bf0 to
2696d6a
Compare
There was a problem hiding this comment.
✅ No new issues found.
( ◦°^°◦) Arr! I re-checked the fresh commit — the cap'n hoisted d.abstractInt/d.abstractFloat into the public d namespace and swapped the test off its ~internal rope. Typecheck be clean, the nine tests sail true, and CI (treeshake-test included) be green. No new reefs spotted.
Reviewed changes
Since the prior pullfrog review (64b1bf6), the branch was rebased and one authored commit (2696d6a) landed:
- Made
d.abstractInt/d.abstractFloatpublic (packages/typegpu/src/data/index.ts): added the two numeric schemas and theirAbstractInt/AbstractFloattypes to thedatabarrel, so they are reachable through the publicdnamespace. - Switched the constant-folding test to the public API (
packages/typegpu/tests/std/typeOf.test.ts): dropped thetypegpu/~internalimport and compares againstd.abstractInt.
npx tsc --noEmit in packages/typegpu is clean, the typeOf suite passes (9 tests), and CI including treeshake-test is green.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
2696d6a to
37f568b
Compare
There was a problem hiding this comment.
ℹ️ No critical issues — one design question inline.
Reviewed changes
Since the prior pullfrog review (2696d6a), a single commit (37f568b) landed, tests only:
- Added coverage for builtin result structs (
packages/typegpu/tests/std/typeOf.test.ts): a newdescribeblock asserting thatstd.typeOfreturns the generated result structs ofstd.frexp(including the abstract{ abstractFloat, abstractInt }case),std.modf, andstd.atomicCompareExchangeWeak, with theirpropTypes; that two same-type results compare===at comptime whilefrexpvsmodfdiffer; that field access resolves to the field type; and that nostructdeclaration is emitted. - Widened the vitest import to
{ describe, expect }to support the new block.
The file passes (15 tests), tsc --noEmit is clean, and oxlint/oxfmt report no issues.
🏴☠️ ( ◦°^°◦) Arr! I re-checked the fresh commit — the cap'n stowed a chest o' tests for the builtin result structs, and the whole fleet sails clean. Only one breeze still rustles: the new tests set the opposite course to the review thread that be lyin' open.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
37f568b to
a0af251
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Since the prior pullfrog review (37f568b), one commit (a0af251) landed, resolving the outstanding maintainer feedback:
- Swapped the
std.typeOftype filter toisWgslData(packages/typegpu/src/std/typeOf.ts): the argument'sdataTypeis now accepted only whenisWgslData, matching the reviewer's note that loose schemas cannot appear in shaders. This is the same predicatecore/buffer/buffer.tsuses to gate shader-usable schemas, and it still admits the abstract types (d.abstractInt/d.abstractFloat). - Narrowed the vitest
Matchersaugmentation (packages/typegpu-testing-utility/src/index.ts):interface Matchers<T>now matches the shape in vitest's docs, dropping theT = anydefault and itsno-explicit-anysuppression. Interface merging with vitest's declaration is still clean undertsc. - Normalized test titles (
packages/typegpu/tests/std/typeOf.test.ts):std.typeof->std.typeOfacross the affected tests.
🏴☠️ ( ◦°^°◦) Arr! I rigged a fresh look at the new commit — the cap'n swapped the type filter to isWgslData, slimmed the Matchers rigging, and squared the test names. The hold be clean: 15 tests sail true, typecheck and linters show no leaks, and no new reefs spotted.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏



No description provided.