-
Notifications
You must be signed in to change notification settings - Fork 28
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
remove dependence on Julia internal Core.Compiler.return_type
#127
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Manifest.toml | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,15 @@ function Indices(iter) | |
iter = collect(iter) | ||
end | ||
|
||
return Indices{eltype(iter)}(iter) | ||
# This is necessary to make map'ing across an empty dictionary work | ||
# In both Julia 1.9 and 1.10 eltype(::Tuple{}) == Union{} | ||
# but in Julia 1.10, this causes problems downstream when Indices{Union{}} | ||
# is used. For an empty iterator, we actually don't know what the | ||
# True(tm) eltype is, so the top of the type hierarchy (Any) is | ||
# just as reasonable as the bottom (Union{}) | ||
I = typeof(iter) == Tuple{} ? Any : eltype(iter) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Small point: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small note: f(it) = (typeof(it) == Tuple{}) ? Any : eltype(it)
g(it) = (it == ()) ? Any : eltype(it)
h(it) = (it isa Tuple{}) ? Any : eltype(it) I vote for EDIT: I think there's actually a style guide or something in Julia's manual that advises not to compare types with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe |
||
|
||
return Indices{I}(iter) | ||
end | ||
|
||
function Indices{I}(iter) where {I} | ||
|
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.
This is worse than just calling
Core.Compiler.return_type
. It still trespasses on the internals of the Julia implementation, as it's not documented thatlast
may be used here, and I guess it's slower thanCore.Compiler.return_type
.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.
@nsajko It's calling
last
on aPair
-- how is that undocumented behavior? It's also only calling public API (an function that appears in the manual). I guess I could also access therettype
property of theCodeInfo
that's the first element of that pair, but I still need to access the pair.It will almost definitely be slower than calling
Core.Compiler.return_type
, because I'm guessing thatCore.Compiler.return_type
is called somewhere in the implementation ofcode_typed
.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.
You're right, sorry.