Skip to content

impr(unplugin-typegpu): Support parsing all metadata fields - #3020

Open
cieplypolar wants to merge 46 commits into
mainfrom
impr/unplugin-ast-ext-parser
Open

cieplypolar wants to merge 46 commits into
mainfrom
impr/unplugin-ast-ext-parser

Conversation

@cieplypolar

@cieplypolar cieplypolar commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

Parse ast and externals out of embedded metadata.

@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/tgpu-gen@5208e45102d4ae4f9de434fd4a3ed0018fedd97b
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@5208e45102d4ae4f9de434fd4a3ed0018fedd97b
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/cli@5208e45102d4ae4f9de434fd4a3ed0018fedd97b
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@5208e45102d4ae4f9de434fd4a3ed0018fedd97b
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@5208e45102d4ae4f9de434fd4a3ed0018fedd97b

benchmark
view benchmark

commit
view commit

@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

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.99, 1.83, 3.67, 6.32, 7.36, 12.57, 23.93, 26.00]
  line [0.93, 1.88, 3.90, 6.48, 7.16, 10.76, 23.80, 24.50]
  line [0.92, 1.94, 4.22, 5.92, 7.20, 11.20, 23.32, 25.01]
Loading
---
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.31, 0.56, 0.72, 0.80, 1.23, 1.23, 1.53, 1.55]
  line [0.30, 0.52, 0.74, 0.87, 1.13, 1.11, 1.44, 1.52]
  line [0.25, 0.51, 0.63, 0.80, 1.06, 1.10, 1.40, 1.56]
Loading
---
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.78, 2.19, 3.36, 6.80, 11.92, 24.52, 53.66, 108.36]
  line [0.82, 2.28, 3.73, 6.49, 11.90, 24.65, 52.09, 107.23]
  line [0.80, 2.25, 3.75, 6.46, 11.53, 24.45, 53.08, 107.40]
Loading

@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Bundle size comparison (import * as ... in PR vs import * as ... in target):

🟢 Decreased ➖ Unchanged 🔴 Increased ❔ Unknown
0 355 0 0

No notable changes.

If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.

@cieplypolar
cieplypolar added this pull request to stack #2951 September 17, 2026 15:41
@cieplypolar
cieplypolar force-pushed the impr/unplugin-ast-ext-parser branch from c6ccc73 to 0e1183c Compare September 17, 2026 15:46
@cieplypolar
cieplypolar removed this pull request from stack #2951 September 17, 2026 15:46
@cieplypolar
cieplypolar changed the base branch from impr/warn-schema-order to main September 17, 2026 15:47
@cieplypolar
cieplypolar force-pushed the impr/unplugin-ast-ext-parser branch from c8b1cdc to 4fcb009 Compare September 22, 2026 13:48
@cieplypolar
cieplypolar marked this pull request as ready for review September 22, 2026 14:56
@cieplypolar
cieplypolar requested review from aleksanderkatan, iwoplaza, reczkok and vende11s and a lite review from Copilot September 22, 2026 14:57

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Re-integrated the metadata parser onto main's #3084 detection helpers: merged main (now containing #3084's rewrite) and adapted getEmbeddedTypegpuMetadata to skipTransparentWrappersUp / isTypegpuMetadataAccess / the broadened isTypegpuMetadataSetCall, adding assignment-RHS and arguments[0] node-identity checks on top of the PR's objectPropertyPath / parseAstPath / parseExternalsPath.
  • Reworked the rewrite tests onto the shared dualTest harness: the five bundler-rewrite variants now assert both the parsed function.ast and an exact __TYPEGPU_META__ occurrence count, so a recognition regression fails on the count rather than passing via re-transformed metadata.
  • Broke the common.ts ⇄ embeddedMetadata.ts value cycle: extracted METADATA_FORMAT_VERSION into the new leaf module src/core/version.ts and repointed babel.ts, factory.ts, and embeddedMetadata.ts at it.

Verified at head: 218/218 unplugin-typegpu tests pass (75 in embedded-metadata.test.ts), test:types clean, tsdown build succeeds, and test:circular-deps reports no cycles. The sole prior Pullfrog thread is resolved.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@aleksanderkatan aleksanderkatan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeppers

Comment thread packages/unplugin-typegpu/test/embedded-metadata.test.ts
Comment thread packages/unplugin-typegpu/test/embedded-metadata.test.ts Outdated
Comment thread packages/unplugin-typegpu/src/core/embeddedMetadata.ts

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Restructured the bundler-rewrite tests (packages/unplugin-typegpu/test/embedded-metadata.test.ts): the shared dualTest block was replaced by explicit [BABEL] / [ROLLUP] tests, and the embedded fn body switched to let a=1,b=2 — a multi-declaration statement tinyest-for-wgsl rejects — so a recognition regression now re-transforms and throws rather than passing on the low occurrence-count assertion alone.
  • Added parses switch statements: asserts the parsed function.ast.body matches transpileBabelFn-derived output for a switch containing fallthrough, default, and an external case ext.
  • Added points astPath to the ast object of the metadata: pins that astPath is the ast property's ObjectExpression (asserting its parentPath is the ast ObjectProperty and that evaluate() yields the expected { params, body }).
  • Dropped the unused output parameter from dualTest, simplifying both collector paths.

The only production source files in this PR are unchanged since the prior review; this delta is test-only. Verified at head: 79/79 tests in embedded-metadata.test.ts pass and pnpm --filter unplugin-typegpu test:types is clean.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

getEmbeddedTypegpuMetadata now throws an unhandled TypeError when a .set(...) call referencing __TYPEGPU_META__ has a single argument — the removed metadataPath === undefined guard was load-bearing. Details inline.

Reviewed changes

  • Descend through metadata wrappers (packages/unplugin-typegpu/src/core/embeddedMetadata.ts): added skipTransparentWrappersDown and switched the metadata argument from skipTransparentWrappersUp(metadataPath) to skipTransparentWrappersDown(callPath.get('arguments.1')), so metadata written as (meta) or (meta as any)! is now unwrapped and recognized.
  • Tests (test/embedded-metadata.test.ts): added a parenthesized metadata variant to the bundler-rewrite matrix and a type-wrapped metadata case asserting the AST parses and the function is not re-transformed. 82 tests pass at head; tsc --noEmit clean.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/unplugin-typegpu/src/core/embeddedMetadata.ts Outdated
@cieplypolar
cieplypolar force-pushed the impr/unplugin-ast-ext-parser branch from 30c30cd to 5208e45 Compare October 29, 2026 13:28
@cieplypolar
cieplypolar added this pull request to stack #3292 October 29, 2026 13:30
@cieplypolar cieplypolar changed the title impr(unplugin-typegpu): support parsing all metadata fields impr(unplugin-typegpu): Support parsing all metadata fields Oct 29, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — the prior crash is fixed; one small test gap inline.

Reviewed changes

  • Restored the metadataPath === undefined guard (packages/unplugin-typegpu/src/core/embeddedMetadata.ts): a .set(...) call referencing __TYPEGPU_META__ with a single argument now returns undefined again instead of throwing TypeError: Cannot read properties of undefined (reading 'node').
  • Kept unwrapping the metadata argument with skipTransparentWrappersDown, so (meta) and (meta as any)! remain recognized; dropped the redundant as NodePath on the callPath.get('arguments.1') call.
  • Tests (test/embedded-metadata.test.ts): added the parenthesized metadata bundler-rewrite variant and a type-wrapped metadata case.

Verified at head 5208e45: 82/82 embedded-metadata.test.ts tests pass, test:types is clean, and a scratch probe confirms the one-argument .set(...) case no longer throws.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants