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

Deprecate assert function in favor of at-assert macro #12565

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ function init_parallel()
global PGRP
global LPROC
LPROC.id = 1
assert(length(PGRP.workers) == 0)
@assert length(PGRP.workers) == 0
register_worker(LPROC)
end

Expand Down
4 changes: 4 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ end

@deprecate ntuple(n::Integer, f::Function) ntuple(f, n)

# 8856

@deprecate assert(x) @assert x

# 0.4 discontinued functions

@noinline function subtypetree(x::DataType, level=-1)
Expand Down
12 changes: 1 addition & 11 deletions base/docs/helpdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2248,16 +2248,6 @@ Applies a function to the preceding argument. This allows for easy function chai
"""
Base.(:(|>))

doc"""
```rst
::
assert(cond)

Throw an ``AssertionError`` if ``cond`` is false. Also available as the macro ``@assert expr``.
```
"""
assert

doc"""
```rst
::
Expand Down Expand Up @@ -12099,7 +12089,7 @@ doc"""
::
@assert cond [text]

Throw an ``AssertionError`` if ``cond`` is false. Preferred syntax for writing assertions.
Throw an ``AssertionError`` if ``cond`` is false.
```
"""
:@assert
Expand Down
3 changes: 1 addition & 2 deletions base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ kwerr(kw) = error("unrecognized keyword argument \"", kw, "\"")

systemerror(p, b::Bool) = b ? throw(Main.Base.SystemError(string(p))) : nothing

## assertion functions and macros ##
## assertion macro ##

assert(x) = x ? nothing : throw(Main.Base.AssertionError())
macro assert(ex, msgs...)
msg = isempty(msgs) ? ex : msgs[1]
if !isempty(msgs) && isa(msg, Expr)
Expand Down
1 change: 0 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,6 @@ export
now,

# errors
assert,
backtrace,
catch_backtrace,
error,
Expand Down
6 changes: 3 additions & 3 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ end
# arrays of types, or `nothing`.
function precise_container_types(args, types, vtypes, sv)
n = length(args)
assert(n == length(types))
@assert n == length(types)
result = cell(n)
for i = 1:n
ai = args[i]; ti = types[i]
Expand Down Expand Up @@ -1432,7 +1432,7 @@ function typeinf_uncached(linfo::LambdaStaticData, atypes::ANY, sparams::SimpleV

args = f_argnames(ast)
la = length(args)
assert(is(ast.head,:lambda))
@assert is(ast.head,:lambda)
vinflist = ast.args[2][1]::Array{Any,1}
vars = map(vi->vi[1], vinflist)
body = (ast.args[3].args)::Array{Any,1}
Expand Down Expand Up @@ -2408,7 +2408,7 @@ function inlineable(f::ANY, e::Expr, atype::ANY, sv::StaticVarInfo, enclosing_as
if isvarargtype(methitype)
methitype = methitype.parameters[1]
else
@assert i==nm
@assert i == nm
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions base/multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ end
const PGRP = ProcessGroup([])

function topology(t)
assert(t in [:all_to_all, :master_slave, :custom])
@assert (t in [:all_to_all, :master_slave, :custom])
if (PGRP.topology==t) || ((myid()==1) && (nprocs()==1)) || (myid() > 1)
PGRP.topology = t
else
Expand Down Expand Up @@ -1059,9 +1059,9 @@ function init_worker(manager::ClusterManager=DefaultClusterManager())
disable_threaded_libs()

# Since our pid has yet to be set, ensure no RemoteRefs have been created or addprocs() called.
assert(nprocs() <= 1)
assert(isempty(PGRP.refs))
assert(isempty(client_refs))
@assert nprocs() <= 1
@assert isempty(PGRP.refs)
@assert isempty(client_refs)

# System is started in head node mode, cleanup entries related to the same
empty!(PGRP.workers)
Expand Down Expand Up @@ -1191,7 +1191,7 @@ end

function create_worker(manager, wconfig)
# only node 1 can add new nodes, since nobody else has the full list of address:port
assert(LPROC.id == 1)
@assert LPROC.id == 1

# initiate a connect. Does not wait for connection completion in case of TCP.
w = Worker()
Expand Down Expand Up @@ -1591,7 +1591,7 @@ function timedwait(testcb::Function, secs::Float64; pollint::Float64=0.1)
end

function interrupt(pid::Integer)
assert(myid() == 1)
@assert myid() == 1
w = map_pid_wrkr[pid]
if isa(w, Worker)
manage(w.manager, w.id, w.config, :interrupt)
Expand All @@ -1600,7 +1600,7 @@ end
interrupt(pids::Integer...) = interrupt([pids...])

function interrupt(pids::AbstractVector=workers())
assert(myid() == 1)
@assert myid() == 1
@sync begin
for pid in pids
@async interrupt(pid)
Expand Down
2 changes: 1 addition & 1 deletion base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ end

const SIGPIPE = 13
function test_success(proc::Process)
assert(process_exited(proc))
@assert process_exited(proc)
if proc.exitcode < 0
#TODO: this codepath is not currently tested
throw(UVError("could not start process $(string(proc.cmd))", proc.exitcode))
Expand Down
2 changes: 1 addition & 1 deletion base/sparse/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ function diag{Tv}(F::Factor{Tv})
xv = f.x
for j in 1:f.n
jj = unsafe_load(c0, j) + 1
assert(unsafe_load(r0, jj) == j - 1)
@assert unsafe_load(r0, jj) == j - 1
res[j] = unsafe_load(xv, jj)
end
end
Expand Down
2 changes: 1 addition & 1 deletion base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ include("intfuncs.jl")
include("nullable.jl")

# I/O
include("show.jl")
include("task.jl")
include("lock.jl")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a gratuitous move of when show.jl is loaded in the system image.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not doing this gave

LoadError(at "sysimg.jl" line 118: LoadError(at "task.jl" line 379: Base.MethodError(f=show, args=(Base.AbstractIOBuffer{Array{UInt8, 1}}(data=Array{UInt8, 1}[], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=9223372036854775807, ptr=1, mark=-1), false))))

If you still think it's gratuitous, I'd be happy to revert the change.

And thank you for the feedback.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. Thanks for the explanation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the kind of thing that's worth mentioning at least briefly in the commit message

include("show.jl")
include("stream.jl")
include("socket.jl")
include("stat.jl")
Expand Down
2 changes: 1 addition & 1 deletion base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ function wait()
return result
end
end
assert(false)
@assert false
end

function pause()
Expand Down
2 changes: 1 addition & 1 deletion examples/clustermanager/0mq/ZMQCM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function recv_data()
try
#println("On $(manager.zid_self) waiting to recv message")
zid = parse(Int,bytestring(ZMQ.recv(manager.sub)))
assert(zid == manager.zid_self)
@assert zid == manager.zid_self

from_zid = parse(Int,bytestring(ZMQ.recv(manager.sub)))
mtype = bytestring(ZMQ.recv(manager.sub))
Expand Down
4 changes: 2 additions & 2 deletions examples/clustermanager/simple/test_simple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ cmanpath = joinpath(dirname(@__FILE__), "UnixDomainCM.jl")
include(cmanpath)

npids = addprocs(UnixDomainCM(2))
assert(length(npids) == 2)
@assert length(npids) == 2
test_pids = [remotecall_fetch(x, myid) for x in npids]
assert(npids == test_pids)
@assert npids == test_pids
rmprocs(npids; waitfor=1.0)

exit(0)
2 changes: 1 addition & 1 deletion examples/juliatypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ extend(d::Dict, k, v) = (x = copy(d); x[k]=v; x)
subst(t::TagT, env) = t===AnyT ? t : TagT(t.name, map(x->subst(x,env), t.params), t.vararg)
subst(t::UnionT, env) = UnionT(subst(t.a,env), subst(t.b,env))
subst(t::Var, env) = get(env, t, t)
subst(t::UnionAllT, env) = (assert(!haskey(env, t.var));
subst(t::UnionAllT, env) = (@assert !haskey(env, t.var);
newVar = Var(t.var.name, subst(t.var.lb, env), subst(t.var.ub, env));
UnionAllT(newVar, subst(t.T, extend(env, t.var, newVar))))
subst(t, env) = t
Expand Down
13 changes: 0 additions & 13 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,6 @@ let bt = backtrace()
end
end

# test assert() method
@test_throws AssertionError assert(false)
let res = assert(true)
@test res === nothing
end
let
ex = @test_throws AssertionError begin
assert(false)
error("unexpected")
end
@test isempty(ex.msg)
end

# test @assert macro
@test_throws AssertionError (@assert 1 == 2)
@test_throws AssertionError (@assert false)
Expand Down
2 changes: 1 addition & 1 deletion test/parallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ for p in procs(d)
idxf = first(idxes_in_p)
idxl = last(idxes_in_p)
d[idxf] = Float64(idxf)
rv = remotecall_fetch(p, (D,idxf,idxl) -> begin assert(D[idxf] == Float64(idxf)); D[idxl] = Float64(idxl); D[idxl]; end, d,idxf,idxl)
rv = remotecall_fetch(p, (D,idxf,idxl) -> begin @assert D[idxf] == Float64(idxf); D[idxl] = Float64(idxl); D[idxl]; end, d,idxf,idxl)
@test d[idxl] == rv
end

Expand Down