Skip to content

Commit 7230e78

Browse files
committed
remove unnecessary special cases for _typeof_captured_variable
1 parent 5d786e4 commit 7230e78

File tree

5 files changed

+8
-28
lines changed

5 files changed

+8
-28
lines changed

base/boot.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ cconvert(::Type{T}, x) where {T} = convert(T, x)
326326
unsafe_convert(::Type{T}, x::T) where {T} = x
327327

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

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

base/compiler/abstractinterpretation.jl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2399,20 +2399,6 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
23992399
return abstract_call_unionall(interp, argtypes, call)
24002400
end
24012401
end
2402-
elseif f === _typeof_captured_variable && la == 2
2403-
t = argtypes[2]
2404-
if t isa Const
2405-
tv = t.val
2406-
rt = Const(has_free_typevars(tv) ? typeof(tv) : Core.Typeof(tv))
2407-
elseif isconstType(t)
2408-
tv = t.parameters[1]
2409-
rt = Const(has_free_typevars(tv) ? typeof(tv) : Core.Typeof(tv))
2410-
elseif !hasintersect(widenconst(t), Type)
2411-
rt = typeof_tfunc(𝕃ᵢ, t)
2412-
else
2413-
rt = DataType
2414-
end
2415-
return Future(CallMeta(rt, Bottom, EFFECTS_TOTAL, MethodResultPure()))
24162402
elseif f === Tuple && la == 2
24172403
aty = argtypes[2]
24182404
ty = isvarargtype(aty) ? unwrapva(aty) : widenconst(aty)

base/compiler/compiler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using Core.Intrinsics, Core.IR
77
import Core: print, println, show, write, unsafe_write, stdout, stderr,
88
_apply_iterate, svec, apply_type, Builtin, IntrinsicFunction,
99
MethodInstance, CodeInstance, MethodTable, MethodMatch, PartialOpaque,
10-
TypeofVararg, _typeof_captured_variable
10+
TypeofVararg
1111

1212
const getproperty = Core.getfield
1313
const setproperty! = Core.setfield!

base/compiler/ssair/inlining.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,13 +1768,6 @@ function late_inline_special_case!(ir::IRCode, idx::Int, stmt::Expr, flag::UInt3
17681768
unionall_call = Expr(:foreigncall, QuoteNode(:jl_type_unionall), Any, svec(Any, Any),
17691769
0, QuoteNode(:ccall), stmt.args[2], stmt.args[3])
17701770
return SomeCase(unionall_call)
1771-
elseif f === _typeof_captured_variable
1772-
if isa(type, Const)
1773-
return SomeCase(quoted(type.val))
1774-
elseif isconstType(type)
1775-
return SomeCase(quoted(type.parameters[1]))
1776-
end
1777-
# TODO we may still want to inline the body of `_typeof_captured_variable` here
17781771
elseif is_return_type(f)
17791772
if isconstType(type)
17801773
return SomeCase(quoted(type.parameters[1]))

test/core.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -800,21 +800,22 @@ let f = g -> x -> g(x)
800800
@test f(Int)(1.0) === 1
801801
@test @inferred(f(Int)) isa Function
802802
@test fieldtype(typeof(f(Int)), 1) === Type{Int}
803-
@test @inferred(f(Rational)) isa Function
803+
@test @inferred(f(Rational{Int})) isa Function
804+
@test fieldtype(typeof(f(Rational{Int})), 1) === Type{Rational{Int}}
805+
@test_broken @inferred(f(Rational)) isa Function
804806
@test fieldtype(typeof(f(Rational)), 1) === Type{Rational}
805807
@test_broken @inferred(f(Rational{Core.TypeVar(:T)})) isa Function
806808
@test fieldtype(typeof(f(Rational{Core.TypeVar(:T)})), 1) === DataType
807809
end
808810
let f() = (T = Rational{Core.TypeVar(:T)}; () -> T)
811+
@test f() isa Function
812+
@test Base.infer_return_type(f()) == DataType
813+
@test fieldtype(typeof(f()), 1) === DataType
809814
t = f()()
810815
@test t isa DataType
811816
@test t.name.wrapper == Rational
812817
@test length(t.parameters) == 1
813818
@test t.parameters[1] isa Core.TypeVar
814-
815-
@test @inferred(f()) isa Function
816-
@test Base.infer_return_type(f()) == DataType
817-
@test fieldtype(typeof(f()), 1) === DataType
818819
end
819820
function issue23618(a::AbstractVector)
820821
T = eltype(a)

0 commit comments

Comments
 (0)