Skip to content

chore: Add type checks to std - #2863

Open
aleksanderkatan wants to merge 74 commits into
mainfrom
chore/add-type-checks-to-std
Open

chore: Add type checks to std#2863
aleksanderkatan wants to merge 74 commits into
mainfrom
chore/add-type-checks-to-std

Conversation

@aleksanderkatan

@aleksanderkatan aleksanderkatan commented Aug 18, 2026

Copy link
Copy Markdown
Member

Closes #2828
These are a runtime overhead, if this turns out to be detrimental, we can add an if to each check that returns early, or put all checks in ifs.

This definitely does not have full coverage, there still are functions with missing implementation/generalization/type checks, but I treat this PR as a step in the right direction, not an absolute std solution.

@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown

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

🟢 Decreased ➖ Unchanged 🔴 Increased (max 3.19%) ❔ Unknown
0 191 134 0

import * as ... in PR vs import * as ... in target (did bundle size increase?):

Click to reveal the results table (134 entries).
Test tsdown
std_neg.ts 39.38 kB ($${\color{red}+3.2\%}$$)
std_add.ts 39.38 kB ($${\color{red}+3.2\%}$$)
std_bitShiftLeft.ts 39.38 kB ($${\color{red}+3.2\%}$$)
std_bitShiftRight.ts 39.38 kB ($${\color{red}+3.2\%}$$)
std_div.ts 39.38 kB ($${\color{red}+3.2\%}$$)
std_mod.ts 39.38 kB ($${\color{red}+3.2\%}$$)
std_mul.ts 39.38 kB ($${\color{red}+3.2\%}$$)
std_sub.ts 39.38 kB ($${\color{red}+3.2\%}$$)
std_rotateX4.ts 40.21 kB ($${\color{red}+3.1\%}$$)
std_scale4.ts 40.21 kB ($${\color{red}+3.1\%}$$)
std_translate4.ts 40.21 kB ($${\color{red}+3.1\%}$$)
std_rotateY4.ts 40.22 kB ($${\color{red}+3.1\%}$$)
std_rotateZ4.ts 40.22 kB ($${\color{red}+3.1\%}$$)
std_dot.ts 58.00 kB ($${\color{red}+3.1\%}$$)
std_length.ts 58.00 kB ($${\color{red}+3.1\%}$$)
std_distance.ts 58.00 kB ($${\color{red}+3.1\%}$$)
std_dot4U8Packed.ts 58.00 kB ($${\color{red}+3.1\%}$$)
std_fract.ts 58.00 kB ($${\color{red}+3.1\%}$$)
std_frexp.ts 58.00 kB ($${\color{red}+3.1\%}$$)
std_mix.ts 58.00 kB ($${\color{red}+3.1\%}$$)
std_modf.ts 58.00 kB ($${\color{red}+3.1\%}$$)
std_abs.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_acos.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_acosh.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_asin.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_asinh.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_atan.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_atan2.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_atanh.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_ceil.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_clamp.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_cos.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_cosh.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_countLeadingZeros.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_countOneBits.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_countTrailingZeros.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_cross.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_degrees.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_determinant.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_dot4I8Packed.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_exp.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_exp2.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_extractBits.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_faceForward.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_firstLeadingBit.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_firstTrailingBit.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_floor.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_fma.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_insertBits.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_intdiv.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_inverseSqrt.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_ldexp.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_log.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_log2.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_max.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_min.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_normalize.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_pow.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_quantizeToF16.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_radians.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_reflect.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_refract.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_reverseBits.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_round.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_saturate.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_sign.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_sin.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_sinh.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_smoothstep.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_sqrt.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_step.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_tan.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_tanh.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_transpose.ts 58.01 kB ($${\color{red}+3.1\%}$$)
std_trunc.ts 58.01 kB ($${\color{red}+3.1\%}$$)
d_vec2b.ts 42.04 kB ($${\color{red}+3.0\%}$$)
d_mat4x4f.ts 42.03 kB ($${\color{red}+3.0\%}$$)
d_vec2u.ts 42.03 kB ($${\color{red}+3.0\%}$$)
d_vec3b.ts 42.03 kB ($${\color{red}+3.0\%}$$)
d_vec3f.ts 42.03 kB ($${\color{red}+3.0\%}$$)
d_vec3u.ts 42.03 kB ($${\color{red}+3.0\%}$$)
d_vec4b.ts 42.03 kB ($${\color{red}+3.0\%}$$)
d_vec4u.ts 42.03 kB ($${\color{red}+3.0\%}$$)
d_mat2x2f.ts 42.04 kB ($${\color{red}+3.0\%}$$)
d_mat3x3f.ts 42.04 kB ($${\color{red}+3.0\%}$$)
d_vec2f.ts 42.04 kB ($${\color{red}+3.0\%}$$)
d_vec2h.ts 42.04 kB ($${\color{red}+3.0\%}$$)
d_vec3h.ts 42.04 kB ($${\color{red}+3.0\%}$$)
d_vec4h.ts 42.04 kB ($${\color{red}+3.0\%}$$)
d_vec2i.ts 42.04 kB ($${\color{red}+3.0\%}$$)
d_vec3i.ts 42.04 kB ($${\color{red}+3.0\%}$$)
d_vec4f.ts 42.04 kB ($${\color{red}+3.0\%}$$)
d_vec4i.ts 42.04 kB ($${\color{red}+3.0\%}$$)
std_bitcastF32toU32.ts 36.93 kB ($${\color{red}+2.8\%}$$)
std_bitcastU32toF32.ts 36.94 kB ($${\color{red}+2.8\%}$$)
std_bitcastU32toI32.ts 36.94 kB ($${\color{red}+2.8\%}$$)
std_bitcast.ts 36.94 kB ($${\color{red}+2.8\%}$$)
std_and.ts 38.59 kB ($${\color{red}+2.4\%}$$)
std_or.ts 38.59 kB ($${\color{red}+2.4\%}$$)
std_all.ts 38.59 kB ($${\color{red}+2.4\%}$$)
std_allEq.ts 38.60 kB ($${\color{red}+2.4\%}$$)
std_any.ts 38.60 kB ($${\color{red}+2.4\%}$$)
std_eq.ts 38.60 kB ($${\color{red}+2.4\%}$$)
std_lt.ts 38.60 kB ($${\color{red}+2.4\%}$$)
std_ne.ts 38.60 kB ($${\color{red}+2.4\%}$$)
std_not.ts 38.60 kB ($${\color{red}+2.4\%}$$)
std_select.ts 38.60 kB ($${\color{red}+2.4\%}$$)
std_ge.ts 38.60 kB ($${\color{red}+2.4\%}$$)
std_gt.ts 38.60 kB ($${\color{red}+2.4\%}$$)
std_isCloseTo.ts 38.60 kB ($${\color{red}+2.4\%}$$)
std_le.ts 38.60 kB ($${\color{red}+2.4\%}$$)
STATIC_std.ts 99.30 kB ($${\color{red}+1.8\%}$$)
STATIC_d.ts 79.00 kB ($${\color{red}+1.6\%}$$)
STATIC_tgpu.ts 274.43 kB ($${\color{red}+0.7\%}$$)
tgpu_fn.ts 274.43 kB ($${\color{red}+0.7\%}$$)
tgpu_init.ts 274.44 kB ($${\color{red}+0.7\%}$$)
tgpu_lazy.ts 274.44 kB ($${\color{red}+0.7\%}$$)
tgpu_slot.ts 274.44 kB ($${\color{red}+0.7\%}$$)
tgpu_const.ts 274.44 kB ($${\color{red}+0.7\%}$$)
tgpu_unroll.ts 274.44 kB ($${\color{red}+0.7\%}$$)
tgpu_resolve.ts 274.44 kB ($${\color{red}+0.7\%}$$)
tgpu_accessor.ts 274.44 kB ($${\color{red}+0.7\%}$$)
tgpu_comptime.ts 274.44 kB ($${\color{red}+0.7\%}$$)
tgpu_vertexFn.ts 274.44 kB ($${\color{red}+0.7\%}$$)
tgpu_computeFn.ts 274.44 kB ($${\color{red}+0.7\%}$$)
tgpu_fragmentFn.ts 274.44 kB ($${\color{red}+0.7\%}$$)
tgpu_privateVar.ts 274.44 kB ($${\color{red}+0.7\%}$$)
tgpu_vertexLayout.ts 274.44 kB ($${\color{red}+0.7\%}$$)
tgpu_workgroupVar.ts 274.44 kB ($${\color{red}+0.7\%}$$)
tgpu_initFromDevice.ts 274.45 kB ($${\color{red}+0.7\%}$$)
tgpu_bindGroupLayout.ts 274.45 kB ($${\color{red}+0.7\%}$$)
tgpu_mutableAccessor.ts 274.45 kB ($${\color{red}+0.7\%}$$)
tgpu_resolveWithContext.ts 274.45 kB ($${\color{red}+0.7\%}$$)
STATIC_allImports.ts 300.69 kB ($${\color{red}+0.6\%}$$)

