Skip to content

Commit

Permalink
take advantage of ::None for identifying unreachable code
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Mar 17, 2013
1 parent 9199a9e commit 544f660
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ macro unexpected()
:(error("unexpected branch reached"))
end

rethrow() = ccall(:jl_rethrow, Void, ())
rethrow(e) = ccall(:jl_rethrow_other, Void, (Any,), e)
rethrow() = ccall(:jl_rethrow, Void, ())::None
rethrow(e) = ccall(:jl_rethrow_other, Void, (Any,), e)::None
backtrace() = ccall(:jl_get_backtrace, Array{Any,1}, ())

## system error handling ##
Expand Down
2 changes: 1 addition & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export
Operators,
Errno,
Meta,

# Types
AbstractMatrix,
AbstractSparseMatrix,
Expand Down
9 changes: 8 additions & 1 deletion base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ precompile(eval_user_input, (Expr, Bool))
precompile(print, (Float64,))
precompile(a2t, (Array{Any,1},))
precompile(flush, (IOStream,))
precompile(getindex, (Type{ByteString}, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString))
precompile(getindex, (Type{ByteString}, ASCIIString, ASCIIString, ASCIIString))
precompile(int, (Int,))
precompile(uint, (Uint,))
precompile(_atexit, ())
Expand Down Expand Up @@ -295,6 +295,13 @@ precompile(abstract_eval_arg, (Uint8, ObjectIdDict, StaticVarInfo))
precompile(occurs_outside_tupleref, (Function, Symbol, StaticVarInfo, Int))
precompile(search, (ASCIIString, Regex, Int))
precompile(setindex!, (Vector{Uint8}, Uint8, Int))
precompile(first, (Range1{Int},))
precompile(last, (Range1{Int},))
precompile(isempty, (ASCIIString,))
precompile(normpath, (ASCIIString,))
precompile(print, (ASCIIString,))
precompile(println, (TTY,))
precompile(print, (TTY,Char))

# invoke type inference, running the existing inference code on the new
# inference code to cache an optimized version of it.
Expand Down
2 changes: 1 addition & 1 deletion src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ static jl_value_t *expr_type(jl_value_t *e, jl_codectx_t *ctx)
return (jl_value_t*)jl_any_type;
}
type_of_constant:
if (jl_is_datatype(e))
if (jl_is_datatype(e) || jl_is_uniontype(e))
return (jl_value_t*)jl_wrap_Type(e);
return (jl_value_t*)jl_typeof(e);
}
Expand Down
12 changes: 11 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,17 @@ static Value *emit_known_call(jl_value_t *ff, jl_value_t **args, size_t nargs,
jl_value_t *tp0 = jl_tparam0(ty);
if (jl_subtype(arg, tp0, 0)) {
JL_GC_POP();
return emit_expr(args[1], ctx);
Value *v = emit_expr(args[1], ctx);
if (tp0 == jl_bottom_type) {
return builder.CreateUnreachable();
}
return v;
}
if (tp0 == jl_bottom_type) {
emit_expr(args[1], ctx);
emit_error("reached code declared unreachable", ctx);
JL_GC_POP();
return builder.CreateUnreachable();
}
if (!jl_is_tuple(tp0) && jl_is_leaf_type(tp0)) {
Value *arg1 = emit_expr(args[1], ctx);
Expand Down

0 comments on commit 544f660

Please sign in to comment.