@@ -1276,7 +1276,7 @@ pub fn alloca(cx: Block, ty: Type, name: &str) -> ValueRef {
1276
1276
return llvm:: LLVMGetUndef ( ty. ptr_to ( ) . to_ref ( ) ) ;
1277
1277
}
1278
1278
}
1279
- debuginfo :: clear_source_location ( cx. fcx ) ;
1279
+ DebugLoc :: None . apply ( cx. fcx ) ;
1280
1280
Alloca ( cx, ty, name)
1281
1281
}
1282
1282
@@ -1400,23 +1400,23 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
1400
1400
pub fn new ( ccx : & ' blk CrateContext < ' blk , ' tcx > ,
1401
1401
llfndecl : ValueRef ,
1402
1402
fn_ty : FnType ,
1403
- def_id : Option < DefId > ,
1404
- param_substs : & ' tcx Substs < ' tcx > ,
1403
+ definition : Option < ( Instance < ' tcx > , & ty:: FnSig < ' tcx > , Abi ) > ,
1405
1404
block_arena : & ' blk TypedArena < common:: BlockS < ' blk , ' tcx > > )
1406
1405
-> 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
+ } ;
1408
1413
1409
1414
let inlined_did = def_id. and_then ( |def_id| inline:: get_local_instance ( ccx, def_id) ) ;
1410
1415
let inlined_id = inlined_did. and_then ( |id| ccx. tcx ( ) . map . as_local_node_id ( id) ) ;
1411
1416
let local_id = def_id. and_then ( |id| ccx. tcx ( ) . map . as_local_node_id ( id) ) ;
1412
1417
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( ) ) ) ;
1420
1420
1421
1421
let cfg = inlined_id. map ( |id| build_cfg ( ccx. tcx ( ) , id) ) ;
1422
1422
let nested_returns = if let Some ( ( blk_id, Some ( ref cfg) ) ) = cfg {
@@ -1428,10 +1428,11 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
1428
1428
let check_attrs = |attrs : & [ ast:: Attribute ] | {
1429
1429
let default_to_mir = ccx. sess ( ) . opts . debugging_opts . orbit ;
1430
1430
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" ) ) )
1432
1433
} ;
1433
1434
1434
- let use_mir = if let Some ( id) = local_id {
1435
+ let ( use_mir, no_debug ) = if let Some ( id) = local_id {
1435
1436
check_attrs ( ccx. tcx ( ) . map . attrs ( id) )
1436
1437
} else if let Some ( def_id) = def_id {
1437
1438
check_attrs ( & ccx. sess ( ) . cstore . item_attrs ( def_id) )
@@ -1445,6 +1446,13 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
1445
1446
None
1446
1447
} ;
1447
1448
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
+
1448
1456
FunctionContext {
1449
1457
needs_ret_allocas : nested_returns && mir. is_none ( ) ,
1450
1458
mir : mir,
@@ -1731,7 +1739,7 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
1731
1739
1732
1740
self . build_return_block ( ret_cx, ret_debug_loc) ;
1733
1741
1734
- debuginfo :: clear_source_location ( self ) ;
1742
+ DebugLoc :: None . apply ( self ) ;
1735
1743
self . cleanup ( ) ;
1736
1744
}
1737
1745
@@ -1810,32 +1818,34 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1810
1818
decl : & hir:: FnDecl ,
1811
1819
body : & hir:: Block ,
1812
1820
llfndecl : ValueRef ,
1813
- param_substs : & ' tcx Substs < ' tcx > ,
1814
- def_id : DefId ,
1821
+ instance : Instance < ' tcx > ,
1815
1822
inlined_id : ast:: NodeId ,
1816
- fn_ty : FnType ,
1823
+ sig : & ty :: FnSig < ' tcx > ,
1817
1824
abi : Abi ,
1818
1825
closure_env : closure:: ClosureEnv ) {
1819
1826
ccx. stats ( ) . n_closures . set ( ccx. stats ( ) . n_closures . get ( ) + 1 ) ;
1820
1827
1821
1828
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) ) ;
1824
1830
}
1825
1831
1826
1832
let _icx = push_ctxt ( "trans_closure" ) ;
1827
1833
attributes:: emit_uwtable ( llfndecl, true ) ;
1828
1834
1829
- debug ! ( "trans_closure(..., param_substs={:?})" , param_substs) ;
1835
+ debug ! ( "trans_closure(..., {})" , instance) ;
1836
+
1837
+ let fn_ty = FnType :: new ( ccx, abi, sig, & [ ] ) ;
1830
1838
1831
1839
let ( arena, fcx) : ( TypedArena < _ > , FunctionContext ) ;
1832
1840
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) ;
1834
1842
1835
1843
if fcx. mir . is_some ( ) {
1836
1844
return mir:: trans_mir ( & fcx) ;
1837
1845
}
1838
1846
1847
+ debuginfo:: fill_scope_map_for_function ( & fcx, decl, body, inlined_id) ;
1848
+
1839
1849
// cleanup scope for the incoming arguments
1840
1850
let fn_cleanup_debug_loc = debuginfo:: get_cleanup_debug_loc_for_ast_node (
1841
1851
ccx, inlined_id, body. span , true ) ;
@@ -1890,10 +1900,8 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1890
1900
}
1891
1901
}
1892
1902
1893
- let ret_debug_loc = DebugLoc :: At ( fn_cleanup_debug_loc. id , fn_cleanup_debug_loc. span ) ;
1894
-
1895
1903
// 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 ( ) ) ;
1897
1905
}
1898
1906
1899
1907
/// Creates an LLVM function corresponding to a source language function.
@@ -1906,25 +1914,23 @@ pub fn trans_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1906
1914
let _s = StatRecorder :: new ( ccx, ccx. tcx ( ) . node_path_str ( id) ) ;
1907
1915
debug ! ( "trans_fn(param_substs={:?})" , param_substs) ;
1908
1916
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, & [ ] ) ;
1915
1917
let def_id = if let Some ( & def_id) = ccx. external_srcs ( ) . borrow ( ) . get ( & id) {
1916
1918
def_id
1917
1919
} else {
1918
1920
ccx. tcx ( ) . map . local_def_id ( id)
1919
1921
} ;
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 ( ) ;
1920
1927
trans_closure ( ccx,
1921
1928
decl,
1922
1929
body,
1923
1930
llfndecl,
1924
- param_substs,
1925
- def_id,
1931
+ Instance :: new ( def_id, param_substs) ,
1926
1932
id,
1927
- fn_ty ,
1933
+ & sig ,
1928
1934
abi,
1929
1935
closure:: ClosureEnv :: NotClosure ) ;
1930
1936
}
@@ -2015,9 +2021,7 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
2015
2021
2016
2022
let ( arena, fcx) : ( TypedArena < _ > , FunctionContext ) ;
2017
2023
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) ;
2021
2025
let bcx = fcx. init ( false , None ) ;
2022
2026
2023
2027
assert ! ( !fcx. needs_ret_allocas) ;
0 commit comments