Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
JeffBezanson committed Feb 28, 2017
1 parent b16d315 commit 99cc0b4
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 138 deletions.
9 changes: 7 additions & 2 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1908,8 +1908,12 @@ function abstract_eval(e::ANY, vtypes::VarTable, sv::InferenceState)
if isdefined(sv.linfo, :def)
spsig = sv.linfo.def.sig
if isa(spsig, UnionAll)
env = data_pointer_from_objref(sv.linfo.sparam_vals) + sizeof(Ptr{Void})
rt = ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), e.args[2], spsig, env)
if !isempty(sv.linfo.sparam_vals)
env = data_pointer_from_objref(sv.linfo.sparam_vals) + sizeof(Ptr{Void})
rt = ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), e.args[2], spsig, env)
else
rt = rewrap_unionall(e.args[2], spsig)
end
end
end
abstract_eval(e.args[1], vtypes, sv)
Expand Down Expand Up @@ -3271,6 +3275,7 @@ function substitute!(e::ANY, na::Int, argexprs::Vector{Any}, spsig::ANY, spvals:
if head === :static_parameter
return spvals[e.args[1]]
elseif head === :foreigncall
@assert !isa(spsig,UnionAll) || !isempty(spvals)
for i = 1:length(e.args)
if i == 2
e.args[2] = ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), e.args[2], spsig, spvals)
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ endif
SRCS := \
jltypes gf typemap ast builtins module interpreter symbol \
dlload sys init task array dump toplevel jl_uv datatype \
simplevector APInt-C runtime_intrinsics runtime_ccall compileout \
simplevector APInt-C runtime_intrinsics runtime_ccall precompile \
threadgroup threading stackwalk gc gc-debug gc-pages method \
jlapi signal-handling safepoint jloptions timing subtype rtutils

