From a2c61fd98ee09b1060eded5dbcfed882dfd61bdd Mon Sep 17 00:00:00 2001 From: Justus Adam Date: Sun, 28 Jul 2024 19:28:22 -0400 Subject: [PATCH] Span encoding doesn't work --- .../flowistry_pdg_construction/src/encoder.rs | 140 +++++++++--------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/crates/flowistry_pdg_construction/src/encoder.rs b/crates/flowistry_pdg_construction/src/encoder.rs index 939f40f90a..95742f1459 100644 --- a/crates/flowistry_pdg_construction/src/encoder.rs +++ b/crates/flowistry_pdg_construction/src/encoder.rs @@ -218,73 +218,73 @@ impl<'tcx, 'a> Decodable> for DefIndex { const TAG_PARTIAL_SPAN: u8 = 0; const TAG_VALID_SPAN_FULL: u8 = 1; -impl<'tcx> Encodable> for Span { - fn encode(&self, s: &mut ParalegalEncoder<'tcx>) { - self.data().encode(s) - } -} - -impl<'tcx> Encodable> for SpanData { - fn encode(&self, s: &mut ParalegalEncoder<'tcx>) { - if self.is_dummy() { - return TAG_PARTIAL_SPAN.encode(s); - } - let source_map = s.tcx.sess.source_map(); - let source_file = source_map.lookup_source_file(self.lo); - if !source_file.contains(self.hi) { - // Unfortunately, macro expansion still sometimes generates Spans - // that malformed in this way. - return TAG_PARTIAL_SPAN.encode(s); - } - TAG_VALID_SPAN_FULL.encode(s); - StableSourceFileId::new(&source_file).encode(s); - - let lo = self.lo - source_file.start_pos; - let len = self.hi - self.lo; - lo.encode(s); - len.encode(s); - } -} - -impl<'tcx> Encodable> for SyntaxContext { - fn encode(&self, _: &mut ParalegalEncoder<'tcx>) {} -} - -impl<'tcx, 'a> Decodable> for Span { - fn decode(d: &mut ParalegalDecoder<'tcx, 'a>) -> Self { - SpanData::decode(d).span() - } -} - -impl<'tcx, 'a> Decodable> for SpanData { - fn decode(d: &mut ParalegalDecoder<'tcx, 'a>) -> Self { - let ctxt = SyntaxContext::decode(d); - let tag = u8::decode(d); - if tag == TAG_PARTIAL_SPAN { - return DUMMY_SP.with_ctxt(ctxt).data(); - } - debug_assert_eq!(tag, TAG_VALID_SPAN_FULL); - let id = StableSourceFileId::decode(d); - let source_file = d - .tcx - .sess - .source_map() - .source_file_by_stable_id(id) - .unwrap(); - let lo = BytePos::decode(d); - let len = BytePos::decode(d); - let hi = lo + len; - SpanData { - lo: source_file.start_pos + lo, - hi: source_file.start_pos + hi, - ctxt, - parent: None, - } - } -} - -impl<'tcx, 'a> Decodable> for SyntaxContext { - fn decode(_: &mut ParalegalDecoder<'tcx, 'a>) -> Self { - SyntaxContext::root() - } -} +// impl<'tcx> Encodable> for Span { +// fn encode(&self, s: &mut ParalegalEncoder<'tcx>) { +// self.data().encode(s) +// } +// } + +// impl<'tcx> Encodable> for SpanData { +// fn encode(&self, s: &mut ParalegalEncoder<'tcx>) { +// if self.is_dummy() { +// return TAG_PARTIAL_SPAN.encode(s); +// } +// let source_map = s.tcx.sess.source_map(); +// let source_file = source_map.lookup_source_file(self.lo); +// if !source_file.contains(self.hi) { +// // Unfortunately, macro expansion still sometimes generates Spans +// // that malformed in this way. +// return TAG_PARTIAL_SPAN.encode(s); +// } +// TAG_VALID_SPAN_FULL.encode(s); +// StableSourceFileId::new(&source_file).encode(s); + +// let lo = self.lo - source_file.start_pos; +// let len = self.hi - self.lo; +// lo.encode(s); +// len.encode(s); +// } +// } + +// impl<'tcx> Encodable> for SyntaxContext { +// fn encode(&self, _: &mut ParalegalEncoder<'tcx>) {} +// } + +// impl<'tcx, 'a> Decodable> for Span { +// fn decode(d: &mut ParalegalDecoder<'tcx, 'a>) -> Self { +// SpanData::decode(d).span() +// } +// } + +// impl<'tcx, 'a> Decodable> for SpanData { +// fn decode(d: &mut ParalegalDecoder<'tcx, 'a>) -> Self { +// let ctxt = SyntaxContext::decode(d); +// let tag = u8::decode(d); +// if tag == TAG_PARTIAL_SPAN { +// return DUMMY_SP.with_ctxt(ctxt).data(); +// } +// debug_assert_eq!(tag, TAG_VALID_SPAN_FULL); +// let id = StableSourceFileId::decode(d); +// let source_file = d +// .tcx +// .sess +// .source_map() +// .source_file_by_stable_id(id) +// .unwrap(); +// let lo = BytePos::decode(d); +// let len = BytePos::decode(d); +// let hi = lo + len; +// SpanData { +// lo: source_file.start_pos + lo, +// hi: source_file.start_pos + hi, +// ctxt, +// parent: None, +// } +// } +// } + +// impl<'tcx, 'a> Decodable> for SyntaxContext { +// fn decode(_: &mut ParalegalDecoder<'tcx, 'a>) -> Self { +// SyntaxContext::root() +// } +// }