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

Add shift operators #23

Merged
merged 2 commits into from
Oct 5, 2023
Merged

Add shift operators #23

merged 2 commits into from
Oct 5, 2023

Conversation

Octogonapus
Copy link
Contributor

@Octogonapus Octogonapus commented Oct 2, 2023

This PR adds support for C's shift operators.
This feature is needed because Clang.jl can emit code like the test I added, which is a method error otherwise.

@codecov-commenter
Copy link

codecov-commenter commented Oct 2, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (c03479a) 58.25% compared to head (22b97c9) 59.61%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #23      +/-   ##
==========================================
+ Coverage   58.25%   59.61%   +1.36%     
==========================================
  Files           2        2              
  Lines         103      104       +1     
==========================================
+ Hits           60       62       +2     
+ Misses         43       42       -1     
Files Coverage Δ
src/operators.jl 91.66% <ø> (ø)

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Octogonapus
Copy link
Contributor Author

@Gnimuc Could you please take a look at this? Thanks!

src/operators.jl Outdated

for op in (:+, :-, :&, :|, :xor, :(==))
for op in (:+, :-, :&, :|, :xor, :(==), :<<, :>>, :>>>)
Copy link
Member

Choose a reason for hiding this comment

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

>> and << are OK, but I don't think C supports >>>.

ref: https://en.cppreference.com/w/c/language/operator_arithmetic

Copy link
Member

Choose a reason for hiding this comment

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

Users can still define >>> in their own package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough

Copy link
Member

Choose a reason for hiding this comment

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

wait, could you confirm the promotion behavior between Julia's >> and C's >> is identical?

Copy link
Contributor Author

@Octogonapus Octogonapus Oct 4, 2023

Choose a reason for hiding this comment

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

From https://en.cppreference.com/w/c/language/operator_arithmetic subsection "Shift operators" it indeed agrees with Julia's shift operators.

Copy link
Member

Choose a reason for hiding this comment

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

Better to add those examples as test cases.

https://godbolt.org/z/W194b656a

Here, we are testing against C's promotion behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@Gnimuc
Copy link
Member

Gnimuc commented Oct 4, 2023

Also, I'd like to release this feature in 0.5.x. This package is indirectly used by many wrapper packages generated by Clang.jl. And if the downstream packages have defined these methods in their own code base, something might be broken. The download number scares me...

@Gnimuc Gnimuc merged commit 8533026 into JuliaInterop:master Oct 5, 2023
@Gnimuc
Copy link
Member

Gnimuc commented Oct 5, 2023

Thanks!

@Octogonapus Octogonapus deleted the add_shift branch October 5, 2023 16:10
@Octogonapus
Copy link
Contributor Author

Could 8533026 please be registered now that this PR is merged?

@ChrisRackauckas
Copy link
Member

What in here is breaking?

@Gnimuc
Copy link
Member

Gnimuc commented Oct 6, 2023

What in here is breaking?

in case someone defined their own shift operators that are not compatible with C's behavior...

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.

4 participants