about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-03-08 14:05:16 -0800
committerPatrick Walton <pcwalton@mimiga.net>2012-03-08 14:05:56 -0800
commit0e17cdb627e460a7c4cf8efe285b56a46592e2eb (patch)
tree1909f49b2b6e5e1d76e2c06fc262803e820c1e1e /src
parentebc1d3e7042f19ed836bf99e6ede10e4ad049776 (diff)
downloadrust-0e17cdb627e460a7c4cf8efe285b56a46592e2eb.tar.gz
rust-0e17cdb627e460a7c4cf8efe285b56a46592e2eb.zip
rustc: Add regions to the type system
Diffstat (limited to 'src')
-rw-r--r--src/rustc/metadata/tyencode.rs18
-rw-r--r--src/rustc/middle/trans/shape.rs5
-rw-r--r--src/rustc/middle/trans/type_of.rs7
-rw-r--r--src/rustc/middle/ty.rs28
-rw-r--r--src/rustc/middle/typeck.rs4
-rw-r--r--src/serializer/serializer.rs2
6 files changed, 59 insertions, 5 deletions
diff --git a/src/rustc/metadata/tyencode.rs b/src/rustc/metadata/tyencode.rs
index aa08e313dd7..d7a17bbe036 100644
--- a/src/rustc/metadata/tyencode.rs
+++ b/src/rustc/metadata/tyencode.rs
@@ -93,6 +93,19 @@ fn enc_mt(w: io::writer, cx: @ctxt, mt: ty::mt) {
     }
     enc_ty(w, cx, mt.ty);
 }
