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

Fix typehint #125

Merged
merged 4 commits into from Apr 24, 2021
Merged

Fix typehint #125

merged 4 commits into from Apr 24, 2021

Conversation

johannesloetzsch
Copy link

fixes #124

@@ -491,7 +491,8 @@
offset (mod idx bits-per-long)
mask (bit-set 0 offset)
value (aget new-bitmap chunk)
new-value (bit-or value ^Long mask)]
new-value #?(:clj (bit-or value ^Long mask)
Copy link

Choose a reason for hiding this comment

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

Is this typehint needed?

mask is allocated from bit-set which is a direct call to clojure.lang.Numbers.setBit. This is a static function with a return type of long, so the Clojure compiler already knows that mask is a long value, so no type hinting is needed.

Strangely though, this code typehints to java.lang.Long. The result of this is to box the value up as a java.lang.Long, and call clojure.lang.Numbers.setBit(long,Object). This then passes the second parameter through the clojure.lang.Numbers.bitOpsCast(Object) method, which checks that it's a Long and then calls clojure.lang.RT.longCast(Object). This method checks that it's a Long, and then returns the result of Number.longValue() on it. Which means that it gets all the way back to the original long value.

In other words, all this typehint does is to slow the operation down. It's also worth noting that the above syntax is not allowed at a repl. I recommend getting rid of the hint entirely, which allows the conditional compilation to go away.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your elaborated thoughts :)

I think you are right and I neither see a reason why the typehint was initially added.
My first commit was the minimal change to solve the linked Issue (for clojurescript) but removing the typehint for all targets seems to be the cleaner solution.

@meditans
Copy link

meditans commented Feb 13, 2021

is there any impediment on merging this @johannesloetzsch @quoll @aysylu ?

@quoll
Copy link

quoll commented Feb 13, 2021

is there any impediment on merging this @johannesloetzsch @quoll @aysylu ?

I’m obviously in support of merging this 👍

@aysylu aysylu merged commit d458f0c into aysylu:master Apr 24, 2021
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.

Wrong typehint for clojurescript
4 participants