@@ -1392,37 +1392,41 @@ fn insert_lllocals<'a>(
1392
1392
let llval = match binding_info. trmode {
1393
1393
// By value bindings: use the stack slot that we
1394
1394
// copied/moved the value into
1395
- TrByValue ( lldest) => {
1396
- if add_cleans {
1397
- add_clean ( bcx , lldest , binding_info. ty ) ;
1398
- }
1395
+ TrByValue ( lldest) => lldest ,
1396
+ // By ref binding: use the ptr into the matched value
1397
+ TrByRef => binding_info. llmatch
1398
+ } ;
1399
1399
1400
- lldest
1401
- }
1400
+ let datum = Datum {
1401
+ val : llval,
1402
+ ty : binding_info. ty ,
1403
+ mode : ByRef ( ZeroMem )
1404
+ } ;
1402
1405
1403
- // By ref binding: use the ptr into the matched value
1404
- TrByRef => {
1405
- binding_info. llmatch
1406
+ if add_cleans {
1407
+ match binding_info. trmode {
1408
+ TrByValue ( _) => datum. add_clean ( bcx) ,
1409
+ _ => { }
1406
1410
}
1407
- } ;
1411
+ }
1408
1412
1409
1413
{
1410
1414
debug ! ( "binding {:?} to {}" ,
1411
1415
binding_info. id,
1412
1416
bcx. val_to_str( llval) ) ;
1413
1417
let mut llmap = bcx. fcx . lllocals . borrow_mut ( ) ;
1414
- llmap. get ( ) . insert ( binding_info. id , llval ) ;
1418
+ llmap. get ( ) . insert ( binding_info. id , datum ) ;
1415
1419
}
1416
1420
1417
1421
if bcx. sess ( ) . opts . extra_debuginfo {
1418
1422
debuginfo:: create_match_binding_metadata ( bcx,
1419
1423
ident,
1420
1424
binding_info. id ,
1421
- binding_info. ty ,
1422
- binding_info . span ) ;
1425
+ binding_info. span ,
1426
+ datum ) ;
1423
1427
}
1424
1428
}
1425
- return bcx;
1429
+ bcx
1426
1430
}
1427
1431
1428
1432
fn compile_guard < ' r ,
@@ -2032,8 +2036,7 @@ pub fn store_local<'a>(
2032
2036
Some ( path) => {
2033
2037
return mk_binding_alloca (
2034
2038
bcx, pat. id , path, BindLocal ,
2035
- |bcx, _, llval| expr:: trans_into ( bcx, init_expr,
2036
- expr:: SaveIn ( llval) ) ) ;
2039
+ |bcx, datum| expr:: trans_into ( bcx, init_expr, expr:: SaveIn ( datum. val ) ) ) ;
2037
2040
}
2038
2041
2039
2042
None => { }
@@ -2067,13 +2070,13 @@ pub fn store_local<'a>(
2067
2070
pat_bindings ( tcx. def_map , pat, |_, p_id, _, path| {
2068
2071
bcx = mk_binding_alloca (
2069
2072
bcx, p_id, path, BindLocal ,
2070
- |bcx, var_ty , llval | { zero_mem ( bcx, llval , var_ty ) ; bcx } ) ;
2073
+ |bcx, datum | { datum . cancel_clean ( bcx) ; bcx } ) ;
2071
2074
} ) ;
2072
2075
bcx
2073
2076
}
2074
2077
}
2075
2078
2076
- pub fn store_arg < ' a > ( mut bcx : & ' a Block < ' a > , pat : @ast:: Pat , llval : ValueRef )
2079
+ pub fn store_arg < ' a > ( mut bcx : & ' a Block < ' a > , pat : @ast:: Pat , arg : Datum )
2077
2080
-> & ' a Block < ' a > {
2078
2081
/*!
2079
2082
* Generates code for argument patterns like `fn foo(<pat>: T)`.
@@ -2093,13 +2096,12 @@ pub fn store_arg<'a>(mut bcx: &'a Block<'a>, pat: @ast::Pat, llval: ValueRef)
2093
2096
// Note that we cannot do it before for fear of a fn like
2094
2097
// fn getaddr(~ref x: ~uint) -> *uint {....}
2095
2098
// (From test `run-pass/func-arg-ref-pattern.rs`)
2096
- let arg_ty = node_id_type ( bcx, pat. id ) ;
2097
- add_clean ( bcx, llval, arg_ty) ;
2099
+ arg. add_clean ( bcx) ;
2098
2100
2099
2101
// Debug information (the llvm.dbg.declare intrinsic to be precise) always expects to get an
2100
2102
// alloca, which only is the case on the general path, so lets disable the optimized path when
2101
2103
// debug info is enabled.
2102
- let arg_is_alloca = unsafe { llvm:: LLVMIsAAllocaInst ( llval ) != ptr:: null ( ) } ;
2104
+ let arg_is_alloca = unsafe { llvm:: LLVMIsAAllocaInst ( arg . val ) != ptr:: null ( ) } ;
2103
2105
2104
2106
let fast_path = ( arg_is_alloca || !bcx. ccx ( ) . sess . opts . extra_debuginfo )
2105
2107
&& simple_identifier ( pat) . is_some ( ) ;
@@ -2109,37 +2111,42 @@ pub fn store_arg<'a>(mut bcx: &'a Block<'a>, pat: @ast::Pat, llval: ValueRef)
2109
2111
// `llval` wholesale as the pointer for `x`, avoiding the
2110
2112
// general logic which may copy out of `llval`.
2111
2113
let mut llargs = bcx. fcx . llargs . borrow_mut ( ) ;
2112
- llargs. get ( ) . insert ( pat. id , llval ) ;
2114
+ llargs. get ( ) . insert ( pat. id , arg ) ;
2113
2115
} else {
2114
2116
// General path. Copy out the values that are used in the
2115
2117
// pattern.
2116
- bcx = bind_irrefutable_pat ( bcx, pat, llval, BindArgument ) ;
2118
+ let llptr = arg. to_ref_llval ( bcx) ;
2119
+ bcx = bind_irrefutable_pat ( bcx, pat, llptr, BindArgument ) ;
2117
2120
}
2118
2121
2119
2122
return bcx;
2120
2123
}
2121
2124
2122
2125
fn mk_binding_alloca < ' a > (
2123
- mut bcx : & ' a Block < ' a > ,
2126
+ bcx : & ' a Block < ' a > ,
2124
2127
p_id : ast:: NodeId ,
2125
2128
path : & ast:: Path ,
2126
2129
binding_mode : IrrefutablePatternBindingMode ,
2127
- populate : |& ' a Block < ' a > ,
2128
- ty:: t ,
2129
- ValueRef |
2130
- -> & ' a Block < ' a > )
2130
+ populate : |& ' a Block < ' a > , Datum | -> & ' a Block < ' a > )
2131
2131
-> & ' a Block < ' a > {
2132
2132
let var_ty = node_id_type( bcx, p_id) ;
2133
2133
let ident = ast_util:: path_to_ident ( path ) ;
2134
2134
let llval = alloc_ty ( bcx, var_ty, bcx. ident ( ident) ) ;
2135
- bcx = populate ( bcx , var_ty , llval ) ;
2136
- let mut llmap = match binding_mode {
2137
- BindLocal => bcx . fcx . lllocals . borrow_mut ( ) ,
2138
- BindArgument => bcx . fcx . llargs . borrow_mut ( ) ,
2135
+ let datum = Datum {
2136
+ val : llval ,
2137
+ ty : var_ty ,
2138
+ mode : ByRef ( ZeroMem )
2139
2139
} ;
2140
- llmap. get ( ) . insert ( p_id, llval) ;
2141
- add_clean ( bcx, llval, var_ty) ;
2142
- return bcx;
2140
+ {
2141
+ let mut llmap = match binding_mode {
2142
+ BindLocal => bcx. fcx . lllocals . borrow_mut ( ) ,
2143
+ BindArgument => bcx. fcx . llargs . borrow_mut ( )
2144
+ } ;
2145
+ llmap. get ( ) . insert ( p_id, datum) ;
2146
+ }
2147
+ let bcx = populate ( bcx, datum) ;
2148
+ datum. add_clean ( bcx) ;
2149
+ bcx
2143
2150
}
2144
2151
2145
2152
fn bind_irrefutable_pat < ' a > (
@@ -2179,7 +2186,7 @@ fn bind_irrefutable_pat<'a>(
2179
2186
2180
2187
let _indenter = indenter ( ) ;
2181
2188
2182
- let _icx = push_ctxt ( "alt ::bind_irrefutable_pat" ) ;
2189
+ let _icx = push_ctxt ( "match ::bind_irrefutable_pat" ) ;
2183
2190
let mut bcx = bcx;
2184
2191
let tcx = bcx. tcx ( ) ;
2185
2192
let ccx = bcx. ccx ( ) ;
@@ -2191,21 +2198,23 @@ fn bind_irrefutable_pat<'a>(
2191
2198
// map.
2192
2199
bcx = mk_binding_alloca (
2193
2200
bcx, pat. id , path, binding_mode,
2194
- |bcx, variable_ty , llvariable_val | {
2201
+ |bcx, var_datum | {
2195
2202
match pat_binding_mode {
2196
2203
ast:: BindByValue ( _) => {
2197
2204
// By value binding: move the value that `val`
2198
2205
// points at into the binding's stack slot.
2199
- let datum = Datum { val : val,
2200
- ty : variable_ty,
2201
- mode : ByRef ( ZeroMem ) } ;
2202
- datum. store_to ( bcx, INIT , llvariable_val)
2206
+ let datum = Datum {
2207
+ val : val,
2208
+ ty : var_datum. ty ,
2209
+ mode : ByRef ( ZeroMem )
2210
+ } ;
2211
+ datum. store_to ( bcx, INIT , var_datum. val )
2203
2212
}
2204
2213
2205
2214
ast:: BindByRef ( _) => {
2206
2215
// By ref binding: the value of the variable
2207
2216
// is the pointer `val` itself.
2208
- Store ( bcx, val, llvariable_val ) ;
2217
+ Store ( bcx, val, var_datum . val ) ;
2209
2218
bcx
2210
2219
}
2211
2220
}
0 commit comments