Skip to content

Commit 68652e1

Browse files
committed
---
yaml --- r: 16349 b: refs/heads/try c: 9ee0137 h: refs/heads/master i: 16347: c59092d v: v3
1 parent 6fcec4a commit 68652e1

File tree

4 files changed

+161
-79
lines changed

4 files changed

+161
-79
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: a494cc159874ce2b46f19abeda4e2e46b351cff2
5+
refs/heads/try: 9ee0137018f6e0a20b07e4192be703d0864e6b13
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rustc/front/intrinsic.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,30 @@ mod intrinsic {
3030
fn visit_char() -> bool;
3131
fn visit_str() -> bool;
3232

33-
// FIXME: possibly pair these as enter/leave calls
34-
// not just enter with implicit number of subsequent
35-
// calls. (#2402)
36-
fn visit_vec_of(mutbl: uint) -> bool;
37-
fn visit_box_of(mutbl: uint) -> bool;
38-
fn visit_uniq_of(mutbl: uint) -> bool;
39-
fn visit_ptr_of(mutbl: uint) -> bool;
40-
fn visit_rptr_of(mutbl: uint) -> bool;
41-
fn visit_rec_of(n_fields: uint) -> bool;
42-
fn visit_rec_field(name: str/&, mutbl: uint) -> bool;
43-
fn visit_tup_of(n_fields: uint) -> bool;
44-
fn visit_tup_field(mutbl: uint) -> bool;
45-
fn visit_enum_of(n_variants: uint) -> bool;
46-
fn visit_enum_variant(name: str/&) -> bool;
33+
fn visit_estr_box() -> bool;
34+
fn visit_estr_uniq() -> bool;
35+
fn visit_estr_slice() -> bool;
36+
fn visit_estr_fixed(sz: uint) -> bool;
37+
38+
fn visit_enter_box(mtbl: uint) -> bool;
39+
fn visit_leave_box(mtbl: uint) -> bool;
40+
fn visit_enter_uniq(mtbl: uint) -> bool;
41+
fn visit_leave_uniq(mtbl: uint) -> bool;
42+
fn visit_enter_ptr(mtbl: uint) -> bool;
43+
fn visit_leave_ptr(mtbl: uint) -> bool;
44+
fn visit_enter_rptr(mtbl: uint) -> bool;
45+
fn visit_leave_rptr(mtbl: uint) -> bool;
46+
47+
fn visit_enter_vec(mtbl: uint) -> bool;
48+
fn visit_leave_vec(mtbl: uint) -> bool;
49+
fn visit_enter_evec_box(mtbl: uint) -> bool;
50+
fn visit_leave_evec_box(mtbl: uint) -> bool;
51+
fn visit_enter_evec_uniq(mtbl: uint) -> bool;
52+
fn visit_leave_evec_uniq(mtbl: uint) -> bool;
53+
fn visit_enter_evec_slice(mtbl: uint) -> bool;
54+
fn visit_leave_evec_slice(mtbl: uint) -> bool;
55+
fn visit_enter_evec_fixed(mtbl: uint, sz: uint) -> bool;
56+
fn visit_leave_evec_fixed(mtbl: uint, sz: uint) -> bool;
4757
}
4858

4959
#[abi = "rust-intrinsic"]

branches/try/src/rustc/middle/trans/reflect.rs

Lines changed: 101 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -10,67 +10,116 @@ import type_of::*;
1010
import ast::def_id;
1111
import util::ppaux::ty_to_str;
1212

