Figure out what tydescs we need to pass when translating parametric function calls

This commit is contained in:
Patrick Walton 2011-01-12 11:05:38 -08:00
parent 59c9e6caff
commit 2aa36777f1
2 changed files with 57 additions and 4 deletions

View file

@ -1772,8 +1772,8 @@ fn lval_val(@block_ctxt cx, ValueRef val) -> lval_result {
llobj=none[ValueRef]);
}
fn trans_name(@block_ctxt cx, &ast.name n, &option.t[ast.def] dopt)
-> lval_result {
fn trans_name(@block_ctxt cx, &ast.name n, &option.t[ast.def] dopt,
&ast.ann ann) -> lval_result {
alt (dopt) {
case (some[ast.def](?def)) {
alt (def) {
@ -1795,6 +1795,15 @@ fn trans_name(@block_ctxt cx, &ast.name n, &option.t[ast.def] dopt)
}
case (ast.def_fn(?did)) {
check (cx.fcx.ccx.fn_pairs.contains_key(did));
check (cx.fcx.ccx.item_ids.contains_key(did));
auto fn_item = cx.fcx.ccx.items.get(did);
auto monoty = node_ann_type(cx.fcx.ccx, ann);
auto tys = ty.resolve_ty_params(fn_item, monoty);
// TODO: build a closure with the type parameters that
// result
ret lval_val(cx, cx.fcx.ccx.fn_pairs.get(did));
}
case (ast.def_obj(?did)) {
@ -1897,8 +1906,8 @@ impure fn trans_index(@block_ctxt cx, &ast.span sp, @ast.expr base,
impure fn trans_lval(@block_ctxt cx, @ast.expr e) -> lval_result {
alt (e.node) {
case (ast.expr_name(?n, ?dopt, _)) {
ret trans_name(cx, n, dopt);
case (ast.expr_name(?n, ?dopt, ?ann)) {
ret trans_name(cx, n, dopt, ann);
}
case (ast.expr_field(?base, ?ident, ?ann)) {
ret trans_field(cx, e.span, base, ident, ann);

View file

@ -12,6 +12,7 @@ import front.ast;
import front.ast.mutability;
import util.common;
import util.common.append;
import util.common.new_def_hash;
import util.common.span;
// Data types
@ -1194,3 +1195,46 @@ fn type_err_to_str(&ty.type_err err) -> str {
}
}
// Type parameter resolution, used in translation
fn resolve_ty_params(@ast.item item, @t monoty) -> vec[@t] {
obj resolve_ty_params_handler(@hashmap[ast.def_id,@t] bindings) {
fn resolve_local(ast.def_id id) -> @t { log "resolve local"; fail; }
fn record_local(ast.def_id id, @t ty) { log "record local"; fail; }
fn unify_expected_param(ast.def_id id, @t expected, @t actual)
-> unify_result {
bindings.insert(id, actual);
ret ures_ok(actual);
}
fn unify_actual_param(ast.def_id id, @t expected, @t actual)
-> unify_result {
bindings.insert(id, expected);
ret ures_ok(expected);
}
}
auto ty_params_and_polyty = item_ty(item);
auto bindings = @new_def_hash[@t]();
auto handler = resolve_ty_params_handler(bindings);
auto unify_res = unify(ty_params_and_polyty._1, monoty, handler);
alt (unify_res) {
case (ures_ok(_)) { /* fall through */ }
case (ures_err(_,?exp,?act)) {
log "resolve_ty_params mismatch: " + ty_to_str(exp) + " " +
ty_to_str(act);
fail;
}
}
let vec[@t] result_tys = vec();
auto ty_param_ids = ty_params_and_polyty._0;
for (ast.def_id tp in ty_param_ids) {
check (bindings.contains_key(tp));
result_tys += vec(bindings.get(tp));
}
ret result_tys;
}