Skip to content

Commit

Permalink
remove the ability for codegen to compute specialized call sites
Browse files Browse the repository at this point in the history
fix #16201
  • Loading branch information
vtjnash committed Jun 17, 2016
1 parent 0f0d8e2 commit 2bcc0bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 62 deletions.
59 changes: 1 addition & 58 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2064,23 +2064,6 @@ static Value *emit_f_is(const jl_cgval_t &arg1, const jl_cgval_t &arg2, jl_codec
#endif
}

static jl_svec_t *call_arg_types(jl_value_t **args, size_t n, jl_codectx_t *ctx)
{
jl_svec_t *t = jl_alloc_svec(n);
JL_GC_PUSH1(&t);
size_t i;
for(i=0; i < n; i++) {
jl_value_t *ty = expr_type(args[i], ctx);
if (!jl_is_leaf_type(ty)) {
t = NULL;
break;
}
jl_svecset(t, i, ty);
}
JL_GC_POP();
return t;
}

static bool emit_builtin_call(jl_cgval_t *ret, jl_value_t *f, jl_value_t **args, size_t nargs,
jl_codectx_t *ctx, jl_value_t *expr)
// returns true if the call has been handled
Expand Down Expand Up @@ -2742,11 +2725,10 @@ static jl_cgval_t emit_call(jl_expr_t *ex, jl_codectx_t *ctx)
size_t nargs = arglen - 1;
assert(arglen >= 1);
Value *theFptr = NULL;
jl_value_t *aty = NULL;
jl_cgval_t result;

jl_function_t *f = (jl_function_t*)static_eval(args[0], ctx, true);
JL_GC_PUSH2(&f, &aty);
JL_GC_PUSH1(&f);
if (f != NULL) {
// function is a compile-time constant
if (jl_typeis(f, jl_intrinsic_type)) {
Expand Down Expand Up @@ -2776,45 +2758,6 @@ static jl_cgval_t emit_call(jl_expr_t *ex, jl_codectx_t *ctx)
}
}

if (ctx->linfo->inferred) {
aty = (jl_value_t*)call_arg_types(args, arglen, ctx);
// attempt compile-time specialization for inferred types
if (aty != NULL) {
aty = (jl_value_t*)jl_apply_tuple_type((jl_svec_t*)aty);
/*if (trace) {
jl_printf(JL_STDOUT, "call %s%s\n",
jl_sprint(args[0]),
jl_sprint((jl_value_t*)aty));
}*/
jl_lambda_info_t *li = jl_get_specialization1((jl_tupletype_t*)aty);
if (li != NULL && !li->inInference) {
jl_compile_linfo(li);
assert(li->functionObjectsDecls.functionObject != NULL);
theFptr = (Value*)li->functionObjectsDecls.functionObject;
jl_cgval_t fval;
if (f != NULL) {
// TODO jb/functions: avoid making too many roots here
if (!jl_is_globalref(args[0]) && !jl_is_symbol(args[0]) &&
!jl_is_leaf_type(f)) {
if (ctx->linfo->def)
jl_add_linfo_root(ctx->linfo, f);
else // for toplevel thunks, just write the value back to the AST to root it
jl_array_ptr_set(ex->args, 0, f);
}
fval = mark_julia_const((jl_value_t*)f);
}
else {
fval = emit_expr(args[0], ctx);
}
if (ctx->linfo->def) // root this li in case it gets deleted from the cache in `f`
jl_add_linfo_root(ctx->linfo, (jl_value_t*)li);
result = emit_call_function_object(li, fval, theFptr, args, nargs, expr, ctx);
JL_GC_POP();
return result;
}
}
}

// emit function and arguments
nargs++; // add function to nargs count
jl_cgval_t *anArg = (jl_cgval_t*)alloca(sizeof(jl_cgval_t) * nargs);
Expand Down
12 changes: 8 additions & 4 deletions test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# issue 9770
@noinline x9770() = false
function f9770(x)
if x9770()
return if x9770()
g9770(:a, :foo)
else
x
end
end
function g9770(x,y)
if isa(y, Symbol)
return if isa(y, Symbol)
f9770(x)
else
g9770(:a, :foo)
Expand Down Expand Up @@ -58,7 +58,7 @@ function g3182(t::DataType)
# subtype of Type, but we cannot infer the T in Type{T} just
# by knowing (at compile time) that the argument is a DataType.
# however the ::Type{T} method should still match at run time.
f3182(t)
return f3182(t)
end
@test g3182(Complex) == 0

Expand Down Expand Up @@ -107,7 +107,7 @@ barTuple2() = fooTuple{tuple(:y)}()
# issue #12476
function f12476(a)
(k, v) = a
v
return v
end
@inferred f12476(1.0 => 1)

Expand Down Expand Up @@ -143,14 +143,17 @@ f12826{I<:Integer}(v::Vector{I}) = v[1]


# non-terminating inference, issue #14009
# non-terminating codegen, issue #16201
type A14009{T}; end
A14009{T}(a::T) = A14009{T}()
f14009(a) = rand(Bool) ? f14009(A14009(a)) : a
code_typed(f14009, (Int,))
code_llvm(DevNull, f14009, (Int,))

type B14009{T}; end
g14009(a) = g14009(B14009{a})
code_typed(g14009, (Type{Int},))
code_llvm(DevNull, f14009, (Int,))


# issue #9232
Expand All @@ -164,6 +167,7 @@ result_type9232{T1<:Number,T2<:Number}(::Type{T1}, ::Type{T2}) = arithtype9232(T
function g10878(x; kw...); end
invoke_g10878() = invoke(g10878, Tuple{Any}, 1)
@code_typed invoke_g10878()
code_llvm(DevNull, invoke_g10878, ())


# issue #10930
Expand Down

0 comments on commit 2bcc0bf

Please sign in to comment.