about summary refs log tree commit diff
path: root/src/comp/middle
diff options
context:
space:
mode:
Diffstat (limited to 'src/comp/middle')
-rw-r--r--src/comp/middle/debuginfo.rs6
-rw-r--r--src/comp/middle/trans.rs10
-rw-r--r--src/comp/middle/trans_closure.rs2
-rw-r--r--src/comp/middle/trans_common.rs43
-rw-r--r--src/comp/middle/trans_impl.rs2
5 files changed, 32 insertions, 31 deletions
diff --git a/src/comp/middle/debuginfo.rs b/src/comp/middle/debuginfo.rs
index babe01963ef..fab7f625b0f 100644
--- a/src/comp/middle/debuginfo.rs
+++ b/src/comp/middle/debuginfo.rs
@@ -394,7 +394,7 @@ fn create_record(cx: @crate_ctxt, t: ty::t, fields: [ast::ty_field],
     let fname = filename_from_span(cx, span);
     let file_node = create_file(cx, fname);
     let scx = create_structure(file_node,
-                               option::get(cx.dbg_cx).names.next("rec"),
+                               option::get(cx.dbg_cx).names("rec"),
                                line_from_span(cx.sess.codemap,
                                               span) as int);
     for field in fields {
@@ -738,10 +738,10 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
       ast_map::node_expr(expr) {
         alt expr.node {
           ast::expr_fn(_, decl, _, _) {
-            (dbg_cx.names.next("fn"), decl.output, expr.id)
+            (dbg_cx.names("fn"), decl.output, expr.id)
           }
           ast::expr_fn_block(decl, _) {
-            (dbg_cx.names.next("fn"), decl.output, expr.id)
+            (dbg_cx.names("fn"), decl.output, expr.id)
           }
         }
       }
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index dd064a60800..38f9ec7813a 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -4119,7 +4119,7 @@ fn new_block_ctxt(cx: @fn_ctxt, parent: block_parent, kind: block_kind,
     let s = "";
     if cx.lcx.ccx.sess.opts.save_temps ||
            cx.lcx.ccx.sess.opts.debuginfo {
-        s = cx.lcx.ccx.names.next(name);
+        s = cx.lcx.ccx.names(name);
     }
     let llbb: BasicBlockRef =
         str::as_buf(s, {|buf| llvm::LLVMAppendBasicBlock(cx.llfn, buf) });
@@ -5665,13 +5665,13 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
     let float_type = T_float(targ_cfg);
     let task_type = T_task(targ_cfg);
     let taskptr_type = T_ptr(task_type);
-    tn.associate("taskptr", taskptr_type);
+    lib::llvm::associate_type(tn, "taskptr", taskptr_type);
     let tydesc_type = T_tydesc(targ_cfg);
-    tn.associate("tydesc", tydesc_type);
+    lib::llvm::associate_type(tn, "tydesc", tydesc_type);
     let crate_map = decl_crate_map(sess, link_meta.name, llmod);
     let dbg_cx = if sess.opts.debuginfo {
         option::some(@{llmetadata: map::new_int_hash(),
-                       names: namegen(0)})
+                       names: new_namegen()})
     } else {
         option::none
     };
@@ -5696,7 +5696,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
           dicts: map::mk_hashmap(hash_dict_id, {|a, b| a == b}),
           module_data: new_str_hash::<ValueRef>(),
           lltypes: ty::new_ty_hash(),
-          names: namegen(0),
+          names: new_namegen(),
           sha: sha,
           type_sha1s: ty::new_ty_hash(),
           type_short_names: ty::new_ty_hash(),
diff --git a/src/comp/middle/trans_closure.rs b/src/comp/middle/trans_closure.rs
index 4bd82d8b803..d4221ea2d25 100644
--- a/src/comp/middle/trans_closure.rs
+++ b/src/comp/middle/trans_closure.rs
@@ -507,7 +507,7 @@ fn trans_expr_fn(bcx: @block_ctxt,
     let ccx = bcx_ccx(bcx), bcx = bcx;
     let fty = node_id_type(ccx, id);
     let llfnty = type_of_fn_from_ty(ccx, sp, fty, []);
-    let sub_cx = extend_path(bcx.fcx.lcx, ccx.names.next("anon"));
+    let sub_cx = extend_path(bcx.fcx.lcx, ccx.names("anon"));
     let s = mangle_internal_name_by_path(ccx, sub_cx.path);
     let llfn = decl_internal_cdecl_fn(ccx.llmod, s, llfnty);
     register_fn(ccx, sp, sub_cx.path, "anon fn", [], id);
diff --git a/src/comp/middle/trans_common.rs b/src/comp/middle/trans_common.rs
index c0f110e65c3..1073234923a 100644
--- a/src/comp/middle/trans_common.rs
+++ b/src/comp/middle/trans_common.rs
@@ -14,7 +14,8 @@ import middle::{resolve, ty};
 import back::{link, abi, upcall};
 import util::common::*;
 import syntax::codemap::span;
-import lib::llvm::{llvm, target_data, type_names};
+import lib::llvm::{llvm, target_data, type_names, associate_type,
+                   name_has_type};
 import lib::llvm::llvm::{ModuleRef, ValueRef, TypeRef, BasicBlockRef};
 import lib::llvm::{True, False, Bool};
 import metadata::{csearch};
@@ -22,8 +23,10 @@ import metadata::{csearch};
 // FIXME: These should probably be pulled in here too.
 import trans::{type_of_fn, drop_ty};
 
-obj namegen(mutable i: int) {
-    fn next(prefix: str) -> str { i += 1; ret prefix + int::str(i); }
+type namegen = fn@(str) -> str;
+fn new_namegen() -> namegen {
+    let i = @mutable 0;
+    ret fn@(prefix: str) -> str { *i += 1; prefix + int::str(*i) };
 }
 
 type derived_tydesc_info = {lltydesc: ValueRef, escapes: bool};
@@ -616,17 +619,17 @@ fn T_tydesc_field(cx: @crate_ctxt, field: int) -> TypeRef unsafe {
 
 fn T_glue_fn(cx: @crate_ctxt) -> TypeRef {
     let s = "glue_fn";
-    if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
+    alt name_has_type(cx.tn, s) { some(t) { ret t; } _ {} }
     let t = T_tydesc_field(cx, abi::tydesc_field_drop_glue);
-    cx.tn.associate(s, t);
+    associate_type(cx.tn, s, t);
     ret t;
 }
 
 fn T_cmp_glue_fn(cx: @crate_ctxt) -> TypeRef {
     let s = "cmp_glue_fn";
-    if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
+    alt name_has_type(cx.tn, s) { some(t) { ret t; } _ {} }
     let t = T_tydesc_field(cx, abi::tydesc_field_cmp_glue);
-    cx.tn.associate(s, t);
+    associate_type(cx.tn, s, t);
     ret t;
 }
 
@@ -691,9 +694,9 @@ fn T_taskptr(cx: @crate_ctxt) -> TypeRef { ret T_ptr(cx.task_type); }
 // This type must never be used directly; it must always be cast away.
 fn T_typaram(tn: type_names) -> TypeRef {
     let s = "typaram";
-    if tn.name_has_type(s) { ret tn.get_type(s); }
+    alt name_has_type(tn, s) { some(t) { ret t; } _ {} }
     let t = T_i8();
-    tn.associate(s, t);
+    associate_type(tn, s, t);
     ret t;
 }
 
@@ -701,13 +704,13 @@ fn T_typaram_ptr(tn: type_names) -> TypeRef { ret T_ptr(T_typaram(tn)); }
 
 fn T_opaque_cbox_ptr(cx: @crate_ctxt) -> TypeRef {
     let s = "*cbox";
-    if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
+    alt name_has_type(cx.tn, s) { some(t) { ret t; } _ {} }
     let t = T_ptr(T_struct([cx.int_type,
                             T_ptr(cx.tydesc_type),
                             T_i8() /* represents closed over tydescs
                             and data go here; see trans_closure.rs*/
                            ]));
-    cx.tn.associate(s, t);
+    associate_type(cx.tn, s, t);
     ret t;
 }
 
@@ -717,20 +720,20 @@ fn T_tag_variant(cx: @crate_ctxt) -> TypeRef {
 
 fn T_tag(cx: @crate_ctxt, size: uint) -> TypeRef {
     let s = "tag_" + uint::to_str(size, 10u);
-    if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
+    alt name_has_type(cx.tn, s) { some(t) { ret t; } _ {} }
     let t =
         if size == 0u {
             T_struct([T_tag_variant(cx)])
         } else { T_struct([T_tag_variant(cx), T_array(T_i8(), size)]) };
-    cx.tn.associate(s, t);
+    associate_type(cx.tn, s, t);
     ret t;
 }
 
 fn T_opaque_tag(cx: @crate_ctxt) -> TypeRef {
     let s = "opaque_tag";
-    if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
+    alt name_has_type(cx.tn, s) { some(t) { ret t; } _ {} }
     let t = T_struct([T_tag_variant(cx), T_i8()]);
-    cx.tn.associate(s, t);
+    associate_type(cx.tn, s, t);
     ret t;
 }
 
@@ -818,7 +821,7 @@ fn C_cstr(cx: @crate_ctxt, s: str) -> ValueRef {
                         llvm::LLVMConstString(buf, str::byte_len(s), False)
                     });
     let g =
-        str::as_buf(cx.names.next("str"),
+        str::as_buf(cx.names("str"),
                     {|buf| llvm::LLVMAddGlobal(cx.llmod, val_ty(sc), buf) });
     llvm::LLVMSetInitializer(g, sc);
     llvm::LLVMSetGlobalConstant(g, True);
@@ -865,11 +868,9 @@ fn C_bytes(bytes: [u8]) -> ValueRef unsafe {
 
 fn C_shape(ccx: @crate_ctxt, bytes: [u8]) -> ValueRef {
     let llshape = C_bytes(bytes);
-    let llglobal =
-        str::as_buf(ccx.names.next("shape"),
-                    {|buf|
-                        llvm::LLVMAddGlobal(ccx.llmod, val_ty(llshape), buf)
-                    });
+    let llglobal = str::as_buf(ccx.names("shape"), {|buf|
+        llvm::LLVMAddGlobal(ccx.llmod, val_ty(llshape), buf)
+    });
     llvm::LLVMSetInitializer(llglobal, llshape);
     llvm::LLVMSetGlobalConstant(llglobal, True);
     llvm::LLVMSetLinkage(llglobal,
diff --git a/src/comp/middle/trans_impl.rs b/src/comp/middle/trans_impl.rs
index 0a883c193f8..55886df07d5 100644
--- a/src/comp/middle/trans_impl.rs
+++ b/src/comp/middle/trans_impl.rs
@@ -340,7 +340,7 @@ fn get_static_dict(bcx: @block_ctxt, origin: typeck::dict_origin)
       none. {}
     }
     let ptrs = C_struct(get_dict_ptrs(bcx, origin).ptrs);
-    let name = ccx.names.next("dict");
+    let name = ccx.names("dict");
     let gvar = str::as_buf(name, {|buf|
         llvm::LLVMAddGlobal(ccx.llmod, val_ty(ptrs), buf)
     });