Skip to content

fix: Fix pointer value assignment type conversion #1526

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

Merged
merged 13 commits into from
Jul 24, 2025
Merged

Conversation

reczkok
Copy link
Contributor

@reczkok reczkok commented Jul 22, 2025

Previously we always made the type conversion system pick the lhs type regardless of all rules which resulted in trying to create a reference for the rhs instead of dereferencing lhs.

const increment = tgpu.fn([d.ptrFn(d.f32)])((val) => {
  val += 1;
});

Before:

val += &1;

After:

*val += 1;

(I also removed the redundant whitespace before the newline in the resolution error, it was driving me crazy. My formatter kept stubbornly removing trailing whitespace in inline snapshots.)

Copy link

github-actions bot commented Jul 22, 2025

pkg.pr.new

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

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@f33921aaccd11e0ca6f4668efb8b817ec8c00e2b
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@f33921aaccd11e0ca6f4668efb8b817ec8c00e2b
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@f33921aaccd11e0ca6f4668efb8b817ec8c00e2b

benchmark
view benchmark

commit
view commit

@reczkok reczkok requested review from aleksanderkatan and iwoplaza and removed request for aleksanderkatan July 22, 2025 12:01
Copy link
Contributor

@aleksanderkatan aleksanderkatan left a comment

Choose a reason for hiding this comment

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

Great! 🪄

Comment on lines +171 to +174
? lhsExpr.dataType.type === 'ptr'
? [lhsExpr.dataType.inner as AnyData]
: [lhsExpr.dataType as AnyData]
: undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was actually a significant bug that completely disabled the type conversion for logical and binary expressions.

const forcedType = expression[0] === NODE.assignmentExpr
    ? [lhsExpr.dataType as AnyData]
    : [];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Passing an empty array to convertToCommonType as the forcedType parameter says that the converted types have to be one of the ones in the array - since it was empty conversions were disabled.

Co-authored-by: Iwo Plaza <[email protected]>
@reczkok
Copy link
Contributor Author

reczkok commented Jul 22, 2025

Should we add a warning (or maybe throw even)?

console.warn(
  'convertToCommonType was called with an empty restrictTo array, which prevents any conversions from being matched. If you want to allow all conversions, pass undefined instead. If this is intentional, consider calling the function conditionally, as the result will always be undefined.',
);

We could also make an empty array act the same way as undefined since calling this function with no legal conversions makes little sense.

Copy link
Collaborator

@iwoplaza iwoplaza left a comment

Choose a reason for hiding this comment

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

Yes please!

@reczkok reczkok requested a review from iwoplaza July 23, 2025 12:28
Copy link
Collaborator

@iwoplaza iwoplaza left a comment

Choose a reason for hiding this comment

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

Awesome blossom! EXTRA AWESOME 🌸

@reczkok reczkok merged commit 4077457 into main Jul 24, 2025
6 checks passed
@reczkok reczkok deleted the fix/pointer-assignment branch July 24, 2025 09:48
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.

3 participants