import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):

Test tsdown
tgpu_init.ts 264.91 kB ($${\color{green}-3.5\%}$$)
tgpu_initFromDevice.ts 264.36 kB ($${\color{green}-3.7\%}$$)
tgpu_resolve.ts 163.51 kB ($${\color{green}-40.4\%}$$)
tgpu_resolveWithContext.ts 163.44 kB ($${\color{green}-40.4\%}$$)
tgpu_bindGroupLayout.ts 63.54 kB ($${\color{green}-76.8\%}$$)
tgpu_mutableAccessor.ts 58.26 kB ($${\color{green}-78.8\%}$$)
tgpu_accessor.ts 58.26 kB ($${\color{green}-78.8\%}$$)
tgpu_privateVar.ts 56.95 kB ($${\color{green}-79.2\%}$$)
tgpu_workgroupVar.ts 56.95 kB ($${\color{green}-79.2\%}$$)
tgpu_const.ts 56.37 kB ($${\color{green}-79.5\%}$$)
tgpu_lazy.ts 56.17 kB ($${\color{green}-79.5\%}$$)
tgpu_fragmentFn.ts 39.68 kB ($${\color{green}-85.5\%}$$)
tgpu_fn.ts 39.62 kB ($${\color{green}-85.6\%}$$)
tgpu_vertexFn.ts 39.50 kB ($${\color{green}-85.6\%}$$)
tgpu_computeFn.ts 39.20 kB ($${\color{green}-85.7\%}$$)
tgpu_vertexLayout.ts 28.33 kB ($${\color{green}-89.7\%}$$)
tgpu_comptime.ts 15.93 kB ($${\color{green}-94.2\%}$$)
tgpu_unroll.ts 1.75 kB ($${\color{green}-99.4\%}$$)
tgpu_slot.ts 1.70 kB ($${\color{green}-99.4\%}$$)

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

