@@ -2249,8 +2249,10 @@ pub fn update_linkage(ccx: &CrateContext,
2249
2249
}
2250
2250
}
2251
2251
2252
- fn set_global_section ( ccx : & CrateContext , llval : ValueRef , i : & hir:: Item ) {
2253
- if let Some ( sect) = attr:: first_attr_value_str_by_name ( & i. attrs , "link_section" ) {
2252
+ pub fn set_link_section ( ccx : & CrateContext ,
2253
+ llval : ValueRef ,
2254
+ attrs : & [ ast:: Attribute ] ) {
2255
+ if let Some ( sect) = attr:: first_attr_value_str_by_name ( attrs, "link_section" ) {
2254
2256
if contains_null ( & sect) {
2255
2257
ccx. sess ( ) . fatal ( & format ! ( "Illegal null byte in link_section value: `{}`" , & sect) ) ;
2256
2258
}
@@ -2280,7 +2282,7 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) {
2280
2282
let empty_substs = ccx. empty_substs_for_def_id ( def_id) ;
2281
2283
let llfn = Callee :: def ( ccx, def_id, empty_substs) . reify ( ccx) . val ;
2282
2284
trans_fn ( ccx, & decl, & body, llfn, empty_substs, item. id ) ;
2283
- set_global_section ( ccx, llfn, item) ;
2285
+ set_link_section ( ccx, llfn, & item. attrs ) ;
2284
2286
update_linkage ( ccx,
2285
2287
llfn,
2286
2288
Some ( item. id ) ,
@@ -2336,13 +2338,9 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) {
2336
2338
enum_variant_size_lint ( ccx, enum_definition, item. span , item. id ) ;
2337
2339
}
2338
2340
}
2339
- hir:: ItemStatic ( _, m, ref expr) => {
2340
- let g = match consts:: trans_static ( ccx, m, expr, item. id , & item. attrs ) {
2341
- Ok ( g) => g,
2342
- Err ( err) => ccx. tcx ( ) . sess . span_fatal ( expr. span , & err. description ( ) ) ,
2343
- } ;
2344
- set_global_section ( ccx, g, item) ;
2345
- update_linkage ( ccx, g, Some ( item. id ) , OriginalTranslation ) ;
2341
+ hir:: ItemStatic ( ..) => {
2342
+ // Don't do anything here. Translation of statics has been moved to
2343
+ // being "collector-driven".
2346
2344
}
2347
2345
_ => { }
2348
2346
}
@@ -2700,6 +2698,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
2700
2698
2701
2699
let codegen_units = collect_and_partition_translation_items ( & shared_ccx) ;
2702
2700
let codegen_unit_count = codegen_units. len ( ) ;
2701
+
2703
2702
assert ! ( tcx. sess. opts. cg. codegen_units == codegen_unit_count ||
2704
2703
tcx. sess. opts. debugging_opts. incremental. is_some( ) ) ;
2705
2704
@@ -2723,6 +2722,33 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
2723
2722
} ;
2724
2723
}
2725
2724
2725
+ // Instantiate translation items without filling out definitions yet...
2726
+ for ccx in crate_context_list. iter ( ) {
2727
+ for ( & trans_item, & linkage) in & ccx. codegen_unit ( ) . items {
2728
+ trans_item. predefine ( & ccx, linkage) ;
2729
+ }
2730
+ }
2731
+
2732
+ // ... and now that we have everything pre-defined, fill out those definitions.
2733
+ for ccx in crate_context_list. iter ( ) {
2734
+ for ( & trans_item, _) in & ccx. codegen_unit ( ) . items {
2735
+ match trans_item {
2736
+ TransItem :: Static ( node_id) => {
2737
+ let item = ccx. tcx ( ) . map . expect_item ( node_id) ;
2738
+ if let hir:: ItemStatic ( _, m, ref expr) = item. node {
2739
+ match consts:: trans_static ( & ccx, m, expr, item. id , & item. attrs ) {
2740
+ Ok ( _) => { /* Cool, everything's alright. */ } ,
2741
+ Err ( err) => ccx. tcx ( ) . sess . span_fatal ( expr. span , & err. description ( ) ) ,
2742
+ } ;
2743
+ } else {
2744
+ span_bug ! ( item. span, "Mismatch between hir::Item type and TransItem type" )
2745
+ }
2746
+ }
2747
+ _ => { }
2748
+ }
2749
+ }
2750
+ }
2751
+
2726
2752
{
2727
2753
let ccx = crate_context_list. get_ccx ( 0 ) ;
2728
2754
0 commit comments