Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nightly rustc -Z ast-json generates malformed json #31025

Closed
erickt opened this issue Jan 19, 2016 · 0 comments
Closed

nightly rustc -Z ast-json generates malformed json #31025

erickt opened this issue Jan 19, 2016 · 0 comments
Labels
regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@erickt
Copy link
Contributor

erickt commented Jan 19, 2016

In #30565, @michaelwoerister changed the encoding of syntax::codemap::Span from serializing the value as a single u64 into serializing two sequential u32 values. Unfortunately this violates the serialization protocol, and causes a span like mk_sp(0, 10) to be serialized as 010. Here's the current implementation:

impl Encodable for Span {
    fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
        try!(s.emit_u32(self.lo.0));
        s.emit_u32(self.hi.0)
    }
}

impl Decodable for Span {
    fn decode<D: Decoder>(d: &mut D) -> Result<Span, D::Error> {
        let lo = BytePos(try! { d.read_u32() });
        let hi = BytePos(try! { d.read_u32() });
        Ok(mk_sp(lo, hi))
    }
}

Semantically speaking these spans should be serialized as a tuple, which would properly delimit the two values, but since that'd add a bunch of tagging overhead to the output, it'd probably be more efficient to just restore the old encoding:

impl Encodable for Span {
    fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
        // Encode spans as a single u64 in order to cut down on tagging overhead
        // added by the RBML metadata encoding. The should be solved differently
        // altogether some time (FIXME #21482)
        s.emit_u64( (self.lo.0 as u64) | ((self.hi.0 as u64) << 32) )
    }
}

impl Decodable for Span {
    fn decode<D: Decoder>(d: &mut D) -> Result<Span, D::Error> {
        let lo_hi: u64 = try! { d.read_u64() };
        let lo = BytePos(lo_hi as u32);
        let hi = BytePos((lo_hi >> 32) as u32);
        Ok(mk_sp(lo, hi))
    }
}
@erickt erickt added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Jan 19, 2016
erickt added a commit to erickt/rust that referenced this issue Jan 20, 2016
The protocol for `serialize::{En,De}code` doesn't allow for two
integers to be serialized next to each other. This switches the
protocol to serializing `Span`s as a struct. rbml structs don't
have any overhead, so the metadata shouldn't increase in size,
but it allows the json format to be properly generated, albeit
slightly more heavy than when it was just serializing a span as
a u64.

Closes rust-lang#31025.

s
bors added a commit that referenced this issue Jan 21, 2016
The protocol for `serialize::{En,De}code` doesn't allow for two integers to be serialized next to each other.

Closes #31025.

cc @michaelwoerister
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

No branches or pull requests

1 participant