Skip to content

Commit

Permalink
stop calling exchange_free on 0-size types
Browse files Browse the repository at this point in the history
A solid step towards fixing #11998. Eventually, the size may always be
passed to `exchange_free` but this will not be required to fix the bug.
  • Loading branch information
thestinger committed Feb 5, 2014
1 parent acb1ec0 commit 1778b63
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/librustc/middle/trans/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use middle::trans::machine::*;
use middle::trans::reflect;
use middle::trans::tvec;
use middle::trans::type_::Type;
use middle::trans::type_of::type_of;
use middle::trans::type_of::{type_of, sizing_type_of};
use middle::ty;
use util::ppaux::ty_to_short_str;
use util::ppaux;
Expand Down Expand Up @@ -100,23 +100,29 @@ pub fn lazily_emit_all_tydesc_glue(ccx: @CrateContext,
lazily_emit_tydesc_glue(ccx, abi::tydesc_field_visit_glue, static_ti);
}

fn simplified_glue_type(tcx: ty::ctxt, field: uint, t: ty::t) -> ty::t {
fn get_glue_type(ccx: &CrateContext, field: uint, t: ty::t) -> ty::t {
let tcx = ccx.tcx;
if field == abi::tydesc_field_drop_glue {
if !ty::type_needs_drop(tcx, t) {
return ty::mk_nil();
return ty::mk_i8();
}
match ty::get(t).sty {
ty::ty_box(typ)
if !ty::type_needs_drop(tcx, typ) =>
return ty::mk_box(tcx, ty::mk_nil()),

ty::ty_uniq(typ)
if !ty::type_needs_drop(tcx, typ) =>
return ty::mk_uniq(tcx, ty::mk_nil()),
ty::ty_box(typ) if !ty::type_needs_drop(tcx, typ) =>
return ty::mk_box(tcx, ty::mk_i8()),

ty::ty_uniq(typ) if !ty::type_needs_drop(tcx, typ) => {
let llty = sizing_type_of(ccx, typ);
// Unique boxes do not allocate for zero-size types. The standard library may assume
// that `free` is never called on the pointer returned for `~ZeroSizeType`.
if llsize_of_alloc(ccx, llty) == 0 {
return ty::mk_i8();
} else {
return ty::mk_uniq(tcx, ty::mk_i8());
}
}

ty::ty_vec(mt, ty::vstore_uniq)
if !ty::type_needs_drop(tcx, mt.ty) =>
return ty::mk_uniq(tcx, ty::mk_nil()),
ty::ty_vec(mt, ty::vstore_uniq) if !ty::type_needs_drop(tcx, mt.ty) =>
return ty::mk_uniq(tcx, ty::mk_i8()),

_ => {}
}
Expand All @@ -128,7 +134,7 @@ fn simplified_glue_type(tcx: ty::ctxt, field: uint, t: ty::t) -> ty::t {
pub fn lazily_emit_tydesc_glue(ccx: @CrateContext, field: uint, ti: @tydesc_info) {
let _icx = push_ctxt("lazily_emit_tydesc_glue");

let simpl = simplified_glue_type(ccx.tcx, field, ti.ty);
let simpl = get_glue_type(ccx, field, ti.ty);
if simpl != ti.ty {
let _icx = push_ctxt("lazily_emit_simplified_tydesc_glue");
let simpl_ti = get_tydesc(ccx, simpl);
Expand Down Expand Up @@ -204,7 +210,7 @@ pub fn call_tydesc_glue_full(bcx: &Block, v: ValueRef, tydesc: ValueRef,
PointerCast(bcx, v, Type::i8p())
} else {
let ty = static_ti.unwrap().ty;
let simpl = simplified_glue_type(ccx.tcx, field, ty);
let simpl = get_glue_type(ccx, field, ty);
if simpl != ty {
PointerCast(bcx, v, type_of(ccx, simpl).ptr_to())
} else {
Expand Down

5 comments on commit 1778b63

@bors
Copy link
Contributor

@bors bors commented on 1778b63 Feb 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 1778b63 Feb 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging thestinger/rust/glue = 1778b63 into auto

@bors
Copy link
Contributor

@bors bors commented on 1778b63 Feb 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thestinger/rust/glue = 1778b63 merged ok, testing candidate = faf6055

@bors
Copy link
Contributor

@bors bors commented on 1778b63 Feb 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 1778b63 Feb 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = faf6055

Please sign in to comment.