Expand Down
5 changes: 3 additions & 2 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ static const std::string verify_ccall_sig(size_t nargs, jl_value_t *&rt, jl_valu
}
else {
static_rt = retboxed || !jl_has_typevar_from_unionall(rt, unionall_env);
if (!static_rt && sparam_vals != NULL) {
if (!static_rt && sparam_vals != NULL && jl_svec_len(sparam_vals) > 0) {
rt = jl_instantiate_type_in_env(rt, unionall_env, jl_svec_data(sparam_vals));
// `rt` is gc-rooted by the caller
static_rt = true;
Expand Down Expand Up @@ -1833,7 +1833,8 @@ jl_cgval_t function_sig_t::emit_a_ccall(
// if we know the function sparams, try to fill those in now
// so that the julia_to_native type checks are more likely to be doable (e.g. leaf types) at compile-time
jl_value_t *jargty_in_env = jargty;
if (ctx->spvals_ptr == NULL && !toboxed && unionall_env && jl_has_typevar_from_unionall(jargty, unionall_env)) {
if (ctx->spvals_ptr == NULL && !toboxed && unionall_env && jl_has_typevar_from_unionall(jargty, unionall_env) &&
jl_svec_len(ctx->linfo->sparam_vals) > 0) {
jargty_in_env = jl_instantiate_type_in_env(jargty_in_env, unionall_env, jl_svec_data(ctx->linfo->sparam_vals));
if (jargty_in_env != jargty)
jl_add_method_root(ctx, jargty_in_env);
Expand Down
2 changes: 1 addition & 1 deletion src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void NotifyDebugger(jit_code_entry *JITCodeEntry)
}
__jit_debug_descriptor.first_entry = JITCodeEntry;
__jit_debug_descriptor.relevant_entry = JITCodeEntry;
jit_debug_register_code();
//jit_debug_register_code();
}
}
// ------------------------ END OF TEMPORARY COPY FROM LLVM -----------------
Expand Down
40 changes: 34 additions & 6 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,32 @@ static int count_union_components(jl_value_t **types, size_t n)
return c;
}

int jl_count_union_components(jl_value_t *v)
{
if (!jl_is_uniontype(v)) return 1;
jl_uniontype_t *u = (jl_uniontype_t*)v;
return jl_count_union_components(u->a) + jl_count_union_components(u->b);
}

static jl_value_t *nth_union_component(jl_value_t *v, int *pi)
{
if (!jl_is_uniontype(v)) {
if (*pi == 0)
return v;
(*pi)--;
return NULL;
}
jl_uniontype_t *u = (jl_uniontype_t*)v;
jl_value_t *a = nth_union_component(u->a, pi);
if (a) return a;
return nth_union_component(u->b, pi);
}

jl_value_t *jl_nth_union_component(jl_value_t *v, int i)
{
return nth_union_component(v, &i);
}

static void flatten_type_union(jl_value_t **types, size_t n, jl_value_t **out, size_t *idx)
{
size_t i;
Expand Down Expand Up @@ -1363,12 +1389,14 @@ static jl_value_t *_jl_instantiate_type_in_env(jl_value_t *ty, jl_unionall_t *en

JL_DLLEXPORT jl_value_t *jl_instantiate_type_in_env(jl_value_t *ty, jl_unionall_t *env, jl_value_t **vals)
{
jl_value_t *typ;
JL_TRY {
typ = _jl_instantiate_type_in_env(ty, env, vals, NULL);
}
JL_CATCH {
typ = jl_bottom_type;
jl_value_t *typ = ty;
if (jl_is_unionall(env)) {
JL_TRY {
typ = _jl_instantiate_type_in_env(ty, env, vals, NULL);
}
JL_CATCH {
typ = jl_bottom_type;
}
}
return typ;
}
Expand Down
3 changes: 3 additions & 0 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ jl_value_t *jl_instantiate_type_with(jl_value_t *t, jl_value_t **env, size_t n);
JL_DLLEXPORT jl_value_t *jl_instantiate_type_in_env(jl_value_t *ty, jl_unionall_t *env, jl_value_t **vals);
jl_value_t *jl_substitute_var(jl_value_t *t, jl_tvar_t *var, jl_value_t *val);
jl_svec_t *jl_outer_unionall_vars(jl_value_t *u);
int jl_count_union_components(jl_value_t *v);
jl_value_t *jl_nth_union_component(jl_value_t *v, int i);
jl_datatype_t *jl_new_uninitialized_datatype(void);
jl_datatype_t *jl_new_abstracttype(jl_value_t *name, jl_datatype_t *super,
jl_svec_t *parameters);
Expand Down Expand Up @@ -489,6 +491,7 @@ JL_DLLEXPORT jl_methtable_t *jl_new_method_table(jl_sym_t *name, jl_module_t *mo
jl_method_instance_t *jl_get_specialization1(jl_tupletype_t *types, size_t world);
JL_DLLEXPORT int jl_has_call_ambiguities(jl_tupletype_t *types, jl_method_t *m);
jl_method_instance_t *jl_get_specialized(jl_method_t *m, jl_value_t *types, jl_svec_t *sp);
int jl_is_rettype_inferred(jl_method_instance_t *li);
JL_DLLEXPORT jl_value_t *jl_methtable_lookup(jl_methtable_t *mt, jl_tupletype_t *type, size_t world);
JL_DLLEXPORT jl_method_instance_t *jl_specializations_get_linfo(jl_method_t *m, jl_value_t *type, jl_svec_t *sparams, size_t world);
JL_DLLEXPORT void jl_method_instance_add_backedge(jl_method_instance_t *callee, jl_method_instance_t *caller);
Expand Down
3 changes: 1 addition & 2 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@
// with MEMDEBUG, every object is allocated explicitly with malloc, and
// filled with 0xbb before being freed. this helps tools like valgrind
// catch invalid accesses.
// #define MEMDEBUG
#define MEMDEBUG

// with MEMFENCE, the object pool headers are verified during sweep
// to help detect corruption due to fence-post write errors
// #define MEMFENCE


// GC_VERIFY force a full verification gc along with every quick gc to ensure no
// reachable memory is freed
#ifndef GC_VERIFY
Expand Down
Loading

0 comments on commit 99cc0b4

Please sign in to comment.