Skip to content

Commit cd5e4c2

Browse files
committed
Add skeleton of copy glue that actually copies
1 parent 7588a89 commit cd5e4c2

File tree

4 files changed

+82
-17
lines changed

4 files changed

+82
-17
lines changed

src/comp/back/abi.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ const tydesc_field_align: int = 2;
5252
const tydesc_field_take_glue: int = 3;
5353
const tydesc_field_drop_glue: int = 4;
5454
const tydesc_field_free_glue: int = 5;
55-
const tydesc_field_sever_glue: int = 6;
56-
const tydesc_field_mark_glue: int = 7;
57-
// FIXME no longer used in rustc, drop when rustboot is gone
58-
const tydesc_field_obj_drop_glue: int = 8;
55+
const tydesc_field_copy_glue: int = 6;
56+
const tydesc_field_sever_glue: int = 7;
57+
const tydesc_field_mark_glue: int = 8;
5958
const tydesc_field_is_stateful: int = 9;
6059
const tydesc_field_cmp_glue: int = 10;
6160
const tydesc_field_shape: int = 11;

src/comp/middle/trans.rs

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,12 +1120,16 @@ fn declare_tydesc(cx: &@local_ctxt, sp: &span, t: &ty::t, ty_params: &[uint])
11201120
mutable drop_glue: none::<ValueRef>,
11211121
mutable free_glue: none::<ValueRef>,
11221122
mutable cmp_glue: none::<ValueRef>,
1123+
mutable copy_glue: none::<ValueRef>,
11231124
ty_params: ty_params};
11241125
log "--- declare_tydesc " + ty_to_str(cx.ccx.tcx, t);
11251126
ret info;
11261127
}
11271128

1128-
type make_generic_glue_helper_fn = fn(&@block_ctxt, ValueRef, &ty::t);
1129+
tag glue_helper {
1130+
default_helper(fn(&@block_ctxt, ValueRef, &ty::t));
1131+
copy_helper(fn(&@block_ctxt, ValueRef, ValueRef, &ty::t));
1132+
}
11291133

