Skip to content

Commit

Permalink
adding the ability to declare a method slot as ANY to prevent special…
Browse files Browse the repository at this point in the history
…ization

using this in a few places internally cuts down compilation overhead
  • Loading branch information
JeffBezanson committed Jul 1, 2011
1 parent 98a70e6 commit cb41e38
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion j/array.j
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ref{T}(a::Array{T,2}, i::Index, j::Index) = arrayref(a, (j-1)*arraysize(a,1)+i)
## Indexing: assign ##

assign(A::Array{Any}, x::Tensor, i::Index) = arrayset(A,i,x)
assign(A::Array{Any}, x, i::Index) = arrayset(A,i,x)
assign(A::Array{Any}, x::ANY, i::Index) = arrayset(A,i,x)
assign{T}(A::Array{T}, x::Tensor, i::Index) = arrayset(A,i,convert(T, x))
assign{T}(A::Array{T}, x, i::Index) = arrayset(A,i,convert(T, x))

Expand Down
4 changes: 2 additions & 2 deletions j/cell.j
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function append(a1::Array{Any,1}, as::Array{Any,1}...)
a
end

function cell_1d(xs...)
function cell_1d(xs::ANY...)
n = length(xs)
a = Array(Any,n)
for i=1:n
Expand All @@ -27,7 +27,7 @@ function cell_1d(xs...)
a
end

function cell_2d(nr, nc, xs...)
function cell_2d(nr, nc, xs::ANY...)
a = Array(Any,nr,nc)
for i=1:(nr*nc)
arrayset(a,i,xs[i])
Expand Down
2 changes: 1 addition & 1 deletion j/expr.j
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ gensym() = ccall(:jl_gensym, Any, ())::Symbol

## expressions ##

expr(hd::Symbol, args...) = Expr(hd, {args...}, Any)
expr(hd::Symbol, args::ANY...) = Expr(hd, {args...}, Any)
expr(hd::Symbol, args::Array{Any,1}) = Expr(hd, args, Any)
copy(e::Expr) = Expr(e.head, copy(e.args), e.type)

Expand Down
10 changes: 5 additions & 5 deletions j/inference.j
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function (T, dims...)
Array{et,nd}
end)

function static_convert(to, from)
function static_convert(to::ANY, from::ANY)
if !isa(to,Tuple) || !isa(from,Tuple)
return (subtype(from, to) ? from : to)
end
Expand Down Expand Up @@ -586,7 +586,7 @@ end

ast_rettype(ast) = ast.args[3].type

function abstract_eval_constant(x)
function abstract_eval_constant(x::ANY)
if isa(x,TagKind) || isa(x,BitsKind) || isa(x,StructKind) ||
isa(x,FuncKind) || isa(x,UnionKind)
return Type{x}
Expand Down Expand Up @@ -674,7 +674,7 @@ function interpret(e::Expr, vtypes, sv::StaticVarInfo)
return vtypes
end

tchanged(n, o) = is(o,NF) || (!is(n,NF) && !subtype(n,o))
tchanged(n::ANY, o::ANY) = is(o,NF) || (!is(n,NF) && !subtype(n,o))

function stchanged(new::Union(StateUpdate,VarTable), old, vars)
if is(old,())
Expand All @@ -691,7 +691,7 @@ end

badunion(t) = ccall(:jl_union_too_complex, Int32, (Any,), t) != 0

function tmerge(typea, typeb)
function tmerge(typea::ANY, typeb::ANY)
if is(typea,NF)
return typeb
end
Expand Down Expand Up @@ -1070,7 +1070,7 @@ function contains_is(arr, item)
return false
end
function exprtype(x)
function exprtype(x::ANY)
if isa(x,Expr)
return x.type
elseif isa(x,Symbol)
Expand Down
4 changes: 2 additions & 2 deletions j/multi.j
Original file line number Diff line number Diff line change
Expand Up @@ -1117,9 +1117,9 @@ function at_each(grp::ProcessGroup, f, args...)
end
end

macro bcast(thk)
macro bcast(ex)
quote
at_each(()->eval($expr(:quote,thk)))
at_each(()->eval($expr(:quote,ex)))
end
end

Expand Down
2 changes: 1 addition & 1 deletion j/operators.j
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,5 @@ ${T<:Int}(x::T, y::T) = no_op_err("\$", T)
## miscellaneous ##
copy(x::Any) = x
copy(x::ANY) = x
foreach(f::Function, itr) = for x = itr; f(x); end
6 changes: 3 additions & 3 deletions j/table.j
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ end
idtable(sz::Int) = IdTable(cell(2*_tablesz(sz)))
idtable() = idtable(0)

function assign(t::IdTable, v, k)
function assign(t::IdTable, v::ANY, k::ANY)
t.ht = ccall(:jl_eqtable_put,
Any, (Any, Any, Any), t.ht, k, v)::Array{Any,1}
t
end

get(t::IdTable, key, default) =
get(t::IdTable, key::ANY, default::ANY) =
ccall(:jl_eqtable_get, Any, (Any, Any, Any), t.ht, key, default)

