Skip to content

Commit

Permalink
Rename get_len() to get_meta()
Browse files Browse the repository at this point in the history
The functions is useful for all kinds of fat pointers, but get_len()
just feels so wrong for trait object fat pointers. Let's use get_meta()
because that's rather neutral.
  • Loading branch information
dotdash committed Aug 24, 2015
1 parent 2375743 commit d80ff12
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
12 changes: 6 additions & 6 deletions src/librustc_trans/trans/_match.rs
Expand Up @@ -886,9 +886,9 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
&format!("comparison of `{}`", rhs_t),
StrEqFnLangItem);
let lhs_data = Load(cx, expr::get_dataptr(cx, lhs));
let lhs_len = Load(cx, expr::get_len(cx, lhs));
let lhs_len = Load(cx, expr::get_meta(cx, lhs));
let rhs_data = Load(cx, expr::get_dataptr(cx, rhs));
let rhs_len = Load(cx, expr::get_len(cx, rhs));
let rhs_len = Load(cx, expr::get_meta(cx, rhs));
callee::trans_lang_call(cx, did, &[lhs_data, lhs_len, rhs_data, rhs_len], None, debug_loc)
}

Expand All @@ -910,14 +910,14 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,

let rhs_str = alloc_ty(cx, ty_str_slice, "rhs_str");
Store(cx, GEPi(cx, rhs, &[0, 0]), expr::get_dataptr(cx, rhs_str));
Store(cx, C_uint(cx.ccx(), pat_len), expr::get_len(cx, rhs_str));
Store(cx, C_uint(cx.ccx(), pat_len), expr::get_meta(cx, rhs_str));

