Skip to content

Commit

Permalink
Merge pull request JuliaLang#25615 from JuliaLang/jb/underscoredeps
Browse files Browse the repository at this point in the history
remove some underscores
  • Loading branch information
JeffBezanson committed Jan 18, 2018
2 parents ae0a3e9 + 6412f06 commit f82f82f
Show file tree
Hide file tree
Showing 26 changed files with 69 additions and 72 deletions.
4 changes: 2 additions & 2 deletions base/asyncmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ then be a function that must accept a `Vector` of argument tuples and must
return a vector of results. The input vector will have a length of `batch_size` or less.
The following examples highlight execution in different tasks by returning
the `object_id` of the tasks in which the mapping function is executed.
the `objectid` of the tasks in which the mapping function is executed.
First, with `ntasks` undefined, each element is processed in a different task.
```
julia> tskoid() = object_id(current_task());
julia> tskoid() = objectid(current_task());
julia> asyncmap(x->tskoid(), 1:5)
5-element Array{UInt64,1}:
Expand Down
7 changes: 7 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,13 @@ end
@deprecate findn(x::AbstractMatrix) (I = findall(!iszero, x); (getindex.(I, 1), getindex.(I, 2)))
@deprecate findn(x::AbstractArray{T, N}) where {T, N} (I = findall(!iszero, x); ntuple(i -> getindex.(I, i), N))

@deprecate catch_stacktrace(c_funcs::Bool) stacktrace(catch_backtrace(), c_funcs)
@deprecate catch_stacktrace() stacktrace(catch_backtrace())

@deprecate method_exists hasmethod

@deprecate object_id objectid

# issue #9053
if Sys.iswindows()
function Filesystem.tempname(uunique::UInt32)
Expand Down
5 changes: 2 additions & 3 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ export
isimmutable,
isless,
ifelse,
object_id,
objectid,
sizeof,

# tasks and conditions
Expand Down Expand Up @@ -745,7 +745,6 @@ export
StackTrace,
StackFrame,
stacktrace,
catch_stacktrace,

# types
convert,
Expand Down Expand Up @@ -789,7 +788,7 @@ export
isconst,
isinteractive,
less,
method_exists,
hasmethod,
methods,
methodswith,
module_name,
Expand Down
2 changes: 1 addition & 1 deletion base/hashing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ hash(w::WeakRef, h::UInt) = hash(w.value, h)

## hashing general objects ##

hash(@nospecialize(x), h::UInt) = hash_uint(3h - object_id(x))
hash(@nospecialize(x), h::UInt) = hash_uint(3h - objectid(x))

## core data hashing functions ##

Expand Down
2 changes: 1 addition & 1 deletion base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ isinteger(::AbstractIrrational) = false
iszero(::AbstractIrrational) = false
isone(::AbstractIrrational) = false

hash(x::Irrational, h::UInt) = 3*object_id(x) - h
hash(x::Irrational, h::UInt) = 3*objectid(x) - h

widen(::Type{T}) where {T<:Irrational} = T

Expand Down
4 changes: 2 additions & 2 deletions base/multimedia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ false
```
"""
mimewritable(::MIME{mime}, x) where {mime} =
method_exists(show, Tuple{IO, MIME{mime}, typeof(x)})
hasmethod(show, Tuple{IO, MIME{mime}, typeof(x)})

"""
show(io, mime, x)
Expand Down Expand Up @@ -313,7 +313,7 @@ function display(m::MIME, x)
end

displayable(d::D, ::MIME{mime}) where {D<:AbstractDisplay,mime} =
method_exists(display, Tuple{D,MIME{mime},Any})
hasmethod(display, Tuple{D,MIME{mime},Any})

function displayable(m::MIME)
for d in displays
Expand Down
2 changes: 1 addition & 1 deletion base/namedtuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ isequal(a::NamedTuple, b::NamedTuple) = false
_nt_names(::NamedTuple{names}) where {names} = names
_nt_names(::Type{T}) where {names,T<:NamedTuple{names}} = names

hash(x::NamedTuple, h::UInt) = xor(object_id(_nt_names(x)), hash(Tuple(x), h))
hash(x::NamedTuple, h::UInt) = xor(objectid(_nt_names(x)), hash(Tuple(x), h))

