aboutsummaryrefslogtreecommitdiff
path: root/src/comp/middle/ty.rs
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2011-01-12 11:05:38 -0800
committerPatrick Walton <[email protected]>2011-01-12 11:05:38 -0800
commit2aa36777f1da8383cd62be6f75ecdaed283b253d (patch)
tree349e3b2095a0601a4da5404dcea4bdcc0704322d /src/comp/middle/ty.rs
parentGuard unguarded log calls that snuck in. Shave 5s off building rustc. (diff)
downloadrust-2aa36777f1da8383cd62be6f75ecdaed283b253d.tar.xz
rust-2aa36777f1da8383cd62be6f75ecdaed283b253d.zip
Figure out what tydescs we need to pass when translating parametric function calls
Diffstat (limited to 'src/comp/middle/ty.rs')
-rw-r--r--src/comp/middle/ty.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs
index ddb7b7a9..ff54a0a1 100644
--- a/src/comp/middle/ty.rs
+++ b/src/comp/middle/ty.rs
@@ -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;
+}
+