1212#![ feature( string_from_utf8_lossy_owned) ]
1313#![ feature( trait_alias) ]
1414#![ feature( try_blocks) ]
15+ #![ recursion_limit = "256" ]
1516// HACK(eddyb) end of `rustc_codegen_ssa` crate-level attributes (see `build.rs`).
1617
1718//! Welcome to the API documentation for the `rust-gpu` project, this API is
@@ -150,7 +151,7 @@ use maybe_pqp_cg_ssa::traits::{
150151 CodegenBackend , ExtraBackendMethods , ModuleBufferMethods , ThinBufferMethods ,
151152 WriteBackendMethods ,
152153} ;
153- use maybe_pqp_cg_ssa:: { CodegenResults , CompiledModule , ModuleCodegen , ModuleKind } ;
154+ use maybe_pqp_cg_ssa:: { CodegenResults , CompiledModule , ModuleCodegen , ModuleKind , TargetConfig } ;
154155use rspirv:: binary:: Assemble ;
155156use rustc_ast:: expand:: allocator:: AllocatorKind ;
156157use rustc_ast:: expand:: autodiff_attrs:: AutoDiffItem ;
@@ -222,21 +223,33 @@ impl CodegenBackend for SpirvCodegenBackend {
222223 rustc_errors:: DEFAULT_LOCALE_RESOURCE
223224 }
224225
225- fn target_features_cfg ( & self , sess : & Session ) -> ( Vec < Symbol > , Vec < Symbol > ) {
226+ fn target_config ( & self , sess : & Session ) -> TargetConfig {
226227 let cmdline = sess. opts . cg . target_feature . split ( ',' ) ;
227228 let cfg = sess. target . options . features . split ( ',' ) ;
228229
229- let all_target_features : Vec < _ > = cfg
230+ let target_features : Vec < _ > = cfg
230231 . chain ( cmdline)
231232 . filter ( |l| l. starts_with ( '+' ) )
232233 . map ( |l| & l[ 1 ..] )
233234 . filter ( |l| !l. is_empty ( ) )
234235 . map ( Symbol :: intern)
235236 . collect ( ) ;
236237
237- // HACK(eddyb) the second list is "including unstable target features",
238+ // HACK(eddyb) this should be a superset of `target_features`,
239+ // which *additionally* also includes unstable target features,
238240 // but there is no reason to make a distinction for SPIR-V ones.
239- ( all_target_features. clone ( ) , all_target_features)
241+ let unstable_target_features = target_features. clone ( ) ;
242+
243+ TargetConfig {
244+ target_features,
245+ unstable_target_features,
246+
247+ // FIXME(eddyb) support and/or emulate `f16` and `f128`.
248+ has_reliable_f16 : false ,
249+ has_reliable_f16_math : false ,
250+ has_reliable_f128 : false ,
251+ has_reliable_f128_math : false ,
252+ }
240253 }
241254
242255 fn provide ( & self , providers : & mut rustc_middle:: util:: Providers ) {
@@ -438,8 +451,8 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
438451 // TODO: Do dep_graph stuff
439452 let cgu = tcx. codegen_unit ( cgu_name) ;
440453
441- let cx = CodegenCx :: new ( tcx, cgu) ;
442- let do_codegen = || {
454+ let mut cx = CodegenCx :: new ( tcx, cgu) ;
455+ let do_codegen = |cx : & mut CodegenCx < ' _ > | {
443456 let mono_items = cx. codegen_unit . items_in_deterministic_order ( cx. tcx ) ;
444457
445458 if let Some ( dir) = & cx. codegen_args . dump_mir {
@@ -448,27 +461,33 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
448461
449462 for & ( mono_item, mono_item_data) in mono_items. iter ( ) {
450463 mono_item. predefine :: < Builder < ' _ , ' _ > > (
451- & cx,
464+ cx,
452465 mono_item_data. linkage ,
453466 mono_item_data. visibility ,
454467 ) ;
455468 }
456469
457470 // ... and now that we have everything pre-defined, fill out those definitions.
458- for & ( mono_item, _ ) in mono_items. iter ( ) {
459- mono_item. define :: < Builder < ' _ , ' _ > > ( & cx ) ;
471+ for & ( mono_item, mono_item_data ) in & mono_items {
472+ mono_item. define :: < Builder < ' _ , ' _ > > ( cx , mono_item_data ) ;
460473 }
461474
462- if let Some ( _entry) = maybe_create_entry_wrapper :: < Builder < ' _ , ' _ > > ( & cx) {
475+ if let Some ( _entry) = maybe_create_entry_wrapper :: < Builder < ' _ , ' _ > > ( cx) {
463476 // attributes::sanitize(&cx, SanitizerSet::empty(), entry);
464477 }
465478 } ;
466- if let Some ( path) = & cx. codegen_args . dump_module_on_panic {
467- let module_dumper = DumpModuleOnPanic { cx : & cx, path } ;
468- with_no_trimmed_paths ! ( do_codegen( ) ) ;
479+ // HACK(eddyb) mutable access needed for `mono_item.define::<...>(cx, ...)`
480+ // but that alone leads to needless cloning and smuggling a mutable borrow
481+ // through `DumpModuleOnPanic` (for both its `Drop` impl and `do_codegen`).
482+ if let Some ( path) = cx. codegen_args . dump_module_on_panic . clone ( ) {
483+ let module_dumper = DumpModuleOnPanic {
484+ cx : & mut cx,
485+ path : & path,
486+ } ;
487+ with_no_trimmed_paths ! ( do_codegen( module_dumper. cx) ) ;
469488 drop ( module_dumper) ;
470489 } else {
471- with_no_trimmed_paths ! ( do_codegen( ) ) ;
490+ with_no_trimmed_paths ! ( do_codegen( & mut cx ) ) ;
472491 }
473492 let spirv_module = cx. finalize_module ( ) . assemble ( ) ;
474493
@@ -495,7 +514,7 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
495514}
496515
497516struct DumpModuleOnPanic < ' a , ' cx , ' tcx > {
498- cx : & ' cx CodegenCx < ' tcx > ,
517+ cx : & ' cx mut CodegenCx < ' tcx > ,
499518 path : & ' a Path ,
500519}
501520
0 commit comments