Skip to content

Commit cc8bdb9

Browse files
committed
---
yaml --- r: 3379 b: refs/heads/master c: 5601a6f h: refs/heads/master i: 3377: eca6147 3375: cb71793 v: v3
1 parent 860a539 commit cc8bdb9

File tree

7 files changed

+263
-246
lines changed

7 files changed

+263
-246
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: ba5c7a570d1bc6f28e7a2f4eb5cfd50b7c19f374
2+
refs/heads/master: 5601a6f534d4b64dc278899b758f82efcd935dd1

trunk/src/comp/back/link.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,13 @@ fn symbol_hash(ty::ctxt tcx, sha1 sha, &ty::t t, str crate_meta_name,
400400
auto cx =
401401
@rec(ds=metadata::cwriter::def_to_str,
402402
tcx=tcx,
403-
abbrevs=metadata::cwriter::ac_no_abbrevs);
403+
abbrevs=metadata::tyencode::ac_no_abbrevs);
404404
sha.reset();
405405
sha.input_str(crate_meta_name);
406406
sha.input_str("-");
407407
sha.input_str(crate_meta_name);
408408
sha.input_str("-");
409-
sha.input_str(metadata::cwriter::encode::ty_str(cx, t));
409+
sha.input_str(metadata::tyencode::ty_str(cx, t));
410410
auto hash = truncated_sha1_result(sha);
411411
// Prefix with _ so that it never blends into adjacent digits
412412