13-
fn visit_ty_steps(bcx: block, t: ty::t,
14-
step: fn(bcx: block,
15-
tyname: str,
16-
args: [ValueRef]) -> block,
17-
sub: fn(bcx: block, t: ty::t) -> block) -> block {
13+
enum reflector = {
14+
visitor_val: ValueRef,
15+
visitor_methods: @[ty::method],
16+
mut bcx: block
17+
};
1818

19-
let ccx = bcx.ccx();
19+
impl methods for reflector {
2020

21-
alt ty::get(t).struct {
22-
ty::ty_bot { step(bcx, "visit_bot", []) }
23-
ty::ty_nil { step(bcx, "visit_nil", []) }
24-
ty::ty_bool { step(bcx, "visit_bool", []) }
25-
ty::ty_int(ast::ty_i) { step(bcx, "visit_int", []) }
26-
ty::ty_int(ast::ty_char) { step(bcx, "visit_char", []) }
27-
ty::ty_int(ast::ty_i8) { step(bcx, "visit_i8", []) }
28-
ty::ty_int(ast::ty_i16) { step(bcx, "visit_i16", []) }
29-
ty::ty_int(ast::ty_i32) { step(bcx, "visit_i32", []) }
30-
ty::ty_int(ast::ty_i64) { step(bcx, "visit_i64", []) }
31-
ty::ty_uint(ast::ty_u) { step(bcx, "visit_uint", []) }
32-
ty::ty_uint(ast::ty_u8) { step(bcx, "visit_u8", []) }
33-
ty::ty_uint(ast::ty_u16) { step(bcx, "visit_u16", []) }
34-
ty::ty_uint(ast::ty_u32) { step(bcx, "visit_u32", []) }
35-
ty::ty_uint(ast::ty_u64) { step(bcx, "visit_u64", []) }
36-
ty::ty_float(ast::ty_f) { step(bcx, "visit_float", []) }
37-
ty::ty_float(ast::ty_f32) { step(bcx, "visit_f32", []) }
38-
ty::ty_float(ast::ty_f64) { step(bcx, "visit_f64", []) }
39-
ty::ty_str { step(bcx, "visit_str", []) }
21+
fn c_uint(u: uint) -> ValueRef {
22+
C_uint(self.bcx.ccx(), u)
23+
}
24+
25+
fn visit(ty_name: str, args: [ValueRef]) {
26+
let tcx = self.bcx.tcx();
27+
let mth_idx = option::get(ty::method_idx("visit_" + ty_name,
28+
*self.visitor_methods));
29+
let mth_ty = ty::mk_fn(tcx, self.visitor_methods[mth_idx].fty);
30+
let v = self.visitor_val;
31+
let get_lval = {|bcx|
32+
impl::trans_iface_callee(bcx, v, mth_ty, mth_idx)
33+
};
34+
self.bcx =
35+
trans_call_inner(self.bcx, none, mth_ty, ty::mk_bool(tcx),
36+
get_lval, arg_vals(args), ignore);
37+
}
38+
39+
fn visit_tydesc(t: ty::t) {
40+
self.bcx =
41+
call_tydesc_glue(self.bcx, self.visitor_val, t,
42+
abi::tydesc_field_visit_glue);
43+
}
44+
45+
fn bracketed_mt(bracket_name: str, mt: ty::mt, extra: [ValueRef]) {
46+
self.visit("enter_" + bracket_name,
47+
[self.c_uint(mt.mutbl as uint)] + extra);
48+
self.visit_tydesc(mt.ty);
49+
self.visit("leave_" + bracket_name,
50+
[self.c_uint(mt.mutbl as uint)] + extra);
51+
}
4052

41-
ty::ty_vec(mt) {
42-
let bcx = step(bcx, "visit_vec_of",
43-
[C_uint(ccx, mt.mutbl as uint)]);
44-
sub(bcx, mt.ty)
45-
}
53+
fn vstore_name_and_extra(vstore: ty::vstore,
54+
f: fn(str,[ValueRef])) {
55+
alt vstore {
56+
ty::vstore_fixed(n) { f("fixed", [self.c_uint(n)]) }
57+
ty::vstore_slice(_) { f("slice", []) }
58+
ty::vstore_uniq { f("uniq", []);}
59+
ty::vstore_box { f("box", []); }
60+
}
61+
}
4662

47-
_ {
48-
// Ideally this would be an unimpl, but sadly we have
49-
// to pretend we can visit everything at this point.
50-
step(bcx, "visit_bot", [])
51-
}
63+
fn leaf(name: str) {
64+
self.visit(name, []);
65+
}
66+
67+
// Entrypoint
68+
fn visit_ty(t: ty::t) {
69+
70+
alt ty::get(t).struct {
71+
ty::ty_bot { self.leaf("bot") }
72+
ty::ty_nil { self.leaf("nil") }
73+
ty::ty_bool { self.leaf("bool") }
74+
ty::ty_int(ast::ty_i) { self.leaf("int") }
75+
ty::ty_int(ast::ty_char) { self.leaf("char") }
76+
ty::ty_int(ast::ty_i8) { self.leaf("i8") }
77+
ty::ty_int(ast::ty_i16) { self.leaf("i16") }
78+
ty::ty_int(ast::ty_i32) { self.leaf("i32") }
79+
ty::ty_int(ast::ty_i64) { self.leaf("i64") }
80+
ty::ty_uint(ast::ty_u) { self.leaf("uint") }
81+
ty::ty_uint(ast::ty_u8) { self.leaf("u8") }
82+
ty::ty_uint(ast::ty_u16) { self.leaf("u16") }
83+
ty::ty_uint(ast::ty_u32) { self.leaf("u32") }
84+
ty::ty_uint(ast::ty_u64) { self.leaf("u64") }
85+
ty::ty_float(ast::ty_f) { self.leaf("float") }
86+
ty::ty_float(ast::ty_f32) { self.leaf("f32") }
87+
ty::ty_float(ast::ty_f64) { self.leaf("f64") }
88+
ty::ty_str { self.leaf("str") }
89+
90+
ty::ty_vec(mt) { self.bracketed_mt("vec", mt, []) }
91+
ty::ty_estr(vst) {
92+
self.vstore_name_and_extra(vst) {|name, extra|
93+
self.visit("estr_" + name, extra)
94+
}
95+
}
96+
ty::ty_evec(mt, vst) {
97+
self.vstore_name_and_extra(vst) {|name, extra|
98+
self.bracketed_mt("evec_" + name, mt, extra)
99+
}
100+
}
101+
ty::ty_box(mt) { self.bracketed_mt("box", mt, []) }
102+
ty::ty_uniq(mt) { self.bracketed_mt("uniq", mt, []) }
103+
ty::ty_ptr(mt) { self.bracketed_mt("ptr", mt, []) }
104+
ty::ty_rptr(_, mt) { self.bracketed_mt("rptr", mt, []) }
105+
106+
// FIXME: finish these.
107+
_ { self.visit("bot", []) }
108+
}
52109
}
53110
}
54111

55112
// Emit a sequence of calls to visit_ty::visit_foo
56113
fn emit_calls_to_iface_visit_ty(bcx: block, t: ty::t,
57114
visitor_val: ValueRef,
58115
visitor_iid: def_id) -> block {
59-
let tcx = bcx.tcx();
60-
let methods = ty::iface_methods(tcx, visitor_iid);
61-
visit_ty_steps(bcx, t,
62-
{|bcx, mth_name, args|
63-
let mth_idx = option::get(ty::method_idx(mth_name,
64-
*methods));
65-
let mth_ty = ty::mk_fn(tcx, methods[mth_idx].fty);
66-
let get_lval = {|bcx|
67-
impl::trans_iface_callee(bcx, visitor_val,
68-
mth_ty, mth_idx)
69-
};
70-
trans_call_inner(bcx, none, mth_ty, ty::mk_bool(tcx),
71-
get_lval, arg_vals(args), ignore)
72-
},
73-
{|bcx, t_sub|
74-
call_tydesc_glue(bcx, visitor_val, t_sub,
75-
abi::tydesc_field_visit_glue)})
116+
117+
let r = reflector({
118+
visitor_val: visitor_val,
119+
visitor_methods: ty::iface_methods(bcx.tcx(), visitor_iid),
120+
mut bcx: bcx
121+
});
122+
123+
r.visit_ty(t);
124+
ret r.bcx;
76125
}

branches/try/src/test/run-pass/reflect-visit-type.rs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,38 @@ impl of intrinsic::ty_visitor for my_visitor {
4747
fn visit_char() -> bool { true }
4848
fn visit_str() -> bool { true }
4949

50-
fn visit_vec_of(_mutbl: uint) -> bool { true }
51-
fn visit_box_of(_mutbl: uint) -> bool { true }
52-
fn visit_uniq_of(_mutbl: uint) -> bool { true }
53-
fn visit_ptr_of(_mutbl: uint) -> bool { true }
54-
fn visit_rptr_of(_mutbl: uint) -> bool { true }
55-
fn visit_rec_of(_n_fields: uint) -> bool { true }
56-
fn visit_rec_field(_name: str/&, _mutbl: uint) -> bool { true }
57-
fn visit_tup_of(_n_fields: uint) -> bool { true }
58-
fn visit_tup_field(_mutbl: uint) -> bool { true }
59-
fn visit_enum_of(_n_variants: uint) -> bool { true }
60-
fn visit_enum_variant(_name: str/&) -> bool { true }
50+
fn visit_estr_box() -> bool { true }
51+
fn visit_estr_uniq() -> bool { true }
52+
fn visit_estr_slice() -> bool { true }
53+
fn visit_estr_fixed(_sz: uint) -> bool { true }
54+
55+
fn visit_enter_box(_mtbl: uint) -> bool { true }
56+
fn visit_leave_box(_mtbl: uint) -> bool { true }
57+
fn visit_enter_uniq(_mtbl: uint) -> bool { true }
58+
fn visit_leave_uniq(_mtbl: uint) -> bool { true }
59+
fn visit_enter_ptr(_mtbl: uint) -> bool { true }
60+
fn visit_leave_ptr(_mtbl: uint) -> bool { true }
61+
fn visit_enter_rptr(_mtbl: uint) -> bool { true }
62+
fn visit_leave_rptr(_mtbl: uint) -> bool { true }
63+
64+
fn visit_enter_vec(_mtbl: uint) -> bool {
65+
self.types += ["["];
66+
#error("visited enter-vec");
67+
true
68+
}
69+
fn visit_leave_vec(_mtbl: uint) -> bool {
70+
self.types += ["]"];
71+
#error("visited leave-vec");
72+
true
73+
}
74+
fn visit_enter_evec_box(_mtbl: uint) -> bool { true }
75+
fn visit_leave_evec_box(_mtbl: uint) -> bool { true }
76+
fn visit_enter_evec_uniq(_mtbl: uint) -> bool { true }
77+
fn visit_leave_evec_uniq(_mtbl: uint) -> bool { true }
78+
fn visit_enter_evec_slice(_mtbl: uint) -> bool { true }
79+
fn visit_leave_evec_slice(_mtbl: uint) -> bool { true }
80+
fn visit_enter_evec_fixed(_mtbl: uint, _sz: uint) -> bool { true }
81+
fn visit_leave_evec_fixed(_mtbl: uint, _sz: uint) -> bool { true }
6182
}
6283

6384
fn main() {
@@ -68,9 +89,11 @@ fn main() {
6889
intrinsic::visit_ty::<int>(vv);
6990
intrinsic::visit_ty::<i8>(vv);
7091
intrinsic::visit_ty::<i16>(vv);
92+
intrinsic::visit_ty::<[int]>(vv);
7193

7294
for v.types.each {|s|
7395
io::println(#fmt("type: %s", s));
7496
}
75-
assert v.types == ["bool", "int", "i8", "i16"];
97+
assert v.types == ["bool", "int", "i8", "i16",
98+
"[", "int", "]"];
7699
}

0 commit comments

Comments
 (0)