-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
introduce constructing functions with typeassert for several types #59441
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
Conversation
In particular, for PR #59377, if no typeasserts are added, these tests fail: Line 300 in 3396562
Line 901 in 3396562
|
9eeaa3b to
7536d40
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reviewed 1 of the hundreds of changes. The argument to _UInt8 in base/sort.jl seems extremely unlikely to not be concretely typed. It this change hurts readability slightly but shouldn't hurt inference or runtime performance.
This type of wide-ranging grep-based PR is slightly risky in the absence of 100% code coverage, though this particular PR's methodology is reasonable and unlikely to cause bugs that are not caught by release PkgEval IMO.
Please demonstrate at least a few examples of where this PR helps inference. I wouldn't want to make hundreds of changes that don't actually help anything.
Whenever possible I like it for Base code to look like ordinary package code to make it more understandable via introspection and easier to contribute to. This is a secondary concern, but this PR does hurt that value.
I'm curious what Triage has to say about this PR.
My comment above mentions two inference tests that fail when decreasing However, it just crossed my mind it might make sense to separate this PR into multiple PRs:
Does that sound like a better plan? |
Introduce functions to construct and typeassert several concrete types: * `Bool` * other primitive integers * `Char` * `String` The new functions are meant to be used internally instead of the original constructors to help inference. Cross-reference issue JuliaLang#42372.
fa84d91 to
b0ede0a
Compare
b0ede0a to
59a28fa
Compare
I personally don't see any improvements to readability or functionality in this PR. "Deduplicating" code is not an end goal. |
|
IMO improvements to inference is good, but this is an ugly code pattern. It seems un-idiomatic, and it's not great to see it proliferate in Base. I think the least bad solution - which does not require solving #42372 more generally - is to spam |
|
I agree with @jakobnissen on all points. We can remove all the annotations in this pattern |
|
OK. I think this would have been a nice solution but I guess I'm the only one. |
|
I'll open other, more localized, PRs to prevent stack overflows and fix inference. EDIT: PR #59506 |
| struct ConstructorStrict{F} <: Function end | ||
| # Keyword arguments are not available at this point in bootstrap, so they're not | ||
| # supported. | ||
| function (::ConstructorStrict{F})(args::Vararg{Any, N}) where {F, N} | ||
| @inline | ||
| r = F(args...) | ||
| r::F | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a historical note, soon after closing this PR I realized there's a nicer way of doing this, based on preexisting functionality and more generic: Base.Fix2(typeassert, F) ∘ F. Registered package based on this idea:
Introduce functions to construct and typeassert several concrete types:
Boolother primitive integers
CharStringThe new functions are applied internally instead of the original constructors to deduplicate code, as typeasserts that were already present inline are eliminated.
The new functions are somewhat of a workaround for issue #42372 local to the implementation here.
Motivation: adding more typeasserts seems necessary to fix the test suite for existing PRs that try to decrease
max_methods, so this PR tries to allow for doing that in the future in a principled manner.Additional motivation: in some cases typeasserts are necessary to prevent stack overflows given user-defined constructor methods with unexpected return types, such as here:
julia/base/file.jl
Lines 373 to 374 in 3396562