Skip to content

Commit 5dd63c1

Browse files
committed
Checkpoint: Refactored librustc_trans, avoid stack-crossing ref cycle.
Namely, `BlockS` used to carry an `fcx: &'blk FunctionContext`, while the `FunctionContext` carries a reference to the arena that holds the blocks, and thus there was a chicken/egg problem where we are attempting to assign the lifetime `'blk` to both the `FunctionContext` and to the arena's blocks, which does not work under the new lifetime rules for `Drop`, since there has to be some order in which the two are torn down. To work around this, I removed the `fcx` from the `BlockS`, and instead turn the `Block` type (which was formerly `&'blk BlockS`) into a tuple carrying both the pointer to the `BlockS` as well as the `fcx`.
1 parent ae0dadf commit 5dd63c1

File tree

19 files changed

+766
-754
lines changed

19 files changed

+766
-754
lines changed

src/librustc_trans/trans/_match.rs

Lines changed: 74 additions & 74 deletions
Large diffs are not rendered by default.

src/librustc_trans/trans/adt.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub struct Struct<'tcx> {
144144
* these, for places in trans where the `Ty` isn't directly
145145
* available.
146146
*/
147-
pub fn represent_node<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
147+
pub fn represent_node<'fcx, 'blk, 'tcx>(bcx: Block<'fcx, 'blk, 'tcx>,
148148
node: ast::NodeId) -> Rc<Repr<'tcx>> {
149149
represent_type(bcx.ccx(), node_id_type(bcx, node))
150150
}
@@ -626,7 +626,7 @@ fn struct_llfields<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, st: &Struct<'tcx>,
626626
*
627627
* This should ideally be less tightly tied to `_match`.
628628
*/
629-
pub fn trans_switch<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
629+
pub fn trans_switch<'fcx, 'blk, 'tcx>(bcx: Block<'fcx, 'blk, 'tcx>,
630630
r: &Repr<'tcx>, scrutinee: ValueRef)
631631
-> (_match::BranchKind, Option<ValueRef>) {
632632
match *r {
@@ -643,7 +643,7 @@ pub fn trans_switch<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
643643

644644

645645
/// Obtain the actual discriminant of a value.
646-
pub fn trans_get_discr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>,
646+
pub fn trans_get_discr<'fcx, 'blk, 'tcx>(bcx: Block<'fcx, 'blk, 'tcx>, r: &Repr<'tcx>,
647647
scrutinee: ValueRef, cast_to: Option<Type>)
648648
-> ValueRef {
649649
let signed;
@@ -719,8 +719,8 @@ fn load_discr(bcx: Block, ity: IntType, ptr: ValueRef, min: Disr, max: Disr)
719719
*
720720
* This should ideally be less tightly tied to `_match`.
721721
*/
722-
pub fn trans_case<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr, discr: Disr)
723-
-> _match::OptResult<'blk, 'tcx> {
722+
pub fn trans_case<'fcx, 'blk, 'tcx>(bcx: Block<'fcx, 'blk, 'tcx>, r: &Repr, discr: Disr)
723+
-> _match::OptResult<'fcx, 'blk, 'tcx> {
724724
match *r {
725725
CEnum(ity, _, _) => {
726726
_match::SingleResult(Result::new(bcx, C_integral(ll_inttype(bcx.ccx(), ity),
@@ -745,7 +745,7 @@ pub fn trans_case<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr, discr: Disr)
745745
* Set the discriminant for a new value of the given case of the given
746746
* representation.
747747
*/
748-
pub fn trans_set_discr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>,
748+
pub fn trans_set_discr<'fcx, 'blk, 'tcx>(bcx: Block<'fcx, 'blk, 'tcx>, r: &Repr<'tcx>,
749749
val: ValueRef, discr: Disr) {
750750
match *r {
751751
CEnum(ity, min, max) => {
@@ -824,7 +824,7 @@ pub fn num_args(r: &Repr, discr: Disr) -> uint {
824824
}
825825

826826
/// Access a field, at a point when the value's case is known.
827-
pub fn trans_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>,
827+
pub fn trans_field_ptr<'fcx, 'blk, 'tcx>(bcx: Block<'fcx, 'blk, 'tcx>, r: &Repr<'tcx>,
828828
val: ValueRef, discr: Disr, ix: uint) -> ValueRef {
829829
// Note: if this ever needs to generate conditionals (e.g., if we
830830
// decide to do some kind of cdr-coding-like non-unique repr
@@ -863,7 +863,7 @@ pub fn trans_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>,
863863
}
864864
}
865865

866-
pub fn struct_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, st: &Struct<'tcx>, val: ValueRef,
866+
pub fn struct_field_ptr<'fcx, 'blk, 'tcx>(bcx: Block<'fcx, 'blk, 'tcx>, st: &Struct<'tcx>, val: ValueRef,
867867
ix: uint, needs_cast: bool) -> ValueRef {
868868
let val = if needs_cast {
869869
let ccx = bcx.ccx();
@@ -877,10 +877,10 @@ pub fn struct_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, st: &Struct<'tcx>, v
877877
GEPi(bcx, val, &[0, ix])
878878
}
879879

880-
pub fn fold_variants<'blk, 'tcx>(
881-
bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>, value: ValueRef,
882-
f: |Block<'blk, 'tcx>, &Struct<'tcx>, ValueRef| -> Block<'blk, 'tcx>)
883-
-> Block<'blk, 'tcx> {
880+
pub fn fold_variants<'fcx, 'blk, 'tcx>(
881+
bcx: Block<'fcx, 'blk, 'tcx>, r: &Repr<'tcx>, value: ValueRef,
882+
f: |Block<'fcx, 'blk, 'tcx>, &Struct<'tcx>, ValueRef| -> Block<'fcx, 'blk, 'tcx>)
883+
-> Block<'fcx, 'blk, 'tcx> {
884884
let fcx = bcx.fcx;
885885
match *r {
886886
Univariant(ref st, _) => {
@@ -892,23 +892,23 @@ pub fn fold_variants<'blk, 'tcx>(
892892
Unreachable(unr_cx);
893893

894894
let discr_val = trans_get_discr(bcx, r, value, None);
895-
let llswitch = Switch(bcx, discr_val, unr_cx.llbb, cases.len());
895+
let llswitch = Switch(bcx, discr_val, unr_cx.data.llbb, cases.len());
896896
let bcx_next = fcx.new_temp_block("enum-variant-iter-next");
897897

898898
for (discr, case) in cases.iter().enumerate() {
899899
let mut variant_cx = fcx.new_temp_block(
900900
format!("enum-variant-iter-{}", discr.to_string()).as_slice()
901901
);
902902
let rhs_val = C_integral(ll_inttype(ccx, ity), discr as u64, true);
903-
AddCase(llswitch, rhs_val, variant_cx.llbb);
903+
AddCase(llswitch, rhs_val, variant_cx.data.llbb);
904904

905905
let fields = case.fields.iter().map(|&ty|
906906
type_of::type_of(bcx.ccx(), ty)).collect::<Vec<_>>();
907907
let real_ty = Type::struct_(ccx, fields.as_slice(), case.packed);
908908
let variant_value = PointerCast(variant_cx, value, real_ty.ptr_to());
909909

910910
variant_cx = f(variant_cx, case, variant_value);
911-
Br(variant_cx, bcx_next.llbb);
911+
Br(variant_cx, bcx_next.data.llbb);
912912
}
913913

914914
bcx_next
@@ -918,8 +918,8 @@ pub fn fold_variants<'blk, 'tcx>(
918918
}
919919

920920
/// Access the struct drop flag, if present.
921-
pub fn trans_drop_flag_ptr<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>, val: ValueRef)
922-
-> datum::DatumBlock<'blk, 'tcx, datum::Expr> {
921+
pub fn trans_drop_flag_ptr<'fcx, 'blk, 'tcx>(mut bcx: Block<'fcx, 'blk, 'tcx>, r: &Repr<'tcx>, val: ValueRef)
922+
-> datum::DatumBlock<'fcx, 'blk, 'tcx, datum::Expr> {
923923
let ptr_ty = ty::mk_imm_ptr(bcx.tcx(), ty::mk_bool());
924924
match *r {
925925
Univariant(ref st, true) => {

src/librustc_trans/trans/asm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use syntax::ast;
2828
use libc::{c_uint, c_char};
2929

3030
// Take an inline assembly expression and splat it out via LLVM
31-
pub fn trans_inline_asm<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ia: &ast::InlineAsm)
32-
-> Block<'blk, 'tcx> {
31+
pub fn trans_inline_asm<'fcx, 'blk, 'tcx>(bcx: Block<'fcx, 'blk, 'tcx>, ia: &ast::InlineAsm)
32+
-> Block<'fcx, 'blk, 'tcx> {
3333
let fcx = bcx.fcx;
3434
let mut bcx = bcx;
3535
let mut constraints = Vec::new();

0 commit comments

Comments
 (0)