Skip to content

impr: Allow numeric literals as bare numbers in the AST - #3244

Draft
iwoplaza wants to merge 1 commit into
mainfrom
impr/bare-numeric-literals
Draft

iwoplaza wants to merge 1 commit into
mainfrom
impr/bare-numeric-literals

Conversation

@iwoplaza

@iwoplaza iwoplaza commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Part of a stack that makes the metadata of 'use gpu' functions smaller and cheaper to load (#3246). This PR doesn't change any output on its own.

Numeric literals in tinyest can now also be plain numbers (0.5), next to the existing [5, '0.5'] node that keeps the source text. The v3 metadata format (#3246) uses plain numbers, which drops [5," and "] from every literal.

  • tinyest: Num is number | [5, string], the same way Bool is already boolean | [107, boolean].
  • WgslGenerator: isNum/extractNum next to isId/isBool. A bare-number expression statement is rejected like a [5, …] one.
  • tseynit and the plugin's obfuscator accept both forms.

Both forms give the same WGSL. The generator already turned the text into a number (parseNumericString), and picks abstractInt or abstractFloat from the value (Number.isInteger), not from the text. A new test resolves both forms side by side (0x10 and 16, '0.5' and 0.5).

Numeric literals can now be encoded as plain numbers (`0.5`) next to the
existing `[5, '0.5']` node, which keeps the source text. The WGSL generator,
tseynit and the obfuscator accept both.
@iwoplaza
iwoplaza added this pull request to stack #3249 October 21, 2026 10:12
@github-actions

Copy link
Copy Markdown

pkg.pr.new

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

https://pkg.pr.new/software-mansion/TypeGPU/tinyest@a286506351773b225582471b47d00a0ba8cda966
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@a286506351773b225582471b47d00a0ba8cda966
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@a286506351773b225582471b47d00a0ba8cda966

benchmark
view benchmark

commit
view commit

@iwoplaza iwoplaza changed the title impr/bare numeric literals impr: Allow numeric literals as bare numbers in the AST Oct 21, 2026
@github-actions

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.51, 1.02, 2.33, 3.53, 3.66, 6.91, 13.58, 14.43]
  line [0.53, 1.10, 2.35, 3.66, 3.92, 6.91, 15.86, 14.91]
  line [0.54, 1.12, 2.40, 3.92, 4.42, 7.13, 13.97, 14.07]
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.18, 0.31, 0.37, 0.44, 0.63, 0.64, 0.80, 0.87]
  line [0.16, 0.27, 0.36, 0.47, 0.66, 0.67, 0.82, 0.84]
  line [0.15, 0.27, 0.35, 0.45, 0.68, 0.69, 0.76, 0.90]
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.48, 1.28, 2.22, 3.92, 6.98, 14.46, 31.55, 63.21]
  line [0.53, 1.20, 2.09, 3.81, 6.83, 14.53, 33.46, 65.80]
  line [0.43, 1.27, 1.96, 4.07, 7.14, 14.22, 32.61, 64.50]
Loading

@github-actions

Copy link
Copy Markdown

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

🟢 Decreased ➖ Unchanged 🔴 Increased (max 0.41%) ❔ Unknown
0 40 312 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.

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.

1 participant