Skip to content

Commit 3ab9978

Browse files
committed
Remove support for dynamically-sized types from translation code
1 parent a4d75a4 commit 3ab9978

File tree

11 files changed

+148
-557
lines changed

11 files changed

+148
-557
lines changed

src/rustc/middle/alias.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,10 @@ fn check_crate(tcx: ty::ctxt, crate: @ast::crate) -> (copy_map, ref_map) {
7676
}
7777

7878
fn visit_fn(cx: @ctx, _fk: visit::fn_kind, decl: ast::fn_decl,
79-
body: ast::blk, sp: span,
79+
body: ast::blk, _sp: span,
8080
id: ast::node_id, sc: scope, v: vt<scope>) {
8181
visit::visit_fn_decl(decl, sc, v);
8282
let fty = ty::node_id_to_type(cx.tcx, id);
83-
let args = ty::ty_fn_args(fty);
84-
for arg in args {
85-
alt ty::resolved_mode(cx.tcx, arg.mode) {
86-
ast::by_val if ty::type_has_dynamic_size(cx.tcx, arg.ty) {
87-
err(*cx, sp, "can not pass a dynamically-sized type by value");
88-
}
89-
_ { /* fallthrough */ }
90-
}
91-
}
9283

9384
// Blocks need to obey any restrictions from the enclosing scope, and may
9485
// be called multiple times.

src/rustc/middle/trans/base.rs

Lines changed: 42 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,8 @@ fn bump_ptr(bcx: block, t: ty::t, base: ValueRef, sz: ValueRef) ->
267267
ValueRef {
268268
let ccx = bcx.ccx();
269269
let bumped = ptr_offs(bcx, base, sz);
270-
if check type_has_static_size(ccx, t) {
271-
let typ = T_ptr(type_of(ccx, t));
272-
PointerCast(bcx, bumped, typ)
273-
} else { bumped }
270+
let typ = T_ptr(type_of(ccx, t));
271+
PointerCast(bcx, bumped, typ)
274272
}
275273

276274
// Replacement for the LLVM 'GEP' instruction when field indexing into a enum.
@@ -310,11 +308,7 @@ fn opaque_box_body(bcx: block,
310308
let ccx = bcx.ccx();
311309
let boxptr = PointerCast(bcx, boxptr, T_ptr(T_box_header(ccx)));
312310
let bodyptr = GEPi(bcx, boxptr, [1]);
313-
if check type_has_static_size(ccx, body_t) {
314-
PointerCast(bcx, bodyptr, T_ptr(type_of(ccx, body_t)))
315-
} else {
316-
PointerCast(bcx, bodyptr, T_ptr(T_i8()))
317-
}
311+
PointerCast(bcx, bodyptr, T_ptr(type_of(ccx, body_t)))
318312
}
319313

320314
// trans_malloc_boxed_raw: expects an unboxed type and returns a pointer to
@@ -350,41 +344,13 @@ fn trans_malloc_boxed(bcx: block, t: ty::t) ->
350344

351345
// Type descriptor and type glue stuff
352346

353-
fn trans_stack_local_derived_tydesc(cx: block, llsz: ValueRef,
354-
llalign: ValueRef, llroottydesc: ValueRef,
355-
llfirstparam: ValueRef, n_params: uint)
356-
-> ValueRef {
357-
let llmyroottydesc = alloca(cx, cx.ccx().tydesc_type);
358-
359-
// By convention, desc 0 is the root descriptor.
360-
let llroottydesc = Load(cx, llroottydesc);
361-
Store(cx, llroottydesc, llmyroottydesc);
362-
363-
// Store a pointer to the rest of the descriptors.
364-
let ccx = cx.ccx();
365-
store_inbounds(cx, llfirstparam, llmyroottydesc,
366-
[0, abi::tydesc_field_first_param]);
367-
store_inbounds(cx, C_uint(ccx, n_params), llmyroottydesc,
368-
[0, abi::tydesc_field_n_params]);
369-
store_inbounds(cx, llsz, llmyroottydesc,
370-
[0, abi::tydesc_field_size]);
371-
store_inbounds(cx, llalign, llmyroottydesc,
372-
[0, abi::tydesc_field_align]);
373-
// FIXME legacy field, can be dropped
374-
store_inbounds(cx, C_uint(ccx, 0u), llmyroottydesc,
375-
[0, abi::tydesc_field_obj_params]);
376-
ret llmyroottydesc;
377-
}
378-
379347
fn get_tydesc_simple(bcx: block, t: ty::t) -> result {
380348
let ti = none;
381349
get_tydesc(bcx, t, ti)
382350
}
383351

384352
fn get_tydesc(cx: block, t: ty::t,
385353
&static_ti: option<@tydesc_info>) -> result {
386-
387-
// FIXME[mono]
388354
assert !ty::type_has_params(t);
389355
// Otherwise, generate a tydesc if necessary, and return it.
390356
let info = get_static_tydesc(cx.ccx(), t);
@@ -452,17 +418,9 @@ fn declare_tydesc(ccx: @crate_ctxt, t: ty::t) -> @tydesc_info {
452418
log(debug, "+++ declare_tydesc " + ty_to_str(ccx.tcx, t));
453419
let llsize;
454420
let llalign;
455-
if check type_has_static_size(ccx, t) {
456-
let llty = type_of(ccx, t);
457-
llsize = llsize_of(ccx, llty);
458-
llalign = llalign_of(ccx, llty);
459-
} else {
460-
// These will be overwritten as the derived tydesc is generated, so
461-
// we create placeholder values.
462-
463-
llsize = C_int(ccx, 0);
464-
llalign = C_int(ccx, 0);
465-
}
421+
let llty = type_of(ccx, t);
422+
llsize = llsize_of(ccx, llty);
423+
llalign = llalign_of(ccx, llty);
466424
let name;
467425
if ccx.sess.opts.debuginfo {
468426
name = mangle_internal_name_by_type_only(ccx, t, "tydesc");
@@ -508,9 +466,7 @@ fn make_generic_glue_inner(ccx: @crate_ctxt, t: ty::t,
508466
// the caller has no idea if it's dealing with something that can be
509467
// passed by value.
510468

511-
let llty = if check type_has_static_size(ccx, t) {
512-
T_ptr(type_of(ccx, t))
513-
} else { T_ptr(T_i8()) };
469+
let llty = T_ptr(type_of(ccx, t));
514470

515471
let bcx = top_scope_block(fcx, none);
516472
let lltop = bcx.llbb;
@@ -1200,17 +1156,12 @@ fn call_memmove(cx: block, dst: ValueRef, src: ValueRef,
12001156
fn memmove_ty(bcx: block, dst: ValueRef, src: ValueRef, t: ty::t) ->
12011157
block {
12021158
let ccx = bcx.ccx();
1203-
if check type_has_static_size(ccx, t) {
1204-
if ty::type_is_structural(t) {
1205-
let llsz = llsize_of(ccx, type_of(ccx, t));
1206-
ret call_memmove(bcx, dst, src, llsz).bcx;
1207-
}
1208-
Store(bcx, Load(bcx, src), dst);
1209-
ret bcx;
1159+
if ty::type_is_structural(t) {
1160+
let llsz = llsize_of(ccx, type_of(ccx, t));
1161+
ret call_memmove(bcx, dst, src, llsz).bcx;
12101162
}
1211-
1212-
let {bcx, val: llsz} = size_of(bcx, t);
1213-
ret call_memmove(bcx, dst, src, llsz).bcx;
1163+
Store(bcx, Load(bcx, src), dst);
1164+
ret bcx;
12141165
}
12151166

12161167
enum copy_action { INIT, DROP_EXISTING, }
@@ -1372,10 +1323,8 @@ fn trans_unary(bcx: block, op: ast::unop, e: @ast::expr,
13721323
// make enums work, since enums have a different LLVM type depending
13731324
// on whether they're boxed or not
13741325
let ccx = bcx.ccx();
1375-
if check type_has_static_size(ccx, e_ty) {
1376-
let llety = T_ptr(type_of(ccx, e_ty));
1377-
body = PointerCast(bcx, body, llety);
1378-
}
1326+
let llety = T_ptr(type_of(ccx, e_ty));
1327+
body = PointerCast(bcx, body, llety);
13791328
bcx = trans_expr_save_in(bcx, e, body);
13801329
revoke_clean(bcx, box);
13811330
ret store_in_dest(bcx, box, dest);
@@ -1583,10 +1532,8 @@ fn autoderef(cx: block, v: ValueRef, t: ty::t) -> result_t {
15831532
// to cast this pointer, since statically-sized enum types have
15841533
// different types depending on whether they're behind a box
15851534
// or not.
1586-
if check type_has_static_size(ccx, t1) {
1587-
let llty = type_of(ccx, t1);
1588-
v1 = PointerCast(cx, body, T_ptr(llty));
1589-
} else { v1 = body; }
1535+
let llty = type_of(ccx, t1);
1536+
v1 = PointerCast(cx, body, T_ptr(llty));
15901537
}
15911538
ty::ty_uniq(_) {
15921539
let derefed = uniq::autoderef(v1, t1);
@@ -1608,9 +1555,7 @@ fn autoderef(cx: block, v: ValueRef, t: ty::t) -> result_t {
16081555
}
16091556
t1 =
16101557
ty::substitute_type_params(ccx.tcx, tps, variants[0].args[0]);
1611-
if check type_has_static_size(ccx, t1) {
1612-
v1 = PointerCast(cx, v1, T_ptr(type_of(ccx, t1)));
1613-
} else { } // FIXME: typestate hack
1558+
v1 = PointerCast(cx, v1, T_ptr(type_of(ccx, t1)));
16141559
}
16151560
_ { break; }
16161561
}
@@ -1724,7 +1669,7 @@ fn trans_for(cx: block, local: @ast::local, seq: @ast::expr,
17241669
body.span);
17251670
Br(bcx, scope_cx.llbb);
17261671
let curr = PointerCast(bcx, curr,
1727-
T_ptr(type_of_or_i8(bcx.ccx(), t)));
1672+
T_ptr(type_of(bcx.ccx(), t)));
17281673
let bcx = alt::bind_irrefutable_pat(scope_cx, local.node.pat,
17291674
curr, false);
17301675
bcx = trans_block(bcx, body, ignore);
@@ -2122,7 +2067,7 @@ fn trans_local_var(cx: block, def: ast::def) -> local_var_result {
21222067
ast::def_self(_) {
21232068
let slf = option::get(cx.fcx.llself);
21242069
let ptr = PointerCast(cx, slf.v,
2125-
T_ptr(type_of_or_i8(cx.ccx(), slf.t)));
2070+
T_ptr(type_of(cx.ccx(), slf.t)));
21262071
ret {val: ptr, kind: owned};
21272072
}
21282073
_ {
@@ -2236,27 +2181,20 @@ fn trans_index(cx: block, ex: @ast::expr, base: @ast::expr,
22362181
} else { ix_val = ix.val; }
22372182

22382183
let unit_ty = node_id_type(cx, ex.id);
2239-
let unit_sz = size_of(bcx, unit_ty);
2240-
bcx = unit_sz.bcx;
2241-
maybe_name_value(cx.ccx(), unit_sz.val, "unit_sz");
2242-
let scaled_ix = Mul(bcx, ix_val, unit_sz.val);
2184+
let llunitty = type_of(ccx, unit_ty);
2185+
let unit_sz = llsize_of(ccx, llunitty);
2186+
maybe_name_value(cx.ccx(), unit_sz, "unit_sz");
2187+
let scaled_ix = Mul(bcx, ix_val, unit_sz);
22432188
maybe_name_value(cx.ccx(), scaled_ix, "scaled_ix");
22442189
let lim = tvec::get_fill(bcx, v);
2245-
let body = tvec::get_dataptr(bcx, v, type_of_or_i8(ccx, unit_ty));
2190+
let body = tvec::get_dataptr(bcx, v, type_of(ccx, unit_ty));
22462191
let bounds_check = ICmp(bcx, lib::llvm::IntUGE, scaled_ix, lim);
22472192
bcx = with_cond(bcx, bounds_check) {|bcx|
22482193
// fail: bad bounds check.
22492194
trans_fail(bcx, some(ex.span), "bounds check")
22502195
};
2251-
let elt = if check type_has_static_size(ccx, unit_ty) {
2252-
let elt_1 = InBoundsGEP(bcx, body, [ix_val]);
2253-
let llunitty = type_of(ccx, unit_ty);
2254-
PointerCast(bcx, elt_1, T_ptr(llunitty))
2255-
} else {
2256-
body = PointerCast(bcx, body, T_ptr(T_i8()));
2257-
InBoundsGEP(bcx, body, [scaled_ix])
2258-
};
2259-
ret lval_owned(bcx, elt);
2196+
let elt = InBoundsGEP(bcx, body, [ix_val]);
2197+
ret lval_owned(bcx, PointerCast(bcx, elt, T_ptr(llunitty)));
22602198
}
22612199

22622200
fn expr_is_lval(bcx: block, e: @ast::expr) -> bool {
@@ -2315,9 +2253,7 @@ fn trans_lval(cx: block, e: @ast::expr) -> lval_result {
23152253
}
23162254
ty::ty_enum(_, _) {
23172255
let ety = expr_ty(cx, e);
2318-
let ellty = if check type_has_static_size(ccx, ety) {
2319-
T_ptr(type_of(ccx, ety))
2320-
} else { T_typaram_ptr(ccx.tn) };
2256+
let ellty = T_ptr(type_of(ccx, ety));
23212257
PointerCast(sub.bcx, sub.val, ellty)
23222258
}
23232259
ty::ty_ptr(_) | ty::ty_uniq(_) | ty::ty_rptr(_,_) { sub.val }
@@ -3194,7 +3130,7 @@ fn trans_fail_expr(bcx: block, sp_opt: option<span>,
31943130

31953131
if ty::type_is_str(e_ty) {
31963132
let data = tvec::get_dataptr(
3197-
bcx, expr_res.val, type_of_or_i8(
3133+
bcx, expr_res.val, type_of(
31983134
ccx, ty::mk_mach_uint(tcx, ast::ty_u8)));
31993135
ret trans_fail_value(bcx, sp_opt, data);
32003136
} else if bcx.unreachable || ty::type_is_bot(e_ty) {
@@ -3345,23 +3281,8 @@ fn zero_alloca(cx: block, llptr: ValueRef, t: ty::t)
33453281
-> block {
33463282
let bcx = cx;
33473283
let ccx = cx.ccx();
3348-
if check type_has_static_size(ccx, t) {
3349-
let llty = type_of(ccx, t);
3350-
Store(bcx, C_null(llty), llptr);
3351-
} else {
3352-
let key = alt ccx.sess.targ_cfg.arch {
3353-
session::arch_x86 | session::arch_arm { "llvm.memset.p0i8.i32" }
3354-
session::arch_x86_64 { "llvm.memset.p0i8.i64" }
3355-
};
3356-
let i = ccx.intrinsics;
3357-
let memset = i.get(key);
3358-
let dst_ptr = PointerCast(cx, llptr, T_ptr(T_i8()));
3359-
let size = size_of(cx, t);
3360-
bcx = size.bcx;
3361-
let align = C_i32(1i32); // cannot use computed value here.
3362-
let volatile = C_bool(false);
3363-
Call(cx, memset, [dst_ptr, C_u8(0u), size.val, align, volatile]);
3364-
}
3284+
let llty = type_of(ccx, t);
3285+
Store(bcx, C_null(llty), llptr);
33653286
ret bcx;
33663287
}
33673288

@@ -3580,7 +3501,7 @@ fn block_locals(b: ast::blk, it: fn(@ast::local)) {
35803501
fn alloc_ty(cx: block, t: ty::t) -> result {
35813502
let bcx = cx, ccx = cx.ccx();
35823503
let llty = type_of(ccx, t);
3583-
assert type_has_static_size(ccx, t);
3504+
assert !ty::type_has_params(t);
35843505
let val = alloca(bcx, llty);
35853506

35863507
// NB: since we've pushed all size calculations in this
@@ -3641,24 +3562,15 @@ fn trans_block(bcx: block, b: ast::blk, dest: dest)
36413562
ret bcx;
36423563
}
36433564

3644-
// Creates the standard quartet of basic blocks: static allocas, copy args,
3645-
// derived tydescs, and dynamic allocas.
3565+
// Creates the standard set of basic blocks for a function
36463566
fn mk_standard_basic_blocks(llfn: ValueRef) ->
3647-
{sa: BasicBlockRef,
3648-
ca: BasicBlockRef,
3649-
dt: BasicBlockRef,
3650-
da: BasicBlockRef,
3651-
rt: BasicBlockRef} {
3652-
ret {sa: str::as_c_str("static_allocas", {|buf|
3653-
llvm::LLVMAppendBasicBlock(llfn, buf) }),
3654-
ca: str::as_c_str("load_env", {|buf|
3655-
llvm::LLVMAppendBasicBlock(llfn, buf) }),
3656-
dt: str::as_c_str("derived_tydescs", {|buf|
3657-
llvm::LLVMAppendBasicBlock(llfn, buf) }),
3658-
da: str::as_c_str("dynamic_allocas", {|buf|
3659-
llvm::LLVMAppendBasicBlock(llfn, buf) }),
3660-
rt: str::as_c_str("return", {|buf|
3661-
llvm::LLVMAppendBasicBlock(llfn, buf) })};
3567+
{sa: BasicBlockRef, ca: BasicBlockRef, rt: BasicBlockRef} {
3568+
{sa: str::as_c_str("static_allocas", {|buf|
3569+
llvm::LLVMAppendBasicBlock(llfn, buf) }),
3570+
ca: str::as_c_str("load_env", {|buf|
3571+
llvm::LLVMAppendBasicBlock(llfn, buf) }),
3572+
rt: str::as_c_str("return", {|buf|
3573+
llvm::LLVMAppendBasicBlock(llfn, buf) })}
36623574
}
36633575

36643576

@@ -3679,16 +3591,12 @@ fn new_fn_ctxt_w_id(ccx: @crate_ctxt, path: path,
36793591
llretptr: llvm::LLVMGetParam(llfndecl, 0u as c_uint),
36803592
mutable llstaticallocas: llbbs.sa,
36813593
mutable llloadenv: llbbs.ca,
3682-
mutable llderivedtydescs_first: llbbs.dt,
3683-
mutable llderivedtydescs: llbbs.dt,
3684-
mutable lldynamicallocas: llbbs.da,
36853594
mutable llreturn: llbbs.rt,
36863595
mutable llself: none,
36873596
mutable personality: none,
36883597
llargs: int_hash::<local_val>(),
36893598
lllocals: int_hash::<local_val>(),
36903599
llupvars: int_hash::<ValueRef>(),
3691-
derived_tydescs: ty::new_ty_hash(),
36923600
id: id,
36933601
self_id: maybe_self_id,
36943602
param_substs: param_substs,
@@ -3776,8 +3684,8 @@ fn copy_args_to_allocas(fcx: fn_ctxt, bcx: block, args: [ast::arg],
37763684
ret bcx;
37773685
}
37783686

3779-
// Ties up the llstaticallocas -> llloadenv -> llderivedtydescs ->
3780-
// lldynamicallocas -> lltop edges, and builds the return block.
3687+
// Ties up the llstaticallocas -> llloadenv -> lltop edges,
3688+
// and builds the return block.
37813689
fn finish_fn(fcx: fn_ctxt, lltop: BasicBlockRef) {
37823690
tie_up_header_blocks(fcx, lltop);
37833691
let ret_cx = raw_block(fcx, fcx.llreturn);
@@ -3786,9 +3694,7 @@ fn finish_fn(fcx: fn_ctxt, lltop: BasicBlockRef) {
37863694

37873695
fn tie_up_header_blocks(fcx: fn_ctxt, lltop: BasicBlockRef) {
37883696
Br(raw_block(fcx, fcx.llstaticallocas), fcx.llloadenv);
3789-
Br(raw_block(fcx, fcx.llloadenv), fcx.llderivedtydescs_first);
3790-
Br(raw_block(fcx, fcx.llderivedtydescs), fcx.lldynamicallocas);
3791-
Br(raw_block(fcx, fcx.lldynamicallocas), lltop);
3697+
Br(raw_block(fcx, fcx.llloadenv), lltop);
37923698
}
37933699

37943700
enum self_arg { impl_self(ty::t), no_self, }
@@ -3884,10 +3790,6 @@ fn trans_res_ctor(ccx: @crate_ctxt, path: path, dtor: ast::fn_decl,
38843790
in trans_res_ctor"); }
38853791
};
38863792
let llretptr = fcx.llretptr;
3887-
if ty::type_has_dynamic_size(ccx.tcx, ty::ty_fn_ret(fty)) {
3888-
let llret_t = T_ptr(T_struct([ccx.int_type, llvm::LLVMTypeOf(arg)]));
3889-
llretptr = BitCast(bcx, llretptr, llret_t);
3890-
}
38913793

38923794
let dst = GEPi(bcx, llretptr, [0, 1]);
38933795
bcx = memmove_ty(bcx, dst, arg, arg_t);
@@ -3946,9 +3848,6 @@ fn trans_enum_variant(ccx: @crate_ctxt, enum_id: ast::node_id,
39463848
some(local_mem(x)) { x }
39473849
};
39483850
let arg_ty = arg_tys[i].ty;
3949-
if ty::type_has_params(arg_ty) {
3950-
lldestptr = PointerCast(bcx, lldestptr, val_ty(llarg));
3951-
}
39523851
bcx = memmove_ty(bcx, lldestptr, llarg, arg_ty);
39533852
i += 1u;
39543853
}
@@ -4718,7 +4617,6 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
47184617
maps: maps,
47194618
stats:
47204619
{mutable n_static_tydescs: 0u,
4721-
mutable n_derived_tydescs: 0u,
47224620
mutable n_glues_created: 0u,
47234621
mutable n_null_glues: 0u,
47244622
mutable n_real_glues: 0u,
@@ -4748,7 +4646,6 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
47484646
if ccx.sess.opts.stats {
47494647
#error("--- trans stats ---");
47504648
#error("n_static_tydescs: %u", ccx.stats.n_static_tydescs);
4751-
#error("n_derived_tydescs: %u", ccx.stats.n_derived_tydescs);
47524649
#error("n_glues_created: %u", ccx.stats.n_glues_created);
47534650
#error("n_null_glues: %u", ccx.stats.n_null_glues);
47544651
#error("n_real_glues: %u", ccx.stats.n_real_glues);

0 commit comments

Comments
 (0)