+fn enc_region(w: io::writer, cx: @ctxt, r: ty::region) {
+    alt r {
+        ty::re_named(did) {
+            w.write_char('n'); w.write_str(cx.ds(did)); w.write_char('|');
+        }
+        ty::re_caller(did) {
+            w.write_char('c'); w.write_str(cx.ds(did)); w.write_char('|');
+        }
+        ty::re_block(nid) {
+            w.write_char('b'); w.write_int(nid); w.write_char('|');
+        }
+    }
+}
 fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
     alt st {
       ty::ty_nil { w.write_char('n'); }
@@ -147,6 +160,11 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
       ty::ty_box(mt) { w.write_char('@'); enc_mt(w, cx, mt); }
       ty::ty_uniq(mt) { w.write_char('~'); enc_mt(w, cx, mt); }
       ty::ty_ptr(mt) { w.write_char('*'); enc_mt(w, cx, mt); }
+      ty::ty_rptr(r, mt) {
+        w.write_char('&');
+        enc_region(w, cx, r);
+        enc_mt(w, cx, mt);
+      }
       ty::ty_vec(mt) { w.write_char('I'); enc_mt(w, cx, mt); }
       ty::ty_rec(fields) {
         w.write_str("R[");
diff --git a/src/rustc/middle/trans/shape.rs b/src/rustc/middle/trans/shape.rs
index 2805778e927..61ccba7c94f 100644
--- a/src/rustc/middle/trans/shape.rs
+++ b/src/rustc/middle/trans/shape.rs
@@ -59,6 +59,7 @@ const shape_bare_fn: u8 = 27u8;
 const shape_tydesc: u8 = 28u8;
 const shape_send_tydesc: u8 = 29u8;
 const shape_class: u8 = 30u8;
+const shape_rptr: u8 = 31u8;
 
 fn hash_res_info(ri: res_info) -> uint {
     let h = 5381u;
@@ -384,6 +385,10 @@ fn shape_of(ccx: crate_ctxt, t: ty::t, ty_param_map: [uint]) -> [u8] {
       }
       ty::ty_iface(_, _) { s += [shape_box_fn]; }
       ty::ty_class(_, _) { s += [shape_class]; }
+      ty::ty_rptr(_, tm) {
+        s += [shape_rptr];
+        add_substr(s, shape_of(ccx, tm.ty, ty_param_map));
+      }
       ty::ty_res(did, raw_subt, tps) {
         let subt = ty::substitute_type_params(ccx.tcx, tps, raw_subt);
         let ri = {did: did, t: subt};
diff --git a/src/rustc/middle/trans/type_of.rs b/src/rustc/middle/trans/type_of.rs
index 89de5e249a2..b293fd80e3a 100644
--- a/src/rustc/middle/trans/type_of.rs
+++ b/src/rustc/middle/trans/type_of.rs
@@ -78,7 +78,12 @@ fn type_of(cx: crate_ctxt, t: ty::t) -> TypeRef {
       }
       ty::ty_ptr(mt) {
         let mt_ty = mt.ty;
-        T_ptr(type_of(cx, mt_ty)) }
+        T_ptr(type_of(cx, mt_ty))
+      }
+      ty::ty_rptr(_, mt) {
+        let mt_ty = mt.ty;
+        T_ptr(type_of(cx, mt_ty))
+      }
       ty::ty_rec(fields) {
         let tys: [TypeRef] = [];
         for f: ty::field in fields {
diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs
index 943731676ed..ddcde34d8ab 100644
--- a/src/rustc/middle/ty.rs
+++ b/src/rustc/middle/ty.rs
@@ -78,6 +78,7 @@ export ty_iface, mk_iface;
 export ty_res, mk_res;
 export ty_param, mk_param;
 export ty_ptr, mk_ptr, mk_mut_ptr, type_is_unsafe_ptr;
+export ty_rptr, mk_rptr;
 export ty_rec, mk_rec;
 export ty_enum, mk_enum, type_is_enum;
 export ty_tup, mk_tup;
@@ -87,6 +88,7 @@ export ty_uint, mk_uint, mk_mach_uint;
 export ty_uniq, mk_uniq, mk_imm_uniq, type_is_unique_box;
 export ty_var, mk_var;
 export ty_self, mk_self;
+export region, re_named, re_caller, re_block;
 export get, type_has_params, type_has_vars, type_id;
 export same_type;
 export ty_var_id;
@@ -218,6 +220,12 @@ type fn_ty = {proto: ast::proto,
               ret_style: ret_style,
               constraints: [@constr]};
 
+enum region {
+    re_named(def_id),
+    re_caller(def_id),
+    re_block(node_id)
+}
+
 // NB: If you change this, you'll probably want to change the corresponding
 // AST structure in front/ast::rs as well.
 enum sty {
@@ -233,6 +241,7 @@ enum sty {
     ty_uniq(mt),
     ty_vec(mt),
     ty_ptr(mt),
+    ty_rptr(region, mt),
     ty_rec([field]),
     ty_fn(fn_ty),
     ty_iface(def_id, [t]),
@@ -369,7 +378,7 @@ fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option<ast::def_id>) -> t {
       ty_enum(_, tys) | ty_iface(_, tys) | ty_class(_, tys) {
         for tt in tys { derive_flags(has_params, has_vars, tt); }
       }
-      ty_box(m) | ty_uniq(m) | ty_vec(m) | ty_ptr(m) {
+      ty_box(m) | ty_uniq(m) | ty_vec(m) | ty_ptr(m) | ty_rptr(_, m) {
         derive_flags(has_params, has_vars, m.ty);
       }
       ty_rec(flds) {
@@ -438,6 +447,8 @@ fn mk_imm_uniq(cx: ctxt, ty: t) -> t { mk_uniq(cx, {ty: ty,
 
 fn mk_ptr(cx: ctxt, tm: mt) -> t { mk_t(cx, ty_ptr(tm)) }
 
+fn mk_rptr(cx: ctxt, r: region, tm: mt) -> t { mk_t(cx, ty_rptr(r, tm)) }
+
 fn mk_mut_ptr(cx: ctxt, ty: t) -> t { mk_ptr(cx, {ty: ty,
                                                   mutbl: ast::m_mutbl}) }
 
@@ -505,7 +516,9 @@ fn walk_ty(cx: ctxt, ty: t, f: fn(t)) {
       ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
       ty_str | ty_send_type | ty_type | ty_opaque_box |
       ty_opaque_closure_ptr(_) | ty_var(_) | ty_param(_, _) {}
-      ty_box(tm) | ty_vec(tm) | ty_ptr(tm) { walk_ty(cx, tm.ty, f); }
+      ty_box(tm) | ty_vec(tm) | ty_ptr(tm) | ty_rptr(_, tm) {
+        walk_ty(cx, tm.ty, f);
+      }
       ty_enum(_, subtys) | ty_iface(_, subtys) | ty_class(_, subtys)
        | ty_self(subtys) {
         for subty: t in subtys { walk_ty(cx, subty, f); }
@@ -1112,6 +1125,13 @@ fn hash_type_structure(st: sty) -> uint {
         }
         h
     }
+    fn hash_region(r: region) -> uint {
+        alt r {
+          re_named(_)   { 1u }
+          re_caller(_)  { 2u }
+          re_block(_)   { 3u }
+        }
+    }
     alt st {
       ty_nil { 0u } ty_bool { 1u }
       ty_int(t) {
@@ -1158,6 +1178,10 @@ fn hash_type_structure(st: sty) -> uint {
       ty_type { 32u }
       ty_bot { 34u }
       ty_ptr(mt) { hash_subty(35u, mt.ty) }
+      ty_rptr(region, mt) {
+        let h = (46u << 2u) + hash_region(region);
+        hash_subty(h, mt.ty)
+      }
       ty_res(did, sub, tps) {
         let h = hash_subty(hash_def(18u, did), sub);
         hash_subtys(h, tps)
diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs
index 275bb862b84..cbc053217f4 100644
--- a/src/rustc/middle/typeck.rs
+++ b/src/rustc/middle/typeck.rs
@@ -319,8 +319,8 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
       ast::ty_ptr(mt) {
         ty::mk_ptr(tcx, ast_mt_to_mt(tcx, mode, mt))
       }
-      ast::ty_rptr(_,_) {
-        fail "TODO: regions";
+      ast::ty_rptr(_, mt) {
+        ty::mk_rptr(tcx, ty::re_block(0), ast_mt_to_mt(tcx, mode, mt))
       }
       ast::ty_tup(fields) {
         let flds = vec::map(fields, bind ast_ty_to_ty(tcx, mode, _));
diff --git a/src/serializer/serializer.rs b/src/serializer/serializer.rs
index 06684474c47..8ab5aa770be 100644
--- a/src/serializer/serializer.rs
+++ b/src/serializer/serializer.rs
@@ -258,6 +258,7 @@ impl serialize_methods for serialize_ctx {
             self.serialize_ty(t, v)
           }
           ty::ty_ptr(_) |
+          ty::ty_rptr(_,_) |
           ty::ty_fn(_) |
           ty::ty_iface(_, _) |
           ty::ty_res(_, _, _) |
@@ -431,6 +432,7 @@ impl deserialize_methods for serialize_ctx {
             self.deserialize_ty(t)
           }
           ty::ty_ptr(_) |
+          ty::ty_rptr(_,_) |
           ty::ty_fn(_) |
           ty::ty_iface(_, _) |
           ty::ty_res(_, _, _) |