-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Integer
s in the type domain
#55571
Integer
s in the type domain
#55571
Conversation
Use `Int8` instead of `Int`, according to the principle of least power. Protect againt unnecessary promotion.
Addition is the more basic operation, avoid subtracting unnecessarily.
More tests would probably be good. Is there a way to get code coverage for the test suite, to help me with seeing which tests are missing? |
the original motivation for static ints as I understood it was mostly stuff like ranges and shapes; you seem to have used them here almost exclusively to reimplement arithmetic and mathematical functions? Do you have any benchmarks that show this is actually useful?
also it seems a bit ambitious, to put it mildly, to label this as a |
Yeah, I do say that "yet other applications are also possible" above.
This isn't tagged with the "performance" label. The motivation is numeric/symbolic accuracy, e.g. the linked issue for the defining identity for
That package is much less type-safe. The types defined there wrap values of a specific type, but the validity is not checked by the type system. In contrast, here the integers are constructed from first principles in a bijective manner. That is, each number has only a single instance, and invalid instances aren't possible. Another benefit of my design is that certain subsets of the integers are expressible in the type system, e.g., negative integers, nonnegative integers, positive integers, integers greater than one, etc.
See the current description above. |
Not sure what you mean? Have you seen the linked issue marked as fixed? Do you disagree that this PR fixes it? |
yes, I saw the issue with
This can already be done with |
No. It's not possible to express "all |
Regarding the size of the PR, I'm aware that it's huge, but I thought it best to initially submit it as-is, as otherwise the motivation perhaps wouldn't be clear. And I'm not sure what would be best to exclude if I'm going to split this up. BTW, the commit history is relatively tidy, so it should be possible to:
|
I appreciate all your work on this, but I am really not convinced we need it. I'm not sure that "fixing" #37977 is really a priority; Julia on its own is not trying to be a computer algebra system. I understand the invalidations are bad when you put something like this in a package, but we really can't use that argument when evolving the language. Base is already way too big as it is, and everybody would put their package in Base if they could for better latency. Triage etc. can have a larger discussion on this but these are my initial thoughts. |
My view: Why type domain integers can go into
|
I would also encourage a package first, IIUC your design is new-ish and different from current packages that provide "Integers in the type domain". Even apart from the fact that Base is too large already, it is valuable to first proof an implementation in the wild, once code goes into Base we are stuck with it for a while. |
As the commit message of the first commit here says, the core design was copied from a package of mine. That said, as discussed above and extensively discussed previously on Discourse and Github, a new subtype of FTR I opened a discussion on the Discourse: https://discourse.julialang.org/t/type-domain-static-integers/118568 Additionally, I can't help but draw a comparison with the recently merged PR #54653. There we had a feature that was a new design, but the feature was, unlike here, perfectly suitable for a user package. Why the double standard? |
First off, I also appreciate that tons of effort that went into this PR. That said, unfortunately I am not at all convinced this really is a "bug fix" other than for surface issues, i.e. the deeper underlying problem with the This is also a rather deep change and I would be greatly surprised if there wasn't code broken by it. As such "bug fix" is not really the right label. It adds a major new feature. I am in particular wary of type instability issues introduced by this. For this reason I also think some careful benchmarking would be in order -- while perhaps some cases may be faster with this PR (because the compiler can now "prove" that something is zero in a few more cases and optimize it away) I am afraid other things might get slower (because type instabilities are introduced and so the compiler can optimize code less). The new code is also rather complex and (in my eyes) under documented, i.e. there is a lot of tricky things going on with zero comments. Moreover, I don't find the comparison with PR #54653 very appropriate: that PR was much smaller, easier to understand, and to estimate its impact. All in all in my eyes the potential risks of this PR far outweigh the potential gains. At least based on the very little data that was presented here so far. I'd be happy to revise my evaluation if more information becomes available regarding the cost/benefit tradeoff. |
A few notes before closing:
|
Introduce
TypeDomainInteger
, a subtype ofInteger
in the type domain. That is, each value is of singleton type.These type domain integers are then applied to many places in
Base
(yet other applications are also possible).To be clear, this should go into
Base
, as opposed to a user package, because:Integer
subtype are horridBase
, e.g., it fixes the bug below for irrationalsFixes #37977
Updates #34003
Closes #44538