Skip to content
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

Make binary operators take their arguments by value #19448

Merged
merged 30 commits into from
Dec 16, 2014
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
14c0a70
syntax/ast_util: add `is_by_value_binop()`
Dec 1, 2014
c3a6d28
Tell typeck which binops are by value
Dec 1, 2014
f64e52a
Tell trans which binops are by value
Dec 1, 2014
5038f5a
Tell expr_use_visitor which binops are by value
Dec 1, 2014
227435a
Tell regionck which binops are by value
Dec 1, 2014
c73259a
libcore: convert binop traits to by value
Dec 1, 2014
65d3a40
libcore: fix move semantics fallout
Dec 1, 2014
dbc7e17
libcollections: Vec<T> + &[T]
Dec 1, 2014
076e932
libcollections: String + &str
Dec 1, 2014
baf79d4
libcollections: make `EnumSet` binops by value
Dec 1, 2014
32168fa
libstd: convert `BitFlags` binops to by value
Dec 1, 2014
9126a24
libstd: convert `Duration` binops to by value
Dec 1, 2014
b5537fa
libtime: convert `Timespec` binops to by value
Dec 1, 2014
265b89a
libsyntax: convert `BytePos`/`CharPos` binops to by value
Dec 1, 2014
c4fa2a3
libsyntax: convert `LockstepIterSize` binops to by value
Dec 1, 2014
eb71976
librustc: convert `TypeContents` binops to by value
Dec 1, 2014
fb1d4f1
librustdoc: convert `Counts` binops to by value
Dec 1, 2014
2b17083
Test that binops consume their arguments
Dec 1, 2014
971add8
Fix run-pass tests
Dec 1, 2014
f0b6567
Fix compile-fail tests
Dec 1, 2014
a672b27
libcollections: fix unit tests
Dec 1, 2014
1ec5650
libcoretest: fix unit tests
Dec 1, 2014
bc23b8e
libstd: fix unit tests
Dec 1, 2014
d193bf3
libcore: fix doctests
Dec 2, 2014
f4abb12
Address Niko's comments
Dec 3, 2014
949b55e
libcollections: add commutative version of `Vec`/`String` addition
Dec 3, 2014
dff2b39
Test binops move semantics
Dec 3, 2014
3084604
libcollections: convert `TrieSet` binops to by value
Dec 6, 2014
e00e461
libcollections: convert `TreeSet` binops to by value
Dec 13, 2014
89d2061
libcollections: convert `BTreeSet` binops to by value
Dec 13, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tell trans which binops are by value
  • Loading branch information
Jorge Aparicio committed Dec 14, 2014
commit f64e52a7f703ecb18cbf7c39bd1479cd99bd20ae
11 changes: 6 additions & 5 deletions src/librustc_trans/trans/callee.rs
Original file line number Diff line number Diff line change
@@ -996,10 +996,11 @@ pub enum CallArgs<'a, 'tcx> {
// value.
ArgVals(&'a [ValueRef]),

// For overloaded operators: `(lhs, Vec(rhs, rhs_id))`. `lhs`
// For overloaded operators: `(lhs, Vec(rhs, rhs_id), autoref)`. `lhs`
// is the left-hand-side and `rhs/rhs_id` is the datum/expr-id of
// the right-hand-side arguments (if any).
ArgOverloadedOp(Datum<'tcx, Expr>, Vec<(Datum<'tcx, Expr>, ast::NodeId)>),
// the right-hand-side arguments (if any). `autoref` indicates whether the `rhs`
// arguments should be auto-referenced
ArgOverloadedOp(Datum<'tcx, Expr>, Vec<(Datum<'tcx, Expr>, ast::NodeId)>, bool),

