Skip to content

Commit 4c5f6eb

Browse files
committed
---
yaml --- r: 16235 b: refs/heads/try c: 01b5777 h: refs/heads/master i: 16233: e803cd2 16231: 2ca1190 v: v3
1 parent bf3d12c commit 4c5f6eb

File tree

11 files changed

+126
-98
lines changed

11 files changed

+126
-98
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: b2ae333917c1ff0293fa93afa335e17608d0ca6e
5+
refs/heads/try: 01b5777c8b6e4c3f580aa9e256de96b4b4b92739
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libcore/comm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ whereupon the caller loses access to it.
156156
"]
157157
fn send<T: send>(ch: chan<T>, -data: T) {
158158
let chan_t(p) = ch;
159-
let res = rustrt::rust_port_id_send(p, data);
159+
let data_ptr = ptr::addr_of(data) as *();
160+
let res = rustrt::rust_port_id_send(p, data_ptr);
160161
if res != 0u unsafe {
161162
// Data sent successfully
162163
unsafe::forget(data);
@@ -250,8 +251,7 @@ type port_id = int;
250251

251252
#[abi = "cdecl"]
252253
native mod rustrt {
253-
fn rust_port_id_send<T: send>(target_port: port_id,
254-
data: T) -> libc::uintptr_t;
254+
fn rust_port_id_send(target_port: port_id, data: *()) -> libc::uintptr_t;
255255

256256
fn new_port(unit_sz: libc::size_t) -> *rust_port;
257257
fn del_port(po: *rust_port);

branches/try/src/libcore/sys.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ enum type_desc = {
1717

1818
#[abi = "cdecl"]
1919
native mod rustrt {
20-
fn refcount<T>(t: @T) -> libc::intptr_t;
20+
fn refcount(t: *()) -> libc::intptr_t;
2121
fn unsupervise();
22-
fn shape_log_str<T>(t: *sys::type_desc, data: T) -> str;
22+
fn shape_log_str(t: *sys::type_desc, data: *()) -> str;
2323
}
2424

2525
#[abi = "rust-intrinsic"]
@@ -62,11 +62,16 @@ fn pref_align_of<T>() -> uint unsafe {
6262

6363
#[doc = "Returns the refcount of a shared box"]
6464
fn refcount<T>(t: @T) -> uint {
65-
ret rustrt::refcount::<T>(t) as uint;
65+
unsafe {
66+
ret rustrt::refcount(unsafe::reinterpret_cast(t)) as uint;
67+
}
6668
}
6769

6870
fn log_str<T>(t: T) -> str {
69-
rustrt::shape_log_str(get_type_desc::<T>(), t)
71+
unsafe {
72+
let data_ptr: *() = unsafe::reinterpret_cast(ptr::addr_of(t));
73+
rustrt::shape_log_str(get_type_desc::<T>(), data_ptr)
74+
}
7075
}
7176

7277
#[cfg(test)]

branches/try/src/libcore/vec.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ export extensions;
8282

8383
#[abi = "cdecl"]
8484
native mod rustrt {
85-
fn vec_reserve_shared<T>(t: *sys::type_desc,
86-
&v: [const T],
87-
n: libc::size_t);
88-
fn vec_from_buf_shared<T>(t: *sys::type_desc,
89-
ptr: *T,
90-
count: libc::size_t) -> [T];
85+
fn vec_reserve_shared(++t: *sys::type_desc,
86+
++v: **unsafe::vec_repr,
87+
++n: libc::size_t);
88+
fn vec_from_buf_shared(++t: *sys::type_desc,
89+
++ptr: *(),
90+
++count: libc::size_t) -> *unsafe::vec_repr;
9191
}
9292

9393
#[doc = "A function used to initialize the elements of a vector"]
@@ -122,7 +122,8 @@ capacity, then no action is taken.
122122
fn reserve<T>(&v: [const T], n: uint) {
123123
// Only make the (slow) call into the runtime if we have to
124124
if capacity(v) < n {
125-
rustrt::vec_reserve_shared(sys::get_type_desc::<T>(), v, n);
125+
let ptr = ptr::addr_of(v) as **unsafe::vec_repr;
126+
rustrt::vec_reserve_shared(sys::get_type_desc::<T>(), ptr, n);
126127
}
127128
}
128129

@@ -1209,8 +1210,10 @@ mod unsafe {
12091210
"]
12101211
#[inline(always)]
12111212
unsafe fn from_buf<T>(ptr: *T, elts: uint) -> [T] {
1212-
ret rustrt::vec_from_buf_shared(sys::get_type_desc::<T>(),
1213-
ptr, elts);
1213+
ret ::unsafe::reinterpret_cast(
1214+
rustrt::vec_from_buf_shared(sys::get_type_desc::<T>(),
1215+
ptr as *(),
1216+
elts));
12141217
}
12151218

12161219
#[doc = "

branches/try/src/libstd/dbg.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,49 @@
11
#[doc = "Unsafe debugging functions for inspecting values."];
22

3+
import unsafe::reinterpret_cast;
4+
5+
export debug_tydesc;
6+
export debug_opaque;
7+
export debug_box;
8+
export debug_tag;
9+
export debug_fn;
10+
export ptr_cast;
11+
export refcount;
12+
313
#[abi = "cdecl"]
414
native mod rustrt {
515
fn debug_tydesc(td: *sys::type_desc);
6-
fn debug_opaque<T>(td: *sys::type_desc, x: T);
7-
fn debug_box<T>(td: *sys::type_desc, x: @T);
8-
fn debug_tag<T>(td: *sys::type_desc, x: T);
9-
fn debug_fn<T>(td: *sys::type_desc, x: T);
10-
fn debug_ptrcast<T, U>(td: *sys::type_desc, x: @T) -> @U;
16+
fn debug_opaque(td: *sys::type_desc, x: *());
17+
fn debug_box(td: *sys::type_desc, x: *());
18+
fn debug_tag(td: *sys::type_desc, x: *());
19+
fn debug_fn(td: *sys::type_desc, x: *());
20+
fn debug_ptrcast(td: *sys::type_desc, x: *()) -> *();
1121
}
1222

1323
fn debug_tydesc<T>() {
1424
rustrt::debug_tydesc(sys::get_type_desc::<T>());
1525
}
1626

1727
fn debug_opaque<T>(x: T) {
18-
rustrt::debug_opaque::<T>(sys::get_type_desc::<T>(), x);
28+
rustrt::debug_opaque(sys::get_type_desc::<T>(), ptr::addr_of(x) as *());
1929
}
2030

2131
fn debug_box<T>(x: @T) {
22-
rustrt::debug_box::<T>(sys::get_type_desc::<T>(), x);
32+
rustrt::debug_box(sys::get_type_desc::<T>(), ptr::addr_of(x) as *());
2333
}
2434

2535
fn debug_tag<T>(x: T) {
26-
rustrt::debug_tag::<T>(sys::get_type_desc::<T>(), x);
36+
rustrt::debug_tag(sys::get_type_desc::<T>(), ptr::addr_of(x) as *());
2737
}
2838

2939
fn debug_fn<T>(x: T) {
30-
rustrt::debug_fn::<T>(sys::get_type_desc::<T>(), x);
40+
rustrt::debug_fn(sys::get_type_desc::<T>(), ptr::addr_of(x) as *());
3141
}
3242

3343
unsafe fn ptr_cast<T, U>(x: @T) -> @U {
34-
ret rustrt::debug_ptrcast::<T, U>(sys::get_type_desc::<T>(), x);
44+
reinterpret_cast(
45+
rustrt::debug_ptrcast(sys::get_type_desc::<T>(),
46+
reinterpret_cast(x)))
3547
}
3648

3749
fn refcount<T>(a: @T) -> uint unsafe {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,7 +2850,7 @@ fn trans_loop_body(bcx: block, e: @ast::expr, ret_flag: option<ValueRef>,
28502850
ast::expr_loop_body(b@@{node: ast::expr_fn_block(decl, body, cap), _}) {
28512851
alt check ty::get(expr_ty(bcx, e)).struct {
28522852
ty::ty_fn({proto, _}) {
2853-
closure::trans_expr_fn(bcx, proto, decl, body, e.span, b.id,
2853+
closure::trans_expr_fn(bcx, proto, decl, body, b.id,
28542854
cap, some(ret_flag),
28552855
dest)
28562856
}
@@ -3556,15 +3556,15 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block {
35563556
}
35573557
ast::expr_addr_of(_, x) { ret trans_addr_of(bcx, x, dest); }
35583558
ast::expr_fn(proto, decl, body, cap_clause) {
3559-
ret closure::trans_expr_fn(bcx, proto, decl, body, e.span, e.id,
3559+
ret closure::trans_expr_fn(bcx, proto, decl, body, e.id,
35603560
cap_clause, none, dest);
35613561
}
35623562
ast::expr_fn_block(decl, body, cap_clause) {
35633563
alt check ty::get(expr_ty(bcx, e)).struct {
35643564
ty::ty_fn({proto, _}) {
35653565
#debug("translating fn_block %s with type %s",
35663566
expr_to_str(e), ty_to_str(tcx, expr_ty(bcx, e)));
3567-
ret closure::trans_expr_fn(bcx, proto, decl, body, e.span,
3567+
ret closure::trans_expr_fn(bcx, proto, decl, body,
35683568
e.id, cap_clause, none, dest);
35693569
}
35703570
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ fn trans_expr_fn(bcx: block,
380380
proto: ast::proto,
381381
decl: ast::fn_decl,
382382
body: ast::blk,
383-
sp: span,
384383
id: ast::node_id,
385384
cap_clause: ast::capture_clause,
386385
is_loop_body: option<option<ValueRef>>,
@@ -393,7 +392,6 @@ fn trans_expr_fn(bcx: block,
393392
let sub_path = bcx.fcx.path + [path_name("anon")];
394393
let s = mangle_internal_name_by_path(ccx, sub_path);
395394
let llfn = decl_internal_cdecl_fn(ccx.llmod, s, llfnty);
396-
register_fn(ccx, sp, sub_path, id);
397395

398396
let trans_closure_env = fn@(ck: ty::closure_kind) -> ValueRef {
399397
let cap_vars = capture::compute_capture_vars(

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ fn type_of_non_gc_box(cx: @crate_ctxt, t: ty::t) -> TypeRef {
6262
}
6363

6464
fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
65-
assert !ty::type_needs_infer(t);
66-
6765
#debug("type_of %?: %?", t, ty::get(t));
6866

6967
// Check the cache.
@@ -133,7 +131,6 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
133131
let sub1 = ty::subst(cx.tcx, substs, sub);
134132
ret T_struct([T_i8(), type_of(cx, sub1)]);
135133
}
136-
ty::ty_param(_, _) { T_typaram(cx.tn) }
137134
ty::ty_type { T_ptr(cx.tydesc_type) }
138135
ty::ty_tup(elts) {
139136
let mut tys = [];
@@ -161,6 +158,7 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
161158
}
162159
ty::ty_self { cx.tcx.sess.unimpl("type_of: ty_self"); }
163160
ty::ty_var(_) { cx.tcx.sess.bug("type_of shouldn't see a ty_var"); }
161+
ty::ty_param(*) { cx.tcx.sess.bug("type_of with ty_param"); }
164162
ty::ty_var_integral(_) {
165163
cx.tcx.sess.bug("type_of shouldn't see a ty_var_integral");
166164
}

branches/try/src/rustc/middle/typeck/check.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,23 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
393393
let tpt_ty = ty::node_id_to_type(ccx.tcx, it.id);
394394
check_bounds_are_used(ccx, t.span, tps, rp, tpt_ty);
395395
}
396+
ast::item_native_mod(m) {
397+
if syntax::attr::native_abi(it.attrs) ==
398+
either::right(ast::native_abi_rust_intrinsic) {
399+
for m.items.each { |item|
400+
check_intrinsic_type(ccx, item);
401+
}
402+
} else {
403+
for m.items.each { |item|
404+
let tpt = ty::lookup_item_type(ccx.tcx, local_def(item.id));
405+
if (*tpt.bounds).is_not_empty() {
406+
ccx.tcx.sess.span_err(
407+
item.span,
408+
#fmt["native items may not have type parameters"]);
409+
}
410+
}
411+
}
412+
}
396413
_ {/* nothing to do */ }
397414
}
398415
}
@@ -2267,3 +2284,57 @@ fn check_bounds_are_used(ccx: @crate_ctxt,
22672284
}
22682285
}
22692286

2287+
fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::native_item) {
2288+
fn param(ccx: @crate_ctxt, n: uint) -> ty::t {
2289+
ty::mk_param(ccx.tcx, n, local_def(0))
2290+
}
2291+
fn arg(m: ast::rmode, ty: ty::t) -> ty::arg {
2292+
{mode: ast::expl(m), ty: ty}
2293+
}
2294+
let tcx = ccx.tcx;
2295+
let (n_tps, inputs, output) = alt it.ident {
2296+
"size_of" |
2297+
"pref_align_of" | "min_align_of" { (1u, [], ty::mk_uint(ccx.tcx)) }
2298+
"get_tydesc" { (1u, [], ty::mk_nil_ptr(tcx)) }
2299+
"init" { (1u, [], param(ccx, 0u)) }
2300+
"forget" { (1u, [arg(ast::by_move, param(ccx, 0u))],
2301+
ty::mk_nil(tcx)) }
2302+
"reinterpret_cast" { (2u, [arg(ast::by_ref, param(ccx, 0u))],
2303+
param(ccx, 1u)) }
2304+
"addr_of" { (1u, [arg(ast::by_ref, param(ccx, 0u))],
2305+
ty::mk_imm_ptr(tcx, param(ccx, 0u))) }
2306+
"needs_drop" { (1u, [], ty::mk_bool(tcx)) }
2307+
2308+
"visit_ty" {
2309+
assert ccx.tcx.intrinsic_ifaces.contains_key("ty_visitor");
2310+
let (_, visitor_iface) = ccx.tcx.intrinsic_ifaces.get("ty_visitor");
2311+
(1u, [arg(ast::by_ref, visitor_iface)], ty::mk_nil(tcx))
2312+
}
2313+
2314+
other {
2315+
tcx.sess.span_err(it.span, "unrecognized intrinsic function: `" +
2316+
other + "`");
2317+
ret;
2318+
}
2319+
};
2320+
let fty = ty::mk_fn(tcx, {purity: ast::impure_fn,
2321+
proto: ast::proto_bare,
2322+
inputs: inputs, output: output,
2323+
ret_style: ast::return_val,
2324+
constraints: []});
2325+
let i_ty = ty::lookup_item_type(ccx.tcx, local_def(it.id));
2326+
let i_n_tps = (*i_ty.bounds).len();
2327+
if i_n_tps != n_tps {
2328+
tcx.sess.span_err(it.span, #fmt("intrinsic has wrong number \
2329+
of type parameters. found %u, \
2330+
expected %u", i_n_tps, n_tps));
2331+
} else {
2332+
require_same_types(
2333+
tcx, it.span, i_ty.ty, fty,
2334+
{|| #fmt["intrinsic has wrong type. \
2335+
expected %s",
2336+
ty_to_str(ccx.tcx, fty)]});
2337+
}
2338+
}
2339+
2340+

branches/try/src/rustc/middle/typeck/collect.rs

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,7 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
301301
let tcx = ccx.tcx;
302302
alt it.node {
303303
// These don't define types.
304-
ast::item_mod(_) {}
305-
ast::item_native_mod(m) {
306-
if syntax::attr::native_abi(it.attrs) ==
307-
either::right(ast::native_abi_rust_intrinsic) {
308-
for m.items.each { |item| check_intrinsic_type(ccx, item); }
309-
}
310-
}
304+
ast::item_native_mod(_) | ast::item_mod(_) {}
311305
ast::item_enum(variants, ty_params, rp) {
312306
let tpt = ty_of_item(ccx, it);
313307
write_ty_to_tcx(tcx, it.id, tpt.ty);
@@ -465,6 +459,7 @@ fn convert_native(ccx: @crate_ctxt, i: @ast::native_item) {
465459
alt i.node {
466460
ast::native_item_fn(_, _) {
467461
write_ty_to_tcx(ccx.tcx, i.id, tpt.ty);
462+
ccx.tcx.tcache.insert(local_def(i.id), tpt);
468463
}
469464
}
470465
}
@@ -491,60 +486,6 @@ fn ty_of_ty_method(self: @crate_ctxt,
491486
purity: m.decl.purity, vis: ast::public}
492487
}
493488

494-
fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::native_item) {
495-
fn param(ccx: @crate_ctxt, n: uint) -> ty::t {
496-
ty::mk_param(ccx.tcx, n, local_def(0))
497-
}
498-
fn arg(m: ast::rmode, ty: ty::t) -> ty::arg {
499-
{mode: ast::expl(m), ty: ty}
500-
}
501-
let tcx = ccx.tcx;
502-
let (n_tps, inputs, output) = alt it.ident {
503-
"size_of" |
504-
"pref_align_of" | "min_align_of" { (1u, [], ty::mk_uint(ccx.tcx)) }
505-
"get_tydesc" { (1u, [], ty::mk_nil_ptr(tcx)) }
506-
"init" { (1u, [], param(ccx, 0u)) }
507-
"forget" { (1u, [arg(ast::by_move, param(ccx, 0u))],
508-
ty::mk_nil(tcx)) }
509-
"reinterpret_cast" { (2u, [arg(ast::by_ref, param(ccx, 0u))],
510-
param(ccx, 1u)) }
511-
"addr_of" { (1u, [arg(ast::by_ref, param(ccx, 0u))],
512-
ty::mk_imm_ptr(tcx, param(ccx, 0u))) }
513-
"needs_drop" { (1u, [], ty::mk_bool(tcx)) }
514-
515-
"visit_ty" {
516-
assert ccx.tcx.intrinsic_ifaces.contains_key("ty_visitor");
517-
let (_, visitor_iface) = ccx.tcx.intrinsic_ifaces.get("ty_visitor");
518-
(1u, [arg(ast::by_ref, visitor_iface)], ty::mk_nil(tcx))
519-
}
520-
521-
other {
522-
tcx.sess.span_err(it.span, "unrecognized intrinsic function: `" +
523-
other + "`");
524-
ret;
525-
}
526-
};
527-
let fty = ty::mk_fn(tcx, {purity: ast::impure_fn,
528-
proto: ast::proto_bare,
529-
inputs: inputs, output: output,
530-
ret_style: ast::return_val,
531-
constraints: []});
532-
let i_ty = ty_of_native_item(ccx, it);
533-
let i_n_tps = (*i_ty.bounds).len();
534-
if i_n_tps != n_tps {
535-
tcx.sess.span_err(it.span, #fmt("intrinsic has wrong number \
536-
of type parameters. found %u, \
537-
expected %u", i_n_tps, n_tps));
538-
} else {
539-
require_same_types(
540-
tcx, it.span, i_ty.ty, fty,
541-
{|| #fmt["intrinsic has wrong type. \
542-
expected %s",
543-
ty_to_str(ccx.tcx, fty)]});
544-
}
545-
}
546-
547-
548489
/*
549490
Instantiates the path for the given iface reference, assuming that
550491
it's bound to a valid iface type. Returns the def_id for the defining

0 commit comments

Comments
 (0)