Skip to content

Fixing json decoding for enums, global type constraints, pretty printing debug!, and other fixes #5578

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

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ impl vtable_decoder_helpers for reader::Decoder {
@self.read_to_vec(|| self.read_vtable_origin(xcx) )
}

#[cfg(stage0)]
fn read_vtable_origin(&self, xcx: @ExtendedDecodeContext)
-> typeck::vtable_origin {
do self.read_enum(~"vtable_origin") {
Expand Down Expand Up @@ -715,6 +716,44 @@ impl vtable_decoder_helpers for reader::Decoder {
}
}
}

#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn read_vtable_origin(&self, xcx: @ExtendedDecodeContext)
-> typeck::vtable_origin {
do self.read_enum("vtable_origin") {
do self.read_enum_variant(["vtable_static", "vtable_param"]) |i| {
match i {
0 => {
typeck::vtable_static(
do self.read_enum_variant_arg(0u) {
self.read_def_id(xcx)
},
do self.read_enum_variant_arg(1u) {
self.read_tys(xcx)
},
do self.read_enum_variant_arg(2u) {
self.read_vtable_res(xcx)
}
)
}
1 => {
typeck::vtable_param(
do self.read_enum_variant_arg(0u) {
self.read_uint()
},
do self.read_enum_variant_arg(1u) {
self.read_uint()
}
)
}
// hard to avoid - user input
_ => fail!(~"bad enum variant")
}
}
}
}
}

