From 366e00a78a90e548cab690c993e5ce36ee15f98c Mon Sep 17 00:00:00 2001 From: Magnus Lie Hetland Date: Sat, 26 Jul 2014 20:26:36 +0200 Subject: [PATCH] Make it possible to disable asserts with --release Renamed current assert function/macro to enforce, and added a conditional assert that delegates to enforce unless the --release switch is provided. --- base/LineEdit.jl | 14 +++++++------- base/REPL.jl | 2 +- base/broadcast.jl | 8 ++++---- base/cartesian.jl | 2 +- base/client.jl | 16 +++++++++++++++- base/constants.jl | 6 +++--- base/darray.jl | 6 +++--- base/error.jl | 18 ++++++++++++++++-- base/exports.jl | 3 +++ base/fftw.jl | 8 ++++---- base/inference.jl | 20 ++++++++++---------- base/linalg/cholmod.jl | 2 +- base/linalg/special.jl | 2 +- base/multi.jl | 6 +++--- base/osutils.jl | 8 ++++---- base/pkg/query.jl | 16 ++++++++-------- base/pkg/resolve.jl | 2 +- base/pkg/resolve/fieldvalue.jl | 2 +- base/pkg/resolve/interface.jl | 8 ++++---- base/pkg/resolve/maxsum.jl | 10 +++++----- base/printf.jl | 2 +- base/process.jl | 4 ++-- base/serialize.jl | 2 +- base/show.jl | 2 +- base/socket.jl | 12 ++++++------ base/stream.jl | 18 +++++++++--------- base/task.jl | 2 +- base/test.jl | 2 +- base/version.jl | 2 +- ui/repl.c | 1 + 30 files changed, 119 insertions(+), 87 deletions(-) diff --git a/base/LineEdit.jl b/base/LineEdit.jl index 2d0072dce043c1..9c9d374e4cb17f 100644 --- a/base/LineEdit.jl +++ b/base/LineEdit.jl @@ -667,12 +667,12 @@ function normalize_key(key::String) c, i == next(key, i) if c == 'C' c, i == next(key, i) - @assert c == '-' + @enforce c == '-' c, i == next(key, i) write(buf, uppercase(c)-64) elseif c == 'M' c, i == next(key, i) - @assert c == '-' + @enforce c == '-' c, i == next(key, i) write(buf, '\e') write(buf, c) @@ -927,7 +927,7 @@ function history_set_backward(s::SearchState, backward) s.backward = backward end -refresh_multi_line(termbuf::TerminalBuffer, term, s::Union(SearchState,PromptState)) = (@assert term == terminal(s); refresh_multi_line(termbuf,s)) +refresh_multi_line(termbuf::TerminalBuffer, term, s::Union(SearchState,PromptState)) = (@enforce term == terminal(s); refresh_multi_line(termbuf,s)) function refresh_multi_line(termbuf::TerminalBuffer, s::SearchState) buf = IOBuffer() write(buf, pointer(s.query_buffer.data), s.query_buffer.ptr-1) @@ -978,10 +978,10 @@ HistoryPrompt{T<:HistoryProvider}(hp::T) = HistoryPrompt{T}(hp) init_state(terminal, p::HistoryPrompt) = SearchState(terminal, p, true, IOBuffer(), IOBuffer()) state(s::MIState, p) = s.mode_state[p] -state(s::PromptState, p) = (@assert s.p == p; s) +state(s::PromptState, p) = (@enforce s.p == p; s) mode(s::MIState) = s.current_mode mode(s::PromptState) = s.p -mode(s::SearchState) = @assert false +mode(s::SearchState) = @enforce false # Search Mode completions function complete_line(s::SearchState, repeats) @@ -1300,7 +1300,7 @@ function activate(p::Union(Prompt,HistoryPrompt), s::Union(SearchState,PromptSta end function activate(p::Union(Prompt,HistoryPrompt), s::MIState, termbuf) - @assert p == s.current_mode + @enforce p == s.current_mode activate(p, s.mode_state[s.current_mode], termbuf) end activate(m::ModalInterface, s::MIState, termbuf) = activate(s.current_mode, s, termbuf) @@ -1407,7 +1407,7 @@ function prompt!(terminal, prompt, s = init_state(terminal, prompt)) return buffer(s), true, true end else - @assert state == :ok + @enforce state == :ok end end finally diff --git a/base/REPL.jl b/base/REPL.jl index fd1e0cbbb98cb6..1b235101263fbf 100644 --- a/base/REPL.jl +++ b/base/REPL.jl @@ -383,7 +383,7 @@ end function history_move(s::LineEdit.MIState, hist::REPLHistoryProvider, idx::Int, save_idx::Int = hist.cur_idx) max_idx = length(hist.history) + 1 - @assert 1 <= hist.cur_idx <= max_idx + @enforce 1 <= hist.cur_idx <= max_idx (1 <= idx <= max_idx) || return :none idx != hist.cur_idx || return :none diff --git a/base/broadcast.jl b/base/broadcast.jl index 2ae6f511e23e1d..50de5835de7a7d 100644 --- a/base/broadcast.jl +++ b/base/broadcast.jl @@ -69,7 +69,7 @@ end function gen_broadcast_body_cartesian(nd::Int, narrays::Int, f::Function) F = Expr(:quote, f) quote - @assert ndims(B) == $nd + @enforce ndims(B) == $nd @ncall $narrays check_broadcast_shape size(B) k->A_k @nloops($nd, i, B, d->(@nexprs $narrays k->(j_d_k = size(A_k, d) == 1 ? 1 : i_d)), # pre @@ -84,7 +84,7 @@ end function gen_broadcast_body_iter(nd::Int, narrays::Int, f::Function) F = Expr(:quote, f) quote - @assert ndims(B) == $nd + @enforce ndims(B) == $nd @ncall $narrays check_broadcast_shape size(B) k->A_k @nexprs 1 d->(@nexprs $narrays k->(state_k_0 = state_k_{$nd} = start(A_k))) @nexprs $nd d->(@nexprs $narrays k->(skip_k_d = size(A_k, d) == 1)) @@ -123,7 +123,7 @@ end function gen_broadcast_body_cartesian_tobitarray(nd::Int, narrays::Int, f::Function) F = Expr(:quote, f) quote - @assert ndims(B) == $nd + @enforce ndims(B) == $nd @ncall $narrays check_broadcast_shape size(B) k->A_k C = Array(Bool, bitcache_size) Bc = B.chunks @@ -152,7 +152,7 @@ end function gen_broadcast_body_iter_tobitarray(nd::Int, narrays::Int, f::Function) F = Expr(:quote, f) quote - @assert ndims(B) == $nd + @enforce ndims(B) == $nd @ncall $narrays check_broadcast_shape size(B) k->A_k C = Array(Bool, bitcache_size) Bc = B.chunks diff --git a/base/cartesian.jl b/base/cartesian.jl index 9fd9abd0ef3827..c585e7214d6d6f 100644 --- a/base/cartesian.jl +++ b/base/cartesian.jl @@ -86,7 +86,7 @@ function ngenerate(itersym, returntypeexpr, prototype, bodyfunc, dims=1:CARTESIA setitersym, extractvarargs = :(), N -> nothing else s = symbol(varname) - setitersym = hasparameter(prototype, itersym) ? (:(@assert $itersym == length($s))) : (:($itersym = length($s))) + setitersym = hasparameter(prototype, itersym) ? (:(@enforce $itersym == length($s))) : (:($itersym = length($s))) extractvarargs = N -> Expr(:block, map(popescape, _nextract(N, s, s).args)...) end fsym = funcsym(prototype) diff --git a/base/client.jl b/base/client.jl index 35209523673c8c..a16a5f9b1f3e94 100644 --- a/base/client.jl +++ b/base/client.jl @@ -255,6 +255,17 @@ function process_options(args::Vector{UTF8String}) startup = false elseif args[i] == "-i" global is_interactive = true + elseif beginswith(args[i], "--release") + if args[i] == "--release" + is_release = true + elseif args[i][13] == '=' + val = args[i][14:end] + if in(val, ("yes","1","true")) + global is_release = true + elseif !in(val, ("no","0","false")) + error("invalid option: ", args[i]) + end + end elseif beginswith(args[i], "--color") if args[i] == "--color" color_set = true @@ -297,6 +308,9 @@ const roottask = current_task() is_interactive = false isinteractive() = (is_interactive::Bool) +is_release = false +isrelease() = (is_release::Bool) + const LOAD_PATH = ByteString[] function init_load_path() vers = "v$(VERSION.major).$(VERSION.minor)" @@ -312,7 +326,7 @@ function init_head_sched() global PGRP global LPROC LPROC.id = 1 - assert(length(PGRP.workers) == 0) + enforce(length(PGRP.workers) == 0) register_worker(LPROC) end diff --git a/base/constants.jl b/base/constants.jl index 2616f251a62b3f..b40a16980055e1 100644 --- a/base/constants.jl +++ b/base/constants.jl @@ -42,9 +42,9 @@ macro math_const(sym, val, def) $bigconvert Base.convert(::Type{Float64}, ::MathConst{$qsym}) = $val Base.convert(::Type{Float32}, ::MathConst{$qsym}) = $(float32(val)) - @assert isa(big($esym), BigFloat) - @assert float64($esym) == float64(big($esym)) - @assert float32($esym) == float32(big($esym)) + @enforce isa(big($esym), BigFloat) + @enforce float64($esym) == float64(big($esym)) + @enforce float32($esym) == float32(big($esym)) end end diff --git a/base/darray.jl b/base/darray.jl index 2685c5fb635f0e..e55fd2485a1e55 100644 --- a/base/darray.jl +++ b/base/darray.jl @@ -13,9 +13,9 @@ type DArray{T,N,A} <: AbstractArray{T,N} function DArray(dims, chunks, pmap, indexes, cuts) # check invariants - assert(size(chunks) == size(indexes)) - assert(length(chunks) == length(pmap)) - assert(dims == map(last,last(indexes))) + enforce(size(chunks) == size(indexes)) + enforce(length(chunks) == length(pmap)) + enforce(dims == map(last,last(indexes))) new(dims, chunks, pmap, indexes, cuts) end end diff --git a/base/error.jl b/base/error.jl index d5007eb5587578..9ee61ab912442d 100644 --- a/base/error.jl +++ b/base/error.jl @@ -40,8 +40,10 @@ systemerror(p, b::Bool) = b ? throw(SystemError(string(p))) : nothing ## assertion functions and macros ## -assert(x) = x ? nothing : error("assertion failed") -macro assert(ex,msgs...) +# unlike assert, enforce cannot be turned off with the --release option + +enforce(x) = x ? nothing : error("assertion failed") +macro enforce(ex,msgs...) msg = isempty(msgs) ? ex : msgs[1] if !isempty(msgs) && isa(msg, Expr) # message is an expression needing evaluating @@ -54,3 +56,15 @@ macro assert(ex,msgs...) end :($(esc(ex)) ? $(nothing) : error($msg)) end + +# assert will be a no-op if --release is supplied on command-line; otherwise +# equivalent to enforce + +assert(x) = isrelease() ? nothing : enforce(x) +macro assert(ex,msgs...) + if isrelease() + :nothing + else + :(@enforce($(esc(ex)),$(esc(msgs))...)) + end +end diff --git a/base/exports.jl b/base/exports.jl index edfa1dfd2e279b..a7da10dab85aab 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -1007,6 +1007,7 @@ export toq, # errors + enforce, assert, backtrace, catch_backtrace, @@ -1051,6 +1052,7 @@ export isconst, isgeneric, isinteractive, + isrelease, less, methods, methodswith, @@ -1323,6 +1325,7 @@ export @bigint_str, @mstr, @unexpected, + @enforce, @assert, @cmd, @time, diff --git a/base/fftw.jl b/base/fftw.jl index 2512c5cc255c91..fe362698696cb7 100644 --- a/base/fftw.jl +++ b/base/fftw.jl @@ -565,7 +565,7 @@ for (Tr,Tc) in ((:Float32,:Complex64),(:Float64,:Complex128)) function brfft(X::StridedArray{$Tc}, d::Integer, region::Integer) osize = [size(X)...] - @assert osize[region] == d>>1 + 1 + @enforce osize[region] == d>>1 + 1 osize[region] = d Y = Array($Tr, osize...) p = Plan(X, Y, region, ESTIMATE | PRESERVE_INPUT, NO_TIMELIMIT) @@ -578,7 +578,7 @@ for (Tr,Tc) in ((:Float32,:Complex64),(:Float64,:Complex128)) function brfftd(X::StridedArray{$Tc}, d::Integer, region) d1 = region[1] osize = [size(X)...] - @assert osize[d1] == d>>1 + 1 + @enforce osize[d1] == d>>1 + 1 osize[d1] = d Y = Array($Tr, osize...) p = Plan(X, Y, region, ESTIMATE, NO_TIMELIMIT) @@ -603,7 +603,7 @@ for (Tr,Tc) in ((:Float32,:Complex64),(:Float64,:Complex128)) function plan_brfft(X::StridedArray{$Tc}, d::Integer, region::Integer, flags::Unsigned, tlim::Real) osize = [size(X)...] - @assert osize[region] == d>>1 + 1 + @enforce osize[region] == d>>1 + 1 osize[region] = d Y = Array($Tr, osize...) p = Plan(X, Y, region, flags | PRESERVE_INPUT, tlim) @@ -622,7 +622,7 @@ for (Tr,Tc) in ((:Float32,:Complex64),(:Float64,:Complex128)) end d1 = region[1] osize = [size(X)...] - @assert osize[d1] == d>>1 + 1 + @enforce osize[d1] == d>>1 + 1 osize[d1] = d Y = Array($Tr, osize...) X = copy(X) diff --git a/base/inference.jl b/base/inference.jl index 08adbcb5af2fc8..71afe9161471f3 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -1090,7 +1090,7 @@ function abstract_interpret(e::ANY, vtypes, sv::StaticVarInfo) if isa(lhs,SymbolNode) lhs = lhs.name end - assert(isa(lhs,Symbol)) + enforce(isa(lhs,Symbol)) return StateUpdate(lhs, t, vtypes) elseif is(e.head,:call) || is(e.head,:call1) abstract_eval(e, vtypes, sv) @@ -1300,7 +1300,7 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop) args = f_argnames(ast) la = length(args) - assert(is(ast.head,:lambda)) + enforce(is(ast.head,:lambda)) locals = (ast.args[2][1])::Array{Any,1} vars = [args, locals] body = (ast.args[3].args)::Array{Any,1} @@ -1521,7 +1521,7 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop) fulltree = type_annotate(ast, s, sv, frame.result, args) if !rec - @assert fulltree.args[3].head === :body + @enforce fulltree.args[3].head === :body fulltree.args[3] = inlining_pass(fulltree.args[3], sv, fulltree)[1] # inlining can add variables sv.vars = append_any(f_argnames(fulltree), fulltree.args[2][1]) @@ -1721,7 +1721,7 @@ function sym_replace(e::ANY, from1, from2, to1, to2) # remove_redundant_temp_vars can only handle Symbols # on the LHS of assignments, so we make sure not to put # something else there - @assert length(e.args) == 2 + @enforce length(e.args) == 2 e2 = _sym_repl(e.args[1]::Symbol, from1, from2, to1, to2, e.args[1]::Symbol) if isa(e2, SymbolNode) e2 = e2.name @@ -2206,11 +2206,11 @@ function inlineable(f, e::Expr, atypes, sv, enclosing_ast) # inference step shortened our call args list, even # though we have too many arguments to actually # call this function - @assert isvarargtype(atypes[na]) + @enforce isvarargtype(atypes[na]) return NF end - @assert na == length(argexprs) + @enforce na == length(argexprs) if needcopy body = astcopy(body) @@ -2288,7 +2288,7 @@ function inlineable(f, e::Expr, atypes, sv, enclosing_ast) if isvarargtype(methitype) methitype = (methitype::Vararg).parameters[1] else - @assert i==nm + @enforce i==nm end end end @@ -2424,8 +2424,8 @@ function inlineable(f, e::Expr, atypes, sv, enclosing_ast) push!(body.args, Expr(:call,:error,"fatal error in type inference")) lastexpr = nothing else - @assert isa(lastexpr,Expr) "inference.jl:1774" - @assert is(lastexpr.head,:return) "inference.jl:1775" + @enforce isa(lastexpr,Expr) "inference.jl:1774" + @enforce is(lastexpr.head,:return) "inference.jl:1775" end for a in body.args push!(stmts, a) @@ -2817,7 +2817,7 @@ function local_typeof(v, varinfo) return typ end end - @assert false "v not in varinfo" + @enforce false "v not in varinfo" end occurs_undef(var, expr) = diff --git a/base/linalg/cholmod.jl b/base/linalg/cholmod.jl index 7ac19eba71ba76..e54dce106273ce 100644 --- a/base/linalg/cholmod.jl +++ b/base/linalg/cholmod.jl @@ -1005,7 +1005,7 @@ function diag{Tv}(L::CholmodFactor{Tv}) xv = L.x for j in 1:L.c.n jj = c0[j]+1 - assert(r0[jj] == j-1) + enforce(r0[jj] == j-1) res[j] = xv[jj] end end diff --git a/base/linalg/special.jl b/base/linalg/special.jl index a6b0ff942f76fc..fba059f3c51034 100644 --- a/base/linalg/special.jl +++ b/base/linalg/special.jl @@ -74,7 +74,7 @@ end # f{S,T}(x::S, y::T) = x+y # f{S,T}(y::T, x::S) = f(x, y) macro commutative(myexpr) - @assert myexpr.head===:(=) || myexpr.head===:function #Make sure it is a function definition + @enforce myexpr.head===:(=) || myexpr.head===:function #Make sure it is a function definition y = copy(myexpr.args[1].args[2:end]) reverse!(y) reversed_call = Expr(:(=), Expr(:call,myexpr.args[1].args[1],y...), myexpr.args[1]) diff --git a/base/multi.jl b/base/multi.jl index 17a005d71b0c1b..5b3ffa0febabe1 100644 --- a/base/multi.jl +++ b/base/multi.jl @@ -240,7 +240,7 @@ end function add_workers(pg::ProcessGroup, ws::Array{Any,1}) # NOTE: currently only node 1 can add new nodes, since nobody else # has the full list of address:port - assert(LPROC.id == 1) + enforce(LPROC.id == 1) for w in ws w.id = get_next_pid() register_worker(w) @@ -1544,7 +1544,7 @@ function timedwait(testcb::Function, secs::Float64; pollint::Float64=0.1) end function interrupt(pid::Integer) - assert(myid() == 1) + enforce(myid() == 1) w = map_pid_wrkr[pid] if isa(w, Worker) w.manage(w.id, w.config, :interrupt) @@ -1553,7 +1553,7 @@ end interrupt(pids::Integer...) = interrupt([pids...]) function interrupt(pids::AbstractVector=workers()) - assert(myid() == 1) + enforce(myid() == 1) @sync begin for pid in pids @async interrupt(pid) diff --git a/base/osutils.jl b/base/osutils.jl index b045222227c68e..b60683a1bf9e0c 100644 --- a/base/osutils.jl +++ b/base/osutils.jl @@ -8,10 +8,10 @@ function is_unix(os::Symbol) end function _os_test(qm,ex,test) - @assert qm == :? - @assert isa(ex,Expr) - @assert ex.head == :(:) - @assert length(ex.args) == 2 + @enforce qm == :? + @enforce isa(ex,Expr) + @enforce ex.head == :(:) + @enforce length(ex.args) == 2 if test return esc(ex.args[1]) else diff --git a/base/pkg/query.jl b/base/pkg/query.jl index b908e365b0cef7..aac33585aa98aa 100644 --- a/base/pkg/query.jl +++ b/base/pkg/query.jl @@ -131,14 +131,14 @@ function prune_versions(reqs::Requires, deps::Dict{ByteString,Dict{VersionNumber # Parse requirements and store allowed versions. allowed = (ByteString=>Dict{VersionNumber, Bool})[] for (p,vs) in reqs - @assert !haskey(allowed, p) + @enforce !haskey(allowed, p) allowed[p] = (VersionNumber=>Bool)[] allowedp = allowed[p] for vn in keys(deps[p]) allowedp[vn] = vn in vs end - @assert !isempty(allowedp) - @assert any(collect(values(allowedp))) + @enforce !isempty(allowedp) + @enforce any(collect(values(allowedp))) end filtered_deps = (ByteString=>Dict{VersionNumber,Available})[] @@ -176,7 +176,7 @@ function prune_versions(reqs::Requires, deps::Dict{ByteString,Dict{VersionNumber # Grow the pattern by the number of classes luds = length(uniqdepssets) - @assert !haskey(vmask, p) + @enforce !haskey(vmask, p) vmask[p] = (VersionNumber=>BitVector)[] vmaskp = vmask[p] for vn in keys(fdepsp) @@ -184,7 +184,7 @@ function prune_versions(reqs::Requires, deps::Dict{ByteString,Dict{VersionNumber end for (vn,a) in fdepsp vmind = findfirst(uniqdepssets, a) - @assert vmind >= 0 + @enforce vmind >= 0 vm = vmaskp[vn] vm[vmind] = true end @@ -200,7 +200,7 @@ function prune_versions(reqs::Requires, deps::Dict{ByteString,Dict{VersionNumber end # Store the dependency info in the patterns - @assert haskey(vmask, p) + @enforce haskey(vmask, p) vmaskp = vmask[p] for (vn,vm) in vmaskp push!(vm, in(vn, vs)) @@ -230,7 +230,7 @@ function prune_versions(reqs::Requires, deps::Dict{ByteString,Dict{VersionNumber if !isempty(cl) vtop = maximum(cl) push!(prunedp, vtop) - @assert !haskey(eqclassp, vtop) + @enforce !haskey(eqclassp, vtop) eqclassp[vtop] = cl end end @@ -260,7 +260,7 @@ function prune_versions(reqs::Requires, deps::Dict{ByteString,Dict{VersionNumber new_deps = (ByteString=>Dict{VersionNumber,Available})[] for (p,depsp) in deps - @assert !haskey(new_deps, p) + @enforce !haskey(new_deps, p) if !haskey(pruned_vers, p) new_deps[p] = depsp continue diff --git a/base/pkg/resolve.jl b/base/pkg/resolve.jl index fd5393fb5a3759..02cb727b483719 100644 --- a/base/pkg/resolve.jl +++ b/base/pkg/resolve.jl @@ -103,7 +103,7 @@ function sanity_check(deps::Dict{ByteString,Dict{VersionNumber,Available}}) let p0 = interface.pdict[p] svn = red_pvers[p0][sol[p0]] - @assert svn == vn + @enforce svn == vn end for p0 = 1:red_np diff --git a/base/pkg/resolve/fieldvalue.jl b/base/pkg/resolve/fieldvalue.jl index 5884b666fc3713..2211dee07ecefc 100644 --- a/base/pkg/resolve/fieldvalue.jl +++ b/base/pkg/resolve/fieldvalue.jl @@ -76,7 +76,7 @@ function Base.indmax(f::Field) mi = j end end - @assert mi != 0 + @enforce mi != 0 return mi end diff --git a/base/pkg/resolve/interface.jl b/base/pkg/resolve/interface.jl index d888849e903147..172e5758440f59 100644 --- a/base/pkg/resolve/interface.jl +++ b/base/pkg/resolve/interface.jl @@ -130,9 +130,9 @@ function verify_solution(sol::Vector{Int}, interface::Interface) # verify requirements for (p,vs) in reqs p0 = pdict[p] - @assert sol[p0] != spp[p0] + @enforce sol[p0] != spp[p0] vn = pvers[p0][sol[p0]] - @assert in(vn, vs) + @enforce in(vn, vs) end # verify dependencies @@ -144,9 +144,9 @@ function verify_solution(sol::Vector{Int}, interface::Interface) if sol[p0] == v0 for (rp, rvs) in a.requires p1 = pdict[rp] - @assert sol[p1] != spp[p1] + @enforce sol[p1] != spp[p1] vn = pvers[p1][sol[p1]] - @assert in(vn, rvs) + @enforce in(vn, rvs) end end end diff --git a/base/pkg/resolve/maxsum.jl b/base/pkg/resolve/maxsum.jl index 70336337d1d081..c2a4a5db96bfac 100644 --- a/base/pkg/resolve/maxsum.jl +++ b/base/pkg/resolve/maxsum.jl @@ -107,7 +107,7 @@ type Graph while j1 <= length(gadj[p1]) && gadj[p1][j1] != p0 j1 += 1 end - @assert (j0 > length(gadj[p0]) && j1 > length(gadj[p1])) || + @enforce (j0 > length(gadj[p0]) && j1 > length(gadj[p1])) || (j0 <= length(gadj[p0]) && j1 <= length(gadj[p1])) if j0 > length(gadj[p0]) @@ -278,7 +278,7 @@ function update(p0::Int, graph::Graph, msgs::Messages) continue end j1 = adjdict0[p1] - #@assert j0 == adjdict[p1][p0] + #@enforce j0 == adjdict[p1][p0] bm1 = gmsk[p1][j1] dir1 = gdir[p1][j1] spp1 = spp[p1] @@ -357,7 +357,7 @@ function shuffleperm(graph::Graph) perm[j], perm[k] = perm[k], perm[j] step += isodd(j) ? 1 : k end - #@assert isperm(perm) + #@enforce isperm(perm) end end @@ -378,7 +378,7 @@ function iterate(graph::Graph, msgs::Messages) end function decimate1(p0::Int, graph::Graph, msgs::Messages) - @assert !msgs.decimated[p0] + @enforce !msgs.decimated[p0] fld0 = msgs.fld[p0] s0 = indmax(fld0) #println("DECIMATING $p0 ($(packages()[p0]) s0=$s0)") @@ -410,7 +410,7 @@ function decimate(n::Int, graph::Graph, msgs::Messages) break end end - @assert n == 0 + @enforce n == 0 return end diff --git a/base/printf.jl b/base/printf.jl index b19483795714b6..229932d1d52434 100644 --- a/base/printf.jl +++ b/base/printf.jl @@ -800,7 +800,7 @@ function bigfloat_printf(out, d, flags::ASCIIString, width::Int, precision::Int, write(fmt, c) write(fmt, uint8(0)) printf_fmt = takebuf_array(fmt) - @assert length(printf_fmt) == fmt_len + @enforce length(printf_fmt) == fmt_len lng = ccall((:mpfr_snprintf,:libmpfr), Int32, (Ptr{Uint8}, Culong, Ptr{Uint8}, Ptr{BigFloat}...), DIGITS, BUFLEN-1, printf_fmt, &d) lng > 0 || error("invalid printf formatting for BigFloat") write(out, pointer(DIGITS), lng) diff --git a/base/process.jl b/base/process.jl index 261074142a2d72..b74673cf244210 100644 --- a/base/process.jl +++ b/base/process.jl @@ -481,7 +481,7 @@ end const SIGPIPE = 13 function test_success(proc::Process) - assert(process_exited(proc)) + enforce(process_exited(proc)) if proc.exitcode < 0 error(UVError("could not start process "*string(proc.cmd), proc.exitcode)) end @@ -523,7 +523,7 @@ end _jl_kill(p::Process, signum::Integer) = ccall(:uv_process_kill, Int32, (Ptr{Void},Int32), p.handle, signum) function kill(p::Process, signum::Integer) if process_running(p) - @assert p.handle != C_NULL + @enforce p.handle != C_NULL _jl_kill(p, signum) else int32(-1) diff --git a/base/serialize.jl b/base/serialize.jl index 3fc127fde606ac..745141daeb6c8c 100644 --- a/base/serialize.jl +++ b/base/serialize.jl @@ -199,7 +199,7 @@ function serialize(s, f::Function) serialize(s, f.env) else linfo = f.code - @assert isa(linfo,LambdaStaticData) + @enforce isa(linfo,LambdaStaticData) write(s, uint8(1)) serialize(s, f.env) serialize(s, linfo) diff --git a/base/show.jl b/base/show.jl index cb37858feed0cc..9aaa989dd69908 100644 --- a/base/show.jl +++ b/base/show.jl @@ -860,7 +860,7 @@ function print_matrix(io::IO, X::AbstractVecOrMat, cols -= length(pre) + length(post) presp = repeat(" ", length(pre)) postsp = "" - @assert strwidth(hdots) == strwidth(ddots) + @enforce strwidth(hdots) == strwidth(ddots) ss = length(sep) m, n = size(X,1), size(X,2) if m <= rows # rows fit diff --git a/base/socket.jl b/base/socket.jl index 435ab9f03dd3c4..58ffd5cfc99821 100644 --- a/base/socket.jl +++ b/base/socket.jl @@ -389,7 +389,7 @@ const UV_UDP_IPV6ONLY = 1 const UV_UDP_PARTIAL = 2 function bind(sock::Union(TcpServer,UdpSocket), host::IPv4, port::Integer) - @assert sock.status == StatusInit + @enforce sock.status == StatusInit err = _bind(sock,host,uint16(port)) if err < 0 if err != UV_EADDRINUSE && err != UV_EACCES @@ -409,7 +409,7 @@ _bind(sock::UdpSocket, host::IPv6, port::Uint16, flags::Uint32 = uint32(0)) = cc sock.handle, hton(port), &hton(host.host), flags) function bind(sock::UdpSocket, host::IPv6, port::Uint16; ipv6only = false) - @assert sock.status == StatusInit + @enforce sock.status == StatusInit err = _bind(sock,host,ipv6only ? UV_UDP_IPV6ONLY : 0) if err < 0 if err != UV_EADDRINUSE && err != UV_EACCES @@ -576,7 +576,7 @@ end ## function connect!(sock::TcpSocket, host::IPv4, port::Integer) - @assert sock.status == StatusInit + @enforce sock.status == StatusInit if !(0 <= port <= typemax(Uint16)) throw(DomainError()) end @@ -586,7 +586,7 @@ function connect!(sock::TcpSocket, host::IPv4, port::Integer) end function connect!(sock::TcpSocket, host::IPv6, port::Integer) - @assert sock.status == StatusInit + @enforce sock.status == StatusInit if !(0 <= port <= typemax(Uint16)) throw(DomainError()) end @@ -607,7 +607,7 @@ connect(addr::InetAddr) = connect(TcpSocket(),addr) default_connectcb(sock,status) = nothing function connect!(sock::TcpSocket, host::String, port::Integer) - @assert sock.status == StatusInit + @enforce sock.status == StatusInit ipaddr = getaddrinfo(host) sock.status = StatusInit connect!(sock,ipaddr,port) @@ -634,7 +634,7 @@ listen(cb::Callback,sock::Socket; backlog::Integer=BACKLOG_DEFAULT) = (sock.ccb= ## function accept_nonblock(server::TcpServer,client::TcpSocket) - @assert client.status == StatusInit + @enforce client.status == StatusInit err = ccall(:uv_accept,Int32,(Ptr{Void},Ptr{Void}),server.handle,client.handle) if err == 0 client.status = StatusOpen diff --git a/base/stream.jl b/base/stream.jl index d6119c7358531e..e22043ed6950a3 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -321,7 +321,7 @@ wait_close(x) = if isopen(x) stream_wait(x,x.closenotify); end #from `connect` function _uv_hook_connectcb(sock::AsyncStream, status::Int32) - @assert sock.status == StatusConnecting + @enforce sock.status == StatusConnecting if status >= 0 sock.status = StatusOpen err = () @@ -358,7 +358,7 @@ function alloc_request(buffer::IOBuffer, recommended_size::Uint) end function _uv_hook_alloc_buf(stream::AsyncStream, recommended_size::Uint) (buf,size) = alloc_request(stream.buffer, recommended_size) - @assert size>0 # because libuv requires this (TODO: possibly stop reading too if it fails) + @enforce size>0 # because libuv requires this (TODO: possibly stop reading too if it fails) (buf,uint(size)) end @@ -662,8 +662,8 @@ end function read!{Uint8}(s::AsyncStream, a::Vector{Uint8}) nb = length(a) sbuf = s.buffer - @assert sbuf.seekable == false - @assert sbuf.maxsize >= nb + @enforce sbuf.seekable == false + @enforce sbuf.maxsize >= nb if nb_available(sbuf) >= nb return read!(sbuf, a) @@ -693,7 +693,7 @@ end function read(this::AsyncStream,::Type{Uint8}) buf = this.buffer - @assert buf.seekable == false + @enforce buf.seekable == false wait_readnb(this,1) read(buf,Uint8) end @@ -704,14 +704,14 @@ readline() = readline(STDIN) function readavailable(this::AsyncStream) buf = this.buffer - @assert buf.seekable == false + @enforce buf.seekable == false wait_readnb(this,1) takebuf_string(buf) end function readuntil(this::AsyncStream,c::Uint8) buf = this.buffer - @assert buf.seekable == false + @enforce buf.seekable == false wait_readbyte(this,c) readuntil(buf,c) end @@ -874,7 +874,7 @@ function _listen(sock::UVServer; backlog::Integer=BACKLOG_DEFAULT) end function bind(server::PipeServer, name::ASCIIString) - @assert server.status == StatusInit + @enforce server.status == StatusInit err = ccall(:uv_pipe_bind, Int32, (Ptr{Void}, Ptr{Uint8}), server.handle, name) if err != 0 @@ -897,7 +897,7 @@ function listen(path::ByteString) end function connect!(sock::Pipe, path::ByteString) - @assert sock.status == StatusInit + @enforce sock.status == StatusInit req = c_malloc(_sizeof_uv_connect) uv_req_set_data(req,C_NULL) ccall(:uv_pipe_connect, Void, (Ptr{Void}, Ptr{Void}, Ptr{Uint8}, Ptr{Void}), req, sock.handle, path, uv_jl_connectcb::Ptr{Void}) diff --git a/base/task.jl b/base/task.jl index f628a248eb814f..cf2a3ee81f5ea1 100644 --- a/base/task.jl +++ b/base/task.jl @@ -282,7 +282,7 @@ function wait() return result end end - assert(false) + enforce(false) end function pause() diff --git a/base/test.jl b/base/test.jl index bc81c611ff02c9..70981baba6d320 100644 --- a/base/test.jl +++ b/base/test.jl @@ -132,7 +132,7 @@ macro inferred(ex) quote vals = ($([esc(ex.args[i]) for i = 2:length(ex.args)]...),) inftypes = Base.return_types($(ex.args[1]), ($([:(typeof(vals[$i])) for i = 1:length(ex.args)-1]...),)) - @assert length(inftypes) == 1 + @enforce length(inftypes) == 1 result = $(esc(ex.args[1]))(vals...) rettype = typeof(result) is(rettype, inftypes[1]) || error("return type $rettype does not match inferred return type $(inftypes[1])") diff --git a/base/version.jl b/base/version.jl index 5e43c384766719..9ee5995caab8b2 100644 --- a/base/version.jl +++ b/base/version.jl @@ -169,7 +169,7 @@ nextminor(v::VersionNumber) = v < thisminor(v) ? thisminor(v) : VersionNumber(v. nextmajor(v::VersionNumber) = v < thismajor(v) ? thismajor(v) : VersionNumber(v.major+1, 0, 0) function check_new_version(existing::Vector{VersionNumber}, ver::VersionNumber) - @assert issorted(existing) + @enforce issorted(existing) if isempty(existing) for v in [v"0", v"0.0.1", v"0.1", v"1"] lowerbound(v) <= ver <= v && return diff --git a/ui/repl.c b/ui/repl.c index c894b3d18ca550..b902dec20429b8 100644 --- a/ui/repl.c +++ b/ui/repl.c @@ -80,6 +80,7 @@ static const char *opts = " --track-allocation={none|user|all}\n" " Count bytes allocated by each source line\n" " --check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations)\n" + " --release={yes|no} Disable or enable assert function and macro\n" " --int-literals={32|64} Select integer literal size independent of platform\n"; void parse_opts(int *argcp, char ***argvp)