-
Notifications
You must be signed in to change notification settings - Fork 13.3k
more dynamic allocation work #14322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
more dynamic allocation work #14322
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,15 +50,30 @@ pub fn trans_free<'a>(cx: &'a Block<'a>, v: ValueRef) -> &'a Block<'a> { | |
Some(expr::Ignore)).bcx | ||
} | ||
|
||
pub fn trans_exchange_free<'a>(cx: &'a Block<'a>, v: ValueRef) | ||
-> &'a Block<'a> { | ||
fn trans_exchange_free<'a>(cx: &'a Block<'a>, v: ValueRef, size: u64, | ||
align: u64) -> &'a Block<'a> { | ||
let _icx = push_ctxt("trans_exchange_free"); | ||
let ccx = cx.ccx(); | ||
callee::trans_lang_call(cx, | ||
langcall(cx, None, "", ExchangeFreeFnLangItem), | ||
[PointerCast(cx, v, Type::i8p(cx.ccx()))], | ||
[PointerCast(cx, v, Type::i8p(ccx)), C_uint(ccx, size as uint), C_uint(ccx, align as uint)], | ||
Some(expr::Ignore)).bcx | ||
} | ||
|
||
pub fn trans_exchange_free_ty<'a>(bcx: &'a Block<'a>, ptr: ValueRef, | ||
content_ty: ty::t) -> &'a Block<'a> { | ||
let sizing_type = sizing_type_of(bcx.ccx(), content_ty); | ||
let content_size = llsize_of_alloc(bcx.ccx(), sizing_type); | ||
|
||
// `Box<ZeroSizeType>` does not allocate. | ||
if content_size != 0 { | ||
let content_align = llalign_of_min(bcx.ccx(), sizing_type); | ||
trans_exchange_free(bcx, ptr, content_size, content_align) | ||
} else { | ||
bcx | ||
} | ||
} | ||
|
||
pub fn take_ty<'a>(bcx: &'a Block<'a>, v: ValueRef, t: ty::t) | ||
-> &'a Block<'a> { | ||
// NB: v is an *alias* of type t here, not a direct value. | ||
|
@@ -87,17 +102,15 @@ fn get_drop_glue_type(ccx: &CrateContext, t: ty::t) -> ty::t { | |
ty::ty_vec(_, None) | ty::ty_str => t, | ||
_ => { | ||
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 `Box<ZeroSizeType>`. | ||
// `Box<ZeroSizeType>` does not allocate. | ||
if llsize_of_alloc(ccx, llty) == 0 { | ||
ty::mk_i8() | ||
} else { | ||
ty::mk_uniq(tcx, ty::mk_i8()) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
_ => t | ||
} | ||
} | ||
|
@@ -285,20 +298,22 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<' | |
ty::ty_vec(mt, None) => { | ||
with_cond(bcx, not_null, |bcx| { | ||
let bcx = tvec::make_drop_glue_unboxed(bcx, llbox, mt.ty); | ||
trans_exchange_free(bcx, llbox) | ||
// FIXME: #13994: the old `Box<[T]>` will not support sized deallocation | ||
trans_exchange_free(bcx, llbox, 0, 8) | ||
}) | ||
} | ||
ty::ty_str => { | ||
with_cond(bcx, not_null, |bcx| { | ||
let unit_ty = ty::sequence_element_type(bcx.tcx(), t); | ||
let bcx = tvec::make_drop_glue_unboxed(bcx, llbox, unit_ty); | ||
trans_exchange_free(bcx, llbox) | ||
// FIXME: #13994: the old `Box<str>` will not support sized deallocation | ||
trans_exchange_free(bcx, llbox, 0, 8) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And soon we'll be able to remove these entirely! |
||
}) | ||
} | ||
_ => { | ||
with_cond(bcx, not_null, |bcx| { | ||
let bcx = drop_ty(bcx, llbox, content_ty); | ||
trans_exchange_free(bcx, llbox) | ||
trans_exchange_free_ty(bcx, llbox, content_ty) | ||
}) | ||
} | ||
} | ||
|
@@ -340,7 +355,8 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<' | |
Call(bcx, dtor, [PointerCast(bcx, cdata, Type::i8p(bcx.ccx()))], []); | ||
|
||
// Free the environment itself | ||
trans_exchange_free(bcx, env) | ||
// FIXME: #13994: pass align and size here | ||
trans_exchange_free(bcx, env, 0, 8) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should be known, right? (today, that is) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it needs to be fixed by freeing the allocation in the destructor function pointer as we do for ~Trait. It could just be done while migrating |
||
}) | ||
} | ||
_ => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I look forward to the day we can remove this entirely.