Skip to content

Commit 25b1523

Browse files
committed
Clean up the tydesc handling code in trans.
1 parent ccee8cb commit 25b1523

File tree

2 files changed

+80
-119
lines changed

2 files changed

+80
-119
lines changed

src/rustc/middle/trans/base.rs

Lines changed: 70 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,11 @@ fn malloc_raw_dyn(bcx: block, t: ty::t, heap: heap,
367367
let llty = type_of(ccx, box_ptr_ty);
368368

369369
// Get the tydesc for the body:
370-
let mut static_ti = none;
371-
let lltydesc = get_tydesc(ccx, t, static_ti);
372-
lazily_emit_all_tydesc_glue(ccx, copy static_ti);
370+
let static_ti = get_tydesc(ccx, t);
371+
lazily_emit_all_tydesc_glue(ccx, static_ti);
373372

374373
// Allocate space:
375-
let rval = Call(bcx, upcall, ~[lltydesc, size]);
374+
let rval = Call(bcx, upcall, ~[static_ti.tydesc, size]);
376375
ret PointerCast(bcx, rval, llty);
377376
}
378377

@@ -409,20 +408,10 @@ fn malloc_unique(bcx: block, t: ty::t) -> {box: ValueRef, body: ValueRef} {
409408
// Type descriptor and type glue stuff
410409

411410
fn get_tydesc_simple(ccx: @crate_ctxt, t: ty::t) -> ValueRef {
412-
let mut ti = none;
413-
get_tydesc(ccx, t, ti)
411+
get_tydesc(ccx, t).tydesc
414412
}
415413

416-
fn get_tydesc(ccx: @crate_ctxt, t: ty::t,
417-
&static_ti: option<@tydesc_info>) -> ValueRef {
418-
assert !ty::type_has_params(t);
419-
// Otherwise, generate a tydesc if necessary, and return it.
420-
let inf = get_static_tydesc(ccx, t);
421-
static_ti = some(inf);
422-
inf.tydesc
423-
}
424-
425-
fn get_static_tydesc(ccx: @crate_ctxt, t: ty::t) -> @tydesc_info {
414+
fn get_tydesc(ccx: @crate_ctxt, t: ty::t) -> @tydesc_info {
426415
alt ccx.tydescs.find(t) {
427416
some(inf) { inf }
428417
_ {
@@ -1090,96 +1079,90 @@ fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
10901079
}
10911080

10921081
fn lazily_emit_all_tydesc_glue(ccx: @crate_ctxt,
1093-
static_ti: option<@tydesc_info>) {
1082+
static_ti: @tydesc_info) {
10941083
lazily_emit_tydesc_glue(ccx, abi::tydesc_field_take_glue, static_ti);
10951084
lazily_emit_tydesc_glue(ccx, abi::tydesc_field_drop_glue, static_ti);
10961085
lazily_emit_tydesc_glue(ccx, abi::tydesc_field_free_glue, static_ti);
10971086
lazily_emit_tydesc_glue(ccx, abi::tydesc_field_visit_glue, static_ti);
10981087
}
10991088

11001089
fn lazily_emit_tydesc_glue(ccx: @crate_ctxt, field: uint,
1101-
static_ti: option<@tydesc_info>) {
1090+
ti: @tydesc_info) {
11021091
let _icx = ccx.insn_ctxt("lazily_emit_tydesc_glue");
1103-
alt static_ti {
1104-
none { }
1105-
some(ti) {
1106-
if field == abi::tydesc_field_take_glue {
1107-
alt ti.take_glue {
1108-
some(_) { }
1109-
none {
1110-
#debug("+++ lazily_emit_tydesc_glue TAKE %s",
1111-
ppaux::ty_to_str(ccx.tcx, ti.ty));
1112-
let glue_fn = declare_generic_glue
1113-
(ccx, ti.ty, T_glue_fn(ccx), "take");
1114-
ti.take_glue = some(glue_fn);
1115-
make_generic_glue(ccx, ti.ty, glue_fn,
1116-
make_take_glue, "take");
1117-
#debug("--- lazily_emit_tydesc_glue TAKE %s",
1118-
ppaux::ty_to_str(ccx.tcx, ti.ty));
1119-
}
1120-
}
1121-
} else if field == abi::tydesc_field_drop_glue {
1122-
alt ti.drop_glue {
1123-
some(_) { }
1124-
none {
1125-
#debug("+++ lazily_emit_tydesc_glue DROP %s",
1126-
ppaux::ty_to_str(ccx.tcx, ti.ty));
1127-
let glue_fn =
1128-
declare_generic_glue(ccx, ti.ty, T_glue_fn(ccx), "drop");
1129-
ti.drop_glue = some(glue_fn);
1130-
make_generic_glue(ccx, ti.ty, glue_fn,
1131-
make_drop_glue, "drop");
1132-
#debug("--- lazily_emit_tydesc_glue DROP %s",
1133-
ppaux::ty_to_str(ccx.tcx, ti.ty));
1134-
}
1135-
}
1136-
} else if field == abi::tydesc_field_free_glue {
1137-
alt ti.free_glue {
1138-
some(_) { }
1139-
none {
1140-
#debug("+++ lazily_emit_tydesc_glue FREE %s",
1141-
ppaux::ty_to_str(ccx.tcx, ti.ty));
1142-
let glue_fn =
1143-
declare_generic_glue(ccx, ti.ty, T_glue_fn(ccx), "free");
1144-
ti.free_glue = some(glue_fn);
1145-
make_generic_glue(ccx, ti.ty, glue_fn,
1146-
make_free_glue, "free");
1147-
#debug("--- lazily_emit_tydesc_glue FREE %s",
1148-
ppaux::ty_to_str(ccx.tcx, ti.ty));
1149-
}
1150-
}
1151-
} else if field == abi::tydesc_field_visit_glue {
1152-
alt ti.visit_glue {
1153-
some(_) { }
1154-
none {
1155-
#debug("+++ lazily_emit_tydesc_glue VISIT %s",
1156-
ppaux::ty_to_str(ccx.tcx, ti.ty));
1157-
let glue_fn =
1158-
declare_generic_glue(ccx, ti.ty, T_glue_fn(ccx), "visit");
1159-
ti.visit_glue = some(glue_fn);
1160-
make_generic_glue(ccx, ti.ty, glue_fn,
1161-
make_visit_glue, "visit");
1162-
#debug("--- lazily_emit_tydesc_glue VISIT %s",
1163-
ppaux::ty_to_str(ccx.tcx, ti.ty));
1164-
}
1165-
}
1092+
if field == abi::tydesc_field_take_glue {
1093+
alt ti.take_glue {
1094+
some(_) { }
1095+
none {
1096+
#debug("+++ lazily_emit_tydesc_glue TAKE %s",
1097+
ppaux::ty_to_str(ccx.tcx, ti.ty));
1098+
let glue_fn = declare_generic_glue
1099+
(ccx, ti.ty, T_glue_fn(ccx), "take");
1100+
ti.take_glue = some(glue_fn);
1101+
make_generic_glue(ccx, ti.ty, glue_fn,
1102+
make_take_glue, "take");
1103+
#debug("--- lazily_emit_tydesc_glue TAKE %s",
1104+
ppaux::ty_to_str(ccx.tcx, ti.ty));
1105+
}
1106+
}
1107+
} else if field == abi::tydesc_field_drop_glue {
1108+
alt ti.drop_glue {
1109+
some(_) { }
1110+
none {
1111+
#debug("+++ lazily_emit_tydesc_glue DROP %s",
1112+
ppaux::ty_to_str(ccx.tcx, ti.ty));
1113+
let glue_fn =
1114+
declare_generic_glue(ccx, ti.ty, T_glue_fn(ccx), "drop");
1115+
ti.drop_glue = some(glue_fn);
1116+
make_generic_glue(ccx, ti.ty, glue_fn,
1117+
make_drop_glue, "drop");
1118+
#debug("--- lazily_emit_tydesc_glue DROP %s",
1119+
ppaux::ty_to_str(ccx.tcx, ti.ty));
1120+
}
1121+
}
1122+
} else if field == abi::tydesc_field_free_glue {
1123+
alt ti.free_glue {
1124+
some(_) { }
1125+
none {
1126+
#debug("+++ lazily_emit_tydesc_glue FREE %s",
1127+
ppaux::ty_to_str(ccx.tcx, ti.ty));
1128+
let glue_fn =
1129+
declare_generic_glue(ccx, ti.ty, T_glue_fn(ccx), "free");
1130+
ti.free_glue = some(glue_fn);
1131+
make_generic_glue(ccx, ti.ty, glue_fn,
1132+
make_free_glue, "free");
1133+
#debug("--- lazily_emit_tydesc_glue FREE %s",
1134+
ppaux::ty_to_str(ccx.tcx, ti.ty));
1135+
}
1136+
}
1137+
} else if field == abi::tydesc_field_visit_glue {
1138+
alt ti.visit_glue {
1139+
some(_) { }
1140+
none {
1141+
#debug("+++ lazily_emit_tydesc_glue VISIT %s",
1142+
ppaux::ty_to_str(ccx.tcx, ti.ty));
1143+
let glue_fn =
1144+
declare_generic_glue(ccx, ti.ty, T_glue_fn(ccx), "visit");
1145+
ti.visit_glue = some(glue_fn);
1146+
make_generic_glue(ccx, ti.ty, glue_fn,
1147+
make_visit_glue, "visit");
1148+
#debug("--- lazily_emit_tydesc_glue VISIT %s",
1149+
ppaux::ty_to_str(ccx.tcx, ti.ty));
1150+
}
11661151
}
1167-
1168-
}
11691152
}
11701153
}
11711154