@github-actions

github-actions Bot commented Aug 18, 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.96, 1.95, 4.37, 7.27, 8.55, 11.39, 25.55, 24.39]
  line [1.05, 2.00, 4.46, 6.44, 7.85, 13.22, 24.95, 26.65]
  line [1.02, 2.03, 4.34, 6.85, 8.44, 12.84, 24.44, 23.34]
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.32, 0.49, 0.73, 0.87, 1.18, 1.31, 1.51, 1.55]
  line [0.29, 0.48, 0.68, 0.81, 1.10, 1.18, 1.40, 1.60]
  line [0.29, 0.51, 0.70, 0.87, 1.23, 1.29, 1.47, 1.72]
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.93, 2.73, 5.29, 8.69, 14.11, 27.87, 59.55, 121.41]
  line [1.00, 2.37, 4.16, 7.30, 12.81, 27.19, 58.22, 118.25]
  line [0.87, 2.15, 3.82, 7.49, 12.90, 27.27, 58.19, 118.91]
Loading

pullfrog[bot]

This comment was marked as outdated.

pullfrog[bot]

This comment was marked as outdated.

@aleksanderkatan
aleksanderkatan marked this pull request as ready for review August 19, 2026 14:23
@aleksanderkatan
aleksanderkatan force-pushed the impr/clean-up-vectorops branch from 5e5d55f to 1fd63f3 Compare August 19, 2026 14:26
Copilot AI lite review requested due to automatic review settings August 19, 2026 14:27

This comment was marked as outdated.

@aleksanderkatan
aleksanderkatan marked this pull request as draft August 19, 2026 14:32
pullfrog[bot]

This comment was marked as outdated.

pullfrog[bot]

This comment was marked as outdated.

Base automatically changed from impr/clean-up-vectorops to main August 20, 2026 11:22
@aleksanderkatan
aleksanderkatan marked this pull request as ready for review August 25, 2026 13:13
pullfrog[bot]

This comment was marked as outdated.

@cieplypolar cieplypolar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Very cool. Left one nit.

]);
export const floatKind: Set<Kind> = new Set([...f32Kind, ...f16Kind]);
export const signedKind: Set<Kind> = new Set([...i32Kind, ...f32Kind, ...f16Kind]);
export const numericKind: Set<Kind> = new Set([...i32Kind, ...u32Kind, ...f32Kind, ...f16Kind]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
export const numericKind: Set<Kind> = new Set([...i32Kind, ...u32Kind, ...f32Kind, ...f16Kind]);
export const numericKind: Set<Kind> = new Set([...signedKind, ...u32Kind]);

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.

fix: Throw when invalid types are passed into select()

3 participants