Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add docstring for return_type #36834

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions base/Base.jl
Expand Up @@ -45,6 +45,9 @@ if isdefined(Core, :Compiler)
Core.atdoc!(CoreDocs.docm)
end

# TODO better place for this?
jw3126 marked this conversation as resolved.
Show resolved Hide resolved
@doc Core.Compiler.docstring_return_type -> Core.Compiler.return_type

include("exports.jl")

if false
Expand Down
13 changes: 13 additions & 0 deletions base/compiler/typeinfer.jl
Expand Up @@ -659,6 +659,19 @@ function typeinf_ext_toplevel(interp::AbstractInterpreter, linfo::MethodInstance
end


const docstring_return_type =
"""
return_type(f, ArgType)

Estimate the return type of `f` given arguments of type `ArgType`. In other words this gives an upper bound for `typeof(f((args::ArgType)...))`.

!!! warning

This function is not part of the stable API. It is an implementation detail of the compiler,
that can and will change any time. For instance it might give sharper bounds as
inference improves or looser bounds to improve latency.
Using `return_type` is very likely to lead to undefined behaviour.
jw3126 marked this conversation as resolved.
Show resolved Hide resolved
"""
function return_type(@nospecialize(f), @nospecialize(t))
world = ccall(:jl_get_tls_world_age, UInt, ())
return ccall(:jl_call_in_typeinf_world, Any, (Ptr{Ptr{Cvoid}}, Cint), Any[_return_type, f, t, world], 4)
Expand Down