isless(a::NamedTuple{n}, b::NamedTuple{n}) where {n} = isless(Tuple(a), Tuple(b))
# TODO: case where one argument's names are a prefix of the other's
Expand Down
12 changes: 6 additions & 6 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ macro isdefined(s::Symbol)
end

"""
object_id(x)
objectid(x)
Get a hash value for `x` based on object identity. `object_id(x)==object_id(y)` if `x === y`.
Get a hash value for `x` based on object identity. `objectid(x)==objectid(y)` if `x === y`.
"""
object_id(@nospecialize(x)) = ccall(:jl_object_id, UInt, (Any,), x)
objectid(@nospecialize(x)) = ccall(:jl_object_id, UInt, (Any,), x)

struct DataTypeLayout
nfields::UInt32
Expand Down Expand Up @@ -1004,18 +1004,18 @@ function function_module(@nospecialize(f), @nospecialize(types))
end

"""
method_exists(f, Tuple type, world=typemax(UInt)) -> Bool
hasmethod(f, Tuple type, world=typemax(UInt)) -> Bool
Determine whether the given generic function has a method matching the given
`Tuple` of argument types with the upper bound of world age given by `world`.
# Examples
```jldoctest
julia> method_exists(length, Tuple{Array})
julia> hasmethod(length, Tuple{Array})
true
```
"""
function method_exists(@nospecialize(f), @nospecialize(t), world=typemax(UInt))
function hasmethod(@nospecialize(f), @nospecialize(t), world=typemax(UInt))
t = to_tuple_type(t)
t = signature_type(f, t)
return ccall(:jl_method_exists, Cint, (Any, Any, UInt), typeof(f).name.mt, t, world) != 0
Expand Down
6 changes: 3 additions & 3 deletions base/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,13 @@ function showerror(io::IO, ex::MethodError)
# Check for local functions that shadow methods in Base
if f_is_function && isdefined(Base, name)
basef = getfield(Base, name)
if basef !== ex.f && method_exists(basef, arg_types)
if basef !== ex.f && hasmethod(basef, arg_types)
println(io)
print(io, "You may have intended to import Base.", name)
end
end
if (ex.world != typemax(UInt) && method_exists(ex.f, arg_types) &&
!method_exists(ex.f, arg_types, ex.world))
if (ex.world != typemax(UInt) && hasmethod(ex.f, arg_types) &&
!hasmethod(ex.f, arg_types, ex.world))
curworld = ccall(:jl_get_world_counter, UInt, ())
println(io)
print(io, "The applicable method may be too new: running in world age $(ex.world), while current world is $(curworld).")
Expand Down
12 changes: 2 additions & 10 deletions base/stacktraces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Base.Serializer: serialize, deserialize
using Base.Printf: @printf
using Base: coalesce

export StackTrace, StackFrame, stacktrace, catch_stacktrace
export StackTrace, StackFrame, stacktrace

"""
StackFrame
Expand Down Expand Up @@ -71,7 +71,7 @@ StackFrame(func, file, line) = StackFrame(Symbol(func), Symbol(file), line,
StackTrace
An alias for `Vector{StackFrame}` provided for convenience; returned by calls to
`stacktrace` and `catch_stacktrace`.
`stacktrace`.
"""
const StackTrace = Vector{StackFrame}

Expand Down Expand Up @@ -261,14 +261,6 @@ end

stacktrace(c_funcs::Bool=false) = stacktrace(backtrace(), c_funcs)

"""
catch_stacktrace([c_funcs::Bool=false]) -> StackTrace
Returns the stack trace for the most recent error thrown, rather than the current execution
context.
"""
catch_stacktrace(c_funcs::Bool=false) = stacktrace(catch_backtrace(), c_funcs)

