Skip to content

More records-to-structs conversions #4498

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

Merged
merged 4 commits into from
Jan 15, 2013
Merged
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
19 changes: 12 additions & 7 deletions src/librustc/front/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,19 @@ fn filter_stmt(cx: ctxt, &&stmt: @ast::stmt) ->
}
}

fn fold_block(cx: ctxt, b: ast::blk_, fld: fold::ast_fold) ->
ast::blk_ {
fn fold_block(
cx: ctxt,
b: ast::blk_,
fld: fold::ast_fold
) -> ast::blk_ {
let filtered_stmts = vec::filter_map(b.stmts, |a| filter_stmt(cx, *a));
return {view_items: /*bad*/copy b.view_items,
stmts: vec::map(filtered_stmts, |x| fld.fold_stmt(*x)),
expr: option::map(&b.expr, |x| fld.fold_expr(*x)),
id: b.id,
rules: b.rules};
ast::blk_ {
view_items: /*bad*/copy b.view_items,
stmts: vec::map(filtered_stmts, |x| fld.fold_stmt(*x)),
expr: option::map(&b.expr, |x| fld.fold_expr(*x)),
id: b.id,
rules: b.rules,
}
}

fn item_in_cfg(cx: ctxt, item: @ast::item) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/front/core_inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn inject_libcore_ref(sess: Session,
new_module = fld.fold_mod(new_module);

// XXX: Bad copy.
let new_crate = { module: new_module, ..copy crate };
let new_crate = ast::crate_ { module: new_module, ..copy crate };
(new_crate, span)
},
fold_mod: |module, fld| {
Expand Down
9 changes: 7 additions & 2 deletions src/librustc/front/intrinsic_inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ fn inject_intrinsic(sess: Session, crate: @ast::crate) -> @ast::crate {
let items = vec::append(~[item], crate.node.module.items);

@ast::spanned {
node: { module: { items: items ,.. /*bad*/copy crate.node.module },
.. /*bad*/copy crate.node},
node: ast::crate_ {
module: {
items: items,
.. /*bad*/copy crate.node.module
},
.. /*bad*/copy crate.node
},
.. /*bad*/copy *crate
}
}
42 changes: 25 additions & 17 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ fn fold_crate(cx: test_ctxt, c: ast::crate_, fld: fold::ast_fold) ->

// Add a special __test module to the crate that will contain code
// generated for the test harness
return {module: add_test_module(cx, /*bad*/copy folded.module),.. folded};
ast::crate_ { module: add_test_module(cx, /*bad*/copy folded.module),
.. folded }
}


Expand Down Expand Up @@ -339,13 +340,13 @@ fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::Ty {
node: ast::ty_path(test_desc_ty_path, cx.sess.next_node_id()),
span: dummy_sp()};

let vec_mt: ast::mt = {ty: @test_desc_ty, mutbl: ast::m_imm};
let vec_mt = ast::mt {ty: @test_desc_ty, mutbl: ast::m_imm};

let inner_ty = @{id: cx.sess.next_node_id(),
node: ast::ty_vec(vec_mt),
span: dummy_sp()};
return @{id: cx.sess.next_node_id(),
node: ast::ty_uniq({ty: inner_ty, mutbl: ast::m_imm}),
node: ast::ty_uniq(ast::mt {ty: inner_ty, mutbl: ast::m_imm}),
span: dummy_sp()};
}

Expand Down Expand Up @@ -388,9 +389,11 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
span: dummy_sp()};


let name_field: ast::field =
nospan({mutbl: ast::m_imm, ident: cx.sess.ident_of(~"name"),
expr: @name_expr});
let name_field = nospan(ast::field_ {
mutbl: ast::m_imm,
ident: cx.sess.ident_of(~"name"),
expr: @name_expr,
});

let fn_path = path_node_global(path);

Expand All @@ -402,9 +405,11 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {

let fn_wrapper_expr = mk_test_wrapper(cx, fn_expr, span);

let fn_field: ast::field =
nospan({mutbl: ast::m_imm, ident: cx.sess.ident_of(~"testfn"),
expr: fn_wrapper_expr});
let fn_field = nospan(ast::field_ {
mutbl: ast::m_imm,
ident: cx.sess.ident_of(~"testfn"),
expr: fn_wrapper_expr,
});

let ignore_lit: ast::lit = nospan(ast::lit_bool(test.ignore));

Expand All @@ -414,9 +419,11 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
node: ast::expr_lit(@ignore_lit),
span: span};

let ignore_field: ast::field =
nospan({mutbl: ast::m_imm, ident: cx.sess.ident_of(~"ignore"),
expr: @ignore_expr});
let ignore_field = nospan(ast::field_ {
mutbl: ast::m_imm,
ident: cx.sess.ident_of(~"ignore"),
expr: @ignore_expr,
});

let fail_lit: ast::lit = nospan(ast::lit_bool(test.should_fail));

