@@ -1392,37 +1392,41 @@ fn insert_lllocals<'a>(
13921392 let llval = match binding_info. trmode {
13931393 // By value bindings: use the stack slot that we
13941394 // 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+ } ;
13991399
1400- lldest
1401- }
1400+ let datum = Datum {
1401+ val : llval,
1402+ ty : binding_info. ty ,
1403+ mode : ByRef ( ZeroMem )
1404+ } ;
14021405
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+ _ => { }
14061410 }
1407- } ;
1411+ }
14081412
14091413 {
14101414 debug ! ( "binding {:?} to {}" ,
14111415 binding_info. id,
14121416 bcx. val_to_str( llval) ) ;
14131417 let mut llmap = bcx. fcx . lllocals . borrow_mut ( ) ;
1414- llmap. get ( ) . insert ( binding_info. id , llval ) ;
1418+ llmap. get ( ) . insert ( binding_info. id , datum ) ;
14151419 }
14161420
14171421 if bcx. sess ( ) . opts . extra_debuginfo {
14181422 debuginfo:: create_match_binding_metadata ( bcx,
14191423 ident,
14201424 binding_info. id ,
1421- binding_info. ty ,
1422- binding_info . span ) ;
1425+ binding_info. span ,
1426+ datum ) ;
14231427 }
14241428 }
1425- return bcx;
1429+ bcx
14261430}
14271431
14281432fn compile_guard < ' r ,
@@ -2032,8 +2036,7 @@ pub fn store_local<'a>(
20322036 Some ( path) => {
20332037 return mk_binding_alloca (
20342038 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 ) ) ) ;
20372040 }
20382041
20392042 None => { }
@@ -2067,13 +2070,13 @@ pub fn store_local<'a>(
20672070 pat_bindings ( tcx. def_map , pat, |_, p_id, _, path| {
20682071 bcx = mk_binding_alloca (
20692072 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 } ) ;
20712074 } ) ;
20722075 bcx
20732076 }
20742077}
20752078
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 )
20772080 -> & ' a Block < ' a > {
20782081 /*!
20792082 * 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)
20932096 // Note that we cannot do it before for fear of a fn like
20942097 // fn getaddr(~ref x: ~uint) -> *uint {....}
20952098 // (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) ;
20982100
20992101 // Debug information (the llvm.dbg.declare intrinsic to be precise) always expects to get an
21002102 // alloca, which only is the case on the general path, so lets disable the optimized path when
21012103 // 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 ( ) } ;
21032105
21042106 let fast_path = ( arg_is_alloca || !bcx. ccx ( ) . sess . opts . extra_debuginfo )
21052107 && simple_identifier ( pat) . is_some ( ) ;
@@ -2109,37 +2111,42 @@ pub fn store_arg<'a>(mut bcx: &'a Block<'a>, pat: @ast::Pat, llval: ValueRef)
21092111 // `llval` wholesale as the pointer for `x`, avoiding the
21102112 // general logic which may copy out of `llval`.
21112113 let mut llargs = bcx. fcx . llargs . borrow_mut ( ) ;
2112- llargs. get ( ) . insert ( pat. id , llval ) ;
2114+ llargs. get ( ) . insert ( pat. id , arg ) ;
21132115 } else {
21142116 // General path. Copy out the values that are used in the
21152117 // 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 ) ;
21172120 }
21182121
21192122 return bcx;
21202123}
21212124
21222125fn mk_binding_alloca < ' a > (
2123- mut bcx : & ' a Block < ' a > ,
2126+ bcx : & ' a Block < ' a > ,
21242127 p_id : ast:: NodeId ,
21252128 path : & ast:: Path ,
21262129 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 > )
21312131 -> & ' a Block < ' a > {
21322132 let var_ty = node_id_type( bcx, p_id) ;
21332133 let ident = ast_util:: path_to_ident ( path ) ;
21342134 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 )
21392139 } ;
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
21432150}
21442151
21452152fn bind_irrefutable_pat < ' a > (
@@ -2179,7 +2186,7 @@ fn bind_irrefutable_pat<'a>(
21792186
21802187 let _indenter = indenter ( ) ;
21812188
2182- let _icx = push_ctxt ( "alt ::bind_irrefutable_pat" ) ;
2189+ let _icx = push_ctxt ( "match ::bind_irrefutable_pat" ) ;
21832190 let mut bcx = bcx;
21842191 let tcx = bcx. tcx ( ) ;
21852192 let ccx = bcx. ccx ( ) ;
@@ -2191,21 +2198,23 @@ fn bind_irrefutable_pat<'a>(
21912198 // map.
21922199 bcx = mk_binding_alloca (
21932200 bcx, pat. id , path, binding_mode,
2194- |bcx, variable_ty , llvariable_val | {
2201+ |bcx, var_datum | {
21952202 match pat_binding_mode {
21962203 ast:: BindByValue ( _) => {
21972204 // By value binding: move the value that `val`
21982205 // 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 )
22032212 }
22042213
22052214 ast:: BindByRef ( _) => {
22062215 // By ref binding: the value of the variable
22072216 // is the pointer `val` itself.
2208- Store ( bcx, val, llvariable_val ) ;
2217+ Store ( bcx, val, var_datum . val ) ;
22092218 bcx
22102219 }
22112220 }
0 commit comments