]> git.lizzy.rs Git - rust.git/commitdiff
Add non_ty_var precondition for type_of_fn, plus minor cleanup
authorTim Chevalier <chevalier@alum.wellesley.edu>
Fri, 16 Sep 2011 17:49:05 +0000 (10:49 -0700)
committerTim Chevalier <chevalier@alum.wellesley.edu>
Fri, 16 Sep 2011 17:58:02 +0000 (10:58 -0700)
src/comp/middle/trans.rs
src/comp/middle/trans_objects.rs

index e1f5d79f6eff48f39b53632a0bb834597d730127..a369d109875e7613fc5c7dc7c43e8bb31f32a864 100644 (file)
@@ -74,11 +74,11 @@ fn type_of_explicit_args(cx: @crate_ctxt, sp: span, inputs: [ty::arg]) ->
 //  - trans_args
 fn type_of_fn(cx: @crate_ctxt, sp: span, proto: ast::proto,
               is_method: bool, ret_ref: bool, inputs: [ty::arg],
-              output: ty::t, ty_param_count: uint) -> TypeRef {
+              output: ty::t, ty_param_count: uint)
+   : non_ty_var(cx, output) -> TypeRef {
     let atys: [TypeRef] = [];
 
     // Arg 0: Output pointer.
-    check non_ty_var(cx, output);
     let out_ty = T_ptr(type_of_inner(cx, sp, output));
     atys += [ret_ref ? T_ptr(out_ty) : out_ty];
 
@@ -2073,6 +2073,7 @@ fn move_val(cx: @block_ctxt, action: copy_action, dst: ValueRef,
         // If we're here, it must be a temporary.
         ret revoke_clean(cx, src_val, t);
     }
+    /* FIXME: suggests a type constraint */
     bcx_ccx(cx).sess.bug("unexpected type in trans::move_val: " +
                              ty_to_str(tcx, t));
 }
@@ -2999,12 +3000,18 @@ fn trans_field(cx: @block_ctxt, sp: span, v: ValueRef, t0: ty::t,
 
         let v = GEP(r.bcx, vtbl, [C_int(0), C_int(ix as int)]);
         let tcx = bcx_tcx(cx);
+        let ccx = bcx_ccx(cx);
+
         let fn_ty: ty::t = ty::method_ty_to_fn_ty(tcx, methods[ix]);
+        let ret_ty = ty::ty_fn_ret(tcx, fn_ty);
         let ret_ref = ast_util::ret_by_ref(ty::ty_fn_ret_style(tcx, fn_ty));
+        // FIXME: constrain ty_obj?
+        check non_ty_var(ccx, ret_ty);
+
         let ll_fn_ty =
-            type_of_fn(bcx_ccx(cx), sp, ty::ty_fn_proto(tcx, fn_ty),
+            type_of_fn(ccx, sp, ty::ty_fn_proto(tcx, fn_ty),
                        true, ret_ref, ty::ty_fn_args(tcx, fn_ty),
-                       ty::ty_fn_ret(tcx, fn_ty), 0u);
+                       ret_ty, 0u);
         v = PointerCast(r.bcx, v, T_ptr(T_ptr(ll_fn_ty)));
         let lvo = lval_mem(r.bcx, v);
         ret {llobj: some::<ValueRef>(r.val) with lvo};
@@ -4581,7 +4588,7 @@ fn trans_stmt(cx: @block_ctxt, s: ast::stmt) -> result {
       }
       _ { bcx_ccx(cx).sess.unimpl("stmt variant"); }
     }
-    ret rslt(bcx, C_nil());
+    rslt(bcx, C_nil())
 }
 
 // You probably don't want to use this one. See the
@@ -5438,7 +5445,7 @@ fn create_main(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
         let vecarg_ty: ty::arg =
             {mode: ast::by_ref,
              ty: ty::mk_vec(ccx.tcx, {ty: unit_ty, mut: ast::imm})};
-        // FIXME: mk_nil should have a post condition
+        // FIXME: mk_nil should have a postcondition
         let nt = ty::mk_nil(ccx.tcx);
         check non_ty_var(ccx, nt);
 
index 4f6dbfaa5f9a937795d22b662293d3151d1a2c1f..1b36cbdee742596a633c92b1ca8b5d4df59dfbb7 100644 (file)
@@ -885,9 +885,9 @@ fn process_normal_mthd(cx: @local_ctxt, m: @ast::method, self_ty: ty::t,
                        ty_params: [ast::ty_param]) -> ValueRef {
 
     let llfnty = T_nil();
+    let ccx = cx.ccx;
     alt ty::struct(cx.ccx.tcx, node_id_type(cx.ccx, m.node.id)) {
       ty::ty_fn(proto, inputs, output, rs, _) {
-        let ccx = cx.ccx;
         check non_ty_var(ccx, output);
         llfnty = type_of_fn(ccx, m.span, proto, true,
                             ast_util::ret_by_ref(rs), inputs, output,
@@ -897,13 +897,13 @@ fn process_normal_mthd(cx: @local_ctxt, m: @ast::method, self_ty: ty::t,
     let mcx: @local_ctxt =
         @{path: cx.path + ["method", m.node.ident] with *cx};
     let s: str = mangle_internal_name_by_path(mcx.ccx, mcx.path);
-    let llfn: ValueRef = decl_internal_fastcall_fn(cx.ccx.llmod, s, llfnty);
+    let llfn: ValueRef = decl_internal_fastcall_fn(ccx.llmod, s, llfnty);
 
     // Every method on an object gets its node_id inserted into the crate-wide
     // item_ids map, together with the ValueRef that points to where that
     // method's definition will be in the executable.
-    cx.ccx.item_ids.insert(m.node.id, llfn);
-    cx.ccx.item_symbols.insert(m.node.id, s);
+    ccx.item_ids.insert(m.node.id, llfn);
+    ccx.item_symbols.insert(m.node.id, s);
     trans_fn(mcx, m.span, m.node.meth, llfn, some(self_ty), ty_params,
              m.node.id);