Expand All @@ -426,10 +433,11 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
node: ast::expr_lit(@fail_lit),
span: span};

let fail_field: ast::field =
nospan({mutbl: ast::m_imm,
ident: cx.sess.ident_of(~"should_fail"),
expr: @fail_expr});
let fail_field = nospan(ast::field_ {
mutbl: ast::m_imm,
ident: cx.sess.ident_of(~"should_fail"),
expr: @fail_expr,
});

let test_desc_path =
mk_path(cx, ~[cx.sess.ident_of(~"test"),
Expand Down Expand Up @@ -468,7 +476,7 @@ fn mk_test_wrapper(cx: test_ctxt,
cf: ast::return_val
};

let wrapper_body: ast::blk = nospan({
let wrapper_body = nospan(ast::blk_ {
view_items: ~[],
stmts: ~[@call_stmt],
expr: option::None,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ fn parse_mt(st: @pstate, conv: conv_did) -> ty::mt {
'?' => { next(st); m = ast::m_const; }
_ => { m = ast::m_imm; }
}
return {ty: parse_ty(st, conv), mutbl: m};
ty::mt { ty: parse_ty(st, conv), mutbl: m }
}

fn parse_def(st: @pstate, conv: conv_did) -> ast::def_id {
Expand Down
5 changes: 4 additions & 1 deletion src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
}
};
// XXX: Bad copy.
let blk_sans_items = { stmts: stmts_sans_items,.. copy blk };
let blk_sans_items = ast::blk_ {
stmts: stmts_sans_items,
.. copy blk
};
fold::noop_fold_block(blk_sans_items, fld)
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ fn ctor_arity(cx: @MatchCheckCtxt, ctor: ctor, ty: ty::t) -> uint {
}

fn wild() -> @pat {
@{id: 0, node: pat_wild, span: ast_util::dummy_sp()}
@pat {id: 0, node: pat_wild, span: ast_util::dummy_sp()}
}

fn specialize(cx: @MatchCheckCtxt, r: ~[@pat], ctor_id: ctor, arity: uint,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ impl &mem_categorization_ctxt {
// know what type lies at the other end, so we just call it
// `()` (the empty tuple).

let mt = {ty: ty::mk_tup(self.tcx, ~[]), mutbl: m_imm};
let mt = ty::mt {ty: ty::mk_tup(self.tcx, ~[]), mutbl: m_imm};
return self.cat_deref_common(node, base_cmt, deref_cnt, mt);
}

Expand Down
16 changes: 8 additions & 8 deletions src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint,
let _indenter = indenter();

let tcx = bcx.tcx();
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, tcx.def_map, m, col, val) |p| {
match /*bad*/copy p.node {
ast::pat_enum(_, subpats) => {
Expand Down Expand Up @@ -600,7 +600,7 @@ fn enter_rec_or_struct(bcx: block, dm: DefMap, m: &[@Match/&r], col: uint,
bcx.val_str(val));
let _indenter = indenter();

let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| {
match /*bad*/copy p.node {
ast::pat_rec(fpats, _) | ast::pat_struct(_, fpats, _) => {
Expand Down Expand Up @@ -632,7 +632,7 @@ fn enter_tup(bcx: block, dm: DefMap, m: &[@Match/&r],
bcx.val_str(val));
let _indenter = indenter();

let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| {
match /*bad*/copy p.node {
ast::pat_tup(elts) => {
Expand All @@ -657,7 +657,7 @@ fn enter_tuple_struct(bcx: block, dm: DefMap, m: &[@Match/&r], col: uint,
bcx.val_str(val));
let _indenter = indenter();

let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| {
match /*bad*/copy p.node {
ast::pat_enum(_, Some(elts)) => Some(elts),
Expand All @@ -680,7 +680,7 @@ fn enter_box(bcx: block, dm: DefMap, m: &[@Match/&r],
bcx.val_str(val));
let _indenter = indenter();

let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| {
match p.node {
ast::pat_box(sub) => {
Expand All @@ -705,7 +705,7 @@ fn enter_uniq(bcx: block, dm: DefMap, m: &[@Match/&r],
bcx.val_str(val));
let _indenter = indenter();

let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| {
match p.node {
ast::pat_uniq(sub) => {
Expand All @@ -730,7 +730,7 @@ fn enter_region(bcx: block, dm: DefMap, m: &[@Match/&r],
bcx.val_str(val));
let _indenter = indenter();

let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
let dummy = @ast::pat { id: 0, node: ast::pat_wild, span: dummy_sp() };
do enter_match(bcx, dm, m, col, val) |p| {
match p.node {
ast::pat_region(sub) => {
Expand Down Expand Up @@ -857,7 +857,7 @@ fn extract_vec_elems(bcx: block, pat_id: ast::node_id,
let tail_begin = tvec::pointer_add(bcx, base, tail_offset);
let tail_len = Sub(bcx, len, tail_offset);
let tail_ty = ty::mk_evec(bcx.tcx(),
{ty: vt.unit_ty, mutbl: ast::m_imm},
ty::mt {ty: vt.unit_ty, mutbl: ast::m_imm},
ty::vstore_slice(ty::re_static)
);
let scratch = scratch_datum(bcx, tail_ty, false);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2184,7 +2184,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef) {
let unit_ty = ty::mk_estr(ccx.tcx, ty::vstore_uniq);
let vecarg_ty: ty::arg =
{mode: ast::expl(ast::by_val),
ty: ty::mk_evec(ccx.tcx, {ty: unit_ty, mutbl: ast::m_imm},
ty: ty::mk_evec(ccx.tcx, ty::mt {ty: unit_ty, mutbl: ast::m_imm},
ty::vstore_uniq)};
let nt = ty::mk_nil(ccx.tcx);
let llfty = type_of_fn(ccx, ~[vecarg_ty], nt);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ fn store_environment(bcx: block,
// tuple. This could be a ptr in uniq or a box or on stack,
// whatever.
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
let cboxptr_ty = ty::mk_ptr(tcx, {ty:cbox_ty, mutbl:ast::m_imm});
let cboxptr_ty = ty::mk_ptr(tcx, ty::mt {ty:cbox_ty, mutbl:ast::m_imm});

let llbox = PointerCast(bcx, llbox, type_of(ccx, cboxptr_ty));
debug!("tuplify_box_ty = %s", ty_to_str(tcx, cbox_ty));
Expand Down
5 changes: 4 additions & 1 deletion src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,10 @@ fn T_opaque_vec(targ_cfg: @session::config) -> TypeRef {
// representation of @T as a tuple (i.e., the ty::t version of what T_box()
// returns).
fn tuplify_box_ty(tcx: ty::ctxt, t: ty::t) -> ty::t {
let ptr = ty::mk_ptr(tcx, {ty: ty::mk_nil(tcx), mutbl: ast::m_imm});
let ptr = ty::mk_ptr(
tcx,
ty::mt {ty: ty::mk_nil(tcx), mutbl: ast::m_imm}
);
return ty::mk_tup(tcx, ~[ty::mk_uint(tcx), ty::mk_type(tcx),
ptr, ptr,
t]);
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ fn trans_to_datum(bcx: block, expr: @ast::expr) -> DatumBlock {

// this type may have a different region/mutability than the
// real one, but it will have the same runtime representation
let slice_ty = ty::mk_evec(tcx, {ty: unit_ty, mutbl: ast::m_imm},
let slice_ty = ty::mk_evec(tcx,
ty::mt { ty: unit_ty, mutbl: ast::m_imm },
ty::vstore_slice(ty::re_static));

let scratch = scratch_datum(bcx, slice_ty, false);
Expand Down
7 changes: 3 additions & 4 deletions src/librustc/middle/trans/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use syntax::parse::token::special_idents;
// nominal type that has pointers to itself in it.
pub fn simplify_type(tcx: ty::ctxt, typ: ty::t) -> ty::t {
fn nilptr(tcx: ty::ctxt) -> ty::t {
ty::mk_ptr(tcx, {ty: ty::mk_nil(tcx), mutbl: ast::m_imm})
ty::mk_ptr(tcx, ty::mt {ty: ty::mk_nil(tcx), mutbl: ast::m_imm})
}
fn simplifier(tcx: ty::ctxt, typ: ty::t) -> ty::t {
match ty::get(typ).sty {
Expand All @@ -45,13 +45,12 @@ pub fn simplify_type(tcx: ty::ctxt, typ: ty::t) -> ty::t {
let simpl_fields = (if ty::ty_dtor(tcx, did).is_present() {
// remember the drop flag
~[{ident: special_idents::dtor,
mt: {ty: ty::mk_u8(tcx),
mutbl: ast::m_mutbl}}] }
mt: ty::mt {ty: ty::mk_u8(tcx), mutbl: ast::m_mutbl}}] }
else { ~[] }) +
do ty::lookup_struct_fields(tcx, did).map |f| {
let t = ty::lookup_field_type(tcx, did, f.id, substs);
{ident: f.ident,
mt: {ty: simplify_type(tcx, t), mutbl: ast::m_const}}
mt: ty::mt {ty: simplify_type(tcx, t), mutbl: ast::m_const}}
};
ty::mk_rec(tcx, simpl_fields)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/tvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ fn trans_slice_vstore(bcx: block,

// Arrange for the backing array to be cleaned up.
let fixed_ty = ty::mk_evec(bcx.tcx(),
{ty: vt.unit_ty, mutbl: ast::m_mutbl},
ty::mt {ty: vt.unit_ty, mutbl: ast::m_mutbl},
ty::vstore_fixed(count));
let llfixed_ty = T_ptr(type_of::type_of(bcx.ccx(), fixed_ty));
let llfixed_casted = BitCast(bcx, llfixed, llfixed_ty);
Expand Down
Loading