2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2011-06-27 16:37:02 -05:00
|
|
|
// Type encoding
|
|
|
|
|
2013-03-26 15:38:07 -05:00
|
|
|
use middle::ty::param_ty;
|
2012-12-23 16:41:37 -06:00
|
|
|
use middle::ty;
|
|
|
|
|
2013-04-03 08:28:36 -05:00
|
|
|
use core::hashmap::HashMap;
|
2012-12-23 16:41:37 -06:00
|
|
|
use core::io::WriterUtil;
|
|
|
|
use core::io;
|
|
|
|
use core::uint;
|
|
|
|
use core::vec;
|
2013-03-13 21:25:28 -05:00
|
|
|
use syntax::abi::AbiSet;
|
2013-04-02 02:40:57 -05:00
|
|
|
use syntax::ast;
|
2012-09-04 13:54:36 -05:00
|
|
|
use syntax::ast::*;
|
|
|
|
use syntax::diagnostic::span_handler;
|
|
|
|
use syntax::print::pprust::*;
|
2011-06-27 16:37:02 -05:00
|
|
|
|
2013-01-29 18:51:16 -06:00
|
|
|
pub struct ctxt {
|
2013-03-12 15:00:50 -05:00
|
|
|
diag: @span_handler,
|
2011-09-02 17:34:58 -05:00
|
|
|
// Def -> str Callback:
|
2013-03-01 14:11:07 -06:00
|
|
|
ds: @fn(def_id) -> ~str,
|
2011-09-02 17:34:58 -05:00
|
|
|
// The type context.
|
2012-04-24 01:40:53 -05:00
|
|
|
tcx: ty::ctxt,
|
2013-03-01 14:11:07 -06:00
|
|
|
reachable: @fn(node_id) -> bool,
|
2012-04-24 01:40:53 -05:00
|
|
|
abbrevs: abbrev_ctxt
|
2013-01-08 16:00:45 -06:00
|
|
|
}
|
2011-06-27 16:37:02 -05:00
|
|
|
|
|
|
|
// Compact string representation for ty.t values. API ty_str & parse_from_str.
|
|
|
|
// Extra parameters are for converting to/from def_ids in the string rep.
|
|
|
|
// Whatever format you choose should not contain pipe characters.
|
2013-02-19 01:40:42 -06:00
|
|
|
pub struct ty_abbrev {
|
|
|
|
pos: uint,
|
|
|
|
len: uint,
|
|
|
|
s: @~str
|
|
|
|
}
|
2011-06-27 16:37:02 -05:00
|
|
|
|
2013-01-29 18:51:16 -06:00
|
|
|
pub enum abbrev_ctxt {
|
|
|
|
ac_no_abbrevs,
|
2013-04-03 08:28:36 -05:00
|
|
|
ac_use_abbrevs(@mut HashMap<ty::t, ty_abbrev>),
|
2013-01-29 18:51:16 -06:00
|
|
|
}
|
2011-06-27 16:37:02 -05:00
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn cx_uses_abbrevs(cx: @ctxt) -> bool {
|
2012-08-06 14:34:08 -05:00
|
|
|
match cx.abbrevs {
|
2012-08-03 21:59:04 -05:00
|
|
|
ac_no_abbrevs => return false,
|
|
|
|
ac_use_abbrevs(_) => return true
|
2011-06-27 16:37:02 -05:00
|
|
|
}
|
|
|
|
}
|
2011-07-07 14:47:39 -05:00
|
|
|
|
2013-03-12 15:00:50 -05:00
|
|
|
pub fn enc_ty(w: @io::Writer, cx: @ctxt, t: ty::t) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match cx.abbrevs {
|
2012-08-03 21:59:04 -05:00
|
|
|
ac_no_abbrevs => {
|
2013-02-05 21:41:45 -06:00
|
|
|
let result_str = match cx.tcx.short_names_cache.find(&t) {
|
2013-03-23 17:55:58 -05:00
|
|
|
Some(&s) => /*bad*/copy *s,
|
2012-09-14 11:40:28 -05:00
|
|
|
None => {
|
|
|
|
let s = do io::with_str_writer |wr| {
|
2013-01-07 16:16:52 -06:00
|
|
|
enc_sty(wr, cx, /*bad*/copy ty::get(t).sty);
|
2012-09-14 11:40:28 -05:00
|
|
|
};
|
2013-01-07 16:16:52 -06:00
|
|
|
cx.tcx.short_names_cache.insert(t, @copy s);
|
2012-09-14 11:40:28 -05:00
|
|
|
s
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-01-11 08:15:54 -06:00
|
|
|
};
|
|
|
|
w.write_str(result_str);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ac_use_abbrevs(abbrevs) => {
|
2013-02-05 21:41:45 -06:00
|
|
|
match abbrevs.find(&t) {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(a) => { w.write_str(*a.s); return; }
|
|
|
|
None => {
|
2012-01-11 08:15:54 -06:00
|
|
|
let pos = w.tell();
|
2013-01-07 16:16:52 -06:00
|
|
|
enc_sty(w, cx, /*bad*/copy ty::get(t).sty);
|
2012-01-11 08:15:54 -06:00
|
|
|
let end = w.tell();
|
2011-07-27 07:19:39 -05:00
|
|
|
let len = end - pos;
|
|
|
|
fn estimate_sz(u: uint) -> uint {
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut n = u;
|
|
|
|
let mut len = 0u;
|
2011-07-27 07:19:39 -05:00
|
|
|
while n != 0u { len += 1u; n = n >> 4u; }
|
2012-08-01 19:30:05 -05:00
|
|
|
return len;
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
let abbrev_len = 3u + estimate_sz(pos) + estimate_sz(len);
|
|
|
|
if abbrev_len < len {
|
|
|
|
// I.e. it's actually an abbreviation.
|
2013-01-24 14:47:57 -06:00
|
|
|
let s = ~"#" + uint::to_str_radix(pos, 16u) + ~":" +
|
|
|
|
uint::to_str_radix(len, 16u) + ~"#";
|
2013-02-19 01:40:42 -06:00
|
|
|
let a = ty_abbrev { pos: pos, len: len, s: @s };
|
2011-07-27 07:19:39 -05:00
|
|
|
abbrevs.insert(t, a);
|
2011-06-27 16:37:02 -05:00
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-06-27 16:37:02 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-06-27 16:37:02 -05:00
|
|
|
}
|
|
|
|
}
|
2013-04-02 02:40:57 -05:00
|
|
|
|
|
|
|
fn enc_mutability(w: @io::Writer, mt: ast::mutability) {
|
|
|
|
match mt {
|
2012-08-03 21:59:04 -05:00
|
|
|
m_imm => (),
|
|
|
|
m_mutbl => w.write_char('m'),
|
|
|
|
m_const => w.write_char('?')
|
2011-06-27 16:37:02 -05:00
|
|
|
}
|
2013-04-02 02:40:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn enc_mt(w: @io::Writer, cx: @ctxt, mt: ty::mt) {
|
|
|
|
enc_mutability(w, mt.mutbl);
|
2011-06-27 16:37:02 -05:00
|
|
|
enc_ty(w, cx, mt.ty);
|
|
|
|
}
|
2012-04-18 23:26:25 -05:00
|
|
|
|
2013-03-12 15:00:50 -05:00
|
|
|
fn enc_opt<T>(w: @io::Writer, t: Option<T>, enc_f: &fn(T)) {
|
2013-04-17 11:15:37 -05:00
|
|
|
match t {
|
|
|
|
None => w.write_char('n'),
|
|
|
|
Some(v) => {
|
2012-04-18 23:26:25 -05:00
|
|
|
w.write_char('s');
|
2013-04-17 11:15:37 -05:00
|
|
|
enc_f(v);
|
2012-04-01 16:28:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-18 23:26:25 -05:00
|
|
|
|
2013-04-17 11:15:37 -05:00
|
|
|
fn enc_substs(w: @io::Writer, cx: @ctxt, substs: &ty::substs) {
|
2012-06-30 18:19:07 -05:00
|
|
|
do enc_opt(w, substs.self_r) |r| { enc_region(w, cx, r) }
|
|
|
|
do enc_opt(w, substs.self_ty) |t| { enc_ty(w, cx, t) }
|
2012-04-18 23:26:25 -05:00
|
|
|
w.write_char('[');
|
2012-09-19 18:55:01 -05:00
|
|
|
for substs.tps.each |t| { enc_ty(w, cx, *t); }
|
2012-04-18 23:26:25 -05:00
|
|
|
w.write_char(']');
|
|
|
|
}
|
|
|
|
|
2013-03-12 15:00:50 -05:00
|
|
|
fn enc_region(w: @io::Writer, cx: @ctxt, r: ty::Region) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match r {
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::re_bound(br) => {
|
2012-04-01 16:28:30 -05:00
|
|
|
w.write_char('b');
|
2012-07-18 18:18:02 -05:00
|
|
|
enc_bound_region(w, cx, br);
|
2012-04-01 16:28:30 -05:00
|
|
|
}
|
2013-04-02 00:32:37 -05:00
|
|
|
ty::re_free(ref fr) => {
|
2012-04-01 16:28:30 -05:00
|
|
|
w.write_char('f');
|
|
|
|
w.write_char('[');
|
2013-04-02 00:32:37 -05:00
|
|
|
w.write_int(fr.scope_id);
|
2012-04-01 16:28:30 -05:00
|
|
|
w.write_char('|');
|
2013-04-02 00:32:37 -05:00
|
|
|
enc_bound_region(w, cx, fr.bound_region);
|
2012-04-01 16:28:30 -05:00
|
|
|
w.write_char(']');
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::re_scope(nid) => {
|
2012-04-01 16:28:30 -05:00
|
|
|
w.write_char('s');
|
|
|
|
w.write_int(nid);
|
|
|
|
w.write_char('|');
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::re_static => {
|
2012-04-05 22:59:36 -05:00
|
|
|
w.write_char('t');
|
|
|
|
}
|
2012-10-19 08:01:01 -05:00
|
|
|
ty::re_infer(_) => {
|
2012-04-18 23:26:25 -05:00
|
|
|
// these should not crop up after typeck
|
2012-07-14 00:57:48 -05:00
|
|
|
cx.diag.handler().bug(~"Cannot encode region variables");
|
2012-04-18 23:26:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-12 15:00:50 -05:00
|
|
|
fn enc_bound_region(w: @io::Writer, cx: @ctxt, br: ty::bound_region) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match br {
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::br_self => w.write_char('s'),
|
2012-08-20 18:53:33 -05:00
|
|
|
ty::br_anon(idx) => {
|
|
|
|
w.write_char('a');
|
|
|
|
w.write_uint(idx);
|
|
|
|
w.write_char('|');
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::br_named(s) => {
|
2012-04-18 23:26:25 -05:00
|
|
|
w.write_char('[');
|
2013-02-10 18:33:16 -06:00
|
|
|
w.write_str(*cx.tcx.sess.str_of(s));
|
2012-04-18 23:26:25 -05:00
|
|
|
w.write_char(']')
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::br_cap_avoid(id, br) => {
|
2012-07-24 18:23:23 -05:00
|
|
|
w.write_char('c');
|
|
|
|
w.write_int(id);
|
|
|
|
w.write_char('|');
|
2012-07-18 18:18:02 -05:00
|
|
|
enc_bound_region(w, cx, *br);
|
2012-07-24 18:23:23 -05:00
|
|
|
}
|
2012-12-05 17:13:24 -06:00
|
|
|
ty::br_fresh(id) => {
|
|
|
|
w.write_uint(id);
|
|
|
|
}
|
2012-03-08 16:05:16 -06:00
|
|
|
}
|
|
|
|
}
|
2012-04-10 20:32:51 -05:00
|
|
|
|
2013-03-12 15:00:50 -05:00
|
|
|
pub fn enc_vstore(w: @io::Writer, cx: @ctxt, v: ty::vstore) {
|
2012-04-10 20:32:51 -05:00
|
|
|
w.write_char('/');
|
2012-08-06 14:34:08 -05:00
|
|
|
match v {
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::vstore_fixed(u) => {
|
2012-04-10 20:32:51 -05:00
|
|
|
w.write_uint(u);
|
|
|
|
w.write_char('|');
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::vstore_uniq => {
|
2012-04-10 20:32:51 -05:00
|
|
|
w.write_char('~');
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::vstore_box => {
|
2012-04-10 20:32:51 -05:00
|
|
|
w.write_char('@');
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::vstore_slice(r) => {
|
2012-04-10 20:32:51 -05:00
|
|
|
w.write_char('&');
|
2012-04-18 23:26:25 -05:00
|
|
|
enc_region(w, cx, r);
|
2012-04-10 20:32:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-27 05:16:28 -05:00
|
|
|
pub fn enc_trait_ref(w: @io::Writer, cx: @ctxt, s: &ty::TraitRef) {
|
|
|
|
w.write_str((cx.ds)(s.def_id));
|
|
|
|
w.write_char('|');
|
2013-04-17 11:15:37 -05:00
|
|
|
enc_substs(w, cx, &s.substs);
|
2013-03-27 05:16:28 -05:00
|
|
|
}
|
|
|
|
|
2013-03-12 15:00:50 -05:00
|
|
|
pub fn enc_trait_store(w: @io::Writer, cx: @ctxt, s: ty::TraitStore) {
|
2013-03-08 23:16:09 -06:00
|
|
|
match s {
|
|
|
|
ty::UniqTraitStore => w.write_char('~'),
|
|
|
|
ty::BoxTraitStore => w.write_char('@'),
|
|
|
|
ty::RegionTraitStore(re) => {
|
|
|
|
w.write_char('&');
|
|
|
|
enc_region(w, cx, re);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:37 -05:00
|
|
|
fn enc_sty(w: @io::Writer, cx: @ctxt, st: ty::sty) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match st {
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::ty_nil => w.write_char('n'),
|
|
|
|
ty::ty_bot => w.write_char('z'),
|
|
|
|
ty::ty_bool => w.write_char('b'),
|
|
|
|
ty::ty_int(t) => {
|
2012-08-06 14:34:08 -05:00
|
|
|
match t {
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_i => w.write_char('i'),
|
|
|
|
ty_char => w.write_char('c'),
|
|
|
|
ty_i8 => w.write_str(&"MB"),
|
|
|
|
ty_i16 => w.write_str(&"MW"),
|
|
|
|
ty_i32 => w.write_str(&"ML"),
|
|
|
|
ty_i64 => w.write_str(&"MD")
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::ty_uint(t) => {
|
2012-08-06 14:34:08 -05:00
|
|
|
match t {
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_u => w.write_char('u'),
|
|
|
|
ty_u8 => w.write_str(&"Mb"),
|
|
|
|
ty_u16 => w.write_str(&"Mw"),
|
|
|
|
ty_u32 => w.write_str(&"Ml"),
|
|
|
|
ty_u64 => w.write_str(&"Md")
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::ty_float(t) => {
|
2012-08-06 14:34:08 -05:00
|
|
|
match t {
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_f => w.write_char('l'),
|
|
|
|
ty_f32 => w.write_str(&"Mf"),
|
|
|
|
ty_f64 => w.write_str(&"MF"),
|
2011-06-27 16:37:02 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-12-04 12:50:00 -06:00
|
|
|
ty::ty_enum(def, ref substs) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
w.write_str(&"t[");
|
2012-11-29 19:51:16 -06:00
|
|
|
w.write_str((cx.ds)(def));
|
2011-07-27 07:19:39 -05:00
|
|
|
w.write_char('|');
|
2013-04-17 11:15:37 -05:00
|
|
|
enc_substs(w, cx, substs);
|
2011-07-27 07:19:39 -05:00
|
|
|
w.write_char(']');
|
|
|
|
}
|
2013-04-02 02:40:57 -05:00
|
|
|
ty::ty_trait(def, ref substs, store, mt) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
w.write_str(&"x[");
|
2012-11-29 19:51:16 -06:00
|
|
|
w.write_str((cx.ds)(def));
|
2011-12-29 04:23:35 -06:00
|
|
|
w.write_char('|');
|
2013-04-17 11:15:37 -05:00
|
|
|
enc_substs(w, cx, substs);
|
2013-03-08 23:16:09 -06:00
|
|
|
enc_trait_store(w, cx, store);
|
2013-04-02 02:40:57 -05:00
|
|
|
enc_mutability(w, mt);
|
2011-12-29 04:23:35 -06:00
|
|
|
w.write_char(']');
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::ty_tup(ts) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
w.write_str(&"T[");
|
2012-09-19 18:55:01 -05:00
|
|
|
for ts.each |t| { enc_ty(w, cx, *t); }
|
2011-08-15 04:40:26 -05:00
|
|
|
w.write_char(']');
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::ty_box(mt) => { w.write_char('@'); enc_mt(w, cx, mt); }
|
|
|
|
ty::ty_uniq(mt) => { w.write_char('~'); enc_mt(w, cx, mt); }
|
|
|
|
ty::ty_ptr(mt) => { w.write_char('*'); enc_mt(w, cx, mt); }
|
|
|
|
ty::ty_rptr(r, mt) => {
|
2012-03-08 16:05:16 -06:00
|
|
|
w.write_char('&');
|
2012-04-18 23:26:25 -05:00
|
|
|
enc_region(w, cx, r);
|
2012-03-08 16:05:16 -06:00
|
|
|
enc_mt(w, cx, mt);
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::ty_evec(mt, v) => {
|
2012-04-10 20:32:51 -05:00
|
|
|
w.write_char('V');
|
|
|
|
enc_mt(w, cx, mt);
|
2012-04-18 23:26:25 -05:00
|
|
|
enc_vstore(w, cx, v);
|
2012-04-10 20:32:51 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::ty_estr(v) => {
|
2012-04-10 20:32:51 -05:00
|
|
|
w.write_char('v');
|
2012-04-18 23:26:25 -05:00
|
|
|
enc_vstore(w, cx, v);
|
2012-04-10 20:32:51 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::ty_unboxed_vec(mt) => { w.write_char('U'); enc_mt(w, cx, mt); }
|
2013-01-31 19:12:29 -06:00
|
|
|
ty::ty_closure(ref f) => {
|
|
|
|
w.write_char('f');
|
|
|
|
enc_closure_ty(w, cx, f);
|
|
|
|
}
|
|
|
|
ty::ty_bare_fn(ref f) => {
|
|
|
|
w.write_char('F');
|
|
|
|
enc_bare_fn_ty(w, cx, f);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-01-22 09:02:09 -06:00
|
|
|
ty::ty_infer(_) => {
|
|
|
|
cx.diag.handler().bug(~"Cannot encode inference variable types");
|
2012-11-07 20:40:34 -06:00
|
|
|
}
|
2013-01-25 18:57:39 -06:00
|
|
|
ty::ty_param(param_ty {idx: id, def_id: did}) => {
|
2011-12-28 10:50:12 -06:00
|
|
|
w.write_char('p');
|
2012-11-29 19:51:16 -06:00
|
|
|
w.write_str((cx.ds)(did));
|
2011-12-29 04:23:35 -06:00
|
|
|
w.write_char('|');
|
2013-02-26 09:36:59 -06:00
|
|
|
w.write_str(uint::to_str(id));
|
2011-07-28 15:29:29 -05:00
|
|
|
}
|
2013-03-19 09:36:02 -05:00
|
|
|
ty::ty_self(did) => {
|
2012-05-09 08:09:58 -05:00
|
|
|
w.write_char('s');
|
2013-03-19 09:36:02 -05:00
|
|
|
w.write_str((cx.ds)(did));
|
|
|
|
w.write_char('|');
|
2012-01-30 04:52:34 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::ty_type => w.write_char('Y'),
|
2012-11-04 22:41:00 -06:00
|
|
|
ty::ty_opaque_closure_ptr(p) => {
|
|
|
|
w.write_str(&"C&");
|
2013-01-31 19:12:29 -06:00
|
|
|
enc_sigil(w, p);
|
2012-11-04 22:41:00 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::ty_opaque_box => w.write_char('B'),
|
2012-12-10 15:47:54 -06:00
|
|
|
ty::ty_struct(def, ref substs) => {
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("~~~~ %s", ~"a[");
|
2012-07-14 00:57:48 -05:00
|
|
|
w.write_str(&"a[");
|
2012-11-29 19:51:16 -06:00
|
|
|
let s = (cx.ds)(def);
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("~~~~ %s", s);
|
2012-03-06 10:02:13 -06:00
|
|
|
w.write_str(s);
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("~~~~ %s", ~"|");
|
2012-04-25 19:18:06 -05:00
|
|
|
w.write_char('|');
|
2013-04-17 11:15:37 -05:00
|
|
|
enc_substs(w, cx, substs);
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("~~~~ %s", ~"]");
|
2012-02-09 16:16:12 -06:00
|
|
|
w.write_char(']');
|
|
|
|
}
|
2013-02-11 21:26:38 -06:00
|
|
|
ty::ty_err => fail!(~"Shouldn't encode error type")
|
2011-06-27 16:37:02 -05:00
|
|
|
}
|
|
|
|
}
|
2012-08-10 20:15:08 -05:00
|
|
|
|
2013-03-12 15:00:50 -05:00
|
|
|
fn enc_sigil(w: @io::Writer, sigil: Sigil) {
|
2013-01-31 19:12:29 -06:00
|
|
|
match sigil {
|
|
|
|
ManagedSigil => w.write_str("@"),
|
|
|
|
OwnedSigil => w.write_str("~"),
|
|
|
|
BorrowedSigil => w.write_str("&"),
|
2011-06-27 16:37:02 -05:00
|
|
|
}
|
|
|
|
}
|
2011-07-19 19:52:34 -05:00
|
|
|
|
2013-03-12 15:00:50 -05:00
|
|
|
pub fn enc_arg(w: @io::Writer, cx: @ctxt, arg: ty::arg) {
|
2012-09-11 23:25:01 -05:00
|
|
|
enc_ty(w, cx, arg.ty);
|
|
|
|
}
|
|
|
|
|
2013-03-12 15:00:50 -05:00
|
|
|
fn enc_purity(w: @io::Writer, p: purity) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match p {
|
2012-08-03 21:59:04 -05:00
|
|
|
pure_fn => w.write_char('p'),
|
|
|
|
impure_fn => w.write_char('i'),
|
|
|
|
unsafe_fn => w.write_char('u'),
|
|
|
|
extern_fn => w.write_char('c')
|
2012-05-25 01:44:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 21:25:28 -05:00
|
|
|
fn enc_abi_set(w: @io::Writer, abis: AbiSet) {
|
|
|
|
w.write_char('[');
|
|
|
|
for abis.each |abi| {
|
|
|
|
w.write_str(abi.name());
|
|
|
|
w.write_char(',');
|
2013-01-31 19:12:29 -06:00
|
|
|
}
|
2013-03-13 21:25:28 -05:00
|
|
|
w.write_char(']')
|
2013-01-31 19:12:29 -06:00
|
|
|
}
|
|
|
|
|
2013-03-12 15:00:50 -05:00
|
|
|
fn enc_onceness(w: @io::Writer, o: Onceness) {
|
2012-11-02 15:33:51 -05:00
|
|
|
match o {
|
|
|
|
Once => w.write_char('o'),
|
|
|
|
Many => w.write_char('m')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-27 09:26:57 -05:00
|
|
|
pub fn enc_bare_fn_ty(w: @io::Writer, cx: @ctxt, ft: &ty::BareFnTy) {
|
2013-01-31 19:12:29 -06:00
|
|
|
enc_purity(w, ft.purity);
|
2013-03-13 21:25:28 -05:00
|
|
|
enc_abi_set(w, ft.abis);
|
2013-01-31 19:12:29 -06:00
|
|
|
enc_fn_sig(w, cx, &ft.sig);
|
|
|
|
}
|
|
|
|
|
2013-03-12 15:00:50 -05:00
|
|
|
fn enc_closure_ty(w: @io::Writer, cx: @ctxt, ft: &ty::ClosureTy) {
|
2013-01-31 19:12:29 -06:00
|
|
|
enc_sigil(w, ft.sigil);
|
|
|
|
enc_purity(w, ft.purity);
|
|
|
|
enc_onceness(w, ft.onceness);
|
|
|
|
enc_region(w, cx, ft.region);
|
|
|
|
enc_fn_sig(w, cx, &ft.sig);
|
|
|
|
}
|
|
|
|
|
2013-03-12 15:00:50 -05:00
|
|
|
fn enc_fn_sig(w: @io::Writer, cx: @ctxt, fsig: &ty::FnSig) {
|
2011-06-27 16:37:02 -05:00
|
|
|
w.write_char('[');
|
2013-01-31 19:12:29 -06:00
|
|
|
for fsig.inputs.each |arg| {
|
2012-09-19 18:55:01 -05:00
|
|
|
enc_arg(w, cx, *arg);
|
2011-06-27 16:37:02 -05:00
|
|
|
}
|
|
|
|
w.write_char(']');
|
2013-01-31 19:12:29 -06:00
|
|
|
enc_ty(w, cx, fsig.output);
|
2011-06-27 16:37:02 -05:00
|
|
|
}
|
2011-07-19 19:52:34 -05:00
|
|
|
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
fn enc_bounds(w: @io::Writer, cx: @ctxt, bs: @~[ty::param_bound]) {
|
2012-09-18 23:41:13 -05:00
|
|
|
for vec::each(*bs) |bound| {
|
2012-09-18 23:41:37 -05:00
|
|
|
match *bound {
|
2012-12-11 15:50:04 -06:00
|
|
|
ty::bound_owned => w.write_char('S'),
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::bound_copy => w.write_char('C'),
|
|
|
|
ty::bound_const => w.write_char('K'),
|
2012-12-11 13:59:45 -06:00
|
|
|
ty::bound_durable => w.write_char('O'),
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::bound_trait(tp) => {
|
2013-03-27 05:16:28 -05:00
|
|
|
w.write_char('I');
|
|
|
|
enc_trait_ref(w, cx, tp);
|
2011-12-28 10:50:12 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-05 06:57:27 -06:00
|
|
|
w.write_char('.');
|
2011-12-28 10:50:12 -06:00
|
|
|
}
|
2011-06-27 16:37:02 -05:00
|
|
|
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
pub fn enc_type_param_def(w: @io::Writer, cx: @ctxt, v: &ty::TypeParameterDef) {
|
|
|
|
w.write_str((cx.ds)(v.def_id));
|
|
|
|
w.write_char('|');
|
|
|
|
enc_bounds(w, cx, v.bounds);
|
|
|
|
}
|