Skip to content

Commit

Permalink
deprecate 2-argument assert function
Browse files Browse the repository at this point in the history
this is a performance trap since it can lead to unconditionally constructing a message string on every call
  • Loading branch information
JeffBezanson committed Oct 17, 2013
1 parent 1073332 commit 57da847
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions base/deprecated.jl
Expand Up @@ -134,6 +134,7 @@ export PipeString
@deprecate min(f::Function,x) minimum(f,x)
@deprecate max(x,_::(),d) maximum(x,d)
@deprecate min(x,_::(),d) minimum(x,d)
@deprecate assert(x,y) (@assert x y)

deprecated_ls() = run(`ls -l`)
deprecated_ls(args::Cmd) = run(`ls -l $args`)
Expand Down
8 changes: 4 additions & 4 deletions base/error.jl
Expand Up @@ -39,10 +39,10 @@ systemerror(p, b::Bool) = b ? throw(SystemError(string(p))) : nothing

## assertion functions and macros ##

assert(x) = assert(x,'?')
assert(x,labl) = x ? nothing : error("assertion failed: ", labl)
macro assert(ex)
:($(esc(ex)) ? nothing : error("assertion failed: ", string($(Expr(:quote,ex)))))
assert(x) = x ? nothing : error("assertion failed")
macro assert(ex,msg...)
msg = isempty(msg) ? :(string($(Expr(:quote,ex)))) : esc(msg[1])
:($(esc(ex)) ? nothing : error("assertion failed: ", $msg))
end

## printing with color ##
Expand Down
8 changes: 4 additions & 4 deletions base/inference.jl
Expand Up @@ -955,7 +955,7 @@ function abstract_interpret(e::Expr, vtypes, sv::StaticVarInfo)
if isa(lhs,SymbolNode)
lhs = lhs.name
end
assert(isa(lhs,Symbol), "inference.jl:579")
assert(isa(lhs,Symbol))
return StateUpdate(lhs, t, vtypes)
elseif is(e.head,:call) || is(e.head,:call1)
abstract_eval(e, vtypes, sv)
Expand Down Expand Up @@ -1168,7 +1168,7 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)

args = f_argnames(ast)
la = length(args)
assert(is(ast.head,:lambda), "inference.jl:745")
assert(is(ast.head,:lambda))
locals = (ast.args[2][1])::Array{Any,1}
vars = [args, locals]
body = (ast.args[3].args)::Array{Any,1}
Expand Down Expand Up @@ -1836,8 +1836,8 @@ function inlineable(f, e::Expr, sv, enclosing_ast)
if length(body) != 1
return NF
end
assert(isa(body[1],Expr), "inference.jl:1050")
assert(is(body[1].head,:return), "inference.jl:1051")
assert(isa(body[1],Expr))
assert(is(body[1].head,:return))
# check for vararg function
args = f_argnames(ast)
expr = body[1].args[1]
Expand Down
2 changes: 1 addition & 1 deletion base/stream.jl
Expand Up @@ -608,7 +608,7 @@ function readall(stream::AsyncStream)
end

function read{T}(this::AsyncStream, a::Array{T})
assert(isbits(T),"Read from Buffer only supports bits types or arrays of bits types")
isbits(T) || error("Read from Buffer only supports bits types or arrays of bits types")
nb = length(a)*sizeof(T)
buf = this.buffer
@assert buf.seekable == false
Expand Down

0 comments on commit 57da847

Please sign in to comment.