Skip to content

ICE when trying to parameterize on ebml::writer::Encoder #11881

Closed

Description

@olsonjeffery

(pnkfelix: Here is a modern example that ICE's (feel free to replace as necessary as rustc changes):)

extern crate ser = "serialize";

use serialize = self::ser; // necessary for deriving(Encodable)
use ser::{Encodable, Encoder};
use ser::json;
use ser::ebml::writer;
use std::io::MemWriter;
use std::str::from_utf8_owned;

#[deriving(Encodable)]
struct Foo {
    baz: bool,
}

#[deriving(Encodable)]
struct Bar {
    froboz: uint
}

enum WireProtocol {
    JSON,
    EBML,
    // ...
}

fn encode_json<'a, T: Encodable<json::Encoder<'a>>>(val: &T, wr: &'a mut MemWriter) {
    let mut encoder = json::Encoder::new(wr);
    val.encode(&mut encoder);
}
fn encode_ebml<'a, T: Encodable<writer::Encoder<'a>>>(val: &T, wr: &'a mut MemWriter) {
    let mut encoder = writer::Encoder(wr);
    val.encode(&mut encoder);
}

pub fn main() {
    let target = Foo { baz: false };
    let mut wr = MemWriter::new();
    let proto = JSON;
    match proto {
        JSON => encode_json(&target, &mut wr),
        EBML => encode_ebml(&target, &mut wr)
    }
}

Original bug description follows

Consider the following:

extern mod extra = "extra#0.10-pre";

use extra::serialize::{Encodable, Encoder};
use extra::json;
use extra::ebml::writer;
use std::io::MemWriter;
use std::str::from_utf8_owned;

#[deriving(Encodable)]
struct Foo {
    baz: bool,
}

#[deriving(Encodable)]
struct Bar {
    froboz: uint
}

enum WireProtocol {
    JSON,
    EBML,
    // ...
}

fn encode_json<'a, T: Encodable<json::Encoder<'a>>>(val: &T, wr: &'a mut MemWriter) {
    let mut encoder = json::Encoder::new(wr);
    val.encode(&mut encoder);
}
fn encode_ebml<'a, T: Encodable<writer::Encoder<'a>>>(val: &T, wr: &'a mut MemWriter) {
    let mut encoder = writer::Encoder(wr);
    val.encode(&mut encoder);
}

fn main() {
    let target = Foo { baz: false };
    let mut wr = MemWriter::new();
    let proto = JSON;
    match proto {
        JSON => encode_json(&target, &mut wr),
        EBML => encode_ebml(&target, &mut wr)
    }
}

This fails with the following ICE:

serialization-branch.rs:31:16: 31:28 error: internal compiler error: Cannot relate bound region: ReLateBound(167, BrNamed(syntax::ast::DefId{crate: 0u32, node: 185u32}, a)) <= ReInfer(0)
This message reflects a bug in the Rust compiler.
We would appreciate a bug report: http://static.rust-lang.org/doc/master/complement-bugreport.html
serialization-branch.rs:31     val.encode(&mut encoder);

But if you comment out the EBML code, like so:

extern mod extra = "extra#0.10-pre";

use extra::serialize::{Encodable, Encoder};
use extra::json;
use extra::ebml::writer;
use std::io::MemWriter;
use std::str::from_utf8_owned;

#[deriving(Encodable)]
struct Foo {
    baz: bool,
}

#[deriving(Encodable)]
struct Bar {
    froboz: uint
}

enum WireProtocol {
    JSON,
    EBML,
    // ...
}

fn encode_json<'a, T: Encodable<json::Encoder<'a>>>(val: &T, wr: &'a mut MemWriter) {
    let mut encoder = json::Encoder::new(wr);
    val.encode(&mut encoder);
}
/*
fn encode_ebml<'a, T: Encodable<writer::Encoder<'a>>>(val: &T, wr: &'a mut MemWriter) {
    let mut encoder = writer::Encoder(wr);
    val.encode(&mut encoder);
}
*/

fn main() {
    let target = Foo { baz: false };
    let mut wr = MemWriter::new();
    let proto = JSON;
    match proto {
        JSON => encode_json(&target, &mut wr),
        _ => {}
        //EBML => encode_ebml(&target, &mut wr)
    }
}

it compiles.

The JSON and EBML serialization code is identifical, but their Encoder impls and how they're exposed are slightly different (I assume because of their respective histories). Something about that difference is triggering this ICE, it seems.

Activity

  1. olsonjeffery commented on Jan 29, 2014

    @olsonjeffery
    ContributorAuthor

    As observed by @huonw , probably related to #5121

  2. pnkfelix commented on Mar 21, 2014

    @pnkfelix
    Contributor

    still reproduces.

    updated description to put in something that builds against rustc 0.10-pre (caf17fe 2014-03-21)

  3. JustAPerson commented on Mar 31, 2014

    @JustAPerson
    Contributor

    This no longer produces an ICE likely due to #13157 and related work towards resolving the outstanding #5121.

    The updated version in the description no longer builds against master due to changes in the libserialize API, so I have updated it again here: https://gist.github.com/JustAPerson/a96dddcde35633ec9d27
    A small diff is provided:

    --- old.rs 2014-03-30 20:40:18.290040065 -0500
    +++ new.rs     2014-03-30 20:47:11.096850380 -0500
    @@ -26 +26 @@
    -fn encode_json<'a, T: Encodable<json::Encoder<'a>>>(val: &T, wr: &'a mut MemWriter) {
    +fn encode_json<'a, T: Encodable<json::Encoder<'a>, std::io::IoError>>(val: &T, wr: &'a mut MemWriter) {
    @@ -30 +30 @@
    -fn encode_ebml<'a, T: Encodable<writer::Encoder<'a>>>(val: &T, wr: &'a mut MemWriter) {
    +fn encode_ebml<'a, T: Encodable<writer::Encoder<'a, MemWriter>, std::io::IoError>>(val: &T, wr: &'a mut MemWriter) {

    Tested with

    rustc 0.10-pre (ec7d0c7 2014-03-30 11:26:44 -0700)
    host: x86_64-unknown-linux-gnu
    
  4. sfackler commented on Mar 31, 2014

    @sfackler
    Member

    Flagging as needstest

  5. added a commit that references this issue on Feb 26, 2024
  6. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions