software-mansion / software-mansion/TypeGPU

fix: Simultaneous implicit casts and derefs

Open
#2,519 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
3.2k
Forks
122
Avg merge
3d 5h
Merged PRs (30d)
34

Description

This code silently produces invalid WGSL.

  it('disallows implicit casts in d.ref', () => {
    const modify = tgpu.fn([d.ptrFn(d.u32)])((numRef) => {
      'use gpu';
      numRef.$ += 1;
    });

    const main = tgpu.fn([])(() => {
      'use gpu';
      const num = d.f32();
      modify(d.ref(num));
    });

    expect(tgpu.resolve([main])).toMatchInlineSnapshot(`
      "fn modify(numRef: ptr<function, u32>) {
        (*numRef) += 1u;
      }

      fn main() {
        const num = 0f;
        modify((&num));
      }"
    `);
  });

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the shown TypeScript test with d.ptrFn, d.ref, and tgpu.resolve as the entry point, and trace how the simultaneous implicit cast and dereference are emitted. Verify the focused test no longer produces invalid WGSL and that implicit casts in d.ref are disallowed as intended.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.