del(t::IdTable, key) =
del(t::IdTable, key::ANY) =
(ccall(:jl_eqtable_del, Int32, (Any, Any), t.ht, key); t)

_secret_table_token_ = (:BOO,)
Expand Down
1 change: 1 addition & 0 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jl_value_t *jl_false;
jl_tag_type_t *jl_undef_type;
jl_tvar_t *jl_typetype_tvar;
jl_tag_type_t *jl_typetype_type;
jl_value_t *jl_ANY_flag;
jl_typector_t *jl_function_type;
jl_struct_type_t *jl_box_type;
jl_type_t *jl_box_any_type;
Expand Down
2 changes: 2 additions & 0 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,8 @@ void jl_init_primitives()
add_builtin("TagKind", (jl_value_t*)jl_tag_kind);
add_builtin("UnionKind", (jl_value_t*)jl_union_kind);

add_builtin("ANY", jl_ANY_flag);

add_builtin("C_NULL", jl_box_pointer(jl_pointer_void_type, NULL));
}

Expand Down
1 change: 1 addition & 0 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ void jl_init_serializer()
jl_seq_type, jl_ntuple_type, jl_tensor_type,
jl_box_type, jl_typector_type, jl_undef_type, jl_any_func,
jl_task_type, jl_union_kind, jl_function_type,
jl_typetype_type, jl_typetype_tvar, jl_ANY_flag,

jl_symbol_type->name, jl_pointer_type->name,
jl_tag_kind->name, jl_union_kind->name, jl_bits_kind->name, jl_struct_kind->name,
Expand Down
9 changes: 5 additions & 4 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ static int cache_match_by_type(jl_value_t **types, size_t n, jl_tuple_t *sig,
}
}
}
//else if (decl == (jl_value_t*)jl_any_type) {
//}
else if (decl == (jl_value_t*)jl_any_type) {
}
else {
if (!jl_types_equal(a, decl))
return 0;
Expand Down Expand Up @@ -127,7 +127,6 @@ static inline int cache_match(jl_value_t **args, size_t n, jl_tuple_t *sig,
}
}
else if (decl == (jl_value_t*)jl_any_type) {
assert(0);
}
else {
/*
Expand Down Expand Up @@ -343,7 +342,7 @@ static jl_function_t *cache_method(jl_methtable_t *mt, jl_tuple_t *type,
for (i=0; i < type->length; i++) {
jl_value_t *elt = jl_tupleref(type,i);
int set_to_any = 0;
if (0 && nth_slot_type(decl,i) == jl_ANY_flag) {
if (nth_slot_type(decl,i) == jl_ANY_flag) {
// don't specialize on slots marked ANY
jl_value_t *orig = jl_tupleref(type, i);
jl_tupleset(type, i, (jl_value_t*)jl_any_type);
Expand All @@ -361,6 +360,8 @@ static jl_function_t *cache_method(jl_methtable_t *mt, jl_tuple_t *type,
curr = curr->next;
}
if (nintr) {
// TODO: even if different specializations of this slot need
// separate cache entries, have them share code.
jl_tupleset(type, i, orig);
}
else {
Expand Down
12 changes: 8 additions & 4 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,9 @@ static jl_value_t *jl_type_intersect(jl_value_t *a, jl_value_t *b,
if (a == b) return a;
if (a == (jl_value_t*)jl_bottom_type || b == (jl_value_t*)jl_bottom_type)
return (jl_value_t*)jl_bottom_type;
if (jl_is_typevar(a))
if (jl_is_typevar(a) && a != jl_ANY_flag)
return intersect_typevar((jl_tvar_t*)a, b, penv, eqc, var);
if (jl_is_typevar(b))
if (jl_is_typevar(b) && b != jl_ANY_flag)
return intersect_typevar((jl_tvar_t*)b, a, penv, eqc, var);
if (!jl_has_typevars(a) && !jl_has_typevars(b)) {
if (jl_subtype(a, b, 0))
Expand All @@ -647,8 +647,10 @@ static jl_value_t *jl_type_intersect(jl_value_t *a, jl_value_t *b,
return intersect_union((jl_uniontype_t*)b, a, penv, eqc, var);
if (a == (jl_value_t*)jl_undef_type) return (jl_value_t*)jl_bottom_type;
if (b == (jl_value_t*)jl_undef_type) return (jl_value_t*)jl_bottom_type;
if (a == (jl_value_t*)jl_any_type) return b;
if (b == (jl_value_t*)jl_any_type) return a;
if (a == (jl_value_t*)jl_any_type ||
a == jl_ANY_flag) return b;
if (b == (jl_value_t*)jl_any_type ||
b == jl_ANY_flag) return a;
// tuple
if (jl_is_tuple(a)) {
jl_value_t *temp=NULL;
Expand Down Expand Up @@ -2209,6 +2211,8 @@ void jl_init_types()
jl_apply_type((jl_value_t*)jl_type_type,
jl_tuple(1,jl_typetype_tvar));

jl_ANY_flag = (jl_value_t*)tvar("ANY");

call_sym = jl_symbol("call");
call1_sym = jl_symbol("call1");
quote_sym = jl_symbol("quote");
Expand Down

0 comments on commit cb41e38

Please sign in to comment.