11721155
// See [Note-arg-mode]
11731156
fn call_tydesc_glue_full(++cx: block, v: ValueRef, tydesc: ValueRef,
11741157
field: uint, static_ti: option<@tydesc_info>) {
11751158
let _icx = cx.insn_ctxt("call_tydesc_glue_full");
1176-
lazily_emit_tydesc_glue(cx.ccx(), field, static_ti);
1177-
if cx.unreachable { ret; }
1159+
if cx.unreachable { ret; }
11781160

11791161
let mut static_glue_fn = none;
11801162
alt static_ti {
11811163
none {/* no-op */ }
11821164
some(sti) {
1165+
lazily_emit_tydesc_glue(cx.ccx(), field, sti);
11831166
if field == abi::tydesc_field_take_glue {
11841167
static_glue_fn = sti.take_glue;
11851168
} else if field == abi::tydesc_field_drop_glue {
@@ -1213,9 +1196,8 @@ fn call_tydesc_glue_full(++cx: block, v: ValueRef, tydesc: ValueRef,
12131196
fn call_tydesc_glue(++cx: block, v: ValueRef, t: ty::t, field: uint)
12141197
-> block {
12151198
let _icx = cx.insn_ctxt("call_tydesc_glue");
1216-
let mut ti = none;
1217-
let td = get_tydesc(cx.ccx(), t, ti);
1218-
call_tydesc_glue_full(cx, v, td, field, ti);
1199+
let ti = get_tydesc(cx.ccx(), t);
1200+
call_tydesc_glue_full(cx, v, ti.tydesc, field, some(ti));
12191201
ret cx;
12201202
}
12211203

src/rustc/middle/trans/closure.rs

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn mk_closure_tys(tcx: ty::ctxt,
146146
fn allocate_cbox(bcx: block,
147147
ck: ty::closure_kind,
148148
cdata_ty: ty::t)
149-
-> (block, ValueRef, ~[ValueRef]) {
149+
-> ValueRef {
150150
let _icx = bcx.insn_ctxt("closure::allocate_cbox");
151151
let ccx = bcx.ccx(), tcx = ccx.tcx;
152152

@@ -160,42 +160,23 @@ fn allocate_cbox(bcx: block,
160160
Store(bcx, rc, ref_cnt);
161161
}
162162

163-
fn store_tydesc(bcx: block,
164-
cdata_ty: ty::t,
165-
llbox: ValueRef,
166-
&ti: option<@tydesc_info>) -> block {
167-
let bound_tydesc = GEPi(bcx, llbox, ~[0u, abi::box_field_tydesc]);
168-
let td = base::get_tydesc(bcx.ccx(), cdata_ty, ti);
169-
Store(bcx, td, bound_tydesc);
170-
bcx
171-
}
172-
173163
// Allocate and initialize the box:
174-
let mut ti = none;
175-
let mut temp_cleanups = ~[];
176-
let (bcx, llbox) = alt ck {
164+
let llbox = alt ck {
177165
ty::ck_box {
178-
get_tydesc(ccx, cdata_ty, ti);
179-
let llbox = malloc_raw(bcx, cdata_ty, heap_shared);
180-
(bcx, llbox)
166+
malloc_raw(bcx, cdata_ty, heap_shared)
181167
}
182168
ty::ck_uniq {
183-
let llbox = malloc_raw(bcx, cdata_ty, heap_exchange);
184-
(bcx, llbox)
169+
malloc_raw(bcx, cdata_ty, heap_exchange)
185170
}
186171
ty::ck_block {
187172
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
188173
let llbox = base::alloc_ty(bcx, cbox_ty);
189174
nuke_ref_count(bcx, llbox);
190-
(bcx, llbox)
175+
llbox
191176
}
192177
};
193178

194-
base::lazily_emit_tydesc_glue(ccx, abi::tydesc_field_take_glue, ti);
195-
base::lazily_emit_tydesc_glue(ccx, abi::tydesc_field_drop_glue, ti);
196-
base::lazily_emit_tydesc_glue(ccx, abi::tydesc_field_free_glue, ti);
197-
198-
ret (bcx, llbox, temp_cleanups);
179+
ret llbox;
199180
}
200181

201182
type closure_result = {
@@ -219,8 +200,8 @@ fn store_environment(bcx: block,
219200
mk_closure_tys(tcx, bound_values);
220201

221202
// allocate closure in the heap
222-
let mut (bcx, llbox, temp_cleanups) =
223-
allocate_cbox(bcx, ck, cdata_ty);
203+
let llbox = allocate_cbox(bcx, ck, cdata_ty);
204+
let mut temp_cleanups = ~[];
224205

225206
// cbox_ty has the form of a tuple: (a, b, c) we want a ptr to a
226207
// tuple. This could be a ptr in uniq or a box or on stack,
@@ -567,10 +548,9 @@ fn make_opaque_cbox_take_glue(
567548
let bcx = take_ty(bcx, tydesc_out, ty::mk_type(tcx));
568549

569550
// Take the data in the tuple
570-
let ti = none;
571551
let cdata_out = GEPi(bcx, cbox_out, ~[0u, abi::box_field_body]);
572552
call_tydesc_glue_full(bcx, cdata_out, tydesc,
573-
abi::tydesc_field_take_glue, ti);
553+
abi::tydesc_field_take_glue, none);
574554
bcx
575555
}
576556
}
@@ -615,10 +595,9 @@ fn make_opaque_cbox_free_glue(
615595
let tydesc = PointerCast(bcx, tydesc, lltydescty);
616596

617597
// Drop the tuple data then free the descriptor
618-
let ti = none;
619598
let cdata = GEPi(bcx, cbox, ~[0u, abi::box_field_body]);
620599
call_tydesc_glue_full(bcx, cdata, tydesc,
621-
abi::tydesc_field_drop_glue, ti);
600+
abi::tydesc_field_drop_glue, none);
622601

623602
// Free the ty descr (if necc) and the box itself
624603
alt ck {

0 commit comments

Comments
 (0)