about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-09-20 18:06:47 -0700
committerBrian Anderson <banderson@mozilla.com>2011-09-20 18:06:47 -0700
commitf809e2269779b5518e648cf63d9538399b00298e (patch)
treec6cab9f354a64310b5274fb1e3e0aca9506fc5a0
parent7ae251789ccd0a647e5abfc8085a8bd42359de65 (diff)
downloadrust-f809e2269779b5518e648cf63d9538399b00298e.tar.gz
rust-f809e2269779b5518e648cf63d9538399b00298e.zip
Represent unique creation as a unop in the AST instead of its own expr
Like the box unop.

Issue #409
-rw-r--r--src/comp/middle/trans.rs6
-rw-r--r--src/comp/middle/tstate/pre_post_conditions.rs1
-rw-r--r--src/comp/middle/tstate/states.rs1
-rw-r--r--src/comp/middle/typeck.rs8
-rw-r--r--src/comp/syntax/ast.rs7
-rw-r--r--src/comp/syntax/ast_util.rs1
-rw-r--r--src/comp/syntax/fold.rs1
-rw-r--r--src/comp/syntax/parse/parser.rs10
-rw-r--r--src/comp/syntax/print/pprust.rs5
-rw-r--r--src/comp/syntax/visit.rs1
10 files changed, 21 insertions, 20 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 697f6d9e05c..7d190ad89b1 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -2183,6 +2183,9 @@ fn trans_unary(cx: @block_ctxt, op: ast::unop, e: @ast::expr,
         let bcx = move_val_if_temp(sub.bcx, INIT, body, lv, e_ty);
         ret rslt(bcx, sub.box);
       }
+      ast::uniq(_) {
+        ret trans_uniq(cx, e, id);
+      }
       ast::deref. {
         bcx_ccx(cx).sess.bug("deref expressions should have been \
                                  translated using trans_lval(), not \
@@ -4246,9 +4249,6 @@ fn trans_expr_out(cx: @block_ctxt, e: @ast::expr, output: out_method) ->
         CondBr(cx, cond, then_cx.llbb, else_cx.llbb);
         ret rslt(join_branches(cx, [check_res, els]), C_nil());
       }
-      ast::expr_uniq(contents) {
-        ret trans_uniq(cx, contents, e.id);
-      }
       ast::expr_break. { ret trans_break(e.span, cx); }
       ast::expr_cont. { ret trans_cont(e.span, cx); }
       ast::expr_ret(ex) { ret trans_ret(cx, ex); }
diff --git a/src/comp/middle/tstate/pre_post_conditions.rs b/src/comp/middle/tstate/pre_post_conditions.rs
index d7697d47668..9f2f1307478 100644
--- a/src/comp/middle/tstate/pre_post_conditions.rs
+++ b/src/comp/middle/tstate/pre_post_conditions.rs
@@ -559,7 +559,6 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) {
           none. { clear_pp(expr_pp(fcx.ccx, e)); }
         }
       }
-      expr_uniq(sub) { find_pre_post_exprs(fcx, [sub], e.id); }
     }
 }
 
diff --git a/src/comp/middle/tstate/states.rs b/src/comp/middle/tstate/states.rs
index fd227d3042f..9997f6ad504 100644
--- a/src/comp/middle/tstate/states.rs
+++ b/src/comp/middle/tstate/states.rs
@@ -608,7 +608,6 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
           none. { ret pure_exp(fcx.ccx, e.id, pres); }
         }
       }
