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

[stdlib] Add UInt __invert__ #3643

Open
wants to merge 7 commits into
base: nightly
Choose a base branch
from

Conversation

martinvuyk
Copy link
Contributor

@martinvuyk martinvuyk commented Oct 11, 2024

Add UInt __invert__

@martinvuyk martinvuyk requested a review from a team as a code owner October 11, 2024 17:26
@soraros
Copy link
Contributor

soraros commented Oct 11, 2024

I believe this won't compile if you add a test case as we can't convert a negative IntLiteral to UInt.

martinvuyk and others added 3 commits October 13, 2024 15:44
Signed-off-by: martinvuyk <[email protected]>
Co-authored-by: soraros <[email protected]>
Signed-off-by: martinvuyk <[email protected]>
Signed-off-by: martinvuyk <[email protected]>
Signed-off-by: martinvuyk <[email protected]>
@helehex
Copy link
Contributor

helehex commented Nov 10, 2024

This looks good, although I wonder why __invert__() doesn't directly use the mlir ops. I noticed that with Int as well.
Maybe we should do something similar to Int.__neg__(), to be consistent, but it's not super important.

@martinvuyk
Copy link
Contributor Author

Hi @helehex , well I think it's just an xor however you express it 🤷‍♂️ . I just want the functionality to do stuff with hashes

@helehex
Copy link
Contributor

helehex commented Nov 10, 2024

Yeah it's just a question about consistency. Hopefully this can get merged soon since it's been missing for a while.

@helehex
Copy link
Contributor

helehex commented Nov 11, 2024

Maybe you should add a test (even though int doesn't have one).

Also, if you use mlir ops, the implementation could be the same between Int and UInt, ie.

return __mlir_op.`index.xor`(
    value.value,
    __mlir_op.`index.constant`[value = __mlir_attr.`-1:index`](),
)

works for Uint and Int, the difference is just the implicit conversion on return.

@martinvuyk
Copy link
Contributor Author

Maybe you should add a test (even though int doesn't have one).

Honestly this makes no difference, it's trivial. Inverting bits doesn't need a test IMO, that would be testing the CPU basically.

works for Uint and Int, the difference is just the implicit conversion on return.

When #3753 gets merged it will fail. And the code is already what gets added by the xor operation

@jackos can we merge this directly?

@helehex
Copy link
Contributor

helehex commented Nov 11, 2024

Both UInt and Int are really just wrappers around the mlir.index type, so i dont see why it would fail when that gets merged, theres no conversion between Int and UInt happening.

It may be trivial, but having a test is nice regardless to make sure it compiles, and to ensure nothing else breaks it down the line.

@helehex
Copy link
Contributor

helehex commented Nov 11, 2024

That being said, I'd be fine with it getting merged as is, it's just some suggestions.

@martinvuyk
Copy link
Contributor Author

i dont see why it would fail when that gets merged, theres no conversion between Int and UInt happening.

yeah you're right I got confused and thought I changed the mlir index constructor in that PR but it was just the Int one.

It may be trivial, but having a test is nice regardless to make sure it compiles, and to ensure nothing else breaks it down the line.

Yeah it would be nice, I'm just a bit frustrated and I don't want to extend this PR further

@jackos
Copy link
Collaborator

jackos commented Nov 11, 2024

When #3753 gets merged it will fail. And the code is already what gets added by the xor operation

Hi @martinvuyk that one is already failing a bunch of internal tests, I'll leave comments in that PR.

But this is separate I'll add a test on the internal PR and see if all the other internal tests pass.

@jackos
Copy link
Collaborator

jackos commented Nov 11, 2024

!sync

@modularbot modularbot added the imported-internally Signals that a given pull request has been imported internally. label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imported-internally Signals that a given pull request has been imported internally.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants