about summary refs log tree commit diff
path: root/src/rustc/middle
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2012-03-07 12:54:00 +0100
committerMarijn Haverbeke <marijnh@gmail.com>2012-03-08 21:17:32 +0100
commitc71306b0dbdec6c8d6aaec06cb6770d5b0a2a7cc (patch)
tree4b3a69f7b3e8af17f7049e4f3b48b1dbfa327579 /src/rustc/middle
parentfd465f91a89450b7daebecdde9c280a923bbe394 (diff)
Explicitly store self_ids use for self locals in methods
This makes it possible to move them between crates without confusion,
and to instantiate them at a point where the monomorphizing
substitutions are known.

Issue #1944
Diffstat (limited to 'src/rustc/middle')
-rw-r--r--src/rustc/middle/ast_map.rs2
-rw-r--r--src/rustc/middle/resolve.rs6
-rw-r--r--src/rustc/middle/trans/base.rs6
-rw-r--r--src/rustc/middle/trans/impl.rs5
-rw-r--r--src/rustc/middle/ty.rs9
-rw-r--r--src/rustc/middle/typeck.rs29
6 files changed, 32 insertions, 25 deletions
diff --git a/src/rustc/middle/ast_map.rs b/src/rustc/middle/ast_map.rs
index 4240c0e5092..d1c80090e8c 100644
--- a/src/rustc/middle/ast_map.rs
+++ b/src/rustc/middle/ast_map.rs
@@ -132,6 +132,8 @@ fn map_arm(arm: arm, cx: ctx, v: vt) {
 fn map_method(impl_did: def_id, impl_path: @path,
               m: @method, cx: ctx) {
     cx.map.insert(m.id, node_method(m, impl_did, impl_path));
+    cx.map.insert(m.self_id, node_local(cx.local_id));
+    cx.local_id += 1u;
 }
 
 fn map_item(i: @item, cx: ctx, v: vt) {
diff --git a/src/rustc/middle/resolve.rs b/src/rustc/middle/resolve.rs
index af71d57dded..c440574334e 100644
--- a/src/rustc/middle/resolve.rs
+++ b/src/rustc/middle/resolve.rs
@@ -530,8 +530,8 @@ fn visit_item_with_scope(e: @env, i: @ast::item, sc: scopes, v: vt<scopes>) {
         v.visit_ty(sty, sc, v);
         for m in methods {
             v.visit_ty_params(m.tps, sc, v);
-            let msc = cons(scope_method(i.id, tps + m.tps), @sc);
-            v.visit_fn(visit::fk_method(m.ident, []),
+            let msc = cons(scope_method(m.self_id, tps + m.tps), @sc);
+            v.visit_fn(visit::fk_method(m.ident, [], m),
                        m.decl, m.body, m.span, m.id, msc, v);
         }
       }
@@ -590,7 +590,7 @@ fn visit_fn_with_scope(e: @env, fk: visit::fn_kind, decl: ast::fn_decl,
     for c: @ast::constr in decl.constraints { resolve_constr(e, c, sc, v); }
     let scope = alt fk {
       visit::fk_item_fn(_, tps) | visit::fk_res(_, tps) |
-      visit::fk_method(_, tps) { scope_bare_fn(decl, id, tps) }
+      visit::fk_method(_, tps, _) { scope_bare_fn(decl, id, tps) }
       visit::fk_anon(ast::proto_bare) { scope_bare_fn(decl, id, []) }
       visit::fk_anon(_) | visit::fk_fn_block { scope_fn_expr(decl, id, []) }
     };
diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs
index 6f53c56e32c..95597bac309 100644
--- a/src/rustc/middle/trans/base.rs
+++ b/src/rustc/middle/trans/base.rs
@@ -2136,7 +2136,7 @@ fn monomorphic_fn(ccx: crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
                            (*tvs).len() == 1u, [], psubsts, lldecl);
       }
       ast_map::node_method(mth, impl_def_id, _) {
-        let selfty = ty::lookup_item_type(ccx.tcx, impl_def_id).ty;
+        let selfty = ty::node_id_to_type(ccx.tcx, mth.self_id);
         let selfty = ty::substitute_type_params(ccx.tcx, substs, selfty);
         trans_fn(ccx, pt, mth.decl, mth.body, lldecl,
                  impl_self(selfty), [], psubsts, fn_id.node, none);
@@ -2315,7 +2315,7 @@ fn trans_local_var(cx: block, def: ast::def) -> local_var_result {
         assert (cx.fcx.lllocals.contains_key(nid));
         ret take_local(cx.fcx.lllocals, nid);
       }
-      ast::def_self(nid) {
+      ast::def_self(_) {
         let slf = option::get(cx.fcx.llself);
         let ptr = PointerCast(cx, slf.v,
                               T_ptr(type_of_or_i8(cx.ccx(), slf.t)));
@@ -4343,7 +4343,7 @@ fn trans_item(ccx: crate_ctxt, item: ast::item) {
         }
       }
       ast::item_impl(tps, _, _, ms) {
-        impl::trans_impl(ccx, *path, item.ident, ms, item.id, tps);
+        impl::trans_impl(ccx, *path, item.ident, ms, tps);
       }
       ast::item_res(decl, tps, body, dtor_id, ctor_id) {
         let llctor_decl = get_item_val(ccx, ctor_id);
diff --git a/src/rustc/middle/trans/impl.rs b/src/rustc/middle/trans/impl.rs
index 16cc55a6f94..1af4a13331b 100644
--- a/src/rustc/middle/trans/impl.rs
+++ b/src/rustc/middle/trans/impl.rs
@@ -44,14 +44,13 @@ import std::map::hashmap;
 // are referenced (ccx.method_map and ccx.dict_map).
 
 fn trans_impl(ccx: crate_ctxt, path: path, name: ast::ident,
-              methods: [@ast::method], id: ast::node_id,
-              tps: [ast::ty_param]) {
+              methods: [@ast::method], tps: [ast::ty_param]) {
     let sub_path = path + [path_name(name)];
     for m in methods {
         let llfn = get_item_val(ccx, m.id);
         let m_bounds = param_bounds(ccx, tps + m.tps);
         trans_fn(ccx, sub_path + [path_name(m.ident)], m.decl, m.body,
-                 llfn, impl_self(ty::node_id_to_type(ccx.tcx, id)),
+                 llfn, impl_self(ty::node_id_to_type(ccx.tcx, m.self_id)),
                  m_bounds, none, m.id, none);
     }
 }
diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs
index fa4e254d934..9d4dbec782c 100644
--- a/src/rustc/middle/ty.rs
+++ b/src/rustc/middle/ty.rs
@@ -2157,8 +2157,13 @@ fn iface_methods(cx: ctxt, id: ast::def_id) -> @[method] {
 
 fn impl_iface(cx: ctxt, id: ast::def_id) -> option<t> {
     if id.crate == ast::local_crate {
-        let t = cx.tcache.get(id).ty;
-        if get(t).struct == ty_nil { none } else { some(t) }
+        alt cx.items.get(id.node) {
+          ast_map::node_item(@{node: ast::item_impl(
+              _, some(@{node: ast::ty_path(_, id), _}), _, _), _}, _) {
+            some(node_id_to_type(cx, id))
+          }
+          _ { none }
+        }
     } else {
         csearch::get_impl_iface(cx, id)
     }
diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs
index 998ffa654d4..275bb862b84 100644
--- a/src/rustc/middle/typeck.rs
+++ b/src/rustc/middle/typeck.rs
@@ -106,7 +106,7 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
         let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, nid));
         ret {bounds: @[], ty: typ};
       }
-      ast::def_self(id) {
+      ast::def_self(_) {
         alt get_self_info(fcx.ccx) {
           some(self_impl(impl_t)) {
             ret {bounds: @[], ty: impl_t};
@@ -362,8 +362,8 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
             }
             ty::mk_param(tcx, n, id)
           }
-          ast::def_self(iface_id) {
-            alt check tcx.items.get(iface_id) {
+          ast::def_self(self_id) {
+            alt check tcx.items.get(self_id) {
               ast_map::node_item(@{node: ast::item_iface(tps, _), _}, _) {
                 if vec::len(tps) != vec::len(path.node.types) {
                     tcx.sess.span_err(ast_ty.span, "incorrect number of type \
@@ -850,7 +850,12 @@ mod collect {
           ast::item_impl(tps, ifce, selfty, ms) {
             let i_bounds = ty_param_bounds(tcx, m_collect, tps);
             let my_methods = [];
+            let selfty = ast_ty_to_ty(tcx, m_collect, selfty);
+            write_ty(tcx, it.id, selfty);
+            tcx.tcache.insert(local_def(it.id), {bounds: i_bounds,
+                                                 ty: selfty});
             for m in ms {
+                write_ty(tcx, m.self_id, selfty);
                 let bounds = ty_param_bounds(tcx, m_collect, m.tps);
                 let mty = ty_of_method(tcx, m_collect, m);
                 my_methods += [{mty: mty, id: m.id, span: m.span}];
@@ -860,15 +865,15 @@ mod collect {
                                       ty: fty});
                 write_ty(tcx, m.id, fty);
             }
-            let selfty = ast_ty_to_ty(tcx, m_collect, selfty);
-            write_ty(tcx, it.id, selfty);
             alt ifce {
               some(t) {
                 let iface_ty = ast_ty_to_ty(tcx, m_collect, t);
-                tcx.tcache.insert(local_def(it.id),
-                                     {bounds: i_bounds, ty: iface_ty});
                 alt ty::get(iface_ty).struct {
                   ty::ty_iface(did, tys) {
+                    // Store the iface type in the type node
+                    alt check t.node {
+                      ast::ty_path(_, t_id) { write_ty(tcx, t_id, iface_ty); }
+                    }
                     if did.crate == ast::local_crate {
                         ensure_iface_methods(tcx, did.node);
                     }
@@ -906,11 +911,7 @@ mod collect {
                   }
                 }
               }
-              _ {
-                // Store the bounds with a nil type.
-                tcx.tcache.insert(local_def(it.id), {bounds: i_bounds,
-                                                     ty: ty::mk_nil(tcx)});
-              }
+              _ {}
             }
           }
           ast::item_res(decl, tps, _, dtor_id, ctor_id) {
@@ -1665,8 +1666,8 @@ fn impl_self_ty(tcx: ty::ctxt, did: ast::def_id) -> {n_tps: uint, ty: ty::t} {
           }
         }
     } else {
-        let tpt = csearch::get_type(tcx, did);
-        {n_tps: vec::len(*tpt.bounds), ty: tpt.ty}
+        let ity = ty::lookup_item_type(tcx, did);
+        {n_tps: vec::len(*ity.bounds), ty: ity.ty}
     }
 }