Added string duplication to deep_copy. Closes #520.

This commit is contained in:
Eric Holk 2011-06-20 13:46:44 -07:00
parent c051501784
commit a2dcd08cc2
6 changed files with 59 additions and 25 deletions

View file

@ -49,6 +49,7 @@ type upcalls =
ValueRef free,
ValueRef mark,
ValueRef new_str,
ValueRef dup_str,
ValueRef new_vec,
ValueRef vec_append,
ValueRef get_type_desc,
@ -101,6 +102,8 @@ fn declare_upcalls(type_names tn, ModuleRef llmod) -> @upcalls {
mark=d("mark", [T_ptr(T_i8())], T_int()),
new_str=d("new_str", [T_ptr(T_i8()), T_size_t()],
T_ptr(T_str())),
dup_str=d("dup_str", [T_ptr(T_str())],
T_ptr(T_str())),
new_vec=d("new_vec", [T_size_t(), T_ptr(T_tydesc(tn))],
T_opaque_vec_ptr()),
vec_append=d("vec_append",

View file

@ -6340,28 +6340,13 @@ fn deep_copy(&@block_ctxt bcx, ValueRef v, ty::t t, ValueRef target_task)
if(ty::type_is_scalar(tcx, t)) {
ret res(bcx, v);
}
else if(ty::type_is_str(tcx, t)) {
ret res(bcx,
bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.dup_str,
[bcx.fcx.lltaskptr, v]));
}
else if(ty::type_is_chan(tcx, t)) {
// If this is a channel, we need to clone it.
/*
log_err "Generating clone call for channel argument.";
log_err #fmt("ty(clone_chan) = %s",
val_str(bcx.fcx.lcx.ccx.tn,
bcx.fcx.lcx.ccx.upcalls.clone_chan));
log_err #fmt("ty(lltaskptr) = %s",
val_str(bcx.fcx.lcx.ccx.tn,
bcx.fcx.lltaskptr));
log_err #fmt("ty(target_task) = %s",
val_str(bcx.fcx.lcx.ccx.tn,
target_task));
log_err #fmt("ty(chan) = %s",
val_str(bcx.fcx.lcx.ccx.tn,
v));
*/
auto chan_ptr = bcx.build.PointerCast(v, T_opaque_chan_ptr());
auto chan_raw_val =
@ -6386,8 +6371,8 @@ fn deep_copy(&@block_ctxt bcx, ValueRef v, ty::t t, ValueRef target_task)
}
else {
bcx.fcx.lcx.ccx.sess.bug("unexpected type in " +
"trans::deep_copy: " +
ty_to_str(tcx, t));
"trans::deep_copy: " +
ty_to_str(tcx, t));
}
}

View file

@ -168,6 +168,7 @@ export type_is_sequence;
export type_is_signed;
export type_is_structural;
export type_is_tup_like;
export type_is_str;
export type_owns_heap_mem;
export type_param;
export unify;
@ -899,6 +900,13 @@ fn type_is_sequence(&ctxt cx, &t ty) -> bool {
}
}
fn type_is_str(&ctxt cx, &t ty) -> bool {
alt (struct(cx, ty)) {
case (ty_str) { ret true; }
case (_) { ret false; }
}
}
fn sequence_is_interior(&ctxt cx, &t ty) -> bool {
alt (struct(cx, ty)) {
case (