Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Reference equality rejects independently constructed pointer and array schemas with matching signatures.
1 open finding
What changed in this PR
Addresses #2453 by reusing already-shelled callbacks rather than interpreting their wrappers as new implementations.
Changes:
- Adds callback reuse and signature validation.
- Tests CPU execution, identity, WGSL preservation, externals, and incompatible signatures.
| File | Description |
|---|---|
| packages/typegpu/tests/function.test.ts | Adds callback reuse and signature rejection tests. |
| packages/typegpu/src/core/function/tgpuFn.ts | Implements and documents reuse for matching shells. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| innerShell.returnType !== shell.returnType || | ||
| innerShell.argTypes.length !== shell.argTypes.length || | ||
| !innerShell.argTypes.every((type, index) => type === shell.argTypes[index]) |
There was a problem hiding this comment.
Addressed in 6284ddb using the existing nominal-aware shallowEqualSchemas, now shared. Equivalent array arguments/returns and independently constructed pointers reuse correctly; different lengths, element types, nominal structs and pointer spaces reject. Full Node 24 suite: 2,840 tests passed. Generated array WGSL dispatched and read back 42 on RX 6600/Vulkan. AI-assisted: GPT-6.1 Sol, openai-codex/gpt-6.1-sol.
There was a problem hiding this comment.
Important
The new signature check compares schemas by reference, so a wrapper whose signature is structurally identical but built from distinct schema objects still throws instead of reusing. Details inline.
Reviewed changes
- Reuse matching shelled callbacks —
createFnearly-returns the already-shelled implementation when its shell'sreturnType/argTypesmatch the wrapping shell, preserving the original core, raw-WGSL body, externals and slot bindings; mismatches throw at construction time, before WGSL generation. - Tests —
packages/typegpu/tests/function.test.tsgains three cases: JS-fn reuse (identity + CPU result + WGSL), raw-WGSL reuse preserving$usesexternals, and rejection of mismatched arg/return arity and types.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Changes since the prior pullfrog review (0fe5360 → 6284ddb) replace reference-equality signature matching with structural comparison and add coverage for it.
- Structural schema matching —
createFnnow rejects a mismatched shell viashallowEqualSchemasinstead of===, so independently constructed but equivalent array and pointer schemas are reused rather than throwing. - Shared helper —
shallowEqualSchemasmoved fromtgsl/shellless.tsintodata/deepEqual.tsand is reused by both the callback-reuse path and the shellless cache, removing the duplicate. - Tests — added cases for structural array/pointer matching, mismatched array/pointer rejection, and nominal struct identity preservation; the prior review's open thread is addressed and resolved.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
…n' into sol50/typegpu-2453
|
Normally merged current main (no rebase/force push), now |
|
This PR should wait until #3209 is merged, and use those utilities |
|
Agreed — holding this for #3209 so I can reuse its equality utilities. |
|
Updated to |
There was a problem hiding this comment.
ℹ️ No critical issues — one minor coverage suggestion inline.
Reviewed changes
Changes since the prior pullfrog review (9e2f0f2 → c6bd12c), which is a merge of main (7c853fa) into the branch:
- Merged
mainand reconciled the PR's matching helper with main's newer utility. - Switched
createFnandShelllessRepository.getfrom the PR-localshallowEqualSchemasto main's sharedschemasEqualNominally, and removed thedata/deepEqual.tshelper the PR had added (that file was removed on main). - Dropped three
expect(wrapped).toBe(...)identity assertions from the reuse tests.
I verified on this head that npx vitest run tests/function.test.ts tests/data/schemasEqualNominally.test.ts tests/tgsl passes (577 tests) and that reuse identity still holds for all three removed assertions.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
| }); | ||
| const wrapped = tgpu.fn([d.u32], d.u32)(callback); | ||
|
|
||
| expect(wrapped(41)).toBe(42); |
There was a problem hiding this comment.
The merge commit c6bd12c dropped the expect(wrapped).toBe(callback) assertions here and at the array case (line 42) and pointer case (wrapped/increment, line 64), but reuse still preserves identity for all three — I re-added them locally and they pass. Since direct identity reuse is the PR's core behavior, keeping these guards against a future regression that re-wraps while still emitting equivalent WGSL; the resolve/CPU assertions do not distinguish the two.
There was a problem hiding this comment.
Keeping the checks on callback behaviour here: CPU/WGSL results, raw WGSL externals, and incompatible signatures. I removed the identity assertions intentionally so the tests do not constrain which JavaScript object implements that behaviour.


Closes #2453.
Reuse an already-shelled callback instead of treating its wrapper as a new JavaScript implementation. Signature checks now use
schemasEqualNominallyfrom #3209: matching arrays/pointers work, while distinct struct identities and pointer spaces stay distinct.Merged main (
7c853fa3) and dropped the old helper move. Shellless cache lookup uses the shared utility too.Checked the TypeGPU source suite: 198 files / 2,960 tests passed. Package typecheck, focused type-aware Oxlint and Oxfmt pass; the core import graph has no circular dependencies. The current public consumer returns 42 on the CPU and rejects seven incompatible signatures. Its fresh WGSL also ran on RX 6600 / RADV / Vulkan (Mesa 26.2.4) and read back 42. No current hosted CI or cross-platform result claimed.
Code, tests and prose are AI-assisted (GPT-6.1 Sol, openai-codex/gpt-6.1-sol).