- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 25
impr: Warn when slot is unused #1853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| pkg.pr.new packages benchmark commit | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a warning system to detect and alert developers when slots are provided to functions or pipelines but never actually used during resolution. The implementation tracks slot usage through the resolution context and emits console warnings for unused slots.
Key Changes:
- Enhanced slot tracking to differentiate between bound and used slots
- Added warning messages when slots are provided via .with()but remain unused
- Removed an unused slot binding from the fluid simulation example
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description | 
|---|---|
| packages/typegpu/src/resolutionCtx.ts | Core implementation: added usedSettracking and warning logic for unused slots | 
| packages/typegpu/tests/slot.test.ts | Comprehensive test coverage for the warning feature across different scenarios | 
| apps/typegpu-docs/src/examples/simulation/fluid-double-buffering/index.ts | Cleanup: removed unused inputGridSlotbinding | 
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
| I'm pretty sure I found a small bug in the resolution code. Take a look at these two snippets: 
   unwrap<T>(eventual: Eventual<T>): T {
    if (isProviding(eventual)) {
      return this.withSlots(
        eventual[$providing].pairs,
        () => this.unwrap(eventual[$providing].inner) as T,
      );
    }
     with(
      slot: TgpuSlot<unknown> | TgpuAccessor,
      value: unknown,
    ): TgpuFn<ImplSchema> {
      return createBoundFunction(fn, [
        ...pairs,
        [isAccessor(slot) ? slot.slot : slot, value],
      ]);
    },I think that if we call      const getSize = tgpu.fn([], d.f32)`...`
      .$uses({ ... })
      .with(sizeSlot, 1)
      .with(colorSlot, RED)
      .with(shapeSlot, 2);then  | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
So, now a warn is thrown when a slot is provided and not used!
Also, I "patched" the bug I talk about in the comment below. Here is an issue for a proper fix: #1854
The cases where I found a false-positive are:
Let me know what you think.