Skip to content
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

feat(runtime): support pointer equality and custom integer comparisons #752

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thevilledev
Copy link
Contributor

Previously, comparing pointer-wrapped custom integer types (e.g. *ModeEnum) with plain integers would fail. This change enables expressions like Mode == 1 to work correctly when Mode is a pointer to a custom integer type.

  • Add pointer equality handling in code generator for "==" operator
  • Generate comparison cases for *T vs T and *T vs *T
  • Add reflection-based fallback for unknown pointer types
  • Support int64 coercion for custom integer type comparisons
  • Handle nil pointer comparisons properly
  • Add test coverage and example for pointer and custom type scenarios

Fixes pointer equality checks and ensures consistent comparison behavior for custom integer types in expressions.

Fixes #730

Previously, comparing pointer-wrapped custom integer types (e.g. `*ModeEnum`)
with plain integers would fail. This change enables expressions like
`Mode == 1` to work correctly when Mode is a pointer to a custom integer
type.

* Add pointer equality handling in code generator for "==" operator
* Generate comparison cases for *T vs T and *T vs *T
* Add reflection-based fallback for unknown pointer types
* Support int64 coercion for custom integer type comparisons
* Handle nil pointer comparisons properly
* Add test coverage and example for pointer and custom type scenarios

Fixes pointer equality checks and ensures consistent comparison behavior for
custom integer types in expressions.

Signed-off-by: Ville Vesilehto <[email protected]>
@@ -10,8 +10,94 @@ import (

func Equal(a, b interface{}) bool {
switch x := a.(type) {
case *uint:
Copy link
Member

Choose a reason for hiding this comment

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

We need to verify what this will not affect performance, as we significantly increased switch size.

Another point: we have a dedicated OpDeref. The runtime functions should work on "dereferenced" values. And the compiler should be able to figure out if dereference is needed before doing runtime operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgot this from the PR description, but I ran the basic set of benchmarks from the repo root from both branches and I didn't see any performance hit. I think we could use a more specific benchmark though, simply for this case.

I'll have a look at OpDeref for #751 and make this a draft PR while doing so

@thevilledev thevilledev marked this pull request as draft January 27, 2025 15:53
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.

Typed int with ref equality
2 participants