1
Fork 0

Add kind-checking for assign-op, copy, ret, be, fail exprs. Fix caught kinding-violations in rustc and libstd.

This commit is contained in:
Graydon Hoare 2011-08-23 15:58:53 -07:00
parent a3c8d4a5a5
commit c011f13144
28 changed files with 45 additions and 35 deletions

View file

@ -108,7 +108,7 @@ fn parse_input_src(sess: session::session, cfg: &ast::crate_cfg, infile: str)
ret {crate: crate, src: src};
}
fn time<T>(do_it: bool, what: str, thunk: fn() -> T) -> T {
fn time<@T>(do_it: bool, what: str, thunk: fn() -> T) -> T {
if !do_it { ret thunk(); }
let start = std::time::precise_time_s();
let rv = thunk();

View file

@ -189,7 +189,7 @@ fn require_unique_names(sess: &session::session, metas: &[@ast::meta_item]) {
}
}
fn span<T>(item: &T) -> ast::spanned<T> {
fn span<@T>(item: &T) -> ast::spanned<T> {
ret {node: item, span: ast_util::dummy_sp()};
}

View file

@ -170,7 +170,7 @@ fn mk_test_module(cx: &test_ctxt) -> @ast::item {
ret @item;
}
fn nospan<T>(t: &T) -> ast::spanned<T> {
fn nospan<@T>(t: &T) -> ast::spanned<T> {
ret {node: t, span: dummy_sp()};
}

View file

@ -76,6 +76,7 @@ import syntax::ast_util;
import syntax::visit;
import std::vec;
import std::option;
import ast::kind;
import ast::kind_unique;
@ -135,7 +136,20 @@ fn check_expr(tcx: &ty::ctxt, e: &@ast::expr) {
alt e.node {
ast::expr_move(a, b) { need_shared_lhs_rhs(tcx, a, b, "<-"); }
ast::expr_assign(a, b) { need_shared_lhs_rhs(tcx, a, b, "="); }
ast::expr_assign_op(_, a, b) { need_shared_lhs_rhs(tcx, a, b, "op="); }
ast::expr_swap(a, b) { need_shared_lhs_rhs(tcx, a, b, "<->"); }
ast::expr_copy(a) {
need_expr_kind(tcx, a, ast::kind_shared, "'copy' operand");
}
ast::expr_ret(option::some(a)) {
need_expr_kind(tcx, a, ast::kind_shared, "'ret' operand");
}
ast::expr_be(a) {
need_expr_kind(tcx, a, ast::kind_shared, "'be' operand");
}
ast::expr_fail(option::some(a)) {
need_expr_kind(tcx, a, ast::kind_shared, "'fail' operand");
}
ast::expr_call(callee, _) {
let tpt = ty::expr_ty_params_and_ty(tcx, callee);

View file

@ -3,7 +3,7 @@ import std::option;
import codemap::span;
import ast::*;
fn respan<T>(sp: &span, t: &T) -> spanned<T> { ret {node: t, span: sp}; }
fn respan<@T>(sp: &span, t: &T) -> spanned<T> { ret {node: t, span: sp}; }
/* assuming that we're not in macro expansion */
fn mk_sp(lo: uint, hi: uint) -> span {

View file

@ -222,7 +222,7 @@ fn expect_gt(p: &parser) {
}
}
fn spanned<T>(lo: uint, hi: uint, node: &T) -> spanned<T> {
fn spanned<@T>(lo: uint, hi: uint, node: &T) -> spanned<T> {
ret {node: node, span: ast_util::mk_sp(lo, hi)};
}

View file

@ -33,7 +33,7 @@ fn intern<@T>(itr: &interner<T>, val: &T) -> uint {
}
}
fn get<T>(itr: &interner<T>, idx: uint) -> T { ret itr.vect[idx]; }
fn get<@T>(itr: &interner<T>, idx: uint) -> T { ret itr.vect[idx]; }
fn len<T>(itr: &interner<T>) -> uint { ret vec::len(itr.vect); }

View file

@ -38,10 +38,6 @@ type task_context = {regs: x86_registers, next: *u8};
resource rust_task_ptr(task: *rust_task) { rustrt::drop_task(task); }
fn get_task_ptr(id: task) -> rust_task_ptr {
ret rust_task_ptr(rustrt::get_task_pointer(id));
}
type task = int;
type task_id = task;
@ -107,7 +103,7 @@ fn spawn_inner(thunk: -fn(), notify: option<comm::chan<task_notification>>) ->
// stack.
// set up the task pointer
let task_ptr = get_task_ptr(id);
let task_ptr = rust_task_ptr(rustrt::get_task_pointer(id));
let regs = ptr::addr_of((**task_ptr).ctx.regs);
(*regs).edx = cast(*task_ptr);;
(*regs).esp = cast((**task_ptr).stack_ptr);

View file

@ -9,7 +9,7 @@ native "rust" mod rustrt {
}
// Casts the value at `src` to U. The two types must have the same length.
fn reinterpret_cast<T, U>(src: &T) -> U { ret rusti::cast(src); }
fn reinterpret_cast<T, @U>(src: &T) -> U { ret rusti::cast(src); }
fn leak<@T>(thing: -T) {
rustrt::leak(thing);

View file

@ -1,6 +1,6 @@
fn id<T>(x: &T) -> T { ret x; }
fn id<@T>(x: &T) -> T { ret x; }
/* FIXME (issue #141): See test/run-pass/constrained-type.rs. Uncomment

View file

@ -1,4 +1,4 @@
// error-pattern: non-copyable
// error-pattern: mismatched kinds
fn lol(f: &block()) -> block() { ret f; }
fn main() { let i = 8; let f = lol(block () { log_err i; }); f(); }

View file

@ -150,7 +150,7 @@ fn worker(p: port<request>) {
}
}
fn with_lib_path<T>(path: &str, f: fn() -> T) -> T {
fn with_lib_path<@T>(path: &str, f: fn() -> T) -> T {
let maybe_oldpath = getenv(util::lib_path_env_var());
append_lib_path(path);
let res = f();

View file

@ -2,6 +2,6 @@
// -*- rust -*-
fn f<T, U>(x: &T, y: &U) -> {a: T, b: U} { ret {a: x, b: y}; }
fn f<@T, @U>(x: &T, y: &U) -> {a: T, b: U} { ret {a: x, b: y}; }
fn main() { log f({x: 3, y: 4, z: 5}, 4).a.x; log f(5, 6).a; }

View file

@ -1,4 +1,4 @@
fn f<T>(x: &[T]) -> T { ret x[0]; }
fn f<@T>(x: &[T]) -> T { ret x[0]; }
fn g(act: fn(&[int]) -> int) -> int { ret act([1, 2, 3]); }

View file

@ -2,7 +2,7 @@
type box<T> = {c: @T};
fn unbox<T>(b: &box<T>) -> T { ret *b.c; }
fn unbox<@T>(b: &box<T>) -> T { ret *b.c; }
fn main() {
let foo: int = 17;

View file

@ -1,8 +1,8 @@
fn fix_help<A, B>(f: @fn(@fn(&A) -> B, &A) -> B, x: &A) -> B {
fn fix_help<A, @B>(f: @fn(@fn(&A) -> B, &A) -> B, x: &A) -> B {
ret f(@bind fix_help(f, _), x);
}
fn fix<A, B>(f: @fn(@fn(&A) -> B, &A) -> B) -> @fn(&A) -> B {
fn fix<A, @B>(f: @fn(@fn(&A) -> B, &A) -> B) -> @fn(&A) -> B {
ret @bind fix_help(f, _);
}

View file

@ -1,6 +1,6 @@
fn id<T>(t: &T) -> T { ret t; }
fn id<@T>(t: &T) -> T { ret t; }
fn main() {
let expected = @100;

View file

@ -1,6 +1,6 @@
fn id<T>(t: &T) -> T { ret t; }
fn id<@T>(t: &T) -> T { ret t; }
fn main() {
let t = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7};

View file

@ -1,6 +1,6 @@
fn id<T>(t: &T) -> T { ret t; }
fn id<@T>(t: &T) -> T { ret t; }
fn main() {
let t = {_0: 1, _1: 2, _2: 3, _3: 4, _4: 5, _5: 6, _6: 7};

View file

@ -1,8 +1,8 @@
fn g<X>(x: &X) -> X { ret x; }
fn g<@X>(x: &X) -> X { ret x; }
fn f<T>(t: &T) -> {a: T, b: T} {
fn f<@T>(t: &T) -> {a: T, b: T} {
type pair = {a: T, b: T};
let x: pair = {a: t, b: t};

View file

@ -4,6 +4,6 @@
// -*- rust -*-
// Issue #45: infer type parameters in function applications
fn id<T>(x: &T) -> T { ret x; }
fn id<@T>(x: &T) -> T { ret x; }
fn main() { let x: int = 42; let y: int = id(x); assert (x == y); }

View file

@ -2,7 +2,7 @@
// -*- rust -*-
fn id<T>(x: &T) -> T { ret x; }
fn id<@T>(x: &T) -> T { ret x; }
type triple = {x: int, y: int, z: int};

View file

@ -1,6 +1,6 @@
obj handle<T>(data: T) {
obj handle<@T>(data: T) {
fn get() -> T { ret data; }
}

View file

@ -1,6 +1,6 @@
obj buf<T>(data: {_0: T, _1: T, _2: T}) {
obj buf<@T>(data: {_0: T, _1: T, _2: T}) {
fn get(i: int) -> T {
if i == 0 {
ret data._0;

View file

@ -1,4 +1,4 @@
fn get_third<T>(t: &(T, T, T)) -> T { let (_, _, x) = t; ret x; }
fn get_third<@T>(t: &(T, T, T)) -> T { let (_, _, x) = t; ret x; }
fn main() {
log get_third((1, 2, 3));

View file

@ -1,5 +1,5 @@
fn quux<T>(x: &T) -> T { let f = id::<T>; ret f(x); }
fn quux<@T>(x: &T) -> T { let f = id::<T>; ret f(x); }
fn id<T>(x: &T) -> T { ret x; }
fn id<@T>(x: &T) -> T { ret x; }
fn main() { assert (quux(10) == 10); }

View file

@ -1,8 +1,8 @@
tag myvec<X> = [X];
fn myvec_deref<X>(mv: &myvec<X>) -> [X] { ret *mv; }
fn myvec_deref<@X>(mv: &myvec<X>) -> [X] { ret *mv; }
fn myvec_elt<X>(mv: &myvec<X>) -> X { ret mv[0]; }
fn myvec_elt<@X>(mv: &myvec<X>) -> X { ret mv[0]; }
fn main() {
let mv = myvec([1, 2, 3]);

View file

@ -2,6 +2,6 @@
tag option<T> { none; some(T); }
fn f<T>() -> option<T> { ret none; }
fn f<@T>() -> option<T> { ret none; }
fn main() { f::<int>(); }