Skip to content

Commit

Permalink
when spawn runs something on the local machine, it needs to copy
Browse files Browse the repository at this point in the history
variable bindings to simulate what happens when closures are copied to
other machines. fixes the bug described in issue #80.
  • Loading branch information
JeffBezanson committed Jun 24, 2011
1 parent 866f802 commit e32c1f2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions j/inference.j
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ fieldtype_tfunc = function (A, s, name)
end
t_func[fieldtype] = (2, 2, fieldtype_tfunc)
t_func[Expr] = (3, 3, (a,b,c)->Expr)
t_func[Box] = (1, 1, (a,)->Box)

# TODO: handle e.g. apply_type(T, R::Union(Type{Int32},Type{Float64}))
apply_type_tfunc = function (A, args...)
Expand Down
9 changes: 9 additions & 0 deletions j/multi.j
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,15 @@ let lastp = 1
lastp = 1
end
end
if p==myid()
# for local spawn, simulate semantics of copying bindings
if isa(env,Tuple)
env = map(x->(isa(x,Box)?Box(x.contents):x), env)
linfo = ccall(:jl_closure_linfo, Any, (Any,), thunk)
thunk = ccall(:jl_new_closure_internal, Any, (Any, Any),
linfo, env)::Function
end
end
spawnat(p, thunk)
end
end
Expand Down
9 changes: 9 additions & 0 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,3 +915,12 @@ JL_CALLABLE(jl_f_new_expr)
ex->etype = args[2];
return (jl_value_t*)ex;
}

JL_CALLABLE(jl_f_new_box)
{
JL_NARGS(Box, 1, 1);
jl_value_t *box = (jl_value_t*)alloc_2w();
box->type = jl_box_any_type;
((jl_value_t**)box)[1] = args[0];
return box;
}
1 change: 1 addition & 0 deletions src/builtin_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// declarations for julia-callable builtin functions

JL_CALLABLE(jl_f_new_expr);
JL_CALLABLE(jl_f_new_box);
JL_CALLABLE(jl_weakref_ctor);
JL_CALLABLE(jl_new_array_internal);
JL_CALLABLE(jl_f_throw);
Expand Down
1 change: 1 addition & 0 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ void jl_init_serializer()
VALUE_TAGS = (ptrint_t)ptrhash_get(&ser_tag, jl_null);

void *fptrs[] = { jl_f_new_expr,
jl_f_new_box,
jl_weakref_ctor,
jl_new_array_internal,
jl_f_throw,
Expand Down
3 changes: 2 additions & 1 deletion src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,7 @@ static jl_tuple_t *jl_typevars(size_t n, ...)
}

JL_CALLABLE(jl_f_new_expr);
JL_CALLABLE(jl_f_new_box);

extern void jl_init_int32_cache();

Expand Down Expand Up @@ -2165,7 +2166,7 @@ void jl_init_types()
jl_any_type, jl_null,
jl_tuple(1, jl_symbol("contents")),
jl_tuple(1, jl_any_type));
//jl_add_constructors(jl_box_type);
jl_box_type->fptr = jl_f_new_box;
jl_box_typename = jl_box_type->name;
jl_box_any_type = (jl_type_t*)jl_box_type;

Expand Down

0 comments on commit e32c1f2

Please sign in to comment.