11use 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 } ;
35
46#[ derive( Copy , Clone , Debug , Hash , TyEncodable , TyDecodable , Eq , PartialEq , Ord , PartialOrd ) ]
57#[ derive( HashStable ) ]
@@ -20,6 +22,7 @@ pub enum ValTree<'tcx> {
2022 /// See the `ScalarInt` documentation for how `ScalarInt` guarantees that equal values
2123 /// of these types have the same representation.
2224 Leaf ( ScalarInt ) ,
25+ SliceOrStr ( ValSlice < ' tcx > ) ,
2326 /// The fields of any kind of aggregate. Structs, tuples and arrays are represented by
2427 /// listing their fields' values in order.
2528 /// Enums are represented by storing their discriminant as a field, followed by all
@@ -32,3 +35,28 @@ impl<'tcx> ValTree<'tcx> {
3235 Self :: Branch ( & [ ] )
3336 }
3437}
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