Skip to content
Open
Show file tree
Hide file tree
Changes from all 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/context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ See also: [`canrecurse`](@ref), [`overdub`](@ref), [`recurse`](@ref), [`prehook
# to `Core.apply_type`. In the future, it would be best for Julia's compiler to better handle
# varargs calls to such functions with type arguments, or at least provide a better way to
# force specialization on the type arguments.
@inline call(::ContextUntagged, f::typeof(Core.apply_type), ::Type{A}, ::Type{B}) where {A,B} = f(A, B)
@inline call(::ContextTagged, f::typeof(Core.apply_type), ::Type{A}, ::Type{B}) where {A,B} = f(A, B)
@inline call(::ContextUntagged, f::typeof(Core.apply_type), a::Type{A}, b::Type{B}) where {A,B} = @isdefined(A) && @isdefined(B) ? f(A, B) : f(a, b)
@inline call(::ContextTagged, f::typeof(Core.apply_type), a::Type{A}, b::Type{B}) where {A,B} = @isdefined(A) && @isdefined(B) ? f(A, B) : f(a, b)
Comment on lines +454 to +455
Copy link

Choose a reason for hiding this comment

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

Suggested change
@inline call(::ContextUntagged, f::typeof(Core.apply_type), a::Type{A}, b::Type{B}) where {A,B} = @isdefined(A) && @isdefined(B) ? f(A, B) : f(a, b)
@inline call(::ContextTagged, f::typeof(Core.apply_type), a::Type{A}, b::Type{B}) where {A,B} = @isdefined(A) && @isdefined(B) ? f(A, B) : f(a, b)
@inline call(::ContextUntagged, f::typeof(Core.apply_type), a::Type{A}, b::Type{B}) where {A,B} = f(a, b)
@inline call(::ContextTagged, f::typeof(Core.apply_type), a::Type{A}, b::Type{B}) where {A,B} = f(a, b)

where {A} preserves only the equality of a type and not its identity. Thus, especially in a context like this, you must always use the value, to avoid corrupting the meaning of the expression. For example, the former may equate Dict{K,V} where {K,V} with Dict{K,V} where {V,K} since they are equivalent types, but the call to apply_type should yield very different results for those two based upon their distinct identity.


"""
```
Expand Down
8 changes: 4 additions & 4 deletions test/misctests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,10 @@ kwargtest(foobar; foo = 1, bar = 2) = nothing
@inferred(overdub(InferCtx(), eltype, rand(1)))
@inferred(overdub(InferCtx(), *, rand(1, 1), rand(1, 1)))
@inferred(overdub(InferCtx(), *, rand(Float32, 1, 1), rand(Float32, 1, 1)))
@inferred(overdub(InferCtx(), *, rand(Float32, 1, 1), rand(Float32, 1)))
@inferred(overdub(InferCtx(), rand, Float32, 1))
@inferred(overdub(InferCtx(), broadcast, +, rand(1), rand(1)))
@inferred(overdub(InferCtx(), relulayer, rand(Float64, 1, 1), rand(Float32, 1), rand(Float32, 1)))
@test_broken @inferred(overdub(InferCtx(), *, rand(Float32, 1, 1), rand(Float32, 1)))
@test_broken @inferred(overdub(InferCtx(), rand, Float32, 1))
@test_broken @inferred(overdub(InferCtx(), broadcast, +, rand(1), rand(1)))
@test_broken @inferred(overdub(InferCtx(), relulayer, rand(Float64, 1, 1), rand(Float32, 1), rand(Float32, 1)))
@inferred(overdub(InferCtx(), () -> kwargtest(42; foo = 1, bar = 2)))

println("done (took ", time() - before_time, " seconds)")
Expand Down