Skip to content

Commit

Permalink
Span encoding doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
JustusAdam committed Jul 28, 2024
1 parent 959acad commit a2c61fd
Showing 1 changed file with 70 additions and 70 deletions.
140 changes: 70 additions & 70 deletions crates/flowistry_pdg_construction/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,73 +218,73 @@ impl<'tcx, 'a> Decodable<ParalegalDecoder<'tcx, 'a>> for DefIndex {
const TAG_PARTIAL_SPAN: u8 = 0;
const TAG_VALID_SPAN_FULL: u8 = 1;

impl<'tcx> Encodable<ParalegalEncoder<'tcx>> for Span {
fn encode(&self, s: &mut ParalegalEncoder<'tcx>) {
self.data().encode(s)
}
}

impl<'tcx> Encodable<ParalegalEncoder<'tcx>> 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<ParalegalEncoder<'tcx>> for SyntaxContext {
fn encode(&self, _: &mut ParalegalEncoder<'tcx>) {}
}

impl<'tcx, 'a> Decodable<ParalegalDecoder<'tcx, 'a>> for Span {
fn decode(d: &mut ParalegalDecoder<'tcx, 'a>) -> Self {
SpanData::decode(d).span()
}
}

impl<'tcx, 'a> Decodable<ParalegalDecoder<'tcx, 'a>> 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<ParalegalDecoder<'tcx, 'a>> for SyntaxContext {
fn decode(_: &mut ParalegalDecoder<'tcx, 'a>) -> Self {
SyntaxContext::root()
}
}
// impl<'tcx> Encodable<ParalegalEncoder<'tcx>> for Span {
// fn encode(&self, s: &mut ParalegalEncoder<'tcx>) {
// self.data().encode(s)
// }
// }

// impl<'tcx> Encodable<ParalegalEncoder<'tcx>> 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<ParalegalEncoder<'tcx>> for SyntaxContext {
// fn encode(&self, _: &mut ParalegalEncoder<'tcx>) {}
// }

// impl<'tcx, 'a> Decodable<ParalegalDecoder<'tcx, 'a>> for Span {
// fn decode(d: &mut ParalegalDecoder<'tcx, 'a>) -> Self {
// SpanData::decode(d).span()
// }
// }

// impl<'tcx, 'a> Decodable<ParalegalDecoder<'tcx, 'a>> 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<ParalegalDecoder<'tcx, 'a>> for SyntaxContext {
// fn decode(_: &mut ParalegalDecoder<'tcx, 'a>) -> Self {
// SyntaxContext::root()
// }
// }

0 comments on commit a2c61fd

Please sign in to comment.