11301134
fn declare_generic_glue(cx: &@local_ctxt, t: &ty::t, llfnty: TypeRef,
11311135
name: &str) -> ValueRef {
@@ -1141,7 +1145,7 @@ fn declare_generic_glue(cx: &@local_ctxt, t: &ty::t, llfnty: TypeRef,
11411145

11421146
fn make_generic_glue_inner(cx: &@local_ctxt, sp: &span, t: &ty::t,
11431147
llfn: ValueRef,
1144-
helper: &make_generic_glue_helper_fn,
1148+
helper: &glue_helper,
11451149
ty_params: &[uint]) -> ValueRef {
11461150
let fcx = new_fn_ctxt(cx, sp, llfn);
11471151
llvm::LLVMSetLinkage(llfn,
@@ -1177,13 +1181,22 @@ fn make_generic_glue_inner(cx: &@local_ctxt, sp: &span, t: &ty::t,
11771181
let lltop = bcx.llbb;
11781182
let llrawptr0 = llvm::LLVMGetParam(llfn, 4u);
11791183
let llval0 = bcx.build.BitCast(llrawptr0, llty);
1180-
helper(bcx, llval0, t);
1184+
alt helper {
1185+
default_helper(helper) {
1186+
helper(bcx, llval0, t);
1187+
}
1188+
copy_helper(helper) {
1189+
let llrawptr1 = llvm::LLVMGetParam(llfn, 4u);
1190+
let llval1 = bcx.build.BitCast(llrawptr1, llty);
1191+
helper(bcx, llval0, llval1, t);
1192+
}
1193+
}
11811194
finish_fn(fcx, lltop);
11821195
ret llfn;
11831196
}
11841197

11851198
fn make_generic_glue(cx: &@local_ctxt, sp: &span, t: &ty::t, llfn: ValueRef,
1186-
helper: &make_generic_glue_helper_fn, ty_params: &[uint],
1199+
helper: &glue_helper, ty_params: &[uint],
11871200
name: &str) -> ValueRef {
11881201
if !cx.ccx.sess.get_opts().stats {
11891202
ret make_generic_glue_inner(cx, sp, t, llfn, helper, ty_params);
@@ -1201,6 +1214,7 @@ fn emit_tydescs(ccx: &@crate_ctxt) {
12011214
for each pair: @{key: ty::t, val: @tydesc_info} in ccx.tydescs.items() {
12021215
let glue_fn_ty = T_ptr(T_glue_fn(*ccx));
12031216
let cmp_fn_ty = T_ptr(T_cmp_glue_fn(*ccx));
1217+
let copy_fn_ty = T_ptr(T_copy_glue_fn(*ccx));
12041218
let ti = pair.val;
12051219
let take_glue =
12061220
alt { ti.take_glue } {
@@ -1222,6 +1236,11 @@ fn emit_tydescs(ccx: &@crate_ctxt) {
12221236
none. { ccx.stats.n_null_glues += 1u; C_null(cmp_fn_ty) }
12231237
some(v) { ccx.stats.n_real_glues += 1u; v }
12241238
};
1239+
let copy_glue =
1240+
alt { ti.copy_glue } {
1241+
none. { ccx.stats.n_null_glues += 1u; C_null(copy_fn_ty) }
1242+
some(v) { ccx.stats.n_real_glues += 1u; v }
1243+
};
12251244

12261245
let shape = shape::shape_of(ccx, pair.key);
12271246
let shape_tables =
@@ -1236,9 +1255,9 @@ fn emit_tydescs(ccx: &@crate_ctxt) {
12361255
take_glue, // take_glue
12371256
drop_glue, // drop_glue
12381257
free_glue, // free_glue
1258+
copy_glue, // copy_glue
12391259
C_null(glue_fn_ty), // sever_glue
12401260
C_null(glue_fn_ty), // mark_glue
1241-
C_null(glue_fn_ty), // obj_drop_glue
12421261
C_null(glue_fn_ty), // is_stateful
12431262
cmp_glue, // cmp_glue
12441263
C_shape(ccx, shape), // shape
@@ -1253,6 +1272,11 @@ fn emit_tydescs(ccx: &@crate_ctxt) {
12531272
}
12541273
}
12551274

1275+
fn make_copy_glue(cx: &@block_ctxt, dst: ValueRef, src: ValueRef, t: &ty::t) {
1276+
let bcx = memmove_ty(cx, dst, src, t).bcx;
1277+
build_return(bcx);
1278+
}
1279+
12561280
fn make_take_glue(cx: &@block_ctxt, v: ValueRef, t: &ty::t) {
12571281
// NB: v is an *alias* of type t here, not a direct value.
12581282

@@ -1970,6 +1994,7 @@ fn lazily_emit_all_tydesc_glue(cx: &@block_ctxt,
19701994
lazily_emit_tydesc_glue(cx, abi::tydesc_field_drop_glue, static_ti);
19711995
lazily_emit_tydesc_glue(cx, abi::tydesc_field_free_glue, static_ti);
19721996
lazily_emit_tydesc_glue(cx, abi::tydesc_field_cmp_glue, static_ti);
1997+
lazily_emit_tydesc_glue(cx, abi::tydesc_field_copy_glue, static_ti);
19731998
}
19741999

19752000
fn lazily_emit_all_generic_info_tydesc_glues(cx: &@block_ctxt,
@@ -1995,7 +2020,8 @@ fn lazily_emit_tydesc_glue(cx: &@block_ctxt, field: int,
19952020
declare_generic_glue(lcx, ti.ty, T_glue_fn(*lcx.ccx),
19962021
"take");
19972022
ti.take_glue = some::<ValueRef>(glue_fn);
1998-
make_generic_glue(lcx, cx.sp, ti.ty, glue_fn, make_take_glue,
2023+
make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
2024+
default_helper(make_take_glue),
19992025
ti.ty_params, "take");
20002026
log #fmt["--- lazily_emit_tydesc_glue TAKE %s",
20012027
ty_to_str(bcx_tcx(cx), ti.ty)];
@@ -2012,13 +2038,14 @@ fn lazily_emit_tydesc_glue(cx: &@block_ctxt, field: int,
20122038
declare_generic_glue(lcx, ti.ty, T_glue_fn(*lcx.ccx),
20132039
"drop");
20142040
ti.drop_glue = some::<ValueRef>(glue_fn);
2015-
make_generic_glue(lcx, cx.sp, ti.ty, glue_fn, make_drop_glue,
2041+
make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
2042+
default_helper(make_drop_glue),
20162043
ti.ty_params, "drop");
20172044
log #fmt["--- lazily_emit_tydesc_glue DROP %s",
20182045
ty_to_str(bcx_tcx(cx), ti.ty)];
20192046
}
20202047
}
2021-
} else if field == abi::tydesc_field_free_glue {
2048+
} else if field == abi::tydesc_field_free_glue {
20222049
alt { ti.free_glue } {
20232050
some(_) { }
20242051
none. {
@@ -2029,7 +2056,8 @@ fn lazily_emit_tydesc_glue(cx: &@block_ctxt, field: int,
20292056
declare_generic_glue(lcx, ti.ty, T_glue_fn(*lcx.ccx),
20302057
"free");
20312058
ti.free_glue = some::<ValueRef>(glue_fn);
2032-
make_generic_glue(lcx, cx.sp, ti.ty, glue_fn, make_free_glue,
2059+
make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
2060+
default_helper(make_free_glue),
20332061
ti.ty_params, "free");
20342062
log #fmt["--- lazily_emit_tydesc_glue FREE %s",
20352063
ty_to_str(bcx_tcx(cx), ti.ty)];
@@ -2046,6 +2074,21 @@ fn lazily_emit_tydesc_glue(cx: &@block_ctxt, field: int,
20462074
ty_to_str(bcx_tcx(cx), ti.ty)];
20472075
}
20482076
}
2077+
} else if field == abi::tydesc_field_copy_glue {
2078+
alt { ti.copy_glue } {
2079+
some(_) {}
2080+
none. {
2081+
let lcx = cx.fcx.lcx;
2082+
let glue_fn =
2083+
declare_generic_glue(lcx, ti.ty, T_copy_glue_fn(*lcx.ccx),
2084+
"copy");
2085+
ti.copy_glue = some(glue_fn);
2086+
make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
2087+
copy_helper(make_copy_glue),
2088+
ti.ty_params, "copy");
2089+
2090+
}
2091+
}
20492092
}
20502093
}
20512094
}
@@ -2065,8 +2108,6 @@ fn call_tydesc_glue_full(cx: &@block_ctxt, v: ValueRef, tydesc: ValueRef,
20652108
static_glue_fn = sti.drop_glue;
20662109
} else if field == abi::tydesc_field_free_glue {
20672110
static_glue_fn = sti.free_glue;
2068-
} else if field == abi::tydesc_field_cmp_glue {
2069-
static_glue_fn = sti.cmp_glue;
20702111
}
20712112
}
20722113
}
@@ -2787,6 +2828,7 @@ mod ivec {
27872828
lazily_emit_tydesc_glue(bcx, abi::tydesc_field_take_glue, none);
27882829
lazily_emit_tydesc_glue(bcx, abi::tydesc_field_drop_glue, none);
27892830
lazily_emit_tydesc_glue(bcx, abi::tydesc_field_free_glue, none);
2831+
lazily_emit_tydesc_glue(bcx, abi::tydesc_field_copy_glue, none);
27902832
let rhs_len_and_data = get_len_and_data(bcx, rhs, unit_ty);
27912833
let rhs_len = rhs_len_and_data.len;
27922834
let rhs_data = rhs_len_and_data.data;

src/comp/middle/trans_common.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ type tydesc_info =
8585
mutable drop_glue: option::t<ValueRef>,
8686
mutable free_glue: option::t<ValueRef>,
8787
mutable cmp_glue: option::t<ValueRef>,
88+
mutable copy_glue: option::t<ValueRef>,
8889
ty_params: [uint]};
8990

9091
/*
@@ -605,6 +606,14 @@ fn T_cmp_glue_fn(cx: &crate_ctxt) -> TypeRef {
605606
ret t;
606607
}
607608

609+
fn T_copy_glue_fn(cx: &crate_ctxt) -> TypeRef {
610+
let s = "copy_glue_fn";
611+
if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
612+
let t = T_tydesc_field(cx, abi::tydesc_field_copy_glue);
613+
cx.tn.associate(s, t);
614+
ret t;
615+
}
616+
608617
fn T_tydesc(taskptr_type: TypeRef) -> TypeRef {
609618
let tydesc = T_named_struct("tydesc");
610619
let tydescpp = T_ptr(T_ptr(tydesc));
@@ -615,10 +624,13 @@ fn T_tydesc(taskptr_type: TypeRef) -> TypeRef {
615624
let cmp_glue_fn_ty =
616625
T_ptr(T_fn([T_ptr(T_i1()), taskptr_type, T_ptr(tydesc), tydescpp,
617626
pvoid, pvoid, T_i8()], T_void()));
627+
let copy_glue_fn_ty =
628+
T_ptr(T_fn([T_ptr(T_nil()), taskptr_type, T_ptr(T_nil()), tydescpp,
629+
pvoid, pvoid], T_void()));
618630

619631
let elems =
620632
[tydescpp, T_int(), T_int(), glue_fn_ty, glue_fn_ty, glue_fn_ty,
621-
glue_fn_ty, glue_fn_ty, glue_fn_ty, glue_fn_ty, cmp_glue_fn_ty,
633+
copy_glue_fn_ty, glue_fn_ty, glue_fn_ty, glue_fn_ty, cmp_glue_fn_ty,
622634
T_ptr(T_i8()), T_ptr(T_i8()), T_int()];
623635
set_struct_body(tydesc, elems);
624636
ret tydesc;
@@ -892,3 +904,13 @@ fn C_shape(ccx: &@crate_ctxt, bytes: &[u8]) -> ValueRef {
892904
ret llvm::LLVMConstPointerCast(llglobal, T_ptr(T_i8()));
893905
}
894906

907+
//
908+
// Local Variables:
909+
// mode: rust
910+
// fill-column: 78;
911+
// indent-tabs-mode: nil
912+
// c-basic-offset: 4
913+
// buffer-file-coding-system: utf-8-unix
914+
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
915+
// End:
916+
//

src/rt/rust_internal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ struct rust_timer {
257257

258258
typedef void CDECL (glue_fn)(void *, rust_task *, void *,
259259
const type_desc **, void *);
260+
typedef void CDECL (copy_glue_fn)(void *, rust_task *, void *,
261+
const type_desc **, void *, void *);
260262
typedef void CDECL (cmp_glue_fn)(void *, rust_task *, void *,
261263
const type_desc **,
262264
void *, void *, int8_t);
@@ -275,9 +277,9 @@ struct type_desc {
275277
glue_fn *take_glue;
276278
glue_fn *drop_glue;
277279
glue_fn *free_glue;
280+
copy_glue_fn *copy_glue;
278281
glue_fn *sever_glue; // For GC.
279282
glue_fn *mark_glue; // For GC.
280-
glue_fn *obj_drop_glue; // For custom destructors.
281283
uintptr_t is_stateful;
282284
cmp_glue_fn *cmp_glue;
283285
const uint8_t *shape;

0 commit comments

Comments
 (0)