1
- use rustc_abi:: { self as abi, Align , HasDataLayout , Primitive } ;
1
+ use rustc_abi:: { self as abi, HasDataLayout , Primitive } ;
2
2
use rustc_ast:: Mutability ;
3
3
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
4
4
use rustc_hashes:: Hash128 ;
@@ -49,24 +49,17 @@ pub trait ConstCodegenMethods<'tcx>:
49
49
fn const_to_opt_uint ( & self , v : Self :: Value ) -> Option < u64 > ;
50
50
fn const_to_opt_u128 ( & self , v : Self :: Value , sign_ext : bool ) -> Option < u128 > ;
51
51
52
- fn const_data_from_alloc ( & self , alloc : ConstAllocation < ' _ > ) -> Self :: Value ;
53
-
54
52
fn const_bitcast ( & self , val : Self :: Value , ty : Self :: Type ) -> Self :: Value ;
55
53
fn const_pointercast ( & self , val : Self :: Value , ty : Self :: Type ) -> Self :: Value ;
56
54
fn const_int_to_ptr ( & self , val : Self :: Value , ty : Self :: Type ) -> Self :: Value ;
57
55
fn const_ptr_to_int ( & self , val : Self :: Value , ty : Self :: Type ) -> Self :: Value ;
58
56
/// Create a global constant.
59
57
///
60
58
/// The returned global variable is a pointer in the default address space for globals.
61
- fn static_addr_of_const (
62
- & self ,
63
- cv : Self :: Value ,
64
- align : Align ,
65
- kind : Option < & str > ,
66
- ) -> Self :: Value ;
59
+ fn static_addr_of_const ( & self , alloc : ConstAllocation < ' _ > , kind : Option < & str > ) -> Self :: Value ;
67
60
68
61
/// Same as `static_addr_of_const`, but does not mark the static as immutable
69
- fn static_addr_of_mut ( & self , cv : Self :: Value , align : Align , kind : Option < & str > ) -> Self :: Value ;
62
+ fn static_addr_of_mut ( & self , alloc : ConstAllocation < ' _ > , kind : Option < & str > ) -> Self :: Value ;
70
63
71
64
fn scalar_to_backend ( & self , cv : Scalar , layout : abi:: Scalar , llty : Self :: Type ) -> Self :: Value {
72
65
let bitsize = if layout. is_bool ( ) { 1 } else { layout. size ( self ) . bits ( ) } ;
@@ -97,18 +90,16 @@ pub trait ConstCodegenMethods<'tcx>:
97
90
self . const_bitcast ( llval, llty)
98
91
} ;
99
92
} else {
100
- let init = self . const_data_from_alloc ( alloc) ;
101
- let alloc = alloc. inner ( ) ;
102
- let value = match alloc. mutability {
103
- Mutability :: Mut => self . static_addr_of_mut ( init, alloc. align , None ) ,
104
- _ => self . static_addr_of_const ( init, alloc. align , None ) ,
93
+ let value = match alloc. inner ( ) . mutability {
94
+ Mutability :: Mut => self . static_addr_of_mut ( alloc, None ) ,
95
+ _ => self . static_addr_of_const ( alloc, None ) ,
105
96
} ;
106
97
if !self . tcx ( ) . sess . fewer_names ( )
107
98
&& self . get_value_name ( value) . is_empty ( )
108
99
{
109
100
let hash = self . tcx ( ) . with_stable_hashing_context ( |mut hcx| {
110
101
let mut hasher = StableHasher :: new ( ) ;
111
- alloc. hash_stable ( & mut hcx, & mut hasher) ;
102
+ alloc. inner ( ) . hash_stable ( & mut hcx, & mut hasher) ;
112
103
hasher. finish :: < Hash128 > ( )
113
104
} ) ;
114
105
self . set_value_name ( value, format ! ( "alloc_{hash:032x}" ) . as_bytes ( ) ) ;
@@ -127,9 +118,7 @@ pub trait ConstCodegenMethods<'tcx>:
127
118
} ) ,
128
119
) ) )
129
120
. unwrap_memory ( ) ;
130
- let init = self . const_data_from_alloc ( alloc) ;
131
- let value = self . static_addr_of_const ( init, alloc. inner ( ) . align , None ) ;
132
- value
121
+ self . static_addr_of_const ( alloc, None )
133
122
}
134
123
GlobalAlloc :: Static ( def_id) => {
135
124
assert ! ( self . tcx( ) . is_static( def_id) ) ;
0 commit comments