let lhs_str;
if val_ty(lhs) == val_ty(rhs) {
// Both the discriminant and the pattern are thin pointers
lhs_str = alloc_ty(cx, ty_str_slice, "lhs_str");
Store(cx, GEPi(cx, lhs, &[0, 0]), expr::get_dataptr(cx, lhs_str));
Store(cx, C_uint(cx.ccx(), pat_len), expr::get_len(cx, lhs_str));
Store(cx, C_uint(cx.ccx(), pat_len), expr::get_meta(cx, lhs_str));
}
else {
// The discriminant is a fat pointer
Expand Down Expand Up @@ -1196,9 +1196,9 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
let llty = type_of::type_of(bcx.ccx(), unsized_ty);
let scratch = alloca_no_lifetime(bcx, llty, "__struct_field_fat_ptr");
let data = adt::trans_field_ptr(bcx, &*repr, struct_val, 0, arg_count);
let len = Load(bcx, expr::get_len(bcx, val.val));
let len = Load(bcx, expr::get_meta(bcx, val.val));
Store(bcx, data, expr::get_dataptr(bcx, scratch));
Store(bcx, len, expr::get_len(bcx, scratch));
Store(bcx, len, expr::get_meta(bcx, scratch));
field_vals.push(scratch);
}
_ => {}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_trans/trans/base.rs
Expand Up @@ -835,7 +835,7 @@ pub fn store_ty<'blk, 'tcx>(cx: Block<'blk, 'tcx>, v: ValueRef, dst: ValueRef, t

if common::type_is_fat_ptr(cx.tcx(), t) {
Store(cx, ExtractValue(cx, v, abi::FAT_PTR_ADDR), expr::get_dataptr(cx, dst));
Store(cx, ExtractValue(cx, v, abi::FAT_PTR_EXTRA), expr::get_len(cx, dst));
Store(cx, ExtractValue(cx, v, abi::FAT_PTR_EXTRA), expr::get_meta(cx, dst));
} else {
let store = Store(cx, from_arg_ty(cx, v, t), to_arg_ty_ptr(cx, dst, t));
unsafe {
Expand Down Expand Up @@ -1389,7 +1389,7 @@ pub fn create_datums_for_fn_args<'a, 'tcx>(mut bcx: Block<'a, 'tcx>,
arg_scope_id, (data, extra),
|(data, extra), bcx, dst| {
Store(bcx, data, expr::get_dataptr(bcx, dst));
Store(bcx, extra, expr::get_len(bcx, dst));
Store(bcx, extra, expr::get_meta(bcx, dst));
bcx
}))
} else {
Expand Down Expand Up @@ -1420,7 +1420,7 @@ pub fn create_datums_for_fn_args<'a, 'tcx>(mut bcx: Block<'a, 'tcx>,
let data = get_param(bcx.fcx.llfn, idx);
let extra = get_param(bcx.fcx.llfn, idx + 1);
Store(bcx, data, expr::get_dataptr(bcx, lldest));
Store(bcx, extra, expr::get_len(bcx, lldest));
Store(bcx, extra, expr::get_meta(bcx, lldest));
idx += 2;
} else {
let datum = datum::Datum::new(
Expand Down Expand Up @@ -1822,7 +1822,7 @@ fn trans_enum_variant_or_tuple_like_struct<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx
i);
if common::type_is_fat_ptr(bcx.tcx(), arg_ty) {
Store(bcx, get_param(fcx.llfn, llarg_idx), expr::get_dataptr(bcx, lldestptr));
Store(bcx, get_param(fcx.llfn, llarg_idx + 1), expr::get_len(bcx, lldestptr));
Store(bcx, get_param(fcx.llfn, llarg_idx + 1), expr::get_meta(bcx, lldestptr));
llarg_idx += 2;
} else {
let arg = get_param(fcx.llfn, llarg_idx);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/callee.rs
Expand Up @@ -1128,7 +1128,7 @@ pub fn trans_arg_datum<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,

if common::type_is_fat_ptr(bcx.tcx(), formal_arg_ty) {
llargs.push(Load(bcx, expr::get_dataptr(bcx, val)));
llargs.push(Load(bcx, expr::get_len(bcx, val)));
llargs.push(Load(bcx, expr::get_meta(bcx, val)));
} else {
llargs.push(val);
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_trans/trans/expr.rs
Expand Up @@ -282,7 +282,7 @@ pub fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
return DatumBlock::new(bcx, datum);
}

pub fn get_len(bcx: Block, fat_ptr: ValueRef) -> ValueRef {
pub fn get_meta(bcx: Block, fat_ptr: ValueRef) -> ValueRef {
GEPi(bcx, fat_ptr, &[0, abi::FAT_PTR_EXTRA])
}

Expand All @@ -292,7 +292,7 @@ pub fn get_dataptr(bcx: Block, fat_ptr: ValueRef) -> ValueRef {

pub fn copy_fat_ptr(bcx: Block, src_ptr: ValueRef, dst_ptr: ValueRef) {
Store(bcx, Load(bcx, get_dataptr(bcx, src_ptr)), get_dataptr(bcx, dst_ptr));
Store(bcx, Load(bcx, get_len(bcx, src_ptr)), get_len(bcx, dst_ptr));
Store(bcx, Load(bcx, get_meta(bcx, src_ptr)), get_meta(bcx, dst_ptr));
}

/// Retrieve the information we are losing (making dynamic) in an unsizing
Expand Down Expand Up @@ -454,7 +454,7 @@ fn coerce_unsized<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
// load out the original data pointer so we can repackage
// it.
(Load(bcx, get_dataptr(bcx, source.val)),
Some(Load(bcx, get_len(bcx, source.val))))
Some(Load(bcx, get_meta(bcx, source.val))))
} else {
let val = if source.kind.is_by_ref() {
load_ty(bcx, source.val, source.ty)
Expand All @@ -473,7 +473,7 @@ fn coerce_unsized<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let base = PointerCast(bcx, base, ptr_ty);

Store(bcx, base, get_dataptr(bcx, target.val));
Store(bcx, info, get_len(bcx, target.val));
Store(bcx, info, get_meta(bcx, target.val));
}

// This can be extended to enums and tuples in the future.
Expand Down Expand Up @@ -729,8 +729,8 @@ fn trans_field<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
} else {
let scratch = rvalue_scratch_datum(bcx, d.ty, "");
Store(bcx, d.val, get_dataptr(bcx, scratch.val));
let info = Load(bcx, get_len(bcx, base_datum.val));
Store(bcx, info, get_len(bcx, scratch.val));
let info = Load(bcx, get_meta(bcx, base_datum.val));
Store(bcx, info, get_meta(bcx, scratch.val));

// Always generate an lvalue datum, because this pointer doesn't own
// the data and cleanup is scheduled elsewhere.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/foreign.rs
Expand Up @@ -302,7 +302,7 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
"__arg");
if type_is_fat_ptr(ccx.tcx(), passed_arg_tys[i]) {
Store(bcx, llargs_rust[i + offset], expr::get_dataptr(bcx, scratch));
Store(bcx, llargs_rust[i + offset + 1], expr::get_len(bcx, scratch));
Store(bcx, llargs_rust[i + offset + 1], expr::get_meta(bcx, scratch));
offset += 1;
} else {
base::store_ty(bcx, llarg_rust, scratch, passed_arg_tys[i]);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/glue.rs
Expand Up @@ -389,7 +389,7 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let (_, bcx) = if type_is_sized(bcx.tcx(), t) {
invoke(bcx, dtor_addr, &[v0], dtor_ty, DebugLoc::None)
} else {
let args = [Load(bcx, expr::get_dataptr(bcx, v0)), Load(bcx, expr::get_len(bcx, v0))];
let args = [Load(bcx, expr::get_dataptr(bcx, v0)), Load(bcx, expr::get_meta(bcx, v0))];
invoke(bcx, dtor_addr, &args, dtor_ty, DebugLoc::None)
};

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/intrinsic.rs
Expand Up @@ -449,7 +449,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
} else {
let scratch = rvalue_scratch_datum(bcx, tp_ty, "tmp");
Store(bcx, llargs[0], expr::get_dataptr(bcx, scratch.val));
Store(bcx, llargs[1], expr::get_len(bcx, scratch.val));
Store(bcx, llargs[1], expr::get_meta(bcx, scratch.val));
fcx.schedule_lifetime_end(cleanup::CustomScope(cleanup_scope), scratch.val);
scratch.val
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/tvec.rs
Expand Up @@ -310,7 +310,7 @@ pub fn get_base_and_len<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
ty::TyArray(_, n) => get_fixed_base_and_len(bcx, llval, n),
ty::TySlice(_) | ty::TyStr => {
let base = Load(bcx, expr::get_dataptr(bcx, llval));
let len = Load(bcx, expr::get_len(bcx, llval));
let len = Load(bcx, expr::get_meta(bcx, llval));
(base, len)
}

Expand Down

0 comments on commit d80ff12

Please sign in to comment.