Skip to content

Commit

Permalink
Need encoder for Span's and SyntaxContext
Browse files Browse the repository at this point in the history
  • Loading branch information
JustusAdam committed Jul 28, 2024
1 parent 4f7e299 commit 959acad
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions crates/flowistry_pdg_construction/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//! unimplemented and will cause a crash if you try to stick an `AllocId` into
//! the Paralegal artifact.

use std::num::NonZeroU64;
use std::path::Path;
use std::{num::NonZeroU64, path::PathBuf};

use rustc_const_eval::interpret::AllocId;

Expand All @@ -19,7 +19,10 @@ use rustc_serialize::{
opaque::{FileEncoder, MemDecoder},
Decodable, Decoder, Encodable, Encoder,
};
use rustc_span::{source_map::StableSourceFileId, BytePos, SpanData, SyntaxContext, DUMMY_SP};
use rustc_span::{
source_map::StableSourceFileId, BytePos, FileName, RealFileName, Span, SpanData, SyntaxContext,
DUMMY_SP,
};
use rustc_type_ir::{TyDecoder, TyEncoder};

macro_rules! encoder_methods {
Expand Down Expand Up @@ -215,6 +218,12 @@ 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() {
Expand All @@ -237,6 +246,16 @@ impl<'tcx> Encodable<ParalegalEncoder<'tcx>> for SpanData {
}
}

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);
Expand All @@ -263,3 +282,9 @@ impl<'tcx, 'a> Decodable<ParalegalDecoder<'tcx, 'a>> for SpanData {
}
}
}

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

0 comments on commit 959acad

Please sign in to comment.