@@ -453,7 +453,6 @@ fn mangle_exported_name(&@crate_ctxt ccx, &vec[str] path, &ty::t t) -> str {
453453
fn mangle_internal_name_by_type_only(&@crate_ctxt ccx, &ty::t t, &str name) ->
454454
str {
455455
auto f = metadata::cwriter::def_to_str;
456-
auto cx = @rec(ds=f, tcx=ccx.tcx, abbrevs=metadata::cwriter::ac_no_abbrevs);
457456
auto s = pretty::ppaux::ty_to_short_str(ccx.tcx, t);
458457
auto hash = get_symbol_hash(ccx, t);
459458
ret mangle([name, s, hash]);

trunk/src/comp/metadata/cwriter.rs

Lines changed: 2 additions & 236 deletions
Original file line numberDiff line numberDiff line change
@@ -97,240 +97,6 @@ const uint tag_meta_item_key = 0x19u;
9797
const uint tag_meta_item_value = 0x20u;
9898

9999

100-
// Type encoding
101-
102-
// Compact string representation for ty.t values. API ty_str & parse_from_str.
103-
// Extra parameters are for converting to/from def_ids in the string rep.
104-
// Whatever format you choose should not contain pipe characters.
105-
type ty_abbrev = rec(uint pos, uint len, str s);
106-
107-
tag abbrev_ctxt { ac_no_abbrevs; ac_use_abbrevs(hashmap[ty::t, ty_abbrev]); }
108-
109-
mod encode {
110-
type ctxt =
111-
rec(fn(&def_id) -> str ds, // Def -> str Callback:
112-
113-
ty::ctxt tcx, // The type context.
114-
115-
abbrev_ctxt abbrevs);
116-
117-
fn cx_uses_abbrevs(&@ctxt cx) -> bool {
118-
alt (cx.abbrevs) {
119-
case (ac_no_abbrevs) { ret false; }
120-
case (ac_use_abbrevs(_)) { ret true; }
121-
}
122-
}
123-
fn ty_str(&@ctxt cx, &ty::t t) -> str {
124-
assert (!cx_uses_abbrevs(cx));
125-
auto sw = io::string_writer();
126-
enc_ty(sw.get_writer(), cx, t);
127-
ret sw.get_str();
128-
}
129-
fn enc_ty(&io::writer w, &@ctxt cx, &ty::t t) {
130-
alt (cx.abbrevs) {
131-
case (ac_no_abbrevs) {
132-
auto result_str;
133-
alt (cx.tcx.short_names_cache.find(t)) {
134-
case (some(?s)) { result_str = s; }
135-
case (none) {
136-
auto sw = io::string_writer();
137-
enc_sty(sw.get_writer(), cx, ty::struct(cx.tcx, t));
138-
result_str = sw.get_str();
139-
cx.tcx.short_names_cache.insert(t, result_str);
140-
}
141-
}
142-
w.write_str(result_str);
143-
}
144-
case (ac_use_abbrevs(?abbrevs)) {
145-
alt (abbrevs.find(t)) {
146-
case (some(?a)) { w.write_str(a.s); ret; }
147-
case (none) {
148-
auto pos = w.get_buf_writer().tell();
149-
auto ss = enc_sty(w, cx, ty::struct(cx.tcx, t));
150-
auto end = w.get_buf_writer().tell();
151-
auto len = end - pos;
152-
fn estimate_sz(uint u) -> uint {
153-
auto n = u;
154-
auto len = 0u;
155-
while (n != 0u) { len += 1u; n = n >> 4u; }
156-
ret len;
157-
}
158-
auto abbrev_len =
159-
3u + estimate_sz(pos) + estimate_sz(len);
160-
if (abbrev_len < len) {
161-
// I.e. it's actually an abbreviation.
162-
163-
auto s =
164-
"#" + uint::to_str(pos, 16u) + ":" +
165-
uint::to_str(len, 16u) + "#";
166-
auto a = rec(pos=pos, len=len, s=s);
167-
abbrevs.insert(t, a);
168-
}
169-
ret;
170-
}
171-
}
172-
}
173-
}
174-
}
175-
fn enc_mt(&io::writer w, &@ctxt cx, &ty::mt mt) {
176-
alt (mt.mut) {
177-
case (imm) { }
178-
case (mut) { w.write_char('m'); }
179-
case (maybe_mut) { w.write_char('?'); }
180-
}
181-
enc_ty(w, cx, mt.ty);
182-
}
183-
fn enc_sty(&io::writer w, &@ctxt cx, &ty::sty st) {
184-
alt (st) {
185-
case (ty::ty_nil) { w.write_char('n'); }
186-
case (ty::ty_bot) { w.write_char('z'); }
187-
case (ty::ty_bool) { w.write_char('b'); }
188-
case (ty::ty_int) { w.write_char('i'); }
189-
case (ty::ty_uint) { w.write_char('u'); }
190-
case (ty::ty_float) { w.write_char('l'); }
191-
case (ty::ty_machine(?mach)) {
192-
alt (mach) {
193-
case (common::ty_u8) { w.write_str("Mb"); }
194-
case (common::ty_u16) { w.write_str("Mw"); }
195-
case (common::ty_u32) { w.write_str("Ml"); }
196-
case (common::ty_u64) { w.write_str("Md"); }
197-
case (common::ty_i8) { w.write_str("MB"); }
198-
case (common::ty_i16) { w.write_str("MW"); }
199-
case (common::ty_i32) { w.write_str("ML"); }
200-
case (common::ty_i64) { w.write_str("MD"); }
201-
case (common::ty_f32) { w.write_str("Mf"); }
202-
case (common::ty_f64) { w.write_str("MF"); }
203-
}
204-
}
205-
case (ty::ty_char) { w.write_char('c'); }
206-
case (ty::ty_str) { w.write_char('s'); }
207-
case (ty::ty_istr) { w.write_char('S'); }
208-
case (ty::ty_tag(?def, ?tys)) {
209-
w.write_str("t[");
210-
w.write_str(cx.ds(def));
211-
w.write_char('|');
212-
for (ty::t t in tys) { enc_ty(w, cx, t); }
213-
w.write_char(']');
214-
}
215-
case (ty::ty_box(?mt)) { w.write_char('@'); enc_mt(w, cx, mt); }
216-
case (ty::ty_ptr(?mt)) { w.write_char('*'); enc_mt(w, cx, mt); }
217-
case (ty::ty_vec(?mt)) { w.write_char('V'); enc_mt(w, cx, mt); }
218-
case (ty::ty_ivec(?mt)) { w.write_char('I'); enc_mt(w, cx, mt); }
219-
case (ty::ty_port(?t)) { w.write_char('P'); enc_ty(w, cx, t); }
220-
case (ty::ty_chan(?t)) { w.write_char('C'); enc_ty(w, cx, t); }
221-
case (ty::ty_tup(?mts)) {
222-
w.write_str("T[");
223-
for (ty::mt mt in mts) { enc_mt(w, cx, mt); }
224-
w.write_char(']');
225-
}
226-
case (ty::ty_rec(?fields)) {
227-
w.write_str("R[");
228-
for (ty::field field in fields) {
229-
w.write_str(field.ident);
230-
w.write_char('=');
231-
enc_mt(w, cx, field.mt);
232-
}
233-
w.write_char(']');
234-
}
235-
case (ty::ty_fn(?proto, ?args, ?out, ?cf, ?constrs)) {
236-
enc_proto(w, proto);
237-
enc_ty_fn(w, cx, args, out, cf, constrs);
238-
}
239-
case (ty::ty_native_fn(?abi, ?args, ?out)) {
240-
w.write_char('N');
241-
alt (abi) {
242-
case (native_abi_rust) { w.write_char('r'); }
243-
case (native_abi_rust_intrinsic) {
244-
w.write_char('i');
245-
}
246-
case (native_abi_cdecl) { w.write_char('c'); }
247-
case (native_abi_llvm) { w.write_char('l'); }
248-
}
249-
enc_ty_fn(w, cx, args, out, return, []);
250-
}
251-
case (ty::ty_obj(?methods)) {
252-
w.write_str("O[");
253-
for (ty::method m in methods) {
254-
enc_proto(w, m.proto);
255-
w.write_str(m.ident);
256-
enc_ty_fn(w, cx, m.inputs, m.output, m.cf, m.constrs);
257-
}
258-
w.write_char(']');
259-
}
260-
case (ty::ty_res(?def, ?ty)) {
261-
w.write_char('r');
262-
w.write_str(cx.ds(def));
263-
w.write_char('|');
264-
enc_ty(w, cx, ty);
265-
}
266-
case (ty::ty_var(?id)) {
267-
w.write_char('X');
268-
w.write_str(common::istr(id));
269-
}
270-
case (ty::ty_native) { w.write_char('E'); }
271-
case (ty::ty_param(?id)) {
272-
w.write_char('p');
273-
w.write_str(common::uistr(id));
274-
}
275-
case (ty::ty_type) { w.write_char('Y'); }
276-
case (ty::ty_task) { w.write_char('a'); }
277-
}
278-
}
279-
fn enc_proto(&io::writer w, proto proto) {
280-
alt (proto) {
281-
case (proto_iter) { w.write_char('W'); }
282-
case (proto_fn) { w.write_char('F'); }
283-
}
284-
}
285-
fn enc_ty_fn(&io::writer w, &@ctxt cx, &vec[ty::arg] args, &ty::t out,
286-
&controlflow cf, &vec[@ty::constr_def] constrs) {
287-
w.write_char('[');
288-
for (ty::arg arg in args) {
289-
alt (arg.mode) {
290-
case (ty::mo_alias(?mut)) {
291-
w.write_char('&');
292-
if (mut) { w.write_char('m'); }
293-
}
294-
case (ty::mo_val) { }
295-
}
296-
enc_ty(w, cx, arg.ty);
297-
}
298-
w.write_char(']');
299-
auto colon = true;
300-
for (@ty::constr_def c in constrs) {
301-
if (colon) {
302-
w.write_char(':');
303-
colon = false;
304-
} else { w.write_char(';'); }
305-
enc_constr(w, cx, c);
306-
}
307-
alt (cf) {
308-
case (noreturn) { w.write_char('!'); }
309-
case (_) { enc_ty(w, cx, out); }
310-
}
311-
312-
}
313-
fn enc_constr(&io::writer w, &@ctxt cx, &@ty::constr_def c) {
314-
w.write_str(path_to_str(c.node.path));
315-
w.write_char('(');
316-
w.write_str(cx.ds(c.node.id));
317-
w.write_char('|');
318-
auto semi = false;
319-
for (@constr_arg a in c.node.args) {
320-
if (semi) { w.write_char(';'); } else { semi = true; }
321-
alt (a.node) {
322-
case (carg_base) { w.write_char('*'); }
323-
case (carg_ident(?i)) {
324-
w.write_uint(i);
325-
}
326-
case (carg_lit(?l)) { w.write_str(lit_to_str(l)); }
327-
}
328-
}
329-
w.write_char(')');
330-
}
331-
}
332-
333-
334100
// Returns a Plain Old LLVM String:
335101
fn C_postr(&str s) -> ValueRef {
336102
ret llvm::LLVMConstString(str::buf(s), str::byte_len(s), False);
@@ -497,8 +263,8 @@ fn encode_type(&@trans::crate_ctxt cx, &ebml::writer ebml_w, &ty::t typ) {
497263
ebml::start_tag(ebml_w, tag_items_data_item_type);
498264
auto f = def_to_str;
499265
auto ty_str_ctxt =
500-
@rec(ds=f, tcx=cx.tcx, abbrevs=ac_use_abbrevs(cx.type_abbrevs));
501-
encode::enc_ty(io::new_writer_(ebml_w.writer), ty_str_ctxt, typ);
266+
@rec(ds=f, tcx=cx.tcx, abbrevs=tyencode::ac_use_abbrevs(cx.type_abbrevs));
267+
tyencode::enc_ty(io::new_writer_(ebml_w.writer), ty_str_ctxt, typ);
502268
ebml::end_tag(ebml_w);
503269
}
504270

0 commit comments

Comments
 (0)