Skip to content

Commit

Permalink
a couple efficiency tweaks
Browse files Browse the repository at this point in the history
there were 2 places where more ASTs can be compressed
clean up some unnecessary objects in LambdaStaticData.tfunc
  • Loading branch information
JeffBezanson committed Sep 15, 2013
1 parent f6b0217 commit e147056
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
4 changes: 2 additions & 2 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ end

## actual functions for broadcast and broadcast! ##

broadcastfuns = (Function=>NTuple{3,Function})[]
broadcastfuns = ObjectIdDict()
function broadcast_functions(op::Function)
(haskey(broadcastfuns, op) ? broadcastfuns[op] :
(broadcastfuns[op] = eval(code_broadcasts(string(op), quot(op)))))
(broadcastfuns[op] = eval(code_broadcasts(string(op), quot(op)))))::NTuple{3,Function}
end

broadcast_function(op::Function) = broadcast_functions(op)[1]
Expand Down
12 changes: 8 additions & 4 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ function abstract_call_gf(f, fargs, argtypes, e)
return (tupleref_tfunc(fargs, argtypes[1], argtypes[2]), Int)
end
end
if f === Main.Base.promote_type || f === Main.Base.typejoin
if (isdefined(Main.Base,:promote_type) && f === Main.Base.promote_type) ||
(isdefined(Main.Base,:typejoin) && f === Main.Base.typejoin)
la = length(argtypes)
c = cell(la)
for i = 1:la
Expand Down Expand Up @@ -1079,12 +1080,13 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
for i = 1:3:length(tfarr)
if typeseq(tfarr[i],atypes)
code = tfarr[i+1]
curtype = ccall(:jl_ast_rettype, Any, (Any,Any), def, code)
if tfarr[i+2]
redo = true
tfunc_idx = i+1
curtype = code
break
end
curtype = ccall(:jl_ast_rettype, Any, (Any,Any), def, code)
return (code, curtype)
end
end
Expand Down Expand Up @@ -1356,10 +1358,12 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
def.tfunc = {}
end
push!(def.tfunc::Array{Any,1}, atypes)
push!(def.tfunc::Array{Any,1}, fulltree)
# in the "rec" state this tree will not be used again, so store
# just the return type in place of it.
push!(def.tfunc::Array{Any,1}, rec ? frame.result : fulltree)
push!(def.tfunc::Array{Any,1}, rec)
else
def.tfunc[tfunc_idx] = fulltree
def.tfunc[tfunc_idx] = rec ? frame.result : fulltree
def.tfunc[tfunc_idx+1] = rec
end

Expand Down
8 changes: 7 additions & 1 deletion base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ end

include("base.jl")
include("reflection.jl")
include("promotion.jl") # We need promote_type() before we can use composite types
include("build_h.jl")
include("c.jl")

# core operations & types
include("promotion.jl")
include("range.jl")
include("tuple.jl")
include("cell.jl")
Expand Down Expand Up @@ -374,6 +374,12 @@ precompile(isslotempty, (Dict{Any,Any}, Int))
precompile(setindex!, (Array{Uint8,1}, Uint8, Int))
precompile(get, (Dict{Any,Any}, Symbol, ASCIIString))
precompile(*, (ASCIIString, ASCIIString, ASCIIString))
precompile(chop, (ASCIIString,))
precompile(ismatch, (Regex, ASCIIString))
precompile(!=, (Bool, Bool))
precompile(nextind, (ASCIIString, Int))
precompile(delete_var!, (Expr, Symbol))
precompile(close, (IOStream,))

# 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 base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ end

# print a warning only once

const have_warned = (ByteString=>Bool)[]
const have_warned = Dict()
function warn_once(msg::String...; depth=0)
msg = bytestring(msg...)
haskey(have_warned,msg) && return
Expand Down
4 changes: 4 additions & 0 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ DLLEXPORT void jl_show_any(jl_value_t *str, jl_value_t *v)
// internal functions ---------------------------------------------------------

extern int jl_in_inference;
extern int jl_boot_file_loaded;
int jl_eval_with_compiler_p(jl_expr_t *expr, int compileloops);

JL_CALLABLE(jl_trampoline)
Expand All @@ -813,6 +814,9 @@ JL_CALLABLE(jl_trampoline)
jl_compile(f);
assert(f->fptr == &jl_trampoline);
jl_generate_fptr(f);
if (jl_boot_file_loaded && jl_is_expr(f->linfo->ast)) {
f->linfo->ast = jl_compress_ast(f->linfo, f->linfo->ast);
}
return jl_apply(f, args, nargs);
}

Expand Down
7 changes: 5 additions & 2 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ static jl_value_t *eval(jl_value_t *e, jl_value_t **locals, size_t nl)
return jl_f_get_field(NULL, gfargs, 2);
}
if (jl_is_lambda_info(e)) {
return (jl_value_t*)jl_new_closure(NULL, (jl_value_t*)jl_null,
(jl_lambda_info_t*)e);
jl_lambda_info_t *li = (jl_lambda_info_t*)e;
if (jl_boot_file_loaded && li->ast && jl_is_expr(li->ast)) {
li->ast = jl_compress_ast(li, li->ast);
}
return (jl_value_t*)jl_new_closure(NULL, (jl_value_t*)jl_null, li);
}
if (jl_is_linenode(e)) {
jl_lineno = jl_linenode_line(e);
Expand Down

0 comments on commit e147056

Please sign in to comment.