aboutsummaryrefslogtreecommitdiff
path: root/src/comp
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2011-05-03 14:36:04 -0700
committerPatrick Walton <[email protected]>2011-05-03 14:41:05 -0700
commite43729ccf2577fad114107a336099da75eff0ded (patch)
tree0ef063c28fc51eae95db8a0ebbb9c0c015ee864c /src/comp
parentrustc: Name type glue properly (diff)
downloadrust-e43729ccf2577fad114107a336099da75eff0ded.tar.xz
rust-e43729ccf2577fad114107a336099da75eff0ded.zip
rustc: Refactor metadata.Encode.* to not require a type abbreviation table if abbreviation isn't enabled
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/metadata.rs83
-rw-r--r--src/comp/middle/trans.rs10
-rw-r--r--src/comp/middle/ty.rs5
3 files changed, 53 insertions, 45 deletions
diff --git a/src/comp/middle/metadata.rs b/src/comp/middle/metadata.rs
index bec62628..2b4ad2a2 100644
--- a/src/comp/middle/metadata.rs
+++ b/src/comp/middle/metadata.rs
@@ -53,59 +53,72 @@ const uint tag_index_table = 0x15u;
type ty_abbrev = rec(uint pos, uint len, str s);
+tag abbrev_ctxt {
+ ac_no_abbrevs;
+ ac_use_abbrevs(hashmap[ty.t, ty_abbrev]);
+}
+
mod Encode {
type ctxt = rec(
fn(ast.def_id) -> str ds, // Def -> str Callback.
ty.ctxt tcx, // The type context.
- bool use_abbrevs,
- hashmap[ty.t, ty_abbrev] abbrevs // Type abbrevs.
+ abbrev_ctxt abbrevs
);
+ fn cx_uses_abbrevs(@ctxt cx) -> bool {
+ alt (cx.abbrevs) {
+ case (ac_no_abbrevs) { ret false; }
+ case (ac_use_abbrevs(_)) { ret true; }
+ }
+ }
+
fn ty_str(@ctxt cx, ty.t t) -> str {
- assert (! cx.use_abbrevs);
+ assert (!cx_uses_abbrevs(cx));
auto sw = io.string_writer();
enc_ty(sw.get_writer(), cx, t);
ret sw.get_str();
}
fn enc_ty(io.writer w, @ctxt cx, ty.t t) {
- if (cx.use_abbrevs) {
- alt (cx.abbrevs.find(t)) {
- case (some[ty_abbrev](?a)) {
- w.write_str(a.s);
- ret;
- }
- case (none[ty_abbrev]) {
- auto pos = w.get_buf_writer().tell();
- auto ss = enc_sty(w, cx, ty.struct(cx.tcx, t));
- auto end = w.get_buf_writer().tell();
- auto len = end-pos;
- fn estimate_sz(uint u) -> uint {
- auto n = u;
- auto len = 0u;
- while (n != 0u) {
- len += 1u;
- n = n >> 4u;
- }
- ret len;
+ alt (cx.abbrevs) {
+ case (ac_no_abbrevs) { enc_sty(w, cx, ty.struct(cx.tcx, t)); }
+ case (ac_use_abbrevs(?abbrevs)) {
+ alt (abbrevs.find(t)) {
+ case (some[ty_abbrev](?a)) {
+ w.write_str(a.s);
+ ret;
}
- auto abbrev_len =
- 3u + estimate_sz(pos) + estimate_sz(len);
-
- if (abbrev_len < len) {
- // I.e. it's actually an abbreviation.
- auto s = ("#"
- + _uint.to_str(pos, 16u) + ":"
- + _uint.to_str(len, 16u) + "#");
- auto a = rec(pos=pos, len=len, s=s);
- cx.abbrevs.insert(t, a);
+ case (none[ty_abbrev]) {
+ auto pos = w.get_buf_writer().tell();
+ auto ss = enc_sty(w, cx, ty.struct(cx.tcx, t));
+ auto end = w.get_buf_writer().tell();
+ auto len = end-pos;
+ fn estimate_sz(uint u) -> uint {
+ auto n = u;
+ auto len = 0u;
+ while (n != 0u) {
+ len += 1u;
+ n = n >> 4u;
+ }
+ ret len;
+ }
+ auto abbrev_len =
+ 3u + estimate_sz(pos) + estimate_sz(len);
+
+ if (abbrev_len < len) {
+ // I.e. it's actually an abbreviation.
+ auto s = ("#"
+ + _uint.to_str(pos, 16u) + ":"
+ + _uint.to_str(len, 16u) + "#");
+ auto a = rec(pos=pos, len=len, s=s);
+ abbrevs.insert(t, a);
+ }
+ ret;
}
- ret;
}
}
}
- enc_sty(w, cx, ty.struct(cx.tcx, t));
}
fn enc_mt(io.writer w, @ctxt cx, &ty.mt mt) {
@@ -406,7 +419,7 @@ fn encode_type(@trans.crate_ctxt cx, &ebml.writer ebml_w, ty.t typ) {
auto f = def_to_str;
auto ty_str_ctxt = @rec(ds=f, tcx=cx.tcx,
- use_abbrevs=true, abbrevs=cx.type_abbrevs);
+ abbrevs=ac_use_abbrevs(cx.type_abbrevs));
Encode.enc_ty(io.new_writer_(ebml_w.writer), ty_str_ctxt, typ);
ebml.end_tag(ebml_w);
}
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 4c9e2990..288624da 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -193,8 +193,7 @@ fn get_type_sha1(@crate_ctxt ccx, ty.t t) -> str {
auto f = metadata.def_to_str;
// NB: do *not* use abbrevs here as we want the symbol names
// to be independent of one another in the crate.
- auto cx = @rec(ds=f, tcx=ccx.tcx,
- use_abbrevs=false, abbrevs=ccx.type_abbrevs);
+ auto cx = @rec(ds=f, tcx=ccx.tcx, abbrevs=metadata.ac_no_abbrevs);
ccx.sha.input_str(metadata.Encode.ty_str(cx, t));
hash = _str.substr(ccx.sha.result_str(), 0u, 16u);
ccx.type_sha1s.insert(t, hash);
@@ -210,8 +209,7 @@ fn mangle_name_by_type(@crate_ctxt ccx, vec[str] path, ty.t t) -> str {
fn mangle_name_by_type_only(@crate_ctxt ccx, ty.t t, str name) -> str {
auto f = metadata.def_to_str;
- auto cx = @rec(ds=f, tcx=ccx.tcx,
- use_abbrevs=false, abbrevs=ccx.type_abbrevs);
+ auto cx = @rec(ds=f, tcx=ccx.tcx, abbrevs=metadata.ac_no_abbrevs);
auto s = metadata.Encode.ty_str(cx, t);
auto hash = get_type_sha1(ccx, t);
@@ -816,9 +814,7 @@ fn type_of_inner(@crate_ctxt cx, ty.t t) -> TypeRef {
}
assert (llty as int != 0);
- llvm.LLVMAddTypeName(cx.llmod,
- _str.buf(ty.ty_to_short_str(cx.tcx,
- cx.type_abbrevs, t)),
+ llvm.LLVMAddTypeName(cx.llmod, _str.buf(ty.ty_to_short_str(cx.tcx, t)),
llty);
cx.lltypes.insert(t, llty);
ret llty;
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs
index 1d170514..c5e5ffa3 100644
--- a/src/comp/middle/ty.rs
+++ b/src/comp/middle/ty.rs
@@ -648,10 +648,9 @@ fn ty_to_str(ctxt cx, &t typ) -> str {
ret s;
}
-fn ty_to_short_str(ctxt cx, hashmap[ty.t, metadata.ty_abbrev] abbrevs,
- t typ) -> str {
+fn ty_to_short_str(ctxt cx, t typ) -> str {
auto f = def_to_str;
- auto ecx = @rec(ds=f, tcx=cx, use_abbrevs=false, abbrevs=abbrevs);
+ auto ecx = @rec(ds=f, tcx=cx, abbrevs=metadata.ac_no_abbrevs);
auto s = metadata.Encode.ty_str(ecx, typ);
if (_str.byte_len(s) >= 64u) { s = _str.substr(s, 0u, 64u); }
ret s;