Skip to content

Commit 5375962

Browse files
committed
---
yaml --- r: 2657 b: refs/heads/master c: 7f938f4 h: refs/heads/master i: 2655: c13f008 v: v3
1 parent 9907472 commit 5375962

File tree

5 files changed

+297
-283
lines changed

5 files changed

+297
-283
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 1d67ee0e88540871af028707163cf8b087837f25
2+
refs/heads/master: 7f938f4945bcf6ba27f872b179a517e4d5c39a4f

trunk/src/comp/front/creader.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,9 @@ fn lookup_def(int cnum, vec[u8] data, &ast::def_id did) -> ast::def {
512512
ret def;
513513
}
514514

515-
fn get_type(session::session sess, ty::ctxt tcx, ast::def_id def)
516-
-> ty::ty_param_count_and_ty {
515+
fn get_type(ty::ctxt tcx, ast::def_id def) -> ty::ty_param_count_and_ty {
517516
auto external_crate_id = def._0;
518-
auto data = sess.get_external_crate(external_crate_id).data;
517+
auto data = tcx.sess.get_external_crate(external_crate_id).data;
519518
auto item = lookup_item(def._1, data);
520519
auto t = item_type(item, external_crate_id, tcx);
521520

@@ -537,14 +536,14 @@ fn get_symbol(session::session sess, ast::def_id def) -> str {
537536
ret item_symbol(lookup_item(def._1, data));
538537
}
539538

540-
fn get_tag_variants(session::session sess, ty::ctxt tcx, ast::def_id def)
541-
-> vec[trans::variant_info] {
539+
fn get_tag_variants(ty::ctxt tcx, ast::def_id def)
540+
-> vec[ty::variant_info] {
542541
auto external_crate_id = def._0;
543-
auto data = sess.get_external_crate(external_crate_id).data;
542+
auto data = tcx.sess.get_external_crate(external_crate_id).data;
544543
auto items = ebml::get_doc(ebml::new_doc(data), metadata::tag_items);
545544
auto item = find_item(def._1, items);
546545

547-
let vec[trans::variant_info] infos = [];
546+
let vec[ty::variant_info] infos = [];
548547
auto variant_ids = tag_variant_ids(item, external_crate_id);
549548
for (ast::def_id did in variant_ids) {
550549
auto item = find_item(did._1, items);

trunk/src/comp/middle/trans.rs

Lines changed: 20 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,8 +1272,8 @@ fn static_size_of_tag(&@crate_ctxt cx, &ast::span sp, &ty::t t) -> uint {
12721272

12731273
// Compute max(variant sizes).
12741274
auto max_size = 0u;
1275-
auto variants = tag_variants(cx, tid);
1276-
for (variant_info variant in variants) {
1275+
auto variants = ty::tag_variants(cx.tcx, tid);
1276+
for (ty::variant_info variant in variants) {
12771277
auto tup_ty = simplify_type(cx, ty::mk_imm_tup(cx.tcx, variant.args));
12781278

12791279
// Perform any type parameter substitutions.
@@ -1345,8 +1345,8 @@ fn dynamic_size_of(&@block_ctxt cx, ty::t t) -> result {
13451345
let ValueRef max_size = alloca(bcx, T_int());
13461346
bcx.build.Store(C_int(0), max_size);
13471347

1348-
auto variants = tag_variants(bcx.fcx.lcx.ccx, tid);
1349-
for (variant_info variant in variants) {
1348+
auto variants = ty::tag_variants(bcx.fcx.lcx.ccx.tcx, tid);
1349+
for (ty::variant_info variant in variants) {
13501350
// Perform type substitution on the raw argument types.
13511351
let vec[ty::t] raw_tys = variant.args;
13521352
let vec[ty::t] tys = [];
@@ -1521,7 +1521,8 @@ fn GEP_tag(@block_ctxt cx,
15211521
&vec[ty::t] ty_substs,
15221522
int ix)
15231523
-> result {
1524-
auto variant = tag_variant_with_id(cx.fcx.lcx.ccx, tag_id, variant_id);
1524+
auto variant = ty::tag_variant_with_id(cx.fcx.lcx.ccx.tcx,
1525+
tag_id, variant_id);
15251526

15261527
// Synthesize a tuple type so that GEP_tup_like() can work its magic.
15271528
// Separately, store the type of the element we're interested in.
@@ -2213,14 +2214,10 @@ fn make_drop_glue(&@block_ctxt cx, ValueRef v0, &ty::t t) {
22132214
}
22142215

22152216
case (_) {
2216-
if (ty::type_is_structural(cx.fcx.lcx.ccx.tcx, t)) {
2217+
if (ty::type_contains_pointers(cx.fcx.lcx.ccx.tcx, t) &&
2218+
ty::type_is_structural(cx.fcx.lcx.ccx.tcx, t)) {
22172219
rslt = iter_structural_ty(cx, v0, t,
22182220
bind drop_ty(_, _, _));
2219-
2220-
} else if (ty::type_is_scalar(cx.fcx.lcx.ccx.tcx, t) ||
2221-
ty::type_is_native(cx.fcx.lcx.ccx.tcx, t) ||
2222-
ty::type_is_nil(cx.fcx.lcx.ccx.tcx, t)) {
2223-
rslt = res(cx, C_nil());
22242221
} else {
22252222
rslt = res(cx, C_nil());
22262223
}
@@ -2543,58 +2540,6 @@ fn make_integral_cmp_glue(&@block_ctxt cx, ValueRef lhs, ValueRef rhs,
25432540
r.bcx.build.RetVoid();
25442541
}
25452542

2546-
2547-
// Tag information
2548-
2549-
type variant_info = rec(vec[ty::t] args, ty::t ctor_ty, ast::def_id id);
2550-
2551-
// Returns information about the variants in a tag.
2552-
fn tag_variants(&@crate_ctxt cx, &ast::def_id id) -> vec[variant_info] {
2553-
if (cx.sess.get_targ_crate_num() != id._0) {
2554-
ret creader::get_tag_variants(cx.sess, cx.tcx, id);
2555-
}
2556-
2557-
assert (cx.items.contains_key(id));
2558-
alt (cx.items.get(id).node) {
2559-
case (ast::item_tag(_, ?variants, _, _, _)) {
2560-
let vec[variant_info] result = [];
2561-
for (ast::variant variant in variants) {
2562-
auto ctor_ty = node_ann_type(cx, variant.node.ann);
2563-
let vec[ty::t] arg_tys = [];
2564-
if (vec::len[ast::variant_arg](variant.node.args) > 0u) {
2565-
for (ty::arg a in ty::ty_fn_args(cx.tcx, ctor_ty)) {
2566-
arg_tys += [a.ty];
2567-
}
2568-
}
2569-
auto did = variant.node.id;
2570-
result += [rec(args=arg_tys, ctor_ty=ctor_ty, id=did)];
2571-
}
2572-
ret result;
2573-
}
2574-
}
2575-
fail; // not reached
2576-
}
2577-
2578-
// Returns information about the tag variant with the given ID:
2579-
fn tag_variant_with_id(&@crate_ctxt cx,
2580-
&ast::def_id tag_id,
2581-
&ast::def_id variant_id) -> variant_info {
2582-
auto variants = tag_variants(cx, tag_id);
2583-
2584-
auto i = 0u;
2585-
while (i < vec::len[variant_info](variants)) {
2586-
auto variant = variants.(i);
2587-
if (common::def_eq(variant.id, variant_id)) {
2588-
ret variant;
2589-
}
2590-
i += 1u;
2591-
}
2592-
2593-
log_err "tag_variant_with_id(): no variant exists with that ID";
2594-
fail;
2595-
}
2596-
2597-
25982543
type val_pair_fn = fn(&@block_ctxt cx, ValueRef dst, ValueRef src) -> result;
25992544

26002545
type val_and_ty_fn = fn(&@block_ctxt cx, ValueRef v, ty::t t) -> result;
@@ -2677,8 +2622,8 @@ fn iter_structural_ty_full(&@block_ctxt cx,
26772622
}
26782623
}
26792624
case (ty::ty_tag(?tid, ?tps)) {
2680-
auto variants = tag_variants(cx.fcx.lcx.ccx, tid);
2681-
auto n_variants = vec::len[variant_info](variants);
2625+
auto variants = ty::tag_variants(cx.fcx.lcx.ccx.tcx, tid);
2626+
auto n_variants = vec::len[ty::variant_info](variants);
26822627

26832628
// Cast the tags to types we can GEP into.
26842629
auto lltagty = T_opaque_tag_ptr(cx.fcx.lcx.ccx.tn);
@@ -2712,7 +2657,7 @@ fn iter_structural_ty_full(&@block_ctxt cx,
27122657
auto next_cx = new_sub_block_ctxt(bcx, "tag-iter-next");
27132658

27142659
auto i = 0u;
2715-
for (variant_info variant in variants) {
2660+
for (ty::variant_info variant in variants) {
27162661
auto variant_cx = new_sub_block_ctxt(bcx,
27172662
"tag-iter-variant-" +
27182663
uint::to_str(i, 10u));
@@ -3167,7 +3112,7 @@ fn drop_ty(&@block_ctxt cx,
31673112
ValueRef v,
31683113
ty::t t) -> result {
31693114

3170-
if (!ty::type_is_scalar(cx.fcx.lcx.ccx.tcx, t)) {
3115+
if (ty::type_contains_pointers(cx.fcx.lcx.ccx.tcx, t)) {
31713116
ret call_tydesc_glue(cx, v, t, false, abi::tydesc_field_drop_glue);
31723117
}
31733118
ret res(cx, C_nil());
@@ -3177,7 +3122,7 @@ fn free_ty(&@block_ctxt cx,
31773122
ValueRef v,
31783123
ty::t t) -> result {
31793124

3180-
if (!ty::type_is_scalar(cx.fcx.lcx.ccx.tcx, t)) {
3125+
if (ty::type_contains_pointers(cx.fcx.lcx.ccx.tcx, t)) {
31813126
ret call_tydesc_glue(cx, v, t, false, abi::tydesc_field_free_glue);
31823127
}
31833128
ret res(cx, C_nil());
@@ -3335,27 +3280,9 @@ fn trans_lit(&@crate_ctxt cx, &ast::lit lit, &ast::ann ann) -> ValueRef {
33353280
}
33363281
}
33373282

3338-
fn target_type(&@crate_ctxt cx, &ty::t t) -> ty::t {
3339-
alt (ty::struct(cx.tcx, t)) {
3340-
case (ty::ty_int) {
3341-
auto struct_ty = ty::mk_mach(cx.tcx,
3342-
cx.sess.get_targ_cfg().int_type);
3343-
ret ty::copy_cname(cx.tcx, struct_ty, t);
3344-
}
3345-
case (ty::ty_uint) {
3346-
auto struct_ty = ty::mk_mach(cx.tcx,
3347-
cx.sess.get_targ_cfg().uint_type);
3348-
ret ty::copy_cname(cx.tcx, struct_ty, t);
3349-
}
3350-
case (_) { /* fall through */ }
3351-
}
3352-
ret t;
3353-
}
3354-
3355-
33563283
// Converts an annotation to a type
33573284
fn node_ann_type(&@crate_ctxt cx, &ast::ann a) -> ty::t {
3358-
ret target_type(cx, ty::ann_to_monotype(cx.tcx, a));
3285+
ret ty::ann_to_monotype(cx.tcx, a);
33593286
}
33603287

33613288
fn node_type(&@crate_ctxt cx, &ast::span sp, &ast::ann a) -> TypeRef {
@@ -4197,9 +4124,9 @@ fn trans_pat_match(&@block_ctxt cx, &@ast::pat pat, ValueRef llval,
41974124
(cx.fcx.lcx.ccx.tcx.def_map.get(ann.id));
41984125
auto variant_tag = 0;
41994126

4200-
auto variants = tag_variants(cx.fcx.lcx.ccx, vdef._0);
4127+
auto variants = ty::tag_variants(cx.fcx.lcx.ccx.tcx, vdef._0);
42014128
auto i = 0;
4202-
for (variant_info v in variants) {
4129+
for (ty::variant_info v in variants) {
42034130
auto this_variant_id = v.id;
42044131
if (vdef._1._0 == this_variant_id._0 &&
42054132
vdef._1._1 == this_variant_id._1) {
@@ -4467,18 +4394,15 @@ fn trans_path(&@block_ctxt cx, &ast::path p, &ast::ann ann) -> lval_result {
44674394
ret lval_mem(cx, cx.fcx.llobjfields.get(did));
44684395
}
44694396
case (ast::def_fn(?did)) {
4470-
auto tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.sess,
4471-
cx.fcx.lcx.ccx.tcx, did);
4397+
auto tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.tcx, did);
44724398
ret lval_generic_fn(cx, tyt, did, ann);
44734399
}
44744400
case (ast::def_obj(?did)) {
4475-
auto tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.sess,
4476-
cx.fcx.lcx.ccx.tcx, did);
4401+
auto tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.tcx, did);
44774402
ret lval_generic_fn(cx, tyt, did, ann);
44784403
}
44794404
case (ast::def_variant(?tid, ?vid)) {
4480-
auto v_tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.sess,
4481-
cx.fcx.lcx.ccx.tcx, vid);
4405+
auto v_tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.tcx, vid);
44824406
alt (ty::struct(cx.fcx.lcx.ccx.tcx, v_tyt._1)) {
44834407
case (ty::ty_fn(_, _, _)) {
44844408
// N-ary variant.
@@ -4519,8 +4443,7 @@ fn trans_path(&@block_ctxt cx, &ast::path p, &ast::ann ann) -> lval_result {
45194443
ret lval_mem(cx, cx.fcx.lcx.ccx.consts.get(did));
45204444
}
45214445
case (ast::def_native_fn(?did)) {
4522-
auto tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.sess,
4523-
cx.fcx.lcx.ccx.tcx, did);
4446+
auto tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.tcx, did);
45244447
ret lval_generic_fn(cx, tyt, did, ann);
45254448
}
45264449
case (_) {

0 commit comments

Comments
 (0)