Skip to content

Commit

Permalink
fix #4688, inlining too early inside method definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Nov 4, 2013
1 parent 1dbd8b5 commit d720865
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
11 changes: 8 additions & 3 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1528,9 +1528,14 @@ function type_annotate(ast::Expr, states::Array{Any,1}, sv::ANY, rettype::ANY,
vi[2] = get(decls, vi[1], vi[2])
end
end
na = length(a.args[1])
li.ast, _ = typeinf(li, ntuple(na+1, i->(i>na ? (Tuple)[1] : Any)),
li.sparams, li, false)
# NOTE: this is disabled, as it leads to inlining too early.
# See issue #4688. We should wait until inner functions are called
# to optimize them; this will be done by the method cache or
# builtins.c:jl_trampoline. However if jl_trampoline is changed then
# this code will need to be restored.
#na = length(a.args[1])
#li.ast, _ = typeinf(li, ntuple(na+1, i->(i>na ? (Tuple)[1] : Any)),
# li.sparams, li, false)
end
end

Expand Down
2 changes: 2 additions & 0 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,8 @@ JL_CALLABLE(jl_trampoline)
jl_function_t *f = (jl_function_t*)F;
assert(f->linfo != NULL);
// to run inference on all thunks. slows down loading files.
// NOTE: if this call to inference is removed, type_annotate in inference.jl
// needs to be updated to infer inner functions.
if (f->linfo->inferred == 0) {
if (!jl_in_inference) {
if (!jl_is_expr(f->linfo->ast)) {
Expand Down
11 changes: 11 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1099,3 +1099,14 @@ f4479(::Real,c) = 1
f4479(::Int, ::Int, ::Bool) = 2
f4479(::Int, x, a...) = 0
@test f4479(1,1,true) == 2

# issue #4688
a4688(y) = "should be unreachable by calling b"
b4688(y) = "not an Int"
begin
a4688(y::Int) = "an Int"
let x = true
b4688(y::Int) = x == true ? a4688(y) : a4688(y)
end
end
@test b4688(1) == "an Int"

0 comments on commit d720865

Please sign in to comment.