// ______________________________________________________________________
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ pub fn check_expr(sess: Session,
expr_paren(e) => { check_expr(sess, def_map, method_map,
tcx, e, is_const, v); }
expr_vstore(_, expr_vstore_slice) |
expr_vstore(_, expr_vstore_fixed(_)) |
expr_vec(_, m_imm) |
expr_addr_of(m_imm, _) |
expr_field(*) |
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ pub fn classify(e: @expr,

ast::expr_vstore(e, vstore) => {
match vstore {
ast::expr_vstore_fixed(_) |
ast::expr_vstore_slice => classify(e, tcx),
ast::expr_vstore_uniq |
ast::expr_vstore_box |
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ pub impl Liveness {
self.propagate_through_expr(l, ln)
}

expr_log(_, l, r) |
expr_log(l, r) |
expr_index(l, r) |
expr_binary(_, l, r) => {
self.propagate_through_exprs(~[l, r], succ)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/moves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ pub impl VisitContext {
self.consume_block(blk, visitor);
}

expr_log(_, a_expr, b_expr) => {
expr_log(a_expr, b_expr) => {
self.consume_expr(a_expr, visitor);
self.use_expr(b_expr, Read, visitor);
}
Expand Down
3 changes: 0 additions & 3 deletions src/librustc/middle/trans/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,6 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
let (v, _, _) = const_vec(cx, e, *es);
v
}
ast::expr_vstore(e, ast::expr_vstore_fixed(_)) => {
const_expr(cx, e)
}
ast::expr_vstore(sub, ast::expr_vstore_slice) => {
match sub.node {
ast::expr_lit(ref lit) => {
Expand Down
5 changes: 1 addition & 4 deletions src/librustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ fn trans_rvalue_stmt_unadjusted(bcx: block, expr: @ast::expr) -> block {
ast::expr_ret(ex) => {
return controlflow::trans_ret(bcx, ex);
}
ast::expr_log(_, lvl, a) => {
ast::expr_log(lvl, a) => {
return controlflow::trans_log(expr, lvl, bcx, a);
}
ast::expr_while(cond, ref body) => {
Expand Down Expand Up @@ -714,9 +714,6 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
ast::expr_vstore(contents, ast::expr_vstore_mut_slice) => {
return tvec::trans_slice_vstore(bcx, expr, contents, dest);
}
ast::expr_vstore(contents, ast::expr_vstore_fixed(_)) => {
return tvec::trans_fixed_vstore(bcx, expr, contents, dest);
}
ast::expr_vec(*) | ast::expr_repeat(*) => {
return tvec::trans_fixed_vstore(bcx, expr, expr, dest);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/type_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ pub fn mark_for_expr(cx: Context, e: @expr) {
type_needs(cx, use_repr, ty::type_autoderef(cx.ccx.tcx, base_ty));
mark_for_method_call(cx, e.id, e.callee_id);
}
expr_log(_, _, val) => {
expr_log(_, val) => {
node_type_needs(cx, use_tydesc, val.id);
}
expr_call(f, _, _) => {
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3117,7 +3117,6 @@ pub fn expr_kind(tcx: ctxt,
ast::expr_lit(@codemap::spanned {node: lit_str(_), _}) |
ast::expr_vstore(_, ast::expr_vstore_slice) |
ast::expr_vstore(_, ast::expr_vstore_mut_slice) |
ast::expr_vstore(_, ast::expr_vstore_fixed(_)) |
ast::expr_vec(*) => {
RvalueDpsExpr
}
Expand Down
10 changes: 1 addition & 9 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2402,7 +2402,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
}
fcx.write_bot(id);
}
ast::expr_log(_, lv, e) => {
ast::expr_log(lv, e) => {
check_expr_has_type(fcx, lv,
ty::mk_mach_uint(tcx, ast::ty_u32));

Expand Down Expand Up @@ -3337,14 +3337,6 @@ pub fn ast_expr_vstore_to_vstore(fcx: @mut FnCtxt,
v: ast::expr_vstore)
-> ty::vstore {
match v {
ast::expr_vstore_fixed(None) => ty::vstore_fixed(n),
ast::expr_vstore_fixed(Some(u)) => {
if n != u {
let s = fmt!("fixed-size sequence mismatch: %u vs. %u",u, n);
fcx.ccx.tcx.sess.span_err(e.span,s);
}
ty::vstore_fixed(u)
}
ast::expr_vstore_uniq => ty::vstore_uniq,
ast::expr_vstore_box | ast::expr_vstore_mut_box => ty::vstore_box,
ast::expr_vstore_slice | ast::expr_vstore_mut_slice => {
Expand Down
56 changes: 54 additions & 2 deletions src/libstd/ebml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ pub mod reader {
self.push_doc(self.next_doc(EsEnum), f)
}

#[cfg(stage0)]
fn read_enum_variant<T>(&self, f: &fn(uint) -> T) -> T {
debug!("read_enum_variant()");
let idx = self._next_uint(EsEnumVid);
Expand All @@ -346,6 +347,18 @@ pub mod reader {
}
}

#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn read_enum_variant<T>(&self, _names: &[&str], f: &fn(uint) -> T) -> T {
debug!("read_enum_variant()");
let idx = self._next_uint(EsEnumVid);
debug!(" idx=%u", idx);
do self.push_doc(self.next_doc(EsEnumBody)) {
f(idx)
}
}

fn read_enum_variant_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
debug!("read_enum_variant_arg(idx=%u)", idx);
f()
Expand Down Expand Up @@ -399,8 +412,37 @@ pub mod reader {
debug!("read_tup_elt(idx=%u)", idx);
f()
}
}

#[cfg(stage0)]
fn read_option<T>(&self, f: &fn() -> T) -> Option<T> {
debug!("read_option()");
do self.read_enum("Option") || {
do self.read_enum_variant |idx| {
match idx {
0 => None,
1 => Some(f()),
_ => fail!(),
}
}
}
}

#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn read_option<T>(&self, f: &fn() -> T) -> Option<T> {
debug!("read_option()");
do self.read_enum("Option") || {
do self.read_enum_variant(["None", "Some"]) |idx| {
match idx {
0 => None,
1 => Some(f()),
_ => fail!(),
}
}
}
}
}
}

pub mod writer {
Expand Down Expand Up @@ -666,9 +708,19 @@ pub mod writer {

fn emit_tup(&self, _len: uint, f: &fn()) { f() }
fn emit_tup_elt(&self, _idx: uint, f: &fn()) { f() }
}

fn emit_option(&self, f: &fn()) {
self.emit_enum("Option", f);
}
fn emit_option_none(&self) {
self.emit_enum_variant("None", 0, 0, || ())
}
fn emit_option_some(&self, f: &fn()) {
self.emit_enum_variant("Some", 1, 1, f)
}
}
}

// ___________________________________________________________________________
// Testing

Expand Down
Loading