@@ -35,7 +35,7 @@ use back::write::{self, OngoingCrateTranslation};
35
35
use llvm:: { ContextRef , ModuleRef , ValueRef , Vector , get_param} ;
36
36
use llvm;
37
37
use metadata;
38
- use rustc:: hir:: def_id:: { CrateNum , LOCAL_CRATE } ;
38
+ use rustc:: hir:: def_id:: { CrateNum , DefId , LOCAL_CRATE } ;
39
39
use rustc:: middle:: lang_items:: StartFnLangItem ;
40
40
use rustc:: middle:: trans:: { Linkage , Visibility } ;
41
41
use rustc:: middle:: cstore:: { EncodedMetadata , EncodedMetadataHashes } ;
@@ -75,7 +75,7 @@ use trans_item::{TransItem, TransItemExt, DefPathBasedNames};
75
75
use type_:: Type ;
76
76
use type_of;
77
77
use value:: Value ;
78
- use rustc:: util:: nodemap:: { NodeSet , FxHashMap , FxHashSet } ;
78
+ use rustc:: util:: nodemap:: { NodeSet , FxHashMap , FxHashSet , DefIdSet } ;
79
79
use CrateInfo ;
80
80
81
81
use libc:: c_uint;
@@ -990,8 +990,9 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
990
990
991
991
// Run the translation item collector and partition the collected items into
992
992
// codegen units.
993
- let ( translation_items, codegen_units) =
994
- shared_ccx. tcx ( ) . collect_and_partition_translation_items ( LOCAL_CRATE ) ;
993
+ let codegen_units =
994
+ shared_ccx. tcx ( ) . collect_and_partition_translation_items ( LOCAL_CRATE ) . 1 ;
995
+ let codegen_units = ( * codegen_units) . clone ( ) ;
995
996
996
997
assert ! ( codegen_units. len( ) <= 1 || !tcx. sess. lto( ) ) ;
997
998
@@ -1076,8 +1077,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1076
1077
let ( ( stats, module) , _) =
1077
1078
tcx. dep_graph . with_task ( dep_node,
1078
1079
AssertDepGraphSafe ( & shared_ccx) ,
1079
- AssertDepGraphSafe ( ( cgu,
1080
- translation_items. clone ( ) ) ) ,
1080
+ AssertDepGraphSafe ( cgu) ,
1081
1081
module_translation) ;
1082
1082
all_stats. extend ( stats) ;
1083
1083
@@ -1118,13 +1118,12 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1118
1118
1119
1119
fn module_translation < ' a , ' tcx > (
1120
1120
scx : AssertDepGraphSafe < & SharedCrateContext < ' a , ' tcx > > ,
1121
- args : AssertDepGraphSafe < ( Arc < CodegenUnit < ' tcx > > ,
1122
- Arc < FxHashSet < TransItem < ' tcx > > > ) > )
1121
+ args : AssertDepGraphSafe < Arc < CodegenUnit < ' tcx > > > )
1123
1122
-> ( Stats , ModuleTranslation )
1124
1123
{
1125
1124
// FIXME(#40304): We ought to be using the id as a key and some queries, I think.
1126
1125
let AssertDepGraphSafe ( scx) = scx;
1127
- let AssertDepGraphSafe ( ( cgu, crate_trans_items ) ) = args;
1126
+ let AssertDepGraphSafe ( cgu) = args;
1128
1127
1129
1128
let cgu_name = cgu. name ( ) . to_string ( ) ;
1130
1129
let cgu_id = cgu. work_product_id ( ) ;
@@ -1164,7 +1163,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1164
1163
}
1165
1164
1166
1165
// Instantiate translation items without filling out definitions yet...
1167
- let lcx = LocalCrateContext :: new ( scx, cgu, crate_trans_items ) ;
1166
+ let lcx = LocalCrateContext :: new ( scx, cgu) ;
1168
1167
let module = {
1169
1168
let ccx = CrateContext :: new ( scx, & lcx) ;
1170
1169
let trans_items = ccx. codegen_unit ( )
@@ -1353,7 +1352,7 @@ fn assert_symbols_are_distinct<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trans_i
1353
1352
fn collect_and_partition_translation_items < ' a , ' tcx > (
1354
1353
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1355
1354
cnum : CrateNum ,
1356
- ) -> ( Arc < FxHashSet < TransItem < ' tcx > > > , Vec < Arc < CodegenUnit < ' tcx > > > )
1355
+ ) -> ( Arc < DefIdSet > , Arc < Vec < Arc < CodegenUnit < ' tcx > > > > )
1357
1356
{
1358
1357
assert_eq ! ( cnum, LOCAL_CRATE ) ;
1359
1358
let time_passes = tcx. sess . time_passes ( ) ;
@@ -1404,7 +1403,12 @@ fn collect_and_partition_translation_items<'a, 'tcx>(
1404
1403
assert ! ( tcx. sess. opts. cg. codegen_units == codegen_units. len( ) ||
1405
1404
tcx. sess. opts. debugging_opts. incremental. is_some( ) ) ;
1406
1405
1407
- let translation_items: FxHashSet < TransItem < ' tcx > > = items. iter ( ) . cloned ( ) . collect ( ) ;
1406
+ let translation_items: DefIdSet = items. iter ( ) . filter_map ( |trans_item| {
1407
+ match * trans_item {
1408
+ TransItem :: Fn ( ref instance) => Some ( instance. def_id ( ) ) ,
1409
+ _ => None ,
1410
+ }
1411
+ } ) . collect ( ) ;
1408
1412
1409
1413
if tcx. sess . opts . debugging_opts . print_trans_items . is_some ( ) {
1410
1414
let mut item_to_cgus = FxHashMap ( ) ;
@@ -1459,7 +1463,7 @@ fn collect_and_partition_translation_items<'a, 'tcx>(
1459
1463
}
1460
1464
}
1461
1465
1462
- ( Arc :: new ( translation_items) , codegen_units)
1466
+ ( Arc :: new ( translation_items) , Arc :: new ( codegen_units) )
1463
1467
}
1464
1468
1465
1469
impl CrateInfo {
@@ -1505,9 +1509,25 @@ impl CrateInfo {
1505
1509
}
1506
1510
}
1507
1511
1508
- pub fn provide ( providers : & mut Providers ) {
1512
+ fn is_translated_function ( tcx : TyCtxt , id : DefId ) -> bool {
1513
+ // FIXME(#42293) needs red/green tracking to avoid failing a bunch of
1514
+ // existing tests
1515
+ tcx. dep_graph . with_ignore ( || {
1516
+ let ( all_trans_items, _) =
1517
+ tcx. collect_and_partition_translation_items ( LOCAL_CRATE ) ;
1518
+ all_trans_items. contains ( & id)
1519
+ } )
1520
+ }
1521
+
1522
+ pub fn provide_local ( providers : & mut Providers ) {
1509
1523
providers. collect_and_partition_translation_items =
1510
1524
collect_and_partition_translation_items;
1525
+
1526
+ providers. is_translated_function = is_translated_function;
1527
+ }
1528
+
1529
+ pub fn provide_extern ( providers : & mut Providers ) {
1530
+ providers. is_translated_function = is_translated_function;
1511
1531
}
1512
1532
1513
1533
pub fn linkage_to_llvm ( linkage : Linkage ) -> llvm:: Linkage {
0 commit comments