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

Closed
wants to merge 7 commits into 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 martinvuyk requested review from jackos and a team as code owners October 13, 2024 18:44
martinvuyk and others added 3 commits October 13, 2024 15:44
Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
Co-authored-by: soraros <soraros@users.noreply.github.com>
Signed-off-by: martinvuyk <110240700+martinvuyk@users.noreply.github.com>
Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
@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
@skongum02 skongum02 deleted the branch modular:main January 29, 2025 18:58
@skongum02 skongum02 closed this Jan 29, 2025
@skongum02 skongum02 reopened this Jan 29, 2025
@skongum02 skongum02 changed the base branch from nightly to main January 29, 2025 20:49
@modularbot
Copy link
Collaborator

✅🟣 This contribution has been merged 🟣✅

Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the main branch during the next Mojo nightly release, typically within the next 24-48 hours.

We use Copybara to merge external contributions, click here to learn more.

@modularbot modularbot added the merged-internally Indicates that this pull request has been merged internally label Feb 13, 2025
@modularbot
Copy link
Collaborator

Landed in f789084! Thank you for your contribution 🎉

@modularbot modularbot added the merged-externally Merged externally in public mojo repo label Feb 15, 2025
@martinvuyk martinvuyk deleted the add-uint-invert branch February 16, 2025 13:06
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. merged-externally Merged externally in public mojo repo merged-internally Indicates that this pull request has been merged internally
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants