@@ -1400,11 +1400,15 @@ 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
- instance : Option < Instance < ' tcx > > ,
1403
+ definition : Option < ( Instance < ' tcx > ,
1404
+ & ty:: FnSig < ' tcx > ,
1405
+ Abi ,
1406
+ & ty:: Generics < ' tcx > ,
1407
+ Option < ast:: Name > ) > ,
1404
1408
block_arena : & ' blk TypedArena < common:: BlockS < ' blk , ' tcx > > )
1405
1409
-> FunctionContext < ' blk , ' tcx > {
1406
- let ( param_substs, def_id) = match instance {
1407
- Some ( instance) => {
1410
+ let ( param_substs, def_id) = match definition {
1411
+ Some ( ( instance, _ , _ , _ , _ ) ) => {
1408
1412
common:: validate_substs ( instance. substs ) ;
1409
1413
( instance. substs , Some ( instance. def ) )
1410
1414
}
@@ -1416,10 +1420,7 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
1416
1420
let local_id = def_id. and_then ( |id| ccx. tcx ( ) . map . as_local_node_id ( id) ) ;
1417
1421
1418
1422
debug ! ( "FunctionContext::new({})" ,
1419
- instance. map_or( String :: new( ) , |i| i. to_string( ) ) ) ;
1420
-
1421
- let debug_context = debuginfo:: create_function_debug_context ( ccx,
1422
- inlined_id. unwrap_or ( ast:: DUMMY_NODE_ID ) , param_substs, llfndecl) ;
1423
+ definition. map_or( String :: new( ) , |d| d. 0 . to_string( ) ) ) ;
1423
1424
1424
1425
let cfg = inlined_id. map ( |id| build_cfg ( ccx. tcx ( ) , id) ) ;
1425
1426
let nested_returns = if let Some ( ( blk_id, Some ( ref cfg) ) ) = cfg {
@@ -1431,10 +1432,11 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
1431
1432
let check_attrs = |attrs : & [ ast:: Attribute ] | {
1432
1433
let default_to_mir = ccx. sess ( ) . opts . debugging_opts . orbit ;
1433
1434
let invert = if default_to_mir { "rustc_no_mir" } else { "rustc_mir" } ;
1434
- default_to_mir ^ attrs. iter ( ) . any ( |item| item. check_name ( invert) )
1435
+ ( default_to_mir ^ attrs. iter ( ) . any ( |item| item. check_name ( invert) ) ,
1436
+ attrs. iter ( ) . any ( |item| item. check_name ( "no_debug" ) ) )
1435
1437
} ;
1436
1438
1437
- let use_mir = if let Some ( id) = local_id {
1439
+ let ( use_mir, no_debug ) = if let Some ( id) = local_id {
1438
1440
check_attrs ( ccx. tcx ( ) . map . attrs ( id) )
1439
1441
} else if let Some ( def_id) = def_id {
1440
1442
check_attrs ( & ccx. sess ( ) . cstore . item_attrs ( def_id) )
@@ -1448,6 +1450,18 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
1448
1450
None
1449
1451
} ;
1450
1452
1453
+ let span = inlined_id. and_then ( |id| ccx. tcx ( ) . map . opt_span ( id) ) ;
1454
+
1455
+ let debug_context = if let ( false , Some ( definition) ) = ( no_debug, definition) {
1456
+ let ( instance, sig, abi, generics, name) = definition;
1457
+ debuginfo:: create_function_debug_context ( ccx, instance, sig,
1458
+ abi, generics, name,
1459
+ span. unwrap_or ( DUMMY_SP ) ,
1460
+ llfndecl)
1461
+ } else {
1462
+ debuginfo:: empty_function_debug_context ( ccx)
1463
+ } ;
1464
+
1451
1465
FunctionContext {
1452
1466
needs_ret_allocas : nested_returns && mir. is_none ( ) ,
1453
1467
mir : mir,
@@ -1462,7 +1476,7 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
1462
1476
lldropflag_hints : RefCell :: new ( DropFlagHintsMap :: new ( ) ) ,
1463
1477
fn_ty : fn_ty,
1464
1478
param_substs : param_substs,
1465
- span : inlined_id . and_then ( |id| ccx . tcx ( ) . map . opt_span ( id ) ) ,
1479
+ span : span ,
1466
1480
block_arena : block_arena,
1467
1481
lpad_arena : TypedArena :: new ( ) ,
1468
1482
ccx : ccx,
@@ -1815,8 +1829,10 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1815
1829
llfndecl : ValueRef ,
1816
1830
instance : Instance < ' tcx > ,
1817
1831
inlined_id : ast:: NodeId ,
1818
- fn_ty : FnType ,
1832
+ sig : & ty :: FnSig < ' tcx > ,
1819
1833
abi : Abi ,
1834
+ generics : & ty:: Generics < ' tcx > ,
1835
+ name : Option < ast:: Name > ,
1820
1836
closure_env : closure:: ClosureEnv ) {
1821
1837
ccx. stats ( ) . n_closures . set ( ccx. stats ( ) . n_closures . get ( ) + 1 ) ;
1822
1838
@@ -1829,14 +1845,19 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1829
1845
1830
1846
debug ! ( "trans_closure(..., {})" , instance) ;
1831
1847
1848
+ let fn_ty = FnType :: new ( ccx, abi, sig, & [ ] ) ;
1849
+
1832
1850
let ( arena, fcx) : ( TypedArena < _ > , FunctionContext ) ;
1833
1851
arena = TypedArena :: new ( ) ;
1834
- fcx = FunctionContext :: new ( ccx, llfndecl, fn_ty, Some ( instance) , & arena) ;
1852
+ fcx = FunctionContext :: new ( ccx, llfndecl, fn_ty,
1853
+ Some ( ( instance, sig, abi, generics, name) ) , & arena) ;
1835
1854
1836
1855
if fcx. mir . is_some ( ) {
1837
1856
return mir:: trans_mir ( & fcx) ;
1838
1857
}
1839
1858
1859
+ debuginfo:: fill_scope_map_for_function ( & fcx, decl, body, inlined_id) ;
1860
+
1840
1861
// cleanup scope for the incoming arguments
1841
1862
let fn_cleanup_debug_loc = debuginfo:: get_cleanup_debug_loc_for_ast_node (
1842
1863
ccx, inlined_id, body. span , true ) ;
@@ -1891,10 +1912,8 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1891
1912
}
1892
1913
}
1893
1914
1894
- let ret_debug_loc = DebugLoc :: At ( fn_cleanup_debug_loc. id , fn_cleanup_debug_loc. span ) ;
1895
-
1896
1915
// Insert the mandatory first few basic blocks before lltop.
1897
- fcx. finish ( bcx, ret_debug_loc ) ;
1916
+ fcx. finish ( bcx, fn_cleanup_debug_loc . debug_loc ( ) ) ;
1898
1917
}
1899
1918
1900
1919
/// Creates an LLVM function corresponding to a source language function.
@@ -1907,25 +1926,27 @@ pub fn trans_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1907
1926
let _s = StatRecorder :: new ( ccx, ccx. tcx ( ) . node_path_str ( id) ) ;
1908
1927
debug ! ( "trans_fn(param_substs={:?})" , param_substs) ;
1909
1928
let _icx = push_ctxt ( "trans_fn" ) ;
1910
- let fn_ty = ccx. tcx ( ) . node_id_to_type ( id) ;
1911
- let fn_ty = monomorphize:: apply_param_substs ( ccx. tcx ( ) , param_substs, & fn_ty) ;
1912
- let sig = ccx. tcx ( ) . erase_late_bound_regions ( fn_ty. fn_sig ( ) ) ;
1913
- let sig = infer:: normalize_associated_type ( ccx. tcx ( ) , & sig) ;
1914
- let abi = fn_ty. fn_abi ( ) ;
1915
- let fn_ty = FnType :: new ( ccx, abi, & sig, & [ ] ) ;
1916
1929
let def_id = if let Some ( & def_id) = ccx. external_srcs ( ) . borrow ( ) . get ( & id) {
1917
1930
def_id
1918
1931
} else {
1919
1932
ccx. tcx ( ) . map . local_def_id ( id)
1920
1933
} ;
1934
+ let scheme = ccx. tcx ( ) . lookup_item_type ( def_id) ;
1935
+ let fn_ty = scheme. ty ;
1936
+ let fn_ty = monomorphize:: apply_param_substs ( ccx. tcx ( ) , param_substs, & fn_ty) ;
1937
+ let sig = ccx. tcx ( ) . erase_late_bound_regions ( fn_ty. fn_sig ( ) ) ;
1938
+ let sig = infer:: normalize_associated_type ( ccx. tcx ( ) , & sig) ;
1939
+ let abi = fn_ty. fn_abi ( ) ;
1921
1940
trans_closure ( ccx,
1922
1941
decl,
1923
1942
body,
1924
1943
llfndecl,
1925
1944
Instance :: new ( def_id, param_substs) ,
1926
1945
id,
1927
- fn_ty ,
1946
+ & sig ,
1928
1947
abi,
1948
+ & scheme. generics ,
1949
+ Some ( ccx. tcx ( ) . item_name ( def_id) ) ,
1929
1950
closure:: ClosureEnv :: NotClosure ) ;
1930
1951
}
1931
1952
0 commit comments