-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
Co-Authored-By: Tim Besard <383068+maleadt@users.noreply.github.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,13 +40,27 @@ See also [`@meta`](@ref). | |
julia> IRTools.meta(Tuple{typeof(gcd),Int,Int}) | ||
Metadata for gcd(a::T, b::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} in Base at intfuncs.jl:31 | ||
""" | ||
function meta(T; types = T, world = worldcounter()) | ||
function meta(T; types = T, world=nothing) | ||
if world === nothing | ||
world = worldcounter() | ||
end | ||
F = T.parameters[1] | ||
F == typeof(invoke) && return invoke_meta(T; world = world) | ||
F isa DataType && (F.name.module === Core.Compiler || | ||
F <: Core.Builtin || | ||
F <: Core.Builtin) && return nothing | ||
_methods = Base._methods_by_ftype(T, -1, world) | ||
min_world = Ref{UInt}(typemin(UInt)) | ||
max_world = Ref{UInt}(typemax(UInt)) | ||
has_ambig = Ptr{Int32}(C_NULL) # don't care about ambiguous results | ||
_methods = if VERSION >= v"1.7.0-DEV.1297" | ||
Base._methods_by_ftype(T, #=mt=# nothing, #=lim=# -1, | ||
world, #=ambig=# false, | ||
min_world, max_world, has_ambig) | ||
else | ||
Base._methods_by_ftype(T, #=lim=# -1, | ||
world, #=ambig=# false, | ||
min_world, max_world, has_ambig) | ||
This comment has been minimized.
Sorry, something went wrong.
vtjnash
Contributor
|
||
end | ||
_methods === nothing && return nothing | ||
_methods isa Bool && return nothing | ||
length(_methods) == 0 && return nothing | ||
|
@@ -88,17 +102,25 @@ function invoke_meta(T; world) | |
end | ||
|
||
""" | ||
@meta f(args...) | ||
@meta [world] f(args...) | ||
Convenience macro for retrieving metadata without writing a full type signature. | ||
julia> IRTools.@meta gcd(10, 5) | ||
Metadata for gcd(a::T, b::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} in Base at intfuncs.jl:31 | ||
""" | ||
macro meta(ex) | ||
isexpr(ex, :call) || error("@meta f(args...)") | ||
f, args = ex.args[1], ex.args[2:end] | ||
:(meta(typesof($(esc.((f, args...))...)))) | ||
macro meta(ex...) | ||
if length(ex) == 1 | ||
world = nothing | ||
call = ex[1] | ||
elseif length(ex) == 2 | ||
world, call = ex | ||
else | ||
error("@meta [world] f(args...)") | ||
end | ||
isexpr(call, :call) || error("@meta [world] f(args...)") | ||
f, args = call.args[1], call.args[2:end] | ||
:(meta(typesof($(esc.((f, args...))...)); world=$(esc(world)))) | ||
end | ||
|
||
function code_ir(f, T) | ||
|
There is no code nor edges nor worlds here. This function itself is pure.