clojure-dev

Issues: https://clojure.atlassian.net/browse/CLJ | Guide: https://insideclojure.org/2015/05/01/contributing-clojure/
ghadi 2021-04-23T19:46:55.034600Z

@seancorfield clojure now works again on the latest release of OpenJ9 (0.26.0)

2đź’Ż
2021-04-23T20:26:47.034900Z

JIT bugs! Scary!

souenzzo 2021-04-23T20:32:01.037100Z

It's not the first time that I see this bug (find [:a :b] 8589934592) => [8589934592 :a] There is a jira for it? The issue is at PersistentVector#valAt

public Object valAt(Object key, Object notFound){
		ensureEditable();
		if(Util.isInteger(key))
			{
			int i = ((Number) key).intValue();
//  here key = 8589934592  generates i = 0
			if(i >= 0 && i < cnt)
				return nth(i);
			}
		return notFound;
	}

2021-04-23T21:32:19.037900Z

This might be a case of one man's bug is another man's performance optimization with a touch of GIGO. That isn't my call to make, though.

slipset 2021-04-23T21:34:29.038700Z

It reminds me of (sort-by - xs) which “works” until we have numbers that are greater than ints can be.

slipset 2021-04-23T21:36:28.040500Z

One could argue that it’s surprising that math operations in Clojure are designed to not overflow, and then other places, stuff overflows silently producing wrong results.

2021-04-23T21:36:35.040800Z

Well, for that example, there is documentation on <http://clojure.org|clojure.org> that warns about that and recommends against it: https://clojure.org/guides/comparators. (beware using subtraction section)

slipset 2021-04-23T21:37:14.041700Z

Ah, but that’s because you wrote that after I highlighted it. At least that’s my recollection of the events 🙂

2021-04-23T21:37:21.041900Z

Clojure on JVM cannot change the compareTo Java interface, while using that interface, and it returns a 32-bit int

2021-04-23T21:37:57.042500Z

I don't know the time ordering of events there. I collected a lot of corner cases there from wherever I could find them.

slipset 2021-04-23T21:38:20.043Z

Not blaming anyone. Just typing when I should have gone to bed.

2021-04-23T21:38:49.043600Z

Another case one could argue is a bug vs. GIGO performance optimization in a hot code path:

user=&gt; (nth [:a :b :c] 1.5)
:b

slipset 2021-04-23T21:39:48.044100Z

Makes sens though, 1.5 is in the middle of 3, right?

2021-04-23T21:40:16.044400Z

Well, 2.5 also returns :c

2021-04-23T21:40:43.044700Z

and -0.1 returns :a

slipset 2021-04-23T21:40:51.044900Z

at least it’s rounding and not flooring.

2021-04-23T21:41:32.045900Z

-0.99 returns :a, too. I don't know what exactly it is doing, but I'd recommend not calling it with floating point values, for sure.

slipset 2021-04-23T21:41:51.046300Z

On a personal note, I think it would be nice with an addendum to the docstring for assoc! to never ever use it without using the return value.

slipset 2021-04-23T21:42:20.046600Z

Not that it would have helped me, but it could help others.

2021-04-23T21:43:00.047200Z

Might be a JIRA for that, but if not, <http://ask.clojure.org|ask.clojure.org> is ready for your suggestion.

slipset 2021-04-23T21:43:34.047400Z

https://github.com/clj-kondo/clj-kondo/issues/1258

slipset 2021-04-23T21:49:16.047700Z

asked 🙂

2021-04-23T21:58:04.048100Z

of transients you need some kind linear dataflow analysis

2021-04-23T21:59:40.049100Z

In general it is probably undecidable, but a linter check that tells you when you are obviously and locally discarding the return value catches a lot of cases. Eastwood has it, and there is a clj-kondo issue for it, too, apparently.

2021-04-23T22:01:39.050200Z

well it is what rust's borrow checker does, and what haskell's new linear types do

2021-04-23T22:04:04.051300Z

but yeah, something like any use of assoc! (or other transient write operation) where the result ends up in what the compiler calls a statement context would catch most of it