push changes through to get things compiling, if not running.
This commit is contained in:
parent
c28ada0368
commit
aa1cd61c84
11 changed files with 103 additions and 60 deletions
|
|
@ -34,9 +34,7 @@ fn collect_freevars(def_map: resolve::def_map, walker: fn@(visit::vt<int>)) ->
|
|||
lambda (expr: @ast::expr, &&depth: int, v: visit::vt<int>) {
|
||||
alt expr.node {
|
||||
ast::expr_fn(f, captures) {
|
||||
if f.proto == ast::proto_block ||
|
||||
f.proto == ast::proto_shared(ast::sugar_normal) ||
|
||||
f.proto == ast::proto_shared(ast::sugar_sexy) {
|
||||
if f.proto != ast::proto_bare {
|
||||
visit::visit_expr(expr, depth + 1, v);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,17 @@ fn check_crate(tcx: ty::ctxt, last_uses: last_use::last_uses,
|
|||
}
|
||||
|
||||
fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
|
||||
|
||||
fn check_free_vars(e: @expr,
|
||||
cx: ctx,
|
||||
check_fn: fn(ctx, ty::t, sp: span)) {
|
||||
for free in *freevars::get_freevars(cx.tcx, e.id) {
|
||||
let id = ast_util::def_id_of_def(free).node;
|
||||
let ty = ty::node_id_to_type(cx.tcx, id);
|
||||
check_fn(cx, ty, e.span);
|
||||
}
|
||||
}
|
||||
|
||||
alt e.node {
|
||||
expr_assign(_, ex) | expr_assign_op(_, _, ex) |
|
||||
expr_block({node: {expr: some(ex), _}, _}) |
|
||||
|
|
@ -65,7 +76,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
|
|||
let ty_fields = alt ty::struct(cx.tcx, t) { ty::ty_rec(f) { f } };
|
||||
for tf in ty_fields {
|
||||
if !vec::any({|f| f.node.ident == tf.ident}, fields) &&
|
||||
ty::type_kind(cx.tcx, tf.mt.ty) == kind_noncopyable {
|
||||
!kind_can_be_copied(ty::type_kind(cx.tcx, tf.mt.ty)) {
|
||||
cx.tcx.sess.span_err(ex.span,
|
||||
"copying a noncopyable value");
|
||||
}
|
||||
|
|
@ -107,19 +118,11 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
|
|||
none. {}
|
||||
}
|
||||
}
|
||||
expr_fn({proto: proto_send, _}, captures) {
|
||||
for free in *freevars::get_freevars(cx.tcx, e.id) {
|
||||
let id = ast_util::def_id_of_def(free).node;
|
||||
let ty = ty::node_id_to_type(cx.tcx, id);
|
||||
check_copy(cx, ty, e.span);
|
||||
}
|
||||
expr_fn({proto: proto_send., _}, captures) { // NDM captures
|
||||
check_free_vars(e, cx, check_send);
|
||||
}
|
||||
expr_fn({proto: proto_shared(_), _}, captures) {
|
||||
for free in *freevars::get_freevars(cx.tcx, e.id) {
|
||||
let id = ast_util::def_id_of_def(free).node;
|
||||
let ty = ty::node_id_to_type(cx.tcx, id);
|
||||
check_copy(cx, ty, e.span);
|
||||
}
|
||||
expr_fn({proto: proto_shared(_), _}, captures) { // NDM captures
|
||||
check_free_vars(e, cx, check_copy);
|
||||
}
|
||||
expr_ternary(_, a, b) { maybe_copy(cx, a); maybe_copy(cx, b); }
|
||||
_ { }
|
||||
|
|
@ -159,11 +162,17 @@ fn check_copy_ex(cx: ctx, ex: @expr, _warn: bool) {
|
|||
}
|
||||
|
||||
fn check_copy(cx: ctx, ty: ty::t, sp: span) {
|
||||
if ty::type_kind(cx.tcx, ty) == kind_noncopyable {
|
||||
if !kind_can_be_copied(ty::type_kind(cx.tcx, ty)) {
|
||||
cx.tcx.sess.span_err(sp, "copying a noncopyable value");
|
||||
}
|
||||
}
|
||||
|
||||
fn check_send(cx: ctx, ty: ty::t, sp: span) {
|
||||
if !kind_can_be_sent(ty::type_kind(cx.tcx, ty)) {
|
||||
cx.tcx.sess.span_err(sp, "not a sendable value");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Local Variables:
|
||||
// mode: rust
|
||||
|
|
|
|||
|
|
@ -49,8 +49,9 @@ fn comma_str(args: [@constr_arg_use]) -> str {
|
|||
|
||||
fn constraint_to_str(tcx: ty::ctxt, c: sp_constr) -> str {
|
||||
alt c.node {
|
||||
ninit(_, i) {
|
||||
ret "init(" + i + " [" + tcx.sess.span_str(c.span) + "])";
|
||||
ninit(id, i) {
|
||||
ret #fmt("init(%s id=%d [%s])",
|
||||
i, id, tcx.sess.span_str(c.span));
|
||||
}
|
||||
npred(p, _, args) {
|
||||
ret path_to_str(p) + "(" + comma_str(args) + ")" + "[" +
|
||||
|
|
|
|||
|
|
@ -278,6 +278,7 @@ fn handle_var(fcx: fn_ctxt, rslt: pre_and_post, id: node_id, name: ident) {
|
|||
}
|
||||
|
||||
fn handle_var_def(fcx: fn_ctxt, rslt: pre_and_post, def: def, name: ident) {
|
||||
log ("handle_var_def: ", def, name);
|
||||
alt def {
|
||||
def_local(d_id, _) | def_arg(d_id, _) {
|
||||
use_var(fcx, d_id.node);
|
||||
|
|
@ -345,6 +346,7 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) {
|
|||
let rslt = expr_pp(fcx.ccx, e);
|
||||
clear_pp(rslt);
|
||||
for def in *freevars::get_freevars(fcx.ccx.tcx, e.id) {
|
||||
log ("handle_var_def: def=", def);
|
||||
handle_var_def(fcx, rslt, def, "upvar");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1971,29 +1971,23 @@ mod unify {
|
|||
}
|
||||
fn unify_fn_proto(e_proto: ast::proto, a_proto: ast::proto,
|
||||
variance: variance) -> option::t<result> {
|
||||
fn rank(proto: ast::proto) -> int {
|
||||
ret alt proto {
|
||||
ast::proto_block. { 0 }
|
||||
ast::proto_shared(_) { 1 }
|
||||
ast::proto_send. { 2 }
|
||||
ast::proto_bare. { 3 }
|
||||
};
|
||||
}
|
||||
|
||||
fn gt(e_proto: ast::proto, a_proto: ast::proto) -> bool {
|
||||
alt e_proto {
|
||||
ast::proto_block. {
|
||||
// Every function type is a subtype of block
|
||||
false
|
||||
}
|
||||
ast::proto_shared(_) {
|
||||
a_proto == ast::proto_block
|
||||
}
|
||||
ast::proto_bare. {
|
||||
a_proto != ast::proto_bare
|
||||
}
|
||||
}
|
||||
ret rank(e_proto) > rank(a_proto);
|
||||
}
|
||||
|
||||
ret if e_proto == a_proto {
|
||||
none
|
||||
} else if variance == invariant {
|
||||
if e_proto != a_proto {
|
||||
some(ures_err(terr_mismatch))
|
||||
} else {
|
||||
fail
|
||||
}
|
||||
some(ures_err(terr_mismatch))
|
||||
} else if variance == covariant {
|
||||
if gt(e_proto, a_proto) {
|
||||
some(ures_err(terr_mismatch))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue