about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-03-25 10:42:57 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-03-25 10:44:24 -0700
commit77a3373d53e3b0d1b87135b21307f19922398af9 (patch)
tree7ab7d8f75daab48a2d94c042aa6f4ad6a0e73297 /src
parent10f336055cb13518690f8d280240d30e3f13e508 (diff)
rustc: Create a crate metadata cache
Diffstat (limited to 'src')
-rw-r--r--src/comp/driver/rustc.rs5
-rw-r--r--src/comp/driver/session.rs13
-rw-r--r--src/comp/middle/ty.rs6
-rw-r--r--src/comp/util/common.rs8
4 files changed, 25 insertions, 7 deletions
diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs
index f0ce9a95f96..b91d09141d0 100644
--- a/src/comp/driver/rustc.rs
+++ b/src/comp/driver/rustc.rs
@@ -9,6 +9,7 @@ import middle.resolve;
 import middle.typeck;
 import util.common;
 
+import std.map.mk_hashmap;
 import std.option;
 import std.option.some;
 import std.option.none;
@@ -112,7 +113,9 @@ impure fn main(vec[str] args) {
                           uint_type = common.ty_u32,
                           float_type = common.ty_f64 );
 
-    auto sess = session.session(target_cfg);
+    auto crate_cache = common.new_int_hash[session.crate_metadata]();
+
+    auto sess = session.session(target_cfg, crate_cache);
     let option.t[str] input_file = none[str];
     let option.t[str] output_file = none[str];
     let vec[str] library_search_paths = vec();
diff --git a/src/comp/driver/session.rs b/src/comp/driver/session.rs
index 95f7466d723..7ad83dc198e 100644
--- a/src/comp/driver/session.rs
+++ b/src/comp/driver/session.rs
@@ -1,6 +1,7 @@
 import util.common.span;
 import util.common.ty_mach;
 import std._uint;
+import std.map;
 
 tag os {
     os_win32;
@@ -20,7 +21,9 @@ type cfg = rec(os os,
                ty_mach uint_type,
                ty_mach float_type);
 
-obj session(cfg targ) {
+type crate_metadata = vec[u8];
+
+obj session(cfg targ, map.hashmap[int, crate_metadata] crates) {
 
     fn get_targ_cfg() -> cfg {
         ret targ;
@@ -66,6 +69,14 @@ obj session(cfg targ) {
         log #fmt("error: unimplemented %s", msg);
         fail;
     }
+
+    fn get_external_crate(int num) -> crate_metadata {
+        ret crates.get(num);
+    }
+
+    fn set_external_crate(int num, &crate_metadata metadata) {
+        crates.insert(num, metadata);
+    }
 }
 
 
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs
index c6394c34149..fba9a1fd78a 100644
--- a/src/comp/middle/ty.rs
+++ b/src/comp/middle/ty.rs
@@ -1530,11 +1530,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
         ret ty.fold_ty(folder(bindings), typ);
     }
 
-    fn hash_int(&int x) -> uint { ret x as uint; }
-    fn eq_int(&int a, &int b) -> bool { ret a == b; }
-    auto hasher = hash_int;
-    auto eqer = eq_int;
-    auto bindings = @map.mk_hashmap[int,@ty.t](hasher, eqer);
+    auto bindings = @common.new_int_hash[@ty.t]();
 
     auto ures = unify_step(bindings, expected, actual, handler);
     alt (ures) {
diff --git a/src/comp/util/common.rs b/src/comp/util/common.rs
index 4b4f54818e9..b23d6a1ef14 100644
--- a/src/comp/util/common.rs
+++ b/src/comp/util/common.rs
@@ -64,6 +64,14 @@ fn new_def_hash[V]() -> std.map.hashmap[ast.def_id,V] {
     ret std.map.mk_hashmap[ast.def_id,V](hasher, eqer);
 }
 
+fn new_int_hash[V]() -> std.map.hashmap[int,V] {
+    fn hash_int(&int x) -> uint { ret x as uint; }
+    fn eq_int(&int a, &int b) -> bool { ret a == b; }
+    auto hasher = hash_int;
+    auto eqer = eq_int;
+    ret std.map.mk_hashmap[int,V](hasher, eqer);
+}
+
 fn istr(int i) -> str {
     ret _int.to_str(i, 10u);
 }