1use rustc_data_structures::fx::FxHashMap;
2use rustc_span::{SpanDecoder, SpanEncoder};
3
4use crate::{Interner, PredicateKind};
5
6pub const SHORTHAND_OFFSET: usize = 0x80;
10
11pub trait RefDecodable<'tcx, D: TyDecoder> {
22 fn decode(d: &mut D) -> &'tcx Self;
23}
24
25pub trait TyEncoder: SpanEncoder {
26 type I: Interner;
27 const CLEAR_CROSS_CRATE: bool;
28
29 fn position(&self) -> usize;
30
31 fn type_shorthands(&mut self) -> &mut FxHashMap<<Self::I as Interner>::Ty, usize>;
32
33 fn predicate_shorthands(&mut self) -> &mut FxHashMap<PredicateKind<Self::I>, usize>;
34
35 fn encode_alloc_id(&mut self, alloc_id: &<Self::I as Interner>::AllocId);
36}
37
38pub trait TyDecoder: SpanDecoder {
39 type I: Interner;
40 const CLEAR_CROSS_CRATE: bool;
41
42 fn interner(&self) -> Self::I;
43
44 fn cached_ty_for_shorthand<F>(
45 &mut self,
46 shorthand: usize,
47 or_insert_with: F,
48 ) -> <Self::I as Interner>::Ty
49 where
50 F: FnOnce(&mut Self) -> <Self::I as Interner>::Ty;
51
52 fn with_position<F, R>(&mut self, pos: usize, f: F) -> R
53 where
54 F: FnOnce(&mut Self) -> R;
55
56 fn positioned_at_shorthand(&self) -> bool {
57 (self.peek_byte() & (SHORTHAND_OFFSET as u8)) != 0
58 }
59
60 fn decode_alloc_id(&mut self) -> <Self::I as Interner>::AllocId;
61}