-      expr_uniq(_) { ret pure_exp(fcx.ccx, e.id, pres); }
     }
 }
 
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index 4d3189d96c2..c6d24802ecd 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -1719,6 +1719,9 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
         let oper_t = expr_ty(tcx, oper);
         alt unop {
           ast::box(mut) { oper_t = ty::mk_box(tcx, {ty: oper_t, mut: mut}); }
+          ast::uniq(mut) {
+            oper_t = ty::mk_uniq(tcx, oper_t);
+          }
           ast::deref. {
             alt structure_of(fcx, expr.span, oper_t) {
               ty::ty_box(inner) { oper_t = inner.ty; }
@@ -2349,11 +2352,6 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
         // Now remove the info from the stack.
         vec::pop::<obj_info>(fcx.ccx.obj_infos);
       }
-      ast::expr_uniq(x) {
-        let t = next_ty_var(fcx);
-        check_expr_with(fcx, x, t);
-        write::ty_only_fixup(fcx, id, ty::mk_uniq(tcx, t));
-      }
       _ { tcx.sess.unimpl("expr type in typeck::check_expr"); }
     }
     if bot { write::ty_only_fixup(fcx, expr.id, ty::mk_bot(tcx)); }
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs
index 6b64d373746..ad6aacb1549 100644
--- a/src/comp/syntax/ast.rs
+++ b/src/comp/syntax/ast.rs
@@ -124,7 +124,11 @@ tag binop {
     gt;
 }
 
-tag unop { box(mutability); deref; not; neg; }
+tag unop {
+    box(mutability);
+    uniq(mutability);
+    deref; not; neg;
+}
 
 tag mode { by_ref; by_mut_ref; by_move; }
 
@@ -215,7 +219,6 @@ tag expr_ {
     expr_if_check(@expr, blk, option::t<@expr>);
     expr_anon_obj(anon_obj);
     expr_mac(mac);
-    expr_uniq(@expr);
 }
 
 /*
diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs
index aebf9b3e680..8350ce9a8bb 100644
--- a/src/comp/syntax/ast_util.rs
+++ b/src/comp/syntax/ast_util.rs
@@ -110,6 +110,7 @@ pure fn lazy_binop(b: binop) -> bool {
 fn unop_to_str(op: unop) -> str {
     alt op {
       box(mt) { if mt == mut { ret "@mutable "; } ret "@"; }
+      uniq(mt) { if mt == mut { ret "~mutable "; } ret "~"; }
       deref. { ret "*"; }
       not. { ret "!"; }
       neg. { ret "-"; }
diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs
index 23293adbd80..c53176e24fb 100644
--- a/src/comp/syntax/fold.rs
+++ b/src/comp/syntax/fold.rs
@@ -424,7 +424,6 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
           }
           expr_anon_obj(ao) { expr_anon_obj(fold_anon_obj(ao)) }
           expr_mac(mac) { expr_mac(fold_mac(mac)) }
-          expr_uniq(e) { expr_uniq(fld.fold_expr(e)) }
         }
 }
 
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index 3e559e1a2a9..6869dc6501d 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -886,9 +886,6 @@ fn parse_bottom_expr(p: parser) -> @ast::expr {
     } else if p.peek() == token::ELLIPSIS {
         p.bump();
         ret mk_mac_expr(p, lo, p.get_hi_pos(), ast::mac_ellipsis);
-    } else if p.peek() == token::TILDE {
-        p.bump();
-        ex = ast::expr_uniq(parse_expr(p));
     } else if eat_word(p, "obj") {
         // Anonymous object
 
@@ -1145,6 +1142,13 @@ fn parse_prefix_expr(p: parser) -> @ast::expr {
         hi = e.span.hi;
         ex = ast::expr_unary(ast::box(m), e);
       }
+      token::TILDE. {
+        p.bump();
+        let m = parse_mutability(p);
+        let e = parse_prefix_expr(p);
+        hi = e.span.hi;
+        ex = ast::expr_unary(ast::uniq(m), e);
+      }
       _ { ret parse_dot_or_call_expr(p); }
     }
     ret mk_expr(p, lo, hi, ex);
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index 3a8e5f2b9be..48031a295db 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -988,7 +988,6 @@ fn print_expr(s: ps, expr: @ast::expr) {
         }
         bclose(s, expr.span);
       }
-      ast::expr_uniq(expr) { word(s.s, "~"); print_expr(s, expr); }
     }
     s.ann.post(ann_node);
     end(s);
@@ -1001,7 +1000,7 @@ fn print_expr_parens_if_not_bot(s: ps, ex: @ast::expr) {
       ast::expr_ternary(_, _, _) | ast::expr_move(_, _) |
       ast::expr_copy(_) | ast::expr_assign(_, _) | ast::expr_be(_) |
       ast::expr_assign_op(_, _, _) | ast::expr_swap(_, _) |
-      ast::expr_log(_, _) | ast::expr_assert(_) | ast::expr_uniq(_) |
+      ast::expr_log(_, _) | ast::expr_assert(_) |
       ast::expr_check(_, _) { true }
       _ { false }
     };
@@ -1658,7 +1657,7 @@ fn ends_in_lit_int(ex: @ast::expr) -> bool {
       ast::expr_ternary(_, _, sub) | ast::expr_move(_, sub) |
       ast::expr_copy(sub) | ast::expr_assign(_, sub) | ast::expr_be(sub) |
       ast::expr_assign_op(_, _, sub) | ast::expr_swap(_, sub) |
-      ast::expr_log(_, sub) | ast::expr_assert(sub) | ast::expr_uniq(sub) |
+      ast::expr_log(_, sub) | ast::expr_assert(sub) |
       ast::expr_check(_, sub) { ends_in_lit_int(sub) }
       ast::expr_fail(osub) | ast::expr_ret(osub) | ast::expr_put(osub) {
         alt osub {
diff --git a/src/comp/syntax/visit.rs b/src/comp/syntax/visit.rs
index d5b39bb7ca5..387434edf15 100644
--- a/src/comp/syntax/visit.rs
+++ b/src/comp/syntax/visit.rs
@@ -325,7 +325,6 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
         }
       }
       expr_mac(mac) { visit_mac(mac, e, v); }
-      expr_uniq(x) { v.visit_expr(x, e, v); }
     }
 }