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

Stop using Core.Compiler.return_type #140

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Dictionary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ function _dictionary(key, value, ::Type{Dictionary}, iter)
tmp = iterate(iter)
if tmp === nothing
IT = Base.@default_eltype(iter)
I = IT == Union{} ? Union{} : Core.Compiler.return_type(first, Tuple{IT})
T = IT == Union{} ? Union{} : Core.Compiler.return_type(last, Tuple{IT})
I = Base.promote_op(first, IT)
T = Base.promote_op(last, IT)
return Dictionary{I, T}()
end
(x, s) = tmp
Expand Down
4 changes: 2 additions & 2 deletions src/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _data(d::BroadcastedDictionary) = getfield(d, :data)
sharetokens = _sharetokens(dicts...)
I = keytype(dicts[1])
Ts = Base.Broadcast.eltypes(data)
T = Core.Compiler.return_type(f, Ts)
T = Base.promote_op(f, Ts...)
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe this should be Ts.parameters...?

Is that construction inferrable? (If not we can make a pure function with @assume_effects)

Copy link
Author

Choose a reason for hiding this comment

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

so it turns out that there already is Base.Broadcast.combine_eltypes that does this functionality (except slightly more correctly).


return BroadcastedDictionary{I, T, typeof(f), typeof(data)}(f, data, sharetokens)
end
Expand Down Expand Up @@ -130,4 +130,4 @@ end
Base.Broadcast.materialize(d::BroadcastedDictionary) = copy(d)
Base.Broadcast.materialize!(out::AbstractDictionary, d::BroadcastedDictionary) = copyto!(out, d)

Base.Broadcast.materialize!(out::AbstractDictionary, bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0}, Nothing, typeof(identity)}) = fill!(out, bc.args[1][])
Base.Broadcast.materialize!(out::AbstractDictionary, bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0}, Nothing, typeof(identity)}) = fill!(out, bc.args[1][])
6 changes: 3 additions & 3 deletions src/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ function Base.map!(f, out::AbstractDictionary)
end

function Base.map(f, d::AbstractDictionary)
out = similar(d, Core.Compiler.return_type(f, Tuple{eltype(d)}))
out = similar(d, Base.promote_op(f, eltype(d)))
@inbounds map!(f, out, d)
return out
end

function Base.map(f, d::AbstractDictionary, ds::AbstractDictionary...)
out = similar(d, Core.Compiler.return_type(f, Tuple{eltype(d), map(eltype, ds)...}))
out = similar(d, Base.promote_op(f, eltype(d), map(eltype, ds)...))
@inbounds map!(f, out, d, ds...)
return out
end
Expand Down Expand Up @@ -145,6 +145,6 @@ empty_type(::Type{<:MappedDictionary{<:Any, <:Any, <:Any, <:Tuple{D, Vararg{Abst

function Iterators.map(f, d::AbstractDictionary)
I = keytype(d)
T = Core.Compiler.return_type(f, Tuple{eltype(d)}) # Base normally wouldn't invoke inference for something like this...
T = Base.promote_op(f, eltype(d)) # Base normally wouldn't invoke inference for something like this...
return MappedDictionary{I, T, typeof(f), Tuple{typeof(d)}}(f, (d,))
end
4 changes: 2 additions & 2 deletions test/map.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@testset "map" begin
function _mapview(f, d::AbstractDictionary)
I = keytype(d)
T = Core.Compiler.return_type(f, Tuple{eltype(d)})
T = Base.promote_op(f, eltype(d))

return MappedDictionary{I, T, typeof(f), Tuple{typeof(d)}}(f, (d,))
end
Expand All @@ -23,4 +23,4 @@

@test _mapview(iseven, d)::Dictionaries.MappedDictionary == dictionary([1=>false, 2=>false, 3=>true, 4=>true, 5=>false])
@test _mapview(isodd, d)::Dictionaries.MappedDictionary == dictionary([1=>true, 2=>true, 3=>false, 4=>false, 5=>true])
end
end
Loading