Skip to content

Commit

Permalink
remove unnecessary special cases for _typeof_captured_variable
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Oct 11, 2024
1 parent 5d786e4 commit 7230e78
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 28 deletions.
2 changes: 1 addition & 1 deletion base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ cconvert(::Type{T}, x) where {T} = convert(T, x)
unsafe_convert(::Type{T}, x::T) where {T} = x

# will be inserted by the frontend for closures
_typeof_captured_variable(@nospecialize t) = (@_total_meta; has_free_typevars(t) ? typeof(t) : Typeof(t))
_typeof_captured_variable(@nospecialize t) = (@_total_meta; t isa Type && has_free_typevars(t) ? typeof(t) : Typeof(t))

has_free_typevars(@nospecialize t) = (@_total_meta; ccall(:jl_has_free_typevars, Int32, (Any,), t) === Int32(1))

Expand Down
14 changes: 0 additions & 14 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2399,20 +2399,6 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
return abstract_call_unionall(interp, argtypes, call)
end
end
elseif f === _typeof_captured_variable && la == 2
t = argtypes[2]
if t isa Const
tv = t.val
rt = Const(has_free_typevars(tv) ? typeof(tv) : Core.Typeof(tv))
elseif isconstType(t)
tv = t.parameters[1]
rt = Const(has_free_typevars(tv) ? typeof(tv) : Core.Typeof(tv))
elseif !hasintersect(widenconst(t), Type)
rt = typeof_tfunc(𝕃ᵢ, t)
else
rt = DataType
end
return Future(CallMeta(rt, Bottom, EFFECTS_TOTAL, MethodResultPure()))
elseif f === Tuple && la == 2
aty = argtypes[2]
ty = isvarargtype(aty) ? unwrapva(aty) : widenconst(aty)
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using Core.Intrinsics, Core.IR
import Core: print, println, show, write, unsafe_write, stdout, stderr,
_apply_iterate, svec, apply_type, Builtin, IntrinsicFunction,
MethodInstance, CodeInstance, MethodTable, MethodMatch, PartialOpaque,
TypeofVararg, _typeof_captured_variable
TypeofVararg

const getproperty = Core.getfield
const setproperty! = Core.setfield!
Expand Down
7 changes: 0 additions & 7 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1768,13 +1768,6 @@ function late_inline_special_case!(ir::IRCode, idx::Int, stmt::Expr, flag::UInt3
unionall_call = Expr(:foreigncall, QuoteNode(:jl_type_unionall), Any, svec(Any, Any),
0, QuoteNode(:ccall), stmt.args[2], stmt.args[3])
return SomeCase(unionall_call)
elseif f === _typeof_captured_variable
if isa(type, Const)
return SomeCase(quoted(type.val))
elseif isconstType(type)
return SomeCase(quoted(type.parameters[1]))
end
# TODO we may still want to inline the body of `_typeof_captured_variable` here
elseif is_return_type(f)
if isconstType(type)
return SomeCase(quoted(type.parameters[1]))
Expand Down
11 changes: 6 additions & 5 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -800,21 +800,22 @@ let f = g -> x -> g(x)
@test f(Int)(1.0) === 1
@test @inferred(f(Int)) isa Function
@test fieldtype(typeof(f(Int)), 1) === Type{Int}
@test @inferred(f(Rational)) isa Function
@test @inferred(f(Rational{Int})) isa Function
@test fieldtype(typeof(f(Rational{Int})), 1) === Type{Rational{Int}}
@test_broken @inferred(f(Rational)) isa Function
@test fieldtype(typeof(f(Rational)), 1) === Type{Rational}
@test_broken @inferred(f(Rational{Core.TypeVar(:T)})) isa Function
@test fieldtype(typeof(f(Rational{Core.TypeVar(:T)})), 1) === DataType
end
let f() = (T = Rational{Core.TypeVar(:T)}; () -> T)
@test f() isa Function
@test Base.infer_return_type(f()) == DataType
@test fieldtype(typeof(f()), 1) === DataType
t = f()()
@test t isa DataType
@test t.name.wrapper == Rational
@test length(t.parameters) == 1
@test t.parameters[1] isa Core.TypeVar

@test @inferred(f()) isa Function
@test Base.infer_return_type(f()) == DataType
@test fieldtype(typeof(f()), 1) === DataType
end
function issue23618(a::AbstractVector)
T = eltype(a)
Expand Down

0 comments on commit 7230e78

Please sign in to comment.