@@ -1276,7 +1276,7 @@ pub fn alloca(cx: Block, ty: Type, name: &str) -> ValueRef {
12761276 return llvm:: LLVMGetUndef ( ty. ptr_to ( ) . to_ref ( ) ) ;
12771277 }
12781278 }
1279- debuginfo :: clear_source_location ( cx. fcx ) ;
1279+ DebugLoc :: None . apply ( cx. fcx ) ;
12801280 Alloca ( cx, ty, name)
12811281}
12821282
@@ -1400,23 +1400,23 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
14001400 pub fn new ( ccx : & ' blk CrateContext < ' blk , ' tcx > ,
14011401 llfndecl : ValueRef ,
14021402 fn_ty : FnType ,
1403- def_id : Option < DefId > ,
1404- param_substs : & ' tcx Substs < ' tcx > ,
1403+ definition : Option < ( Instance < ' tcx > , & ty:: FnSig < ' tcx > , Abi ) > ,
14051404 block_arena : & ' blk TypedArena < common:: BlockS < ' blk , ' tcx > > )
14061405 -> FunctionContext < ' blk , ' tcx > {
1407- common:: validate_substs ( param_substs) ;
1406+ let ( param_substs, def_id) = match definition {
1407+ Some ( ( instance, _, _) ) => {
1408+ common:: validate_substs ( instance. substs ) ;
1409+ ( instance. substs , Some ( instance. def ) )
1410+ }
1411+ None => ( ccx. tcx ( ) . mk_substs ( Substs :: empty ( ) ) , None )
1412+ } ;
14081413
14091414 let inlined_did = def_id. and_then ( |def_id| inline:: get_local_instance ( ccx, def_id) ) ;
14101415 let inlined_id = inlined_did. and_then ( |id| ccx. tcx ( ) . map . as_local_node_id ( id) ) ;
14111416 let local_id = def_id. and_then ( |id| ccx. tcx ( ) . map . as_local_node_id ( id) ) ;
14121417
1413- debug ! ( "FunctionContext::new(path={}, def_id={:?}, param_substs={:?})" ,
1414- inlined_id. map_or( String :: new( ) , |id| ccx. tcx( ) . node_path_str( id) ) ,
1415- def_id,
1416- param_substs) ;
1417-
1418- let debug_context = debuginfo:: create_function_debug_context ( ccx,
1419- inlined_id. unwrap_or ( ast:: DUMMY_NODE_ID ) , param_substs, llfndecl) ;
1418+ debug ! ( "FunctionContext::new({})" ,
1419+ definition. map_or( String :: new( ) , |d| d. 0 . to_string( ) ) ) ;
14201420
14211421 let cfg = inlined_id. map ( |id| build_cfg ( ccx. tcx ( ) , id) ) ;
14221422 let nested_returns = if let Some ( ( blk_id, Some ( ref cfg) ) ) = cfg {
@@ -1428,10 +1428,11 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
14281428 let check_attrs = |attrs : & [ ast:: Attribute ] | {
14291429 let default_to_mir = ccx. sess ( ) . opts . debugging_opts . orbit ;
14301430 let invert = if default_to_mir { "rustc_no_mir" } else { "rustc_mir" } ;
1431- default_to_mir ^ attrs. iter ( ) . any ( |item| item. check_name ( invert) )
1431+ ( default_to_mir ^ attrs. iter ( ) . any ( |item| item. check_name ( invert) ) ,
1432+ attrs. iter ( ) . any ( |item| item. check_name ( "no_debug" ) ) )
14321433 } ;
14331434
1434- let use_mir = if let Some ( id) = local_id {
1435+ let ( use_mir, no_debug ) = if let Some ( id) = local_id {
14351436 check_attrs ( ccx. tcx ( ) . map . attrs ( id) )
14361437 } else if let Some ( def_id) = def_id {
14371438 check_attrs ( & ccx. sess ( ) . cstore . item_attrs ( def_id) )
@@ -1445,6 +1446,13 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
14451446 None
14461447 } ;
14471448
1449+ let debug_context = if let ( false , Some ( definition) ) = ( no_debug, definition) {
1450+ let ( instance, sig, abi) = definition;
1451+ debuginfo:: create_function_debug_context ( ccx, instance, sig, abi, llfndecl)
1452+ } else {
1453+ debuginfo:: empty_function_debug_context ( ccx)
1454+ } ;
1455+
14481456 FunctionContext {
14491457 needs_ret_allocas : nested_returns && mir. is_none ( ) ,
14501458 mir : mir,
@@ -1731,7 +1739,7 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
17311739
17321740 self . build_return_block ( ret_cx, ret_debug_loc) ;
17331741
1734- debuginfo :: clear_source_location ( self ) ;
1742+ DebugLoc :: None . apply ( self ) ;
17351743 self . cleanup ( ) ;
17361744 }
17371745
@@ -1810,32 +1818,34 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
18101818 decl : & hir:: FnDecl ,
18111819 body : & hir:: Block ,
18121820 llfndecl : ValueRef ,
1813- param_substs : & ' tcx Substs < ' tcx > ,
1814- def_id : DefId ,
1821+ instance : Instance < ' tcx > ,
18151822 inlined_id : ast:: NodeId ,
1816- fn_ty : FnType ,
1823+ sig : & ty :: FnSig < ' tcx > ,
18171824 abi : Abi ,
18181825 closure_env : closure:: ClosureEnv ) {
18191826 ccx. stats ( ) . n_closures . set ( ccx. stats ( ) . n_closures . get ( ) + 1 ) ;
18201827
18211828 if collector:: collecting_debug_information ( ccx) {
1822- ccx. record_translation_item_as_generated (
1823- TransItem :: Fn ( Instance :: new ( def_id, param_substs) ) ) ;
1829+ ccx. record_translation_item_as_generated ( TransItem :: Fn ( instance) ) ;
18241830 }
18251831
18261832 let _icx = push_ctxt ( "trans_closure" ) ;
18271833 attributes:: emit_uwtable ( llfndecl, true ) ;
18281834
1829- debug ! ( "trans_closure(..., param_substs={:?})" , param_substs) ;
1835+ debug ! ( "trans_closure(..., {})" , instance) ;
1836+
1837+ let fn_ty = FnType :: new ( ccx, abi, sig, & [ ] ) ;
18301838
18311839 let ( arena, fcx) : ( TypedArena < _ > , FunctionContext ) ;
18321840 arena = TypedArena :: new ( ) ;
1833- fcx = FunctionContext :: new ( ccx, llfndecl, fn_ty, Some ( def_id ) , param_substs , & arena) ;
1841+ fcx = FunctionContext :: new ( ccx, llfndecl, fn_ty, Some ( ( instance , sig , abi ) ) , & arena) ;
18341842
18351843 if fcx. mir . is_some ( ) {
18361844 return mir:: trans_mir ( & fcx) ;
18371845 }
18381846
1847+ debuginfo:: fill_scope_map_for_function ( & fcx, decl, body, inlined_id) ;
1848+
18391849 // cleanup scope for the incoming arguments
18401850 let fn_cleanup_debug_loc = debuginfo:: get_cleanup_debug_loc_for_ast_node (
18411851 ccx, inlined_id, body. span , true ) ;
@@ -1890,10 +1900,8 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
18901900 }
18911901 }
18921902
1893- let ret_debug_loc = DebugLoc :: At ( fn_cleanup_debug_loc. id , fn_cleanup_debug_loc. span ) ;
1894-
18951903 // Insert the mandatory first few basic blocks before lltop.
1896- fcx. finish ( bcx, ret_debug_loc ) ;
1904+ fcx. finish ( bcx, fn_cleanup_debug_loc . debug_loc ( ) ) ;
18971905}
18981906
18991907/// Creates an LLVM function corresponding to a source language function.
@@ -1906,25 +1914,23 @@ pub fn trans_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
19061914 let _s = StatRecorder :: new ( ccx, ccx. tcx ( ) . node_path_str ( id) ) ;
19071915 debug ! ( "trans_fn(param_substs={:?})" , param_substs) ;
19081916 let _icx = push_ctxt ( "trans_fn" ) ;
1909- let fn_ty = ccx. tcx ( ) . node_id_to_type ( id) ;
1910- let fn_ty = monomorphize:: apply_param_substs ( ccx. tcx ( ) , param_substs, & fn_ty) ;
1911- let sig = ccx. tcx ( ) . erase_late_bound_regions ( fn_ty. fn_sig ( ) ) ;
1912- let sig = infer:: normalize_associated_type ( ccx. tcx ( ) , & sig) ;
1913- let abi = fn_ty. fn_abi ( ) ;
1914- let fn_ty = FnType :: new ( ccx, abi, & sig, & [ ] ) ;
19151917 let def_id = if let Some ( & def_id) = ccx. external_srcs ( ) . borrow ( ) . get ( & id) {
19161918 def_id
19171919 } else {
19181920 ccx. tcx ( ) . map . local_def_id ( id)
19191921 } ;
1922+ let fn_ty = ccx. tcx ( ) . lookup_item_type ( def_id) . ty ;
1923+ let fn_ty = monomorphize:: apply_param_substs ( ccx. tcx ( ) , param_substs, & fn_ty) ;
1924+ let sig = ccx. tcx ( ) . erase_late_bound_regions ( fn_ty. fn_sig ( ) ) ;
1925+ let sig = infer:: normalize_associated_type ( ccx. tcx ( ) , & sig) ;
1926+ let abi = fn_ty. fn_abi ( ) ;
19201927 trans_closure ( ccx,
19211928 decl,
19221929 body,
19231930 llfndecl,
1924- param_substs,
1925- def_id,
1931+ Instance :: new ( def_id, param_substs) ,
19261932 id,
1927- fn_ty ,
1933+ & sig ,
19281934 abi,
19291935 closure:: ClosureEnv :: NotClosure ) ;
19301936}
@@ -2015,9 +2021,7 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
20152021
20162022 let ( arena, fcx) : ( TypedArena < _ > , FunctionContext ) ;
20172023 arena = TypedArena :: new ( ) ;
2018- fcx = FunctionContext :: new ( ccx, llfndecl, fn_ty,
2019- Some ( ccx. tcx ( ) . map . local_def_id ( ctor_id) ) ,
2020- param_substs, & arena) ;
2024+ fcx = FunctionContext :: new ( ccx, llfndecl, fn_ty, None , & arena) ;
20212025 let bcx = fcx. init ( false , None ) ;
20222026
20232027 assert ! ( !fcx. needs_ret_allocas) ;
0 commit comments