Skip to content

Commit f64f4fc

Browse files
committed
---
yaml --- r: 60844 b: refs/heads/auto c: 5209709 h: refs/heads/master v: v3
1 parent efe9dc3 commit f64f4fc

File tree

14 files changed

+228
-223
lines changed

14 files changed

+228
-223
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: a39429887a570f05c5da3e5dc8dfbcb6eea98f49
17+
refs/heads/auto: 5209709e46ecfac2fd4db527952fe7ef96400801
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/doc/rust.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,8 +2033,7 @@ as
20332033
=
20342034
~~~~
20352035

2036-
Operators at the same precedence level are evaluated left-to-right. [Unary operators](#unary-operator-expressions)
2037-
have the same precedence level and it is stronger than any of the binary operators'.
2036+
Operators at the same precedence level are evaluated left-to-right.
20382037

20392038
### Grouped expressions
20402039

branches/auto/src/librustc/middle/trans/_match.rs

Lines changed: 82 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@
140140
* the various values we copied explicitly. Note that guards and moves are
141141
* just plain incompatible.
142142
*
143+
* Some relevant helper functions that manage bindings:
144+
* - `create_bindings_map()`
145+
* - `store_non_ref_bindings()`
146+
* - `insert_lllocals()`
147+
*
143148
*/
144149

145150
use core::prelude::*;
@@ -314,7 +319,6 @@ pub fn variant_opt(bcx: block, pat_id: ast::node_id)
314319
pub enum TransBindingMode {
315320
TrByValue(/*ismove:*/ bool, /*llbinding:*/ ValueRef),
316321
TrByRef,
317-
TrByImplicitRef
318322
}
319323

320324
/**
@@ -670,8 +674,8 @@ pub fn enter_tup<'r>(bcx: block,
670674
let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
671675
do enter_match(bcx, dm, m, col, val) |p| {
672676
match p.node {
673-
ast::pat_tup(/*bad*/copy elts) => {
674-
Some(elts)
677+
ast::pat_tup(ref elts) => {
678+
Some(copy *elts)
675679
}
676680
_ => {
677681
assert_is_binding_or_wild(bcx, p);
@@ -698,7 +702,7 @@ pub fn enter_tuple_struct<'r>(bcx: block,
698702
let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
699703
do enter_match(bcx, dm, m, col, val) |p| {
700704
match p.node {
701-
ast::pat_enum(_, Some(/*bad*/copy elts)) => Some(elts),
705+
ast::pat_enum(_, Some(ref elts)) => Some(copy *elts),
702706
_ => {
703707
assert_is_binding_or_wild(bcx, p);
704708
Some(vec::from_elem(n_elts, dummy))
@@ -881,7 +885,7 @@ fn match_datum(bcx: block, val: ValueRef, pat_id: ast::node_id) -> Datum {
881885
//! we should just pass around a Datum and be done with it.
882886
883887
let ty = node_id_type(bcx, pat_id);
884-
Datum {val: val, ty: ty, mode: datum::ByRef, source: RevokeClean}
888+
Datum {val: val, ty: ty, mode: datum::ByRef(RevokeClean)}
885889
}
886890

887891

@@ -988,7 +992,7 @@ pub fn root_pats_as_necessary(mut bcx: block,
988992
let pat_id = br.pats[col].id;
989993
if pat_id != 0 {
990994
let datum = Datum {val: val, ty: node_id_type(bcx, pat_id),
991-
mode: ByRef, source: ZeroMem};
995+
mode: ByRef(ZeroMem)};
992996
bcx = datum.root_and_write_guard(bcx, br.pats[col].span, pat_id, 0);
993997
}
994998
}
@@ -1125,10 +1129,10 @@ pub fn compare_values(cx: block,
11251129
}
11261130
}
11271131

1128-
pub fn store_non_ref_bindings(bcx: block,
1129-
data: &ArmData,
1130-
opt_temp_cleanups: Option<&mut ~[ValueRef]>)
1131-
-> block
1132+
fn store_non_ref_bindings(bcx: block,
1133+
bindings_map: &BindingsMap,
1134+
mut opt_temp_cleanups: Option<&mut ~[ValueRef]>)
1135+
-> block
11321136
{
11331137
/*!
11341138
*
@@ -1140,13 +1144,12 @@ pub fn store_non_ref_bindings(bcx: block,
11401144
*/
11411145

11421146
let mut bcx = bcx;
1143-
let mut opt_temp_cleanups = opt_temp_cleanups;
1144-
for data.bindings_map.each_value |&binding_info| {
1147+
for bindings_map.each_value |&binding_info| {
11451148
match binding_info.trmode {
11461149
TrByValue(is_move, lldest) => {
11471150
let llval = Load(bcx, binding_info.llmatch); // get a T*
11481151
let datum = Datum {val: llval, ty: binding_info.ty,
1149-
mode: ByRef, source: ZeroMem};
1152+
mode: ByRef(ZeroMem)};
11501153
bcx = {
11511154
if is_move {
11521155
datum.move_to(bcx, INIT, lldest)
@@ -1161,22 +1164,28 @@ pub fn store_non_ref_bindings(bcx: block,
11611164
temp_cleanups
11621165
}
11631166
}
1164-
TrByRef | TrByImplicitRef => {}
1167+
TrByRef => {}
11651168
}
11661169
}
11671170
return bcx;
11681171
}
11691172

1170-
pub fn insert_lllocals(bcx: block,
1171-
data: &ArmData,
1172-
add_cleans: bool) -> block {
1173+
fn insert_lllocals(bcx: block,
1174+
bindings_map: &BindingsMap,
1175+
binding_mode: IrrefutablePatternBindingMode,
1176+
add_cleans: bool) -> block {
11731177
/*!
1174-
*
11751178
* For each binding in `data.bindings_map`, adds an appropriate entry into
11761179
* the `fcx.lllocals` map. If add_cleans is true, then adds cleanups for
1177-
* the bindings. */
1180+
* the bindings.
1181+
*/
11781182

1179-
for data.bindings_map.each_value |&binding_info| {
1183+
let llmap = match binding_mode {
1184+
BindLocal => bcx.fcx.lllocals,
1185+
BindArgument => bcx.fcx.llargs
1186+
};
1187+
1188+
for bindings_map.each_value |&binding_info| {
11801189
let llval = match binding_info.trmode {
11811190
// By value bindings: use the stack slot that we
11821191
// copied/moved the value into
@@ -1192,17 +1201,12 @@ pub fn insert_lllocals(bcx: block,
11921201
TrByRef => {
11931202
binding_info.llmatch
11941203
}
1195-
1196-
// Ugly: for implicit ref, we actually want a T*, but
1197-
// we have a T**, so we had to load. This will go away
1198-
// once implicit refs go away.
1199-
TrByImplicitRef => {
1200-
Load(bcx, binding_info.llmatch)
1201-
}
12021204
};
12031205

1204-
bcx.fcx.lllocals.insert(binding_info.id,
1205-
local_mem(llval));
1206+
debug!("binding %? to %s",
1207+
binding_info.id,
1208+
val_str(bcx.ccx().tn, llval));
1209+
llmap.insert(binding_info.id, llval);
12061210
}
12071211
return bcx;
12081212
}
@@ -1223,8 +1227,8 @@ pub fn compile_guard(bcx: block,
12231227

12241228
let mut bcx = bcx;
12251229
let mut temp_cleanups = ~[];
1226-
bcx = store_non_ref_bindings(bcx, data, Some(&mut temp_cleanups));
1227-
bcx = insert_lllocals(bcx, data, false);
1230+
bcx = store_non_ref_bindings(bcx, &data.bindings_map, Some(&mut temp_cleanups));
1231+
bcx = insert_lllocals(bcx, &data.bindings_map, BindLocal, false);
12281232

12291233
let val = unpack_result!(bcx, {
12301234
do with_scope_result(bcx, guard_expr.info(),
@@ -1254,7 +1258,7 @@ pub fn compile_guard(bcx: block,
12541258
TrByValue(_, llval) => {
12551259
bcx = glue::drop_ty(bcx, llval, binding_info.ty);
12561260
}
1257-
TrByRef | TrByImplicitRef => {}
1261+
TrByRef => {}
12581262
}
12591263
bcx.fcx.lllocals.remove(&binding_info.id);
12601264
}
@@ -1621,6 +1625,42 @@ pub fn trans_match(bcx: block,
16211625
}
16221626
}
16231627

1628+
fn create_bindings_map(bcx: block, pat: @ast::pat) -> BindingsMap {
1629+
// Create the bindings map, which is a mapping from each binding name
1630+
// to an alloca() that will be the value for that local variable.
1631+
// Note that we use the names because each binding will have many ids
1632+
// from the various alternatives.
1633+
let ccx = bcx.ccx();
1634+
let tcx = bcx.tcx();
1635+
let mut bindings_map = HashMap::new();
1636+
do pat_bindings(tcx.def_map, pat) |bm, p_id, _s, path| {
1637+
let ident = path_to_ident(path);
1638+
let variable_ty = node_id_type(bcx, p_id);
1639+
let llvariable_ty = type_of::type_of(ccx, variable_ty);
1640+
1641+
let llmatch, trmode;
1642+
match bm {
1643+
ast::bind_by_copy | ast::bind_infer => {
1644+
// in this case, the final type of the variable will be T,
1645+
// but during matching we need to store a *T as explained
1646+
// above
1647+
let is_move = ccx.maps.moves_map.contains(&p_id);
1648+
llmatch = alloca(bcx, T_ptr(llvariable_ty));
1649+
trmode = TrByValue(is_move, alloca(bcx, llvariable_ty));
1650+
}
1651+
ast::bind_by_ref(_) => {
1652+
llmatch = alloca(bcx, llvariable_ty);
1653+
trmode = TrByRef;
1654+
}
1655+
};
1656+
bindings_map.insert(ident, BindingInfo {
1657+
llmatch: llmatch, trmode: trmode,
1658+
id: p_id, ty: variable_ty
1659+
});
1660+
}
1661+
return bindings_map;
1662+
}
1663+
16241664
pub fn trans_match_inner(scope_cx: block,
16251665
discr_expr: @ast::expr,
16261666
arms: &[ast::arm],
@@ -1637,41 +1677,9 @@ pub fn trans_match_inner(scope_cx: block,
16371677
}
16381678

16391679
let mut arm_datas = ~[], matches = ~[];
1640-
for arms.each |arm| {
1680+
for vec::each(arms) |arm| {
16411681
let body = scope_block(bcx, arm.body.info(), "case_body");
1642-
1643-
// Create the bindings map, which is a mapping from each binding name
1644-
// to an alloca() that will be the value for that local variable.
1645-
// Note that we use the names because each binding will have many ids
1646-
// from the various alternatives.
1647-
let mut bindings_map = HashMap::new();
1648-
do pat_bindings(tcx.def_map, arm.pats[0]) |bm, p_id, _s, path| {
1649-
let ident = path_to_ident(path);
1650-
let variable_ty = node_id_type(bcx, p_id);
1651-
let llvariable_ty = type_of::type_of(bcx.ccx(), variable_ty);
1652-
1653-
let llmatch, trmode;
1654-
match bm {
1655-
ast::bind_by_copy | ast::bind_infer => {
1656-
// in this case, the final type of the variable will be T,
1657-
// but during matching we need to store a *T as explained
1658-
// above
1659-
let is_move =
1660-
scope_cx.ccx().maps.moves_map.contains(&p_id);
1661-
llmatch = alloca(bcx, T_ptr(llvariable_ty));
1662-
trmode = TrByValue(is_move, alloca(bcx, llvariable_ty));
1663-
}
1664-
ast::bind_by_ref(_) => {
1665-
llmatch = alloca(bcx, llvariable_ty);
1666-
trmode = TrByRef;
1667-
}
1668-
};
1669-
bindings_map.insert(ident, BindingInfo {
1670-
llmatch: llmatch, trmode: trmode,
1671-
id: p_id, ty: variable_ty
1672-
});
1673-
}
1674-
1682+
let bindings_map = create_bindings_map(bcx, arm.pats[0]);
16751683
let arm_data = @ArmData {bodycx: body,
16761684
arm: arm,
16771685
bindings_map: bindings_map};
@@ -1693,7 +1701,7 @@ pub fn trans_match_inner(scope_cx: block,
16931701
None
16941702
}
16951703
};
1696-
let lldiscr = discr_datum.to_ref_llval(bcx);
1704+
let lldiscr = discr_datum.to_zeroable_ref_llval(bcx);
16971705
compile_submatch(bcx, matches, [lldiscr], chk);
16981706

16991707
let mut arm_cxs = ~[];
@@ -1705,11 +1713,11 @@ pub fn trans_match_inner(scope_cx: block,
17051713
// is just to reduce code space. See extensive comment at the start
17061714
// of the file for more details.
17071715
if arm_data.arm.guard.is_none() {
1708-
bcx = store_non_ref_bindings(bcx, *arm_data, None);
1716+
bcx = store_non_ref_bindings(bcx, &arm_data.bindings_map, None);
17091717
}
17101718

17111719
// insert bindings into the lllocals map and add cleanups
1712-
bcx = insert_lllocals(bcx, *arm_data, true);
1720+
bcx = insert_lllocals(bcx, &arm_data.bindings_map, BindLocal, true);
17131721

17141722
bcx = controlflow::trans_block(bcx, &arm_data.arm.body, dest);
17151723
bcx = trans_block_cleanups(bcx, block_cleanups(arm_data.bodycx));
@@ -1757,27 +1765,25 @@ pub fn bind_irrefutable_pat(bcx: block,
17571765
if make_copy {
17581766
let binding_ty = node_id_type(bcx, pat.id);
17591767
let datum = Datum {val: val, ty: binding_ty,
1760-
mode: ByRef, source: RevokeClean};
1768+
mode: ByRef(RevokeClean)};
17611769
let scratch = scratch_datum(bcx, binding_ty, false);
17621770
datum.copy_to_datum(bcx, INIT, scratch);
17631771
match binding_mode {
17641772
BindLocal => {
1765-
bcx.fcx.lllocals.insert(pat.id,
1766-
local_mem(scratch.val));
1773+
bcx.fcx.lllocals.insert(pat.id, scratch.val);
17671774
}
17681775
BindArgument => {
1769-
bcx.fcx.llargs.insert(pat.id,
1770-
local_mem(scratch.val));
1776+
bcx.fcx.llargs.insert(pat.id, scratch.val);
17711777
}
17721778
}
17731779
add_clean(bcx, scratch.val, binding_ty);
17741780
} else {
17751781
match binding_mode {
17761782
BindLocal => {
1777-
bcx.fcx.lllocals.insert(pat.id, local_mem(val));
1783+
bcx.fcx.lllocals.insert(pat.id, val);
17781784
}
17791785
BindArgument => {
1780-
bcx.fcx.llargs.insert(pat.id, local_mem(val));
1786+
bcx.fcx.llargs.insert(pat.id, val);
17811787
}
17821788
}
17831789
}

branches/auto/src/librustc/middle/trans/base.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,8 +1105,8 @@ pub fn init_local(bcx: block, local: @ast::local) -> block {
11051105
}
11061106
}
11071107

1108-
let llptr = match bcx.fcx.lllocals.find(&local.node.id) {
1109-
Some(&local_mem(v)) => v,
1108+
let llptr = match bcx.fcx.lllocals.find_copy(&local.node.id) {
1109+
Some(v) => v,
11101110
_ => {
11111111
bcx.tcx().sess.span_bug(local.span,
11121112
"init_local: Someone forgot to document why it's\
@@ -1432,7 +1432,7 @@ pub fn alloc_local(cx: block, local: @ast::local) -> block {
14321432
});
14331433
}
14341434
}
1435-
cx.fcx.lllocals.insert(local.node.id, local_mem(val));
1435+
cx.fcx.lllocals.insert(local.node.id, val);
14361436
cx
14371437
}
14381438

@@ -1726,7 +1726,7 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt,
17261726
let mut bcx = bcx;
17271727

17281728
match fcx.llself {
1729-
Some(copy slf) => {
1729+
Some(slf) => {
17301730
// We really should do this regardless of whether self is owned, but
17311731
// it doesn't work right with default method impls yet. (FIXME: #2794)
17321732
if slf.is_owned {
@@ -1768,7 +1768,7 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt,
17681768
false,
17691769
_match::BindArgument);
17701770

1771-
fcx.llargs.insert(arg_id, local_mem(llarg));
1771+
fcx.llargs.insert(arg_id, llarg);
17721772

17731773
if fcx.ccx.sess.opts.extra_debuginfo && fcx_has_nonzero_span(fcx) {
17741774
debuginfo::create_arg(bcx, args[arg_n], args[arg_n].ty.span);
@@ -1801,7 +1801,7 @@ pub fn build_return_block(fcx: fn_ctxt) {
18011801
pub fn tie_up_header_blocks(fcx: fn_ctxt, lltop: BasicBlockRef) {
18021802
let _icx = fcx.insn_ctxt("tie_up_header_blocks");
18031803
match fcx.llloadenv {
1804-
Some(copy ll) => {
1804+
Some(ll) => {
18051805
Br(raw_block(fcx, false, fcx.llstaticallocas), ll);
18061806
Br(raw_block(fcx, false, ll), lltop);
18071807
}
@@ -2004,7 +2004,7 @@ pub fn trans_enum_variant(ccx: @CrateContext,
20042004
// this function as an opaque blob due to the way that type_of()
20052005
// works. So we have to cast to the destination's view of the type.
20062006
let llarg = match fcx.llargs.find(&va.id) {
2007-
Some(&local_mem(x)) => x,
2007+
Some(&x) => x,
20082008
_ => fail!("trans_enum_variant: how do we know this works?"),
20092009
};
20102010
let arg_ty = arg_tys[i];
@@ -2074,12 +2074,7 @@ pub fn trans_tuple_struct(ccx: @CrateContext,
20742074
fcx.llretptr.get(),
20752075
0,
20762076
i);
2077-
let llarg = match fcx.llargs.get_copy(&field.node.id) {
2078-
local_mem(x) => x,
2079-
_ => {
2080-
ccx.tcx.sess.bug("trans_tuple_struct: llarg wasn't local_mem")
2081-
}
2082-
};
2077+
let llarg = fcx.llargs.get_copy(&field.node.id);
20832078
let arg_ty = arg_tys[i];
20842079
memcpy_ty(bcx, lldestptr, llarg, arg_ty);
20852080
}

0 commit comments

Comments
 (0)