Skip to content

Commit 01bcb1d

Browse files
committed
Split part of typeck.check_fn out into typeck.check_item_fn, then check all fns, including obj fns.
1 parent 7210a31 commit 01bcb1d

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

src/comp/middle/typeck.rs

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,38 +2383,52 @@ fn check_const(&@crate_ctxt ccx, &span sp, ast.ident ident, @ast.ty t,
23832383
ret @fold.respan[ast.item_](sp, item);
23842384
}
23852385

2386-
fn check_fn(&@crate_ctxt ccx, &span sp, ast.ident ident, &ast._fn f,
2387-
vec[ast.ty_param] ty_params, ast.def_id id,
2388-
ast.ann ann) -> @ast.item {
2386+
fn check_fn(&@crate_ctxt ccx, ast.effect effect,
2387+
vec[ast.arg] inputs,
2388+
@ast.ty output, &ast.block body) -> ast._fn {
23892389
auto local_ty_table = @common.new_def_hash[@ty]();
23902390

23912391
// FIXME: duplicate work: the item annotation already has the arg types
23922392
// and return type translated to typeck.ty values. We don't need do to it
23932393
// again here, we can extract them.
23942394

23952395
// Store the type of each argument in the table.
2396-
let vec[arg] inputs = vec();
2397-
for (ast.arg arg in f.inputs) {
2396+
for (ast.arg arg in inputs) {
23982397
auto input_ty = ast_ty_to_ty_crate(ccx, arg.ty);
2399-
inputs += vec(rec(mode=arg.mode, ty=input_ty));
24002398
local_ty_table.insert(arg.id, input_ty);
24012399
}
2402-
2403-
auto output_ty = ast_ty_to_ty_crate(ccx, f.output);
2404-
auto fn_sty = ty_fn(inputs, output_ty);
2405-
auto fn_ann = ast.ann_type(plain_ty(fn_sty));
2406-
2407-
let fn_ctxt fcx = rec(ret_ty = output_ty,
2400+
let fn_ctxt fcx = rec(ret_ty = ast_ty_to_ty_crate(ccx, output),
24082401
locals = local_ty_table,
24092402
ccx = ccx);
24102403

24112404
// TODO: Make sure the type of the block agrees with the function type.
2412-
auto block_t = check_block(fcx, f.body);
2405+
auto block_t = check_block(fcx, body);
24132406
auto block_wb = writeback(fcx, block_t);
24142407

2415-
auto fn_t = rec(effect=f.effect, inputs=f.inputs, output=f.output,
2408+
auto fn_t = rec(effect=effect, inputs=inputs, output=output,
24162409
body=block_wb);
2417-
auto item = ast.item_fn(ident, fn_t, ty_params, id, fn_ann);
2410+
ret fn_t;
2411+
}
2412+
2413+
fn check_item_fn(&@crate_ctxt ccx, &span sp, ast.ident ident, &ast._fn f,
2414+
vec[ast.ty_param] ty_params, ast.def_id id,
2415+
ast.ann ann) -> @ast.item {
2416+
2417+
// FIXME: duplicate work: the item annotation already has the arg types
2418+
// and return type translated to typeck.ty values. We don't need do to it
2419+
// again here, we can extract them.
2420+
2421+
let vec[arg] inputs = vec();
2422+
for (ast.arg arg in f.inputs) {
2423+
auto input_ty = ast_ty_to_ty_crate(ccx, arg.ty);
2424+
inputs += vec(rec(mode=arg.mode, ty=input_ty));
2425+
}
2426+
2427+
auto output_ty = ast_ty_to_ty_crate(ccx, f.output);
2428+
auto fn_sty = ty_fn(inputs, output_ty);
2429+
auto fn_ann = ast.ann_type(plain_ty(fn_sty));
2430+
2431+
auto item = ast.item_fn(ident, f, ty_params, id, fn_ann);
24182432
ret @fold.respan[ast.item_](sp, item);
24192433
}
24202434

@@ -2424,8 +2438,10 @@ fn check_crate(session.session sess, @ast.crate crate) -> @ast.crate {
24242438
auto ccx = @rec(sess=sess, item_types=result._1, mutable next_var_id=0);
24252439

24262440
auto fld = fold.new_identity_fold[@crate_ctxt]();
2427-
auto f = check_fn; // FIXME: trans_const_lval bug
2428-
fld = @rec(fold_item_fn = f with *fld);
2441+
2442+
fld = @rec(fold_fn = bind check_fn(_,_,_,_,_),
2443+
fold_item_fn = bind check_item_fn(_,_,_,_,_,_,_)
2444+
with *fld);
24292445
ret fold.fold_crate[@crate_ctxt](ccx, fld, result._0);
24302446
}
24312447

0 commit comments

Comments
 (0)