2014-02-10 08:36:31 -06:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 18:48:01 -06:00
|
|
|
// 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
|
|
|
|
|
2014-03-21 20:05:05 -05:00
|
|
|
#![allow(unused_must_use)] // as with encoding, everything is a no-fail MemWriter
|
|
|
|
#![allow(non_camel_case_types)]
|
2014-01-29 20:42:19 -06:00
|
|
|
|
2013-12-20 22:18:52 -06:00
|
|
|
use std::cell::RefCell;
|
2014-05-29 21:03:06 -05:00
|
|
|
use std::collections::HashMap;
|
2014-01-15 15:25:09 -06:00
|
|
|
use std::io::MemWriter;
|
2013-05-17 17:28:44 -05:00
|
|
|
|
2014-05-13 10:35:42 -05:00
|
|
|
use middle::subst;
|
2014-05-31 17:53:13 -05:00
|
|
|
use middle::subst::VecPerParamSpace;
|
|
|
|
use middle::ty::ParamTy;
|
2012-12-23 16:41:37 -06:00
|
|
|
use middle::ty;
|
|
|
|
|
2014-04-02 03:19:41 -05:00
|
|
|
use syntax::abi::Abi;
|
2013-04-02 02:40:57 -05:00
|
|
|
use syntax::ast;
|
2012-09-04 13:54:36 -05:00
|
|
|
use syntax::ast::*;
|
2013-12-31 08:17:59 -06:00
|
|
|
use syntax::diagnostic::SpanHandler;
|
2014-02-13 23:07:09 -06:00
|
|
|
use syntax::parse::token;
|
2011-06-27 16:37:02 -05:00
|
|
|
|
2014-05-10 16:05:06 -05:00
|
|
|
macro_rules! mywrite( ($($arg:tt)*) => ({ write!($($arg)*); }) )
|
2013-10-21 19:11:42 -05:00
|
|
|
|
2014-03-05 21:07:47 -06:00
|
|
|
pub struct ctxt<'a> {
|
2014-03-28 12:05:27 -05:00
|
|
|
pub diag: &'a SpanHandler,
|
2011-09-02 17:34:58 -05:00
|
|
|
// Def -> str Callback:
|
2014-05-22 18:57:53 -05:00
|
|
|
pub ds: fn(DefId) -> String,
|
2011-09-02 17:34:58 -05:00
|
|
|
// The type context.
|
2014-03-28 12:05:27 -05:00
|
|
|
pub tcx: &'a ty::ctxt,
|
2014-04-22 11:06:43 -05:00
|
|
|
pub abbrevs: &'a abbrev_map
|
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 {
|
2014-05-22 18:57:53 -05:00
|
|
|
s: String
|
2013-02-19 01:40:42 -06:00
|
|
|
}
|
2011-06-27 16:37:02 -05:00
|
|
|
|
2014-04-22 11:06:43 -05:00
|
|
|
pub type abbrev_map = RefCell<HashMap<ty::t, ty_abbrev>>;
|
2011-06-27 16:37:02 -05:00
|
|
|
|
2014-05-28 11:24:28 -05:00
|
|
|
pub fn enc_ty(w: &mut MemWriter, cx: &ctxt, t: ty::t) {
|
|
|
|
match cx.abbrevs.borrow_mut().find(&t) {
|
|
|
|
Some(a) => { w.write(a.s.as_bytes()); return; }
|
|
|
|
None => {}
|
|
|
|
}
|
|
|
|
let pos = w.tell().unwrap();
|
|
|
|
enc_sty(w, cx, &ty::get(t).sty);
|
|
|
|
let end = w.tell().unwrap();
|
|
|
|
let len = end - pos;
|
|
|
|
fn estimate_sz(u: u64) -> u64 {
|
|
|
|
let mut n = u;
|
|
|
|
let mut len = 0;
|
|
|
|
while n != 0 { len += 1; n = n >> 4; }
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
let abbrev_len = 3 + estimate_sz(pos) + estimate_sz(len);
|
|
|
|
if abbrev_len < len {
|
|
|
|
// I.e. it's actually an abbreviation.
|
|
|
|
cx.abbrevs.borrow_mut().insert(t, ty_abbrev {
|
|
|
|
s: format!("#{:x}:{:x}#", pos, len)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2013-04-02 02:40:57 -05:00
|
|
|
|
2013-12-20 19:36:07 -06:00
|
|
|
fn enc_mutability(w: &mut MemWriter, mt: ast::Mutability) {
|
2013-04-02 02:40:57 -05:00
|
|
|
match mt {
|
2013-10-21 19:11:42 -05:00
|
|
|
MutImmutable => (),
|
|
|
|
MutMutable => mywrite!(w, "m"),
|
2011-06-27 16:37:02 -05:00
|
|
|
}
|
2013-04-02 02:40:57 -05:00
|
|
|
}
|
|
|
|
|
2014-03-05 21:28:28 -06:00
|
|
|
fn enc_mt(w: &mut MemWriter, cx: &ctxt, mt: ty::mt) {
|
2013-04-02 02:40:57 -05:00
|
|
|
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-12-20 19:36:07 -06:00
|
|
|
fn enc_opt<T>(w: &mut MemWriter, t: Option<T>, enc_f: |&mut MemWriter, T|) {
|
2013-04-17 11:15:37 -05:00
|
|
|
match t {
|
2013-10-21 19:11:42 -05:00
|
|
|
None => mywrite!(w, "n"),
|
|
|
|
Some(v) => {
|
|
|
|
mywrite!(w, "s");
|
2013-12-20 19:36:07 -06:00
|
|
|
enc_f(w, v);
|
2013-10-21 19:11:42 -05:00
|
|
|
}
|
2012-04-01 16:28:30 -05:00
|
|
|
}
|
|
|
|
}
|
2012-04-18 23:26:25 -05:00
|
|
|
|
2014-05-31 17:53:13 -05:00
|
|
|
fn enc_vec_per_param_space<T>(w: &mut MemWriter,
|
|
|
|
cx: &ctxt,
|
|
|
|
v: &VecPerParamSpace<T>,
|
|
|
|
op: |&mut MemWriter, &ctxt, &T|) {
|
|
|
|
for &space in subst::ParamSpace::all().iter() {
|
|
|
|
mywrite!(w, "[");
|
2014-07-04 09:39:28 -05:00
|
|
|
for t in v.get_slice(space).iter() {
|
2014-05-31 17:53:13 -05:00
|
|
|
op(w, cx, t);
|
|
|
|
}
|
|
|
|
mywrite!(w, "]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-13 10:35:42 -05:00
|
|
|
pub fn enc_substs(w: &mut MemWriter, cx: &ctxt, substs: &subst::Substs) {
|
2013-07-24 15:52:57 -05:00
|
|
|
enc_region_substs(w, cx, &substs.regions);
|
2014-05-31 17:53:13 -05:00
|
|
|
enc_vec_per_param_space(w, cx, &substs.types,
|
|
|
|
|w, cx, &ty| enc_ty(w, cx, ty));
|
2012-04-18 23:26:25 -05:00
|
|
|
}
|
|
|
|
|
2014-05-13 10:35:42 -05:00
|
|
|
fn enc_region_substs(w: &mut MemWriter, cx: &ctxt, substs: &subst::RegionSubsts) {
|
2013-07-24 15:52:57 -05:00
|
|
|
match *substs {
|
2014-05-13 10:35:42 -05:00
|
|
|
subst::ErasedRegions => {
|
2013-10-21 19:11:42 -05:00
|
|
|
mywrite!(w, "e");
|
2013-07-24 15:52:57 -05:00
|
|
|
}
|
2014-05-13 10:35:42 -05:00
|
|
|
subst::NonerasedRegions(ref regions) => {
|
2013-10-21 19:11:42 -05:00
|
|
|
mywrite!(w, "n");
|
2014-05-31 17:53:13 -05:00
|
|
|
enc_vec_per_param_space(w, cx, regions,
|
|
|
|
|w, cx, &r| enc_region(w, cx, r));
|
2013-07-24 15:52:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 21:28:28 -06:00
|
|
|
fn enc_region(w: &mut MemWriter, cx: &ctxt, r: ty::Region) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match r {
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::ReLateBound(id, br) => {
|
2013-10-29 05:03:32 -05:00
|
|
|
mywrite!(w, "b[{}|", id);
|
2013-10-21 19:11:42 -05:00
|
|
|
enc_bound_region(w, cx, br);
|
2013-10-29 05:03:32 -05:00
|
|
|
mywrite!(w, "]");
|
|
|
|
}
|
2014-05-31 17:53:13 -05:00
|
|
|
ty::ReEarlyBound(node_id, space, index, name) => {
|
|
|
|
mywrite!(w, "B[{}|{}|{}|{}]",
|
2013-10-29 05:03:32 -05:00
|
|
|
node_id,
|
2014-05-31 17:53:13 -05:00
|
|
|
space.to_uint(),
|
2013-10-29 05:03:32 -05:00
|
|
|
index,
|
2014-03-04 23:59:35 -06:00
|
|
|
token::get_name(name));
|
2013-10-21 19:11:42 -05:00
|
|
|
}
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::ReFree(ref fr) => {
|
2013-10-21 19:11:42 -05:00
|
|
|
mywrite!(w, "f[{}|", fr.scope_id);
|
|
|
|
enc_bound_region(w, cx, fr.bound_region);
|
|
|
|
mywrite!(w, "]");
|
|
|
|
}
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::ReScope(nid) => {
|
2013-10-29 05:03:32 -05:00
|
|
|
mywrite!(w, "s{}|", nid);
|
|
|
|
}
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::ReStatic => {
|
2013-10-29 05:03:32 -05:00
|
|
|
mywrite!(w, "t");
|
|
|
|
}
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::ReEmpty => {
|
2013-10-29 05:03:32 -05:00
|
|
|
mywrite!(w, "e");
|
|
|
|
}
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::ReInfer(_) => {
|
2013-10-21 19:11:42 -05:00
|
|
|
// these should not crop up after typeck
|
2014-02-06 03:38:08 -06:00
|
|
|
cx.diag.handler().bug("cannot encode region variables");
|
2013-10-21 19:11:42 -05:00
|
|
|
}
|
2012-04-18 23:26:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 21:28:28 -06:00
|
|
|
fn enc_bound_region(w: &mut MemWriter, cx: &ctxt, br: ty::BoundRegion) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match br {
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::BrAnon(idx) => {
|
2013-10-29 05:03:32 -05:00
|
|
|
mywrite!(w, "a{}|", idx);
|
|
|
|
}
|
2014-03-04 23:59:35 -06:00
|
|
|
ty::BrNamed(d, name) => {
|
2013-10-29 05:03:32 -05:00
|
|
|
mywrite!(w, "[{}|{}]",
|
|
|
|
(cx.ds)(d),
|
2014-03-04 23:59:35 -06:00
|
|
|
token::get_name(name));
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::BrFresh(id) => {
|
2013-10-29 05:03:32 -05:00
|
|
|
mywrite!(w, "f{}|", id);
|
|
|
|
}
|
2012-03-08 16:05:16 -06:00
|
|
|
}
|
|
|
|
}
|
2012-04-10 20:32:51 -05:00
|
|
|
|
2014-03-05 21:28:28 -06:00
|
|
|
pub fn enc_trait_ref(w: &mut MemWriter, cx: &ctxt, s: &ty::TraitRef) {
|
2013-10-21 19:11:42 -05:00
|
|
|
mywrite!(w, "{}|", (cx.ds)(s.def_id));
|
2013-04-17 11:15:37 -05:00
|
|
|
enc_substs(w, cx, &s.substs);
|
2013-03-27 05:16:28 -05:00
|
|
|
}
|
|
|
|
|
2014-03-05 21:28:28 -06:00
|
|
|
pub fn enc_trait_store(w: &mut MemWriter, cx: &ctxt, s: ty::TraitStore) {
|
2013-03-08 23:16:09 -06:00
|
|
|
match s {
|
2013-10-21 19:11:42 -05:00
|
|
|
ty::UniqTraitStore => mywrite!(w, "~"),
|
2014-04-11 01:01:31 -05:00
|
|
|
ty::RegionTraitStore(re, m) => {
|
2013-10-21 19:11:42 -05:00
|
|
|
mywrite!(w, "&");
|
2013-03-08 23:16:09 -06:00
|
|
|
enc_region(w, cx, re);
|
2014-04-11 01:01:31 -05:00
|
|
|
enc_mutability(w, m);
|
2013-03-08 23:16:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 21:28:28 -06:00
|
|
|
fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
|
2013-07-02 14:47:32 -05:00
|
|
|
match *st {
|
2013-10-21 19:11:42 -05:00
|
|
|
ty::ty_nil => mywrite!(w, "n"),
|
|
|
|
ty::ty_bot => mywrite!(w, "z"),
|
|
|
|
ty::ty_bool => mywrite!(w, "b"),
|
|
|
|
ty::ty_char => mywrite!(w, "c"),
|
|
|
|
ty::ty_int(t) => {
|
|
|
|
match t {
|
2014-01-09 07:05:33 -06:00
|
|
|
TyI => mywrite!(w, "i"),
|
|
|
|
TyI8 => mywrite!(w, "MB"),
|
|
|
|
TyI16 => mywrite!(w, "MW"),
|
|
|
|
TyI32 => mywrite!(w, "ML"),
|
|
|
|
TyI64 => mywrite!(w, "MD")
|
2013-10-21 19:11:42 -05:00
|
|
|
}
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2013-10-21 19:11:42 -05:00
|
|
|
ty::ty_uint(t) => {
|
|
|
|
match t {
|
2014-01-09 07:05:33 -06:00
|
|
|
TyU => mywrite!(w, "u"),
|
|
|
|
TyU8 => mywrite!(w, "Mb"),
|
|
|
|
TyU16 => mywrite!(w, "Mw"),
|
|
|
|
TyU32 => mywrite!(w, "Ml"),
|
|
|
|
TyU64 => mywrite!(w, "Md")
|
2013-10-21 19:11:42 -05:00
|
|
|
}
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2013-10-21 19:11:42 -05:00
|
|
|
ty::ty_float(t) => {
|
|
|
|
match t {
|
2014-01-09 07:05:33 -06:00
|
|
|
TyF32 => mywrite!(w, "Mf"),
|
|
|
|
TyF64 => mywrite!(w, "MF"),
|
2013-10-21 19:11:42 -05:00
|
|
|
}
|
2011-06-27 16:37:02 -05:00
|
|
|
}
|
2013-10-21 19:11:42 -05:00
|
|
|
ty::ty_enum(def, ref substs) => {
|
|
|
|
mywrite!(w, "t[{}|", (cx.ds)(def));
|
|
|
|
enc_substs(w, cx, substs);
|
|
|
|
mywrite!(w, "]");
|
|
|
|
}
|
2014-05-05 20:56:44 -05:00
|
|
|
ty::ty_trait(box ty::TyTrait {
|
|
|
|
def_id,
|
|
|
|
ref substs,
|
|
|
|
bounds
|
|
|
|
}) => {
|
2014-03-19 06:01:30 -05:00
|
|
|
mywrite!(w, "x[{}|", (cx.ds)(def_id));
|
2013-10-21 19:11:42 -05:00
|
|
|
enc_substs(w, cx, substs);
|
|
|
|
let bounds = ty::ParamBounds {builtin_bounds: bounds,
|
2014-03-04 12:02:49 -06:00
|
|
|
trait_bounds: Vec::new()};
|
2013-10-21 19:11:42 -05:00
|
|
|
enc_bounds(w, cx, &bounds);
|
|
|
|
mywrite!(w, "]");
|
|
|
|
}
|
|
|
|
ty::ty_tup(ref ts) => {
|
|
|
|
mywrite!(w, "T[");
|
|
|
|
for t in ts.iter() { enc_ty(w, cx, *t); }
|
|
|
|
mywrite!(w, "]");
|
|
|
|
}
|
2013-12-30 20:57:48 -06:00
|
|
|
ty::ty_box(typ) => { mywrite!(w, "@"); enc_ty(w, cx, typ); }
|
2014-01-11 18:25:51 -06:00
|
|
|
ty::ty_uniq(typ) => { mywrite!(w, "~"); enc_ty(w, cx, typ); }
|
2013-10-21 19:11:42 -05:00
|
|
|
ty::ty_ptr(mt) => { mywrite!(w, "*"); enc_mt(w, cx, mt); }
|
|
|
|
ty::ty_rptr(r, mt) => {
|
|
|
|
mywrite!(w, "&");
|
|
|
|
enc_region(w, cx, r);
|
|
|
|
enc_mt(w, cx, mt);
|
|
|
|
}
|
2014-04-09 02:15:31 -05:00
|
|
|
ty::ty_vec(mt, sz) => {
|
2013-10-21 19:11:42 -05:00
|
|
|
mywrite!(w, "V");
|
2014-04-09 02:15:31 -05:00
|
|
|
enc_mt(w, cx, mt);
|
|
|
|
mywrite!(w, "/");
|
|
|
|
match sz {
|
|
|
|
Some(n) => mywrite!(w, "{}|", n),
|
|
|
|
None => mywrite!(w, "|"),
|
|
|
|
}
|
2013-10-21 19:11:42 -05:00
|
|
|
}
|
2014-04-28 20:10:23 -05:00
|
|
|
ty::ty_str => {
|
2013-10-21 19:11:42 -05:00
|
|
|
mywrite!(w, "v");
|
|
|
|
}
|
|
|
|
ty::ty_closure(ref f) => {
|
|
|
|
mywrite!(w, "f");
|
2014-07-07 18:35:15 -05:00
|
|
|
enc_closure_ty(w, cx, &**f);
|
2013-10-21 19:11:42 -05:00
|
|
|
}
|
|
|
|
ty::ty_bare_fn(ref f) => {
|
|
|
|
mywrite!(w, "F");
|
|
|
|
enc_bare_fn_ty(w, cx, f);
|
|
|
|
}
|
|
|
|
ty::ty_infer(_) => {
|
2014-02-06 03:38:08 -06:00
|
|
|
cx.diag.handler().bug("cannot encode inference variable types");
|
2013-10-21 19:11:42 -05:00
|
|
|
}
|
2014-05-31 17:53:13 -05:00
|
|
|
ty::ty_param(ParamTy {space, idx: id, def_id: did}) => {
|
|
|
|
mywrite!(w, "p{}|{}|{}|", (cx.ds)(did), id, space.to_uint())
|
2013-10-21 19:11:42 -05:00
|
|
|
}
|
|
|
|
ty::ty_struct(def, ref substs) => {
|
|
|
|
mywrite!(w, "a[{}|", (cx.ds)(def));
|
|
|
|
enc_substs(w, cx, substs);
|
|
|
|
mywrite!(w, "]");
|
|
|
|
}
|
2014-05-31 17:53:13 -05:00
|
|
|
ty::ty_err => {
|
|
|
|
mywrite!(w, "e");
|
|
|
|
}
|
2011-06-27 16:37:02 -05:00
|
|
|
}
|
|
|
|
}
|
2012-08-10 20:15:08 -05:00
|
|
|
|
2014-04-06 20:04:40 -05:00
|
|
|
fn enc_fn_style(w: &mut MemWriter, p: FnStyle) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match p {
|
2014-04-06 20:04:40 -05:00
|
|
|
NormalFn => mywrite!(w, "n"),
|
2014-01-09 07:05:33 -06:00
|
|
|
UnsafeFn => mywrite!(w, "u"),
|
2012-05-25 01:44:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-02 03:19:41 -05:00
|
|
|
fn enc_abi(w: &mut MemWriter, abi: Abi) {
|
2013-10-21 19:11:42 -05:00
|
|
|
mywrite!(w, "[");
|
2014-04-02 03:19:41 -05:00
|
|
|
mywrite!(w, "{}", abi.name());
|
2013-10-21 19:11:42 -05:00
|
|
|
mywrite!(w, "]")
|
2013-01-31 19:12:29 -06:00
|
|
|
}
|
|
|
|
|
2013-12-20 19:36:07 -06:00
|
|
|
fn enc_onceness(w: &mut MemWriter, o: Onceness) {
|
2012-11-02 15:33:51 -05:00
|
|
|
match o {
|
2013-10-21 19:11:42 -05:00
|
|
|
Once => mywrite!(w, "o"),
|
|
|
|
Many => mywrite!(w, "m")
|
2012-11-02 15:33:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 21:28:28 -06:00
|
|
|
pub fn enc_bare_fn_ty(w: &mut MemWriter, cx: &ctxt, ft: &ty::BareFnTy) {
|
2014-04-06 20:04:40 -05:00
|
|
|
enc_fn_style(w, ft.fn_style);
|
2014-04-02 03:19:41 -05:00
|
|
|
enc_abi(w, ft.abi);
|
2013-01-31 19:12:29 -06:00
|
|
|
enc_fn_sig(w, cx, &ft.sig);
|
|
|
|
}
|
|
|
|
|
2014-03-05 21:28:28 -06:00
|
|
|
fn enc_closure_ty(w: &mut MemWriter, cx: &ctxt, ft: &ty::ClosureTy) {
|
2014-04-06 20:04:40 -05:00
|
|
|
enc_fn_style(w, ft.fn_style);
|
2013-01-31 19:12:29 -06:00
|
|
|
enc_onceness(w, ft.onceness);
|
2014-04-11 10:03:10 -05:00
|
|
|
enc_trait_store(w, cx, ft.store);
|
2013-05-10 14:57:27 -05:00
|
|
|
let bounds = ty::ParamBounds {builtin_bounds: ft.bounds,
|
2014-03-04 12:02:49 -06:00
|
|
|
trait_bounds: Vec::new()};
|
2013-05-10 14:57:27 -05:00
|
|
|
enc_bounds(w, cx, &bounds);
|
2013-01-31 19:12:29 -06:00
|
|
|
enc_fn_sig(w, cx, &ft.sig);
|
|
|
|
}
|
|
|
|
|
2014-03-05 21:28:28 -06:00
|
|
|
fn enc_fn_sig(w: &mut MemWriter, cx: &ctxt, fsig: &ty::FnSig) {
|
2013-10-29 05:03:32 -05:00
|
|
|
mywrite!(w, "[{}|", fsig.binder_id);
|
2013-08-03 11:45:23 -05:00
|
|
|
for ty in fsig.inputs.iter() {
|
2013-04-26 21:13:38 -05:00
|
|
|
enc_ty(w, cx, *ty);
|
2011-06-27 16:37:02 -05:00
|
|
|
}
|
2013-10-21 19:11:42 -05:00
|
|
|
mywrite!(w, "]");
|
2013-10-25 00:56:34 -05:00
|
|
|
if fsig.variadic {
|
2013-10-29 05:03:32 -05:00
|
|
|
mywrite!(w, "V");
|
|
|
|
} else {
|
|
|
|
mywrite!(w, "N");
|
2013-10-25 00:56:34 -05:00
|
|
|
}
|
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
|
|
|
|
2014-03-05 21:28:28 -06:00
|
|
|
fn enc_bounds(w: &mut MemWriter, cx: &ctxt, bs: &ty::ParamBounds) {
|
2013-07-25 23:53:29 -05:00
|
|
|
for bound in bs.builtin_bounds.iter() {
|
2013-05-07 16:30:21 -05:00
|
|
|
match bound {
|
2013-10-21 19:11:42 -05:00
|
|
|
ty::BoundSend => mywrite!(w, "S"),
|
|
|
|
ty::BoundStatic => mywrite!(w, "O"),
|
|
|
|
ty::BoundSized => mywrite!(w, "Z"),
|
2014-03-26 18:01:11 -05:00
|
|
|
ty::BoundCopy => mywrite!(w, "P"),
|
2014-03-03 16:27:46 -06:00
|
|
|
ty::BoundShare => mywrite!(w, "T"),
|
2011-12-28 10:50:12 -06:00
|
|
|
}
|
2013-07-25 23:53:29 -05:00
|
|
|
}
|
2013-05-07 16:30:21 -05:00
|
|
|
|
2014-04-21 18:21:52 -05:00
|
|
|
for tp in bs.trait_bounds.iter() {
|
2013-10-21 19:11:42 -05:00
|
|
|
mywrite!(w, "I");
|
2014-04-21 18:21:52 -05:00
|
|
|
enc_trait_ref(w, cx, &**tp);
|
2013-05-07 16:30:21 -05:00
|
|
|
}
|
|
|
|
|
2013-10-21 19:11:42 -05:00
|
|
|
mywrite!(w, ".");
|
2011-12-28 10:50:12 -06:00
|
|
|
}
|
2011-06-27 16:37:02 -05:00
|
|
|
|
2014-03-05 21:28:28 -06:00
|
|
|
pub fn enc_type_param_def(w: &mut MemWriter, cx: &ctxt, v: &ty::TypeParameterDef) {
|
2014-05-31 17:53:13 -05:00
|
|
|
mywrite!(w, "{}:{}|{}|{}|",
|
|
|
|
token::get_ident(v.ident), (cx.ds)(v.def_id),
|
|
|
|
v.space.to_uint(), v.index);
|
2014-04-20 07:11:18 -05:00
|
|
|
enc_bounds(w, cx, &*v.bounds);
|
2014-01-30 11:28:02 -06:00
|
|
|
enc_opt(w, v.default, |w, t| enc_ty(w, cx, t));
|
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
|
|
|
}
|