@@ -250,19 +250,14 @@ impl ConstCodegenMethods for CodegenCx<'_> {
250250 let alloc_id = prov. alloc_id ( ) ;
251251 let ( base_addr, _base_addr_space) = match self . tcx . global_alloc ( alloc_id) {
252252 GlobalAlloc :: Memory ( alloc) => {
253- let pointee = match self . lookup_type ( ty) {
253+ let _pointee = match self . lookup_type ( ty) {
254254 SpirvType :: Pointer { pointee } => pointee,
255255 other => self . tcx . dcx ( ) . fatal ( format ! (
256256 "GlobalAlloc::Memory type not implemented: {}" ,
257257 other. debug( ty, self )
258258 ) ) ,
259259 } ;
260- // FIXME(eddyb) always use `const_data_from_alloc`, and
261- // defer the actual `try_read_from_const_alloc` step.
262- let init = self
263- . try_read_from_const_alloc ( alloc, pointee)
264- . unwrap_or_else ( || self . const_data_from_alloc ( alloc) ) ;
265- let value = self . static_addr_of ( init, alloc. inner ( ) . align , None ) ;
260+ let value = self . static_addr_of ( alloc, None ) ;
266261 ( value, AddressSpace :: ZERO )
267262 }
268263 GlobalAlloc :: Function { instance } => (
@@ -279,19 +274,14 @@ impl ConstCodegenMethods for CodegenCx<'_> {
279274 } ) ,
280275 ) ) )
281276 . unwrap_memory ( ) ;
282- let pointee = match self . lookup_type ( ty) {
277+ let _pointee = match self . lookup_type ( ty) {
283278 SpirvType :: Pointer { pointee } => pointee,
284279 other => self . tcx . dcx ( ) . fatal ( format ! (
285280 "GlobalAlloc::VTable type not implemented: {}" ,
286281 other. debug( ty, self )
287282 ) ) ,
288283 } ;
289- // FIXME(eddyb) always use `const_data_from_alloc`, and
290- // defer the actual `try_read_from_const_alloc` step.
291- let init = self
292- . try_read_from_const_alloc ( alloc, pointee)
293- . unwrap_or_else ( || self . const_data_from_alloc ( alloc) ) ;
294- let value = self . static_addr_of ( init, alloc. inner ( ) . align , None ) ;
284+ let value = self . static_addr_of ( alloc, None ) ;
295285 ( value, AddressSpace :: ZERO )
296286 }
297287 GlobalAlloc :: Static ( def_id) => {
@@ -317,20 +307,6 @@ impl ConstCodegenMethods for CodegenCx<'_> {
317307 }
318308 }
319309
320- // HACK(eddyb) this uses a symbolic `ConstDataFromAlloc`, to allow deferring
321- // the actual value generation until after a pointer to this value is cast
322- // to its final type (e.g. that will be loaded as).
323- // FIXME(eddyb) replace this with `qptr` handling of constant data.
324- fn const_data_from_alloc ( & self , alloc : ConstAllocation < ' _ > ) -> Self :: Value {
325- // HACK(eddyb) the `ConstCodegenMethods` trait no longer guarantees the
326- // lifetime that `alloc` is interned for, but since it *is* interned,
327- // we can cheaply recover it (see also the `ty::Lift` infrastructure).
328- let alloc = self . tcx . lift ( alloc) . unwrap ( ) ;
329-
330- let void_type = SpirvType :: Void . def ( DUMMY_SP , self ) ;
331- self . def_constant ( void_type, SpirvConst :: ConstDataFromAlloc ( alloc) )
332- }
333-
334310 fn const_ptr_byte_offset ( & self , val : Self :: Value , offset : Size ) -> Self :: Value {
335311 if offset == Size :: ZERO {
336312 val
@@ -345,6 +321,20 @@ impl ConstCodegenMethods for CodegenCx<'_> {
345321}
346322
347323impl < ' tcx > CodegenCx < ' tcx > {
324+ // HACK(eddyb) this uses a symbolic `ConstDataFromAlloc`, to allow deferring
325+ // the actual value generation until after a pointer to this value is cast
326+ // to its final type (e.g. that will be loaded as).
327+ // FIXME(eddyb) replace this with `qptr` handling of constant data.
328+ pub ( crate ) fn const_data_from_alloc ( & self , alloc : ConstAllocation < ' _ > ) -> SpirvValue {
329+ // HACK(eddyb) the `ConstCodegenMethods` trait no longer guarantees the
330+ // lifetime that `alloc` is interned for, but since it *is* interned,
331+ // we can cheaply recover it (see also the `ty::Lift` infrastructure).
332+ let alloc = self . tcx . lift ( alloc) . unwrap ( ) ;
333+
334+ let void_type = SpirvType :: Void . def ( DUMMY_SP , self ) ;
335+ self . def_constant ( void_type, SpirvConst :: ConstDataFromAlloc ( alloc) )
336+ }
337+
348338 pub fn const_bitcast ( & self , val : SpirvValue , ty : Word ) -> SpirvValue {
349339 // HACK(eddyb) special-case `const_data_from_alloc` + `static_addr_of`
350340 // as the old `from_const_alloc` (now `OperandRef::from_const_alloc`).
@@ -353,9 +343,9 @@ impl<'tcx> CodegenCx<'tcx> {
353343 && let Some ( SpirvConst :: ConstDataFromAlloc ( alloc) ) =
354344 self . builder . lookup_const_by_id ( pointee)
355345 && let SpirvType :: Pointer { pointee } = self . lookup_type ( ty)
356- && let Some ( init ) = self . try_read_from_const_alloc ( alloc, pointee)
346+ && self . try_read_from_const_alloc ( alloc, pointee) . is_some ( )
357347 {
358- return self . static_addr_of ( init , alloc. inner ( ) . align , None ) ;
348+ return self . static_addr_of ( alloc, None ) ;
359349 }
360350
361351 if val. ty == ty {
0 commit comments