Skip to content

Commit 199b766

Browse files
committed
auto merge of #13004 : eddyb/rust/datumize, r=nikomatsakis
Datums are safer than plain ValueRefs, as they hold a type and a kind (specifying how the value should be handled), and potentially more efficient (e.g. repeated type lookups can be expensive, because of substitutions). This PR begins the conversion of old code using ValueRefs to Datums. It also introduces a new Datum kind, PodValue, which can be freely shared, akin to an Lvalue.
2 parents 11d9483 + 575fb68 commit 199b766

18 files changed

+854
-1030
lines changed

src/librustc/middle/trans/_match.rs

+8-18
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ use driver::session::FullDebugInfo;
199199
use lib::llvm::{llvm, ValueRef, BasicBlockRef};
200200
use middle::const_eval;
201201
use middle::borrowck::root_map_key;
202-
use middle::lang_items::{UniqStrEqFnLangItem, StrEqFnLangItem};
202+
use middle::lang_items::StrEqFnLangItem;
203203
use middle::pat_util::*;
204204
use middle::resolve::DefMap;
205205
use middle::trans::adt;
@@ -1278,30 +1278,20 @@ fn compare_values<'a>(
12781278
-> Result<'a> {
12791279
let _icx = push_ctxt("compare_values");
12801280
if ty::type_is_scalar(rhs_t) {
1281-
let rs = compare_scalar_types(cx, lhs, rhs, rhs_t, ast::BiEq);
1282-
return rslt(rs.bcx, rs.val);
1281+
return compare_scalar_types(cx, lhs, rhs, rhs_t, ast::BiEq);
12831282
}
12841283

12851284
match ty::get(rhs_t).sty {
1286-
ty::ty_str(ty::vstore_uniq) => {
1287-
let scratch_lhs = alloca(cx, val_ty(lhs), "__lhs");
1288-
Store(cx, lhs, scratch_lhs);
1289-
let scratch_rhs = alloca(cx, val_ty(rhs), "__rhs");
1290-
Store(cx, rhs, scratch_rhs);
1291-
let did = langcall(cx, None,
1292-
format!("comparison of `{}`", cx.ty_to_str(rhs_t)),
1293-
UniqStrEqFnLangItem);
1294-
let result = callee::trans_lang_call(cx, did, [scratch_lhs, scratch_rhs], None);
1295-
Result {
1296-
bcx: result.bcx,
1297-
val: bool_to_i1(result.bcx, result.val)
1298-
}
1299-
}
13001285
ty::ty_str(_) => {
13011286
let did = langcall(cx, None,
13021287
format!("comparison of `{}`", cx.ty_to_str(rhs_t)),
13031288
StrEqFnLangItem);
1304-
let result = callee::trans_lang_call(cx, did, [lhs, rhs], None);
1289+
let result = callee::trans_call(cx, None,
1290+
callee::Fn(callee::trans_fn_ref_with_vtables(cx, did, ExprId(0), [], None)),
1291+
[lhs, rhs].iter(), |bcx, &val| {
1292+
DatumBlock(bcx, Datum(val, rhs_t, RvalueExpr(Rvalue(ByRef))))
1293+
},
1294+
None);
13051295
Result {
13061296
bcx: result.bcx,
13071297
val: bool_to_i1(result.bcx, result.val)

src/librustc/middle/trans/asm.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ pub fn trans_inline_asm<'a>(bcx: &'a Block<'a>, ia: &ast::InlineAsm)
4848
// Now the input operands
4949
let inputs = ia.inputs.map(|&(ref c, input)| {
5050
constraints.push((*c).clone());
51-
52-
let in_datum = unpack_datum!(bcx, expr::trans(bcx, input));
53-
unpack_result!(bcx, {
54-
callee::trans_arg_datum(bcx,
55-
expr_ty(bcx, input),
56-
in_datum,
57-
cleanup::CustomScope(temp_scope),
58-
callee::DontAutorefArg)
59-
})
51+
let input = expr::trans(bcx, input);
52+
let input_ty = input.datum.ty;
53+
let input = unpack_datum!(bcx, {
54+
callee::trans_arg_datum(input, input_ty,
55+
cleanup::CustomScope(temp_scope))
56+
});
57+
input.val
6058
});
6159

6260
// no failure occurred preparing operands, no need to cleanup

0 commit comments

Comments
 (0)