// Supply value of arguments as a list of expressions that must be
// translated, for overloaded call operators.
@@ -1171,7 +1172,7 @@ pub fn trans_args<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>,
arg_cleanup_scope,
ignore_self)
}
ArgOverloadedOp(lhs, rhs) => {
ArgOverloadedOp(lhs, rhs, autoref) => {
assert!(!variadic);

llargs.push(unpack_result!(bcx, {
@@ -1185,7 +1186,7 @@ pub fn trans_args<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>,
llargs.push(unpack_result!(bcx, {
trans_arg_datum(bcx, arg_tys[1], rhs,
arg_cleanup_scope,
DoAutorefArg(rhs_id))
if autoref { DoAutorefArg(rhs_id) } else { DontAutorefArg })
}));
}
}
23 changes: 14 additions & 9 deletions src/librustc_trans/trans/expr.rs
Original file line number Diff line number Diff line change
@@ -609,7 +609,8 @@ fn trans_datum_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
method_call,
base_datum,
args,
Some(SaveIn(scratch.val))));
Some(SaveIn(scratch.val)),
true));
DatumBlock::new(bcx, scratch.to_expr_datum())
}
ast::ExprBox(_, ref contents) => {
@@ -762,7 +763,8 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
method_call,
base_datum,
vec![(ix_datum, idx.id)],
Some(SaveIn(scratch.val))));
Some(SaveIn(scratch.val)),
true));
let datum = scratch.to_expr_datum();
if ty::type_is_sized(bcx.tcx(), elt_ty) {
Datum::new(datum.to_llscalarish(bcx), elt_ty, LvalueExpr)
@@ -1092,25 +1094,26 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
callee::ArgExprs(args.as_slice()),
dest)
}
ast::ExprBinary(_, ref lhs, ref rhs) => {
ast::ExprBinary(op, ref lhs, ref rhs) => {
// if not overloaded, would be RvalueDatumExpr
let lhs = unpack_datum!(bcx, trans(bcx, &**lhs));
let rhs_datum = unpack_datum!(bcx, trans(bcx, &**rhs));
trans_overloaded_op(bcx, expr, MethodCall::expr(expr.id), lhs,
vec![(rhs_datum, rhs.id)], Some(dest)).bcx
vec![(rhs_datum, rhs.id)], Some(dest),
!ast_util::is_by_value_binop(op)).bcx
}
ast::ExprUnary(_, ref subexpr) => {
// if not overloaded, would be RvalueDatumExpr
let arg = unpack_datum!(bcx, trans(bcx, &**subexpr));
trans_overloaded_op(bcx, expr, MethodCall::expr(expr.id),
arg, Vec::new(), Some(dest)).bcx
arg, Vec::new(), Some(dest), true).bcx
}
ast::ExprIndex(ref base, ref idx) => {
// if not overloaded, would be RvalueDatumExpr
let base = unpack_datum!(bcx, trans(bcx, &**base));
let idx_datum = unpack_datum!(bcx, trans(bcx, &**idx));
trans_overloaded_op(bcx, expr, MethodCall::expr(expr.id), base,
vec![(idx_datum, idx.id)], Some(dest)).bcx
vec![(idx_datum, idx.id)], Some(dest), true).bcx
}
ast::ExprCast(ref val, _) => {
// DPS output mode means this is a trait cast:
@@ -1803,7 +1806,8 @@ fn trans_overloaded_op<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
method_call: MethodCall,
lhs: Datum<'tcx, Expr>,
rhs: Vec<(Datum<'tcx, Expr>, ast::NodeId)>,
dest: Option<Dest>)
dest: Option<Dest>,
autoref: bool)
-> Result<'blk, 'tcx> {
let method_ty = (*bcx.tcx().method_map.borrow())[method_call].ty;
callee::trans_call_inner(bcx,
@@ -1815,7 +1819,7 @@ fn trans_overloaded_op<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
None,
arg_cleanup_scope)
},
callee::ArgOverloadedOp(lhs, rhs),
callee::ArgOverloadedOp(lhs, rhs, autoref),
dest)
}

@@ -2122,7 +2126,8 @@ fn deref_once<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let scratch = rvalue_scratch_datum(bcx, ref_ty, "overloaded_deref");

unpack_result!(bcx, trans_overloaded_op(bcx, expr, method_call,
datum, Vec::new(), Some(SaveIn(scratch.val))));
datum, Vec::new(), Some(SaveIn(scratch.val)),
false));
scratch.to_expr_datum()
}
None => {