Skip to content

Commit d7dccc5

Browse files
authored
fix #44153, limit input types of reflection utilities (#44155)
After #43113 Julia compiler can inline `@nospecialize ::AbstractType` signature, so we can reintroduce the input type annotations. Still I want to keep the current `::Any` signature for those utility functions heavily in `Core.Compiler` (e.g. `isbitstype`) because `isa(t, Type)` check inserted by the inliner otherwise might involve some cost. But I agree that the other non-performance sensitive functions like `which` is better to have input type restrictions.
1 parent d65fd0f commit d7dccc5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

base/reflection.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ end
12301230
Similar to [`code_typed`](@ref), except the argument is a tuple type describing
12311231
a full signature to query.
12321232
"""
1233-
function code_typed_by_type(@nospecialize(tt#=::Type=#);
1233+
function code_typed_by_type(@nospecialize(tt::Type);
12341234
optimize=true,
12351235
debuginfo::Symbol=:default,
12361236
world = get_world_counter(),
@@ -1301,7 +1301,7 @@ function print_statement_costs(io::IO, @nospecialize(f), @nospecialize(t); kwarg
13011301
print_statement_costs(io, tt; kwargs...)
13021302
end
13031303

1304-
function print_statement_costs(io::IO, @nospecialize(tt#=::Type=#);
1304+
function print_statement_costs(io::IO, @nospecialize(tt::Type);
13051305
world = get_world_counter(),
13061306
interp = Core.Compiler.NativeInterpreter(world))
13071307
matches = _methods_by_ftype(tt, -1, world)::Vector
@@ -1329,9 +1329,9 @@ function print_statement_costs(io::IO, @nospecialize(tt#=::Type=#);
13291329
end
13301330
end
13311331

1332-
print_statement_costs(args...; kwargs...) = print_statement_costs(stdout, args...; kwargs...)
1332+
print_statement_costs(args...; kwargs...) = print_statement_costs(stdout::IO, args...; kwargs...)
13331333

1334-
function _which(@nospecialize(tt#=::Type=#), world=get_world_counter())
1334+
function _which(@nospecialize(tt::Type), world=get_world_counter())
13351335
min_valid = RefValue{UInt}(typemin(UInt))
13361336
max_valid = RefValue{UInt}(typemax(UInt))
13371337
match = ccall(:jl_gf_invoke_lookup_worlds, Any,

0 commit comments

Comments
 (0)