diff options
| author | Graydon Hoare <[email protected]> | 2011-04-29 15:26:28 +0000 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2011-04-29 15:26:28 +0000 |
| commit | a2f68b2d585f0b467f0911d162f3cb9bc7d1ad14 (patch) | |
| tree | d91937cb020dd2e69aa94bbe987b4851cf9c1d4f /src/comp/middle/ty.rs | |
| parent | rustc: Fix vec append glue for strings. Add a test case. (diff) | |
| download | rust-a2f68b2d585f0b467f0911d162f3cb9bc7d1ad14.tar.xz rust-a2f68b2d585f0b467f0911d162f3cb9bc7d1ad14.zip | |
Intern metadata while writing, shrink stage1 from 12mb to 5.7mb.
Diffstat (limited to 'src/comp/middle/ty.rs')
| -rw-r--r-- | src/comp/middle/ty.rs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index b99ae33a..83befefc 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -46,7 +46,10 @@ type mt = rec(t ty, ast.mutability mut); // Contains information needed to resolve types and (in the future) look up // the types of AST nodes. -type ctxt = rec(@type_store ts, session.session sess); +type creader_cache = hashmap[tup(int,uint,uint),ty.t]; +type ctxt = rec(@type_store ts, + session.session sess, + creader_cache rcache); type ty_ctxt = ctxt; // Needed for disambiguation from Unify.ctxt. // Convert from method type to function type. Pretty easy; we just drop @@ -200,8 +203,26 @@ fn mk_type_store() -> @type_store { others=map.mk_hashmap[t,t](hasher, eqer)); } -fn mk_ctxt(session.session s) -> ctxt { ret rec(ts=mk_type_store(), sess=s); } +fn mk_rcache() -> creader_cache { + fn hash_cache_entry(&tup(int,uint,uint) k) -> uint { + ret (k._0 as uint) + k._1 + k._2; + } + fn eq_cache_entries(&tup(int,uint,uint) a, + &tup(int,uint,uint) b) -> bool { + ret a._0 == b._0 && + a._1 == b._1 && + a._2 == b._2; + } + auto h = hash_cache_entry; + auto e = eq_cache_entries; + ret map.mk_hashmap[tup(int,uint,uint),t](h, e); +} +fn mk_ctxt(session.session s) -> ctxt { + ret rec(ts = mk_type_store(), + sess = s, + rcache = mk_rcache()); +} // Type constructors fn mk_ty_full(&sty st, option.t[str] cname) -> t { @@ -627,9 +648,10 @@ fn ty_to_str(ctxt cx, &t typ) -> str { ret s; } -fn ty_to_abbrev_str(ctxt cx, t typ) -> str { +fn ty_to_short_str(ctxt cx, hashmap[ty.t, metadata.ty_abbrev] abbrevs, + t typ) -> str { auto f = def_to_str; - auto ecx = @rec(ds=f, tcx=cx); + auto ecx = @rec(ds=f, tcx=cx, use_abbrevs=false, abbrevs=abbrevs); auto s = metadata.Encode.ty_str(ecx, typ); if (_str.byte_len(s) >= 64u) { s = _str.substr(s, 0u, 64u); } ret s; |