software-mansion / software-mansion/TypeGPU

bug: WGSL generator resolves object properties out of JS order

Open
#2,944 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

it('resolves object fields in schema declaration order', () => {
  using consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});

  const fieldX = tgpu.comptime(() => {
    console.log('fieldX');
    return 6;
  });
  const fieldY = tgpu.comptime(() => {
    console.log('fieldY');
    return 7;
  });

  const f = tgpu.fn(
    [],
    d.struct({ x: d.u32, y: d.u32 }),
  )(() => {
    'use gpu';
    return {
      y: fieldY(),
      x: fieldX(),
    };
  });

  tgpu.resolve([f]);

  expect(consoleLogSpy.mock.calls).toEqual([['fieldX'], ['fieldY']]);
});

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

Start with the WGSL generator path exercised by tgpu.resolve([f]) and the object return in the provided Vitest case. Reproduce the case with the schema declaring x before y but the returned object using y before x; done means the console calls are [['fieldX'], ['fieldY']] as shown.

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
Active
Clarity
Mostly clear
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.