"""
remove_frames!(stack::StackTrace, name::Symbol)
Expand Down
4 changes: 2 additions & 2 deletions doc/src/base/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Core.typeassert
Core.typeof
Core.tuple
Base.ntuple
Base.object_id
Base.objectid
Base.hash
Base.finalizer
Base.finalize
Expand Down Expand Up @@ -176,7 +176,7 @@ Base.Enums.@enum

```@docs
Core.Function
Base.method_exists
Base.hasmethod
Core.applicable
Core.invoke
Base.invokelatest
Expand Down
1 change: 0 additions & 1 deletion doc/src/base/stacktraces.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Base.StackTraces.StackFrame
Base.StackTraces.StackTrace
Base.StackTraces.stacktrace
Base.StackTraces.catch_stacktrace
```

The following methods and types in `Base.StackTraces` are not exported and need to be called e.g.
Expand Down
2 changes: 1 addition & 1 deletion doc/src/manual/metaprogramming.md
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ When defining generated functions, there are four main differences to ordinary f
3. Instead of calculating something or performing some action, you return a *quoted expression* which,
when evaluated, does what you want.
4. Generated functions must not *mutate* or *observe* any non-constant global state (including,
for example, IO, locks, non-local dictionaries, or using `method_exists`).
for example, IO, locks, non-local dictionaries, or using `hasmethod`).
This means they can only read global constants, and cannot have any side effects.
In other words, they must be completely pure.
Due to an implementation limitation, this also means that they currently cannot define a closure
Expand Down
4 changes: 2 additions & 2 deletions doc/src/manual/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ are a trickier case. In the common case where the keys are numbers, strings, sy
`Expr`, or compositions of these types (via arrays, tuples, sets, pairs, etc.) they are safe to
precompile. However, for a few other key types, such as `Function` or `DataType` and generic
user-defined types where you haven't defined a `hash` method, the fallback `hash` method depends
on the memory address of the object (via its `object_id`) and hence may change from run to run.
on the memory address of the object (via its `objectid`) and hence may change from run to run.
If you have one of these key types, or if you aren't sure, to be safe you can initialize this
dictionary from within your `__init__` function. Alternatively, you can use the `IdDict`
dictionary type, which is specially handled by precompilation so that it is safe to initialize
Expand Down Expand Up @@ -328,7 +328,7 @@ Other known potential failure scenarios include:
at the end of compilation. All subsequent usages of this incrementally compiled module will start
from that same counter value.

Note that `object_id` (which works by hashing the memory pointer) has similar issues (see notes
Note that `objectid` (which works by hashing the memory pointer) has similar issues (see notes
on `Dict` usage below).

One alternative is to use a macro to capture [`@__MODULE__`](@ref) and store it alone with the current `counter` value,
Expand Down
8 changes: 4 additions & 4 deletions doc/src/manual/stacktraces.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ frame is missing entirely. This is understandable, given that [`stacktrace`](@re
from the context of the *catch*. While in this example it's fairly easy to find the actual source
of the error, in complex cases tracking down the source of the error becomes nontrivial.

This can be remedied by calling [`catch_stacktrace`](@ref) instead of [`stacktrace`](@ref).
Instead of returning callstack information for the current context, [`catch_stacktrace`](@ref)
This can be remedied by passing the result of [`catch_backtrace`](@ref) to [`stacktrace`](@ref).
Instead of returning callstack information for the current context, [`catch_backtrace`](@ref)
returns stack information for the context of the most recent exception:

```julia-repl
Expand All @@ -142,7 +142,7 @@ bad_function (generic function with 1 method)
julia> @noinline example() = try
bad_function()
catch
catch_stacktrace()
stacktrace(catch_backtrace())
end
example (generic function with 1 method)
Expand All @@ -167,7 +167,7 @@ julia> @noinline function grandparent()
parent()
catch err
println("ERROR: ", err.msg)
catch_stacktrace()
stacktrace(catch_backtrace())
end
end
grandparent (generic function with 1 method)
Expand Down
2 changes: 1 addition & 1 deletion examples/staged.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ macro staged(fdef)
($gengf)() = 0 # should be initially empty GF
function ($fname)($(argspec...))
($argtypes) = typeof(tuple($(argnames...)))
if !method_exists($gengf, $argtypes)
if !hasmethod($gengf, $argtypes)
($genbody) = apply(($expander), ($argtypes))
add_method($gengf, Any[$(qargnames...)],
$argtypes, $genbody)
Expand Down
10 changes: 5 additions & 5 deletions stdlib/Distributed/src/clusterserialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mutable struct ClusterSerializer{I<:IO} <: AbstractSerializer

pid::Int # Worker we are connected to.
tn_obj_sent::Set{UInt64} # TypeName objects sent
glbs_sent::Dict{UInt64, UInt64} # (key,value) -> (object_id, hash_value)
glbs_sent::Dict{UInt64, UInt64} # (key,value) -> (objectid, hash_value)
glbs_in_tnobj::Dict{UInt64, Vector{Symbol}} # Track globals referenced in
# anonymous functions.
anonfunc_id::UInt64
Expand Down Expand Up @@ -116,7 +116,7 @@ function serialize(s::ClusterSerializer, g::GlobalRef)
end

# Send/resend a global object if
# a) has not been sent previously, i.e., we are seeing this object_id for the first time, or,
# a) has not been sent previously, i.e., we are seeing this objectid for the first time, or,
# b) hash value has changed or
# c) is a bits type
function syms_2b_sent(s::ClusterSerializer, identifier)
Expand All @@ -128,7 +128,7 @@ function syms_2b_sent(s::ClusterSerializer, identifier)
if isbits(v)
push!(lst, sym)
else
oid = object_id(v)
oid = objectid(v)
if haskey(s.glbs_sent, oid)
# We have sent this object before, see if it has changed.
s.glbs_sent[oid] != hash(sym, hash(v)) && push!(lst, sym)
Expand All @@ -143,7 +143,7 @@ end
function serialize_global_from_main(s::ClusterSerializer, sym)
v = getfield(Main, sym)

oid = object_id(v)
oid = objectid(v)
record_v = true
if isbits(v)
record_v = false
Expand Down Expand Up @@ -179,7 +179,7 @@ function deserialize_global_from_main(s::ClusterSerializer, sym)
end

function delete_global_tracker(s::ClusterSerializer, v)
oid = object_id(v)
oid = objectid(v)
if haskey(s.glbs_sent, oid)
delete!(s.glbs_sent, oid)
end
Expand Down
16 changes: 8 additions & 8 deletions stdlib/Distributed/test/distributed_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1161,8 +1161,8 @@ v6 = FooModEverywhere
Base.Serializer.serialize_type(s, TestSerCnt)
serialize(s, t.v)
global testsercnt_d
cnt = get!(testsercnt_d, object_id(t), 0)
testsercnt_d[object_id(t)] = cnt+1
cnt = get!(testsercnt_d, objectid(t), 0)
testsercnt_d[objectid(t)] = cnt+1
end

Base.deserialize(s::AbstractSerializer, ::Type{TestSerCnt}) = TestSerCnt(deserialize(s))
Expand All @@ -1174,22 +1174,22 @@ for i in 1:5
remotecall_fetch(()->tsc, id_other)
end
# should have been serialized only once
@test testsercnt_d[object_id(tsc)] == 1
@test testsercnt_d[objectid(tsc)] == 1

# hash values are changed
n=5
testsercnt_d[object_id(tsc)] = 0
testsercnt_d[objectid(tsc)] = 0
for i in 1:n
tsc.v[i] = i
remotecall_fetch(()->tsc, id_other)
end
# should have been serialized as many times as the loop
@test testsercnt_d[object_id(tsc)] == n
@test testsercnt_d[objectid(tsc)] == n

# Multiple references in a closure should be serialized only once.
global mrefs = TestSerCnt(fill(1.,10))
@test remotecall_fetch(()->(mrefs.v, 2*mrefs.v, 3*mrefs.v), id_other) == (fill(1.,10), fill(2.,10), fill(3.,10))
@test testsercnt_d[object_id(mrefs)] == 1
@test testsercnt_d[objectid(mrefs)] == 1


# nested anon functions
Expand Down Expand Up @@ -1239,9 +1239,9 @@ global ids_func = ()->ids_cleanup
clust_ser = (Distributed.worker_from_id(id_other)).w_serializer
@test remotecall_fetch(ids_func, id_other) == ids_cleanup

@test haskey(clust_ser.glbs_sent, object_id(ids_cleanup))
@test haskey(clust_ser.glbs_sent, objectid(ids_cleanup))
finalize(ids_cleanup)
@test !haskey(clust_ser.glbs_sent, object_id(ids_cleanup))
@test !haskey(clust_ser.glbs_sent, objectid(ids_cleanup))

# TODO Add test for cleanup from `clust_ser.glbs_in_tnobj`

Expand Down
2 changes: 1 addition & 1 deletion stdlib/SharedArrays/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ finalize(d)
let
aorig = a1 = SharedArray{Float64}((3, 3))
a1 = remotecall_fetch(fill!, id_other, a1, 1.0)
@test object_id(aorig) == object_id(a1)
@test objectid(aorig) == objectid(a1)
id = a1.id
aorig = nothing
a1 = remotecall_fetch(fill!, id_other, a1, 1.0)
Expand Down
Loading

0 comments on commit f82f82f

Please sign in to comment.