@@ -11,10 +11,7 @@ use rustc_target::abi::{HasDataLayout, Size};
11
11
12
12
use crate :: ty:: { ParamEnv , ScalarInt , Ty , TyCtxt } ;
13
13
14
- use super :: {
15
- AllocId , AllocRange , ConstAllocation , InterpResult , Pointer , PointerArithmetic , Provenance ,
16
- ScalarSizeMismatch ,
17
- } ;
14
+ use super :: { AllocId , InterpResult , Pointer , PointerArithmetic , Provenance , ScalarSizeMismatch } ;
18
15
19
16
/// Represents the result of const evaluation via the `eval_to_allocation` query.
20
17
#[ derive( Copy , Clone , HashStable , TyEncodable , TyDecodable , Debug , Hash , Eq , PartialEq ) ]
@@ -28,9 +25,9 @@ pub struct ConstAlloc<'tcx> {
28
25
/// Represents a constant value in Rust. `Scalar` and `Slice` are optimizations for
29
26
/// array length computations, enum discriminants and the pattern matching logic.
30
27
#[ derive( Copy , Clone , Debug , Eq , PartialEq , TyEncodable , TyDecodable , Hash ) ]
31
- #[ derive( HashStable , Lift ) ]
32
- pub enum ConstValue < ' tcx > {
33
- /// Used for types with `layout::abi::Scalar` ABI.
28
+ #[ derive( HashStable ) ]
29
+ pub enum ConstValue {
30
+ /// Used only for types with `layout::abi::Scalar` ABI.
34
31
///
35
32
/// Not using the enum `Value` to encode that this must not be `Uninit`.
36
33
Scalar ( Scalar ) ,
@@ -41,7 +38,10 @@ pub enum ConstValue<'tcx> {
41
38
/// Used for `&[u8]` and `&str`.
42
39
///
43
40
/// This is worth the optimization since Rust has literals of that type.
44
- Slice { data : ConstAllocation < ' tcx > , start : usize , end : usize } ,
41
+ /// See `Indirect` for why we are using an `AllocId`.
42
+ /// We allow `None` for empty slices; in that case `start == end` and `start` is the absolute
43
+ /// address of the slice.
44
+ Slice { alloc_id : Option < AllocId > , start : usize , end : usize } ,
45
45
46
46
/// A value not representable by the other variants; needs to be stored in-memory.
47
47
Indirect {
@@ -58,9 +58,11 @@ pub enum ConstValue<'tcx> {
58
58
}
59
59
60
60
#[ cfg( all( target_arch = "x86_64" , target_pointer_width = "64" ) ) ]
61
- static_assert_size ! ( ConstValue <' _>, 32 ) ;
61
+ static_assert_size ! ( ConstValue , 32 ) ;
62
+
63
+ TrivialTypeTraversalAndLiftImpls ! { ConstValue }
62
64
63
- impl < ' tcx > ConstValue < ' tcx > {
65
+ impl < ' tcx > ConstValue {
64
66
#[ inline]
65
67
pub fn try_to_scalar ( & self ) -> Option < Scalar < AllocId > > {
66
68
match * self {
@@ -511,18 +513,3 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> {
511
513
Ok ( Double :: from_bits ( self . to_u64 ( ) ?. into ( ) ) )
512
514
}
513
515
}
514
-
515
- /// Gets the bytes of a constant slice value.
516
- pub fn get_slice_bytes < ' tcx > ( cx : & impl HasDataLayout , val : ConstValue < ' tcx > ) -> & ' tcx [ u8 ] {
517
- if let ConstValue :: Slice { data, start, end } = val {
518
- let len = end - start;
519
- data. inner ( )
520
- . get_bytes_strip_provenance (
521
- cx,
522
- AllocRange { start : Size :: from_bytes ( start) , size : Size :: from_bytes ( len) } ,
523
- )
524
- . unwrap_or_else ( |err| bug ! ( "const slice is invalid: {:?}" , err) )
525
- } else {
526
- bug ! ( "expected const slice, but found another const value" ) ;
527
- }
528
- }
0 commit comments