1
1
use super :: ScalarInt ;
2
- use rustc_macros:: HashStable ;
2
+ use crate :: ty:: codec:: TyDecoder ;
3
+ use rustc_macros:: { HashStable , TyDecodable , TyEncodable } ;
4
+ use rustc_serialize:: { Decodable , Encodable , Encoder } ;
3
5
4
6
#[ derive( Copy , Clone , Debug , Hash , TyEncodable , TyDecodable , Eq , PartialEq , Ord , PartialOrd ) ]
5
7
#[ derive( HashStable ) ]
@@ -20,6 +22,7 @@ pub enum ValTree<'tcx> {
20
22
/// See the `ScalarInt` documentation for how `ScalarInt` guarantees that equal values
21
23
/// of these types have the same representation.
22
24
Leaf ( ScalarInt ) ,
25
+ SliceOrStr ( ValSlice < ' tcx > ) ,
23
26
/// The fields of any kind of aggregate. Structs, tuples and arrays are represented by
24
27
/// listing their fields' values in order.
25
28
/// Enums are represented by storing their discriminant as a field, followed by all
@@ -32,3 +35,28 @@ impl<'tcx> ValTree<'tcx> {
32
35
Self :: Branch ( & [ ] )
33
36
}
34
37
}
38
+
39
+ #[ derive( Copy , Clone , Debug , HashStable , Hash , Eq , PartialEq , PartialOrd , Ord ) ]
40
+ pub struct ValSlice < ' tcx > {
41
+ pub bytes : & ' tcx [ u8 ] ,
42
+ }
43
+
44
+ impl < ' tcx , S : Encoder > Encodable < S > for ValSlice < ' tcx > {
45
+ fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
46
+ s. emit_usize ( self . bytes . len ( ) ) ?;
47
+ s. emit_raw_bytes ( self . bytes ) ?;
48
+
49
+ Ok ( ( ) )
50
+ }
51
+ }
52
+
53
+ impl < ' tcx , D : TyDecoder < ' tcx > > Decodable < D > for ValSlice < ' tcx > {
54
+ fn decode ( d : & mut D ) -> Self {
55
+ let tcx = d. tcx ( ) ;
56
+ let len = d. read_usize ( ) ;
57
+ let bytes_raw = d. read_raw_bytes ( len) ;
58
+ let bytes = tcx. arena . alloc_slice ( & bytes_raw[ ..] ) ;
59
+
60
+ ValSlice { bytes }
61
+ }
62
+ }
0 commit comments