2014-02-10 15:36:31 +01:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 16:48:01 -08: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 14:37:02 -07:00
|
|
|
// Type encoding
|
|
|
|
|
2014-03-21 18:05:05 -07:00
|
|
|
#![allow(unused_must_use)] // as with encoding, everything is a no-fail MemWriter
|
|
|
|
#![allow(non_camel_case_types)]
|
2014-01-29 18:42:19 -08:00
|
|
|
|
2013-12-20 20:18:52 -08:00
|
|
|
use std::cell::RefCell;
|
2013-05-17 15:28:44 -07:00
|
|
|
|
2014-11-18 14:22:59 +01:00
|
|
|
use middle::region;
|
2014-05-13 11:35:42 -04:00
|
|
|
use middle::subst;
|
2014-05-31 18:53:13 -04:00
|
|
|
use middle::subst::VecPerParamSpace;
|
|
|
|
use middle::ty::ParamTy;
|
2015-01-03 22:42:21 -05:00
|
|
|
use middle::ty::{self, Ty};
|
2014-11-10 00:59:56 +02:00
|
|
|
use util::nodemap::FnvHashMap;
|
2012-12-23 17:41:37 -05:00
|
|
|
|
2014-04-02 01:19:41 -07:00
|
|
|
use syntax::abi::Abi;
|
2013-04-02 03:40:57 -04:00
|
|
|
use syntax::ast;
|
2013-12-31 23:17:59 +09:00
|
|
|
use syntax::diagnostic::SpanHandler;
|
2014-02-14 07:07:09 +02:00
|
|
|
use syntax::parse::token;
|
2011-06-27 14:37:02 -07:00
|
|
|
|
2014-07-29 18:27:28 -07:00
|
|
|
use rbml::io::SeekableMemWriter;
|
2014-07-29 16:31:39 -07:00
|
|
|
|
2014-11-14 09:18:10 -08:00
|
|
|
macro_rules! mywrite { ($($arg:tt)*) => ({ write!($($arg)*); }) }
|
2013-10-21 17:11:42 -07:00
|
|
|
|
2014-04-22 15:56:37 +03:00
|
|
|
pub struct ctxt<'a, 'tcx: 'a> {
|
2014-03-28 10:05:27 -07:00
|
|
|
pub diag: &'a SpanHandler,
|
2011-09-02 15:34:58 -07:00
|
|
|
// Def -> str Callback:
|
2014-09-13 20:10:34 +03:00
|
|
|
pub ds: fn(ast::DefId) -> String,
|
2011-09-02 15:34:58 -07:00
|
|
|
// The type context.
|
2014-04-22 15:56:37 +03:00
|
|
|
pub tcx: &'a ty::ctxt<'tcx>,
|
2014-09-29 22:11:30 +03:00
|
|
|
pub abbrevs: &'a abbrev_map<'tcx>
|
2013-01-08 14:00:45 -08:00
|
|
|
}
|
2011-06-27 14:37:02 -07:00
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
// Compact string representation for Ty values. API ty_str & parse_from_str.
|
2011-06-27 14:37:02 -07:00
|
|
|
// 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 02:40:42 -05:00
|
|
|
pub struct ty_abbrev {
|
2014-05-22 16:57:53 -07:00
|
|
|
s: String
|
2013-02-19 02:40:42 -05:00
|
|
|
}
|
2011-06-27 14:37:02 -07:00
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub type abbrev_map<'tcx> = RefCell<FnvHashMap<Ty<'tcx>, ty_abbrev>>;
|
2011-06-27 14:37:02 -07:00
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) {
|
2014-11-06 12:25:16 -05:00
|
|
|
match cx.abbrevs.borrow_mut().get(&t) {
|
2015-01-23 10:46:14 -08:00
|
|
|
Some(a) => { w.write_all(a.s.as_bytes()); return; }
|
2014-05-28 09:24:28 -07:00
|
|
|
None => {}
|
|
|
|
}
|
|
|
|
let pos = w.tell().unwrap();
|
2014-12-16 18:38:06 +02:00
|
|
|
|
|
|
|
match t.sty {
|
|
|
|
ty::ty_bool => mywrite!(w, "b"),
|
|
|
|
ty::ty_char => mywrite!(w, "c"),
|
|
|
|
ty::ty_int(t) => {
|
|
|
|
match t {
|
2015-01-08 20:13:14 +11:00
|
|
|
ast::TyIs(_) => mywrite!(w, "is"),
|
2014-12-16 18:38:06 +02:00
|
|
|
ast::TyI8 => mywrite!(w, "MB"),
|
|
|
|
ast::TyI16 => mywrite!(w, "MW"),
|
|
|
|
ast::TyI32 => mywrite!(w, "ML"),
|
|
|
|
ast::TyI64 => mywrite!(w, "MD")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ty::ty_uint(t) => {
|
|
|
|
match t {
|
2015-01-08 20:13:14 +11:00
|
|
|
ast::TyUs(_) => mywrite!(w, "us"),
|
2014-12-16 18:38:06 +02:00
|
|
|
ast::TyU8 => mywrite!(w, "Mb"),
|
|
|
|
ast::TyU16 => mywrite!(w, "Mw"),
|
|
|
|
ast::TyU32 => mywrite!(w, "Ml"),
|
|
|
|
ast::TyU64 => mywrite!(w, "Md")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ty::ty_float(t) => {
|
|
|
|
match t {
|
|
|
|
ast::TyF32 => mywrite!(w, "Mf"),
|
|
|
|
ast::TyF64 => mywrite!(w, "MF"),
|
|
|
|
}
|
|
|
|
}
|
2014-12-26 22:33:56 +11:00
|
|
|
ty::ty_enum(def, substs) => {
|
2014-12-16 18:38:06 +02:00
|
|
|
mywrite!(w, "t[{}|", (cx.ds)(def));
|
|
|
|
enc_substs(w, cx, substs);
|
|
|
|
mywrite!(w, "]");
|
|
|
|
}
|
|
|
|
ty::ty_trait(box ty::TyTrait { ref principal,
|
|
|
|
ref bounds }) => {
|
|
|
|
mywrite!(w, "x[");
|
2014-12-26 03:31:58 -05:00
|
|
|
enc_trait_ref(w, cx, &*principal.0);
|
2014-12-16 18:38:06 +02:00
|
|
|
enc_existential_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, "]");
|
|
|
|
}
|
|
|
|
ty::ty_uniq(typ) => { mywrite!(w, "~"); enc_ty(w, cx, typ); }
|
|
|
|
ty::ty_ptr(mt) => { mywrite!(w, "*"); enc_mt(w, cx, mt); }
|
|
|
|
ty::ty_rptr(r, mt) => {
|
|
|
|
mywrite!(w, "&");
|
2014-12-26 22:33:56 +11:00
|
|
|
enc_region(w, cx, *r);
|
2014-12-16 18:38:06 +02:00
|
|
|
enc_mt(w, cx, mt);
|
|
|
|
}
|
|
|
|
ty::ty_vec(t, sz) => {
|
|
|
|
mywrite!(w, "V");
|
|
|
|
enc_ty(w, cx, t);
|
|
|
|
mywrite!(w, "/");
|
|
|
|
match sz {
|
|
|
|
Some(n) => mywrite!(w, "{}|", n),
|
|
|
|
None => mywrite!(w, "|"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ty::ty_str => {
|
|
|
|
mywrite!(w, "v");
|
|
|
|
}
|
2014-12-26 22:33:56 +11:00
|
|
|
ty::ty_bare_fn(Some(def_id), f) => {
|
2014-12-16 18:38:06 +02:00
|
|
|
mywrite!(w, "F");
|
2014-11-26 05:53:15 -05:00
|
|
|
mywrite!(w, "{}|", (cx.ds)(def_id));
|
|
|
|
enc_bare_fn_ty(w, cx, f);
|
|
|
|
}
|
2014-12-26 22:33:56 +11:00
|
|
|
ty::ty_bare_fn(None, f) => {
|
2014-11-26 05:53:15 -05:00
|
|
|
mywrite!(w, "G");
|
2014-12-16 18:38:06 +02:00
|
|
|
enc_bare_fn_ty(w, cx, f);
|
|
|
|
}
|
|
|
|
ty::ty_infer(_) => {
|
|
|
|
cx.diag.handler().bug("cannot encode inference variable types");
|
|
|
|
}
|
2014-12-27 19:42:27 -05:00
|
|
|
ty::ty_param(ParamTy {space, idx, name}) => {
|
|
|
|
mywrite!(w, "p[{}|{}|{}]", idx, space.to_uint(), token::get_name(name))
|
2014-12-16 18:38:06 +02:00
|
|
|
}
|
2014-12-26 22:33:56 +11:00
|
|
|
ty::ty_struct(def, substs) => {
|
2014-12-16 18:38:06 +02:00
|
|
|
mywrite!(w, "a[{}|", (cx.ds)(def));
|
|
|
|
enc_substs(w, cx, substs);
|
|
|
|
mywrite!(w, "]");
|
|
|
|
}
|
2015-01-24 22:00:03 +02:00
|
|
|
ty::ty_closure(def, region, substs) => {
|
2014-12-16 18:38:06 +02:00
|
|
|
mywrite!(w, "k[{}|", (cx.ds)(def));
|
2014-12-26 22:33:56 +11:00
|
|
|
enc_region(w, cx, *region);
|
2014-12-16 18:38:06 +02:00
|
|
|
enc_substs(w, cx, substs);
|
|
|
|
mywrite!(w, "]");
|
|
|
|
}
|
2014-12-17 14:16:28 -05:00
|
|
|
ty::ty_projection(ref data) => {
|
|
|
|
mywrite!(w, "P[");
|
2014-12-26 03:31:58 -05:00
|
|
|
enc_trait_ref(w, cx, &*data.trait_ref);
|
2014-12-17 14:16:28 -05:00
|
|
|
mywrite!(w, "{}]", token::get_name(data.item_name));
|
|
|
|
}
|
2014-12-16 18:38:06 +02:00
|
|
|
ty::ty_err => {
|
|
|
|
mywrite!(w, "e");
|
|
|
|
}
|
|
|
|
ty::ty_open(_) => {
|
|
|
|
cx.diag.handler().bug("unexpected type in enc_sty (ty_open)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-28 09:24:28 -07:00
|
|
|
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 03:40:57 -04:00
|
|
|
|
2014-07-29 16:31:39 -07:00
|
|
|
fn enc_mutability(w: &mut SeekableMemWriter, mt: ast::Mutability) {
|
2013-04-02 03:40:57 -04:00
|
|
|
match mt {
|
2014-09-13 20:10:34 +03:00
|
|
|
ast::MutImmutable => (),
|
|
|
|
ast::MutMutable => mywrite!(w, "m"),
|
2011-06-27 14:37:02 -07:00
|
|
|
}
|
2013-04-02 03:40:57 -04:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
fn enc_mt<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
|
|
|
mt: ty::mt<'tcx>) {
|
2013-04-02 03:40:57 -04:00
|
|
|
enc_mutability(w, mt.mutbl);
|
2011-06-27 14:37:02 -07:00
|
|
|
enc_ty(w, cx, mt.ty);
|
|
|
|
}
|
2012-04-18 21:26:25 -07:00
|
|
|
|
2014-12-08 20:26:43 -05:00
|
|
|
fn enc_opt<T, F>(w: &mut SeekableMemWriter, t: Option<T>, enc_f: F) where
|
|
|
|
F: FnOnce(&mut SeekableMemWriter, T),
|
|
|
|
{
|
2013-04-17 12:15:37 -04:00
|
|
|
match t {
|
2013-10-21 17:11:42 -07:00
|
|
|
None => mywrite!(w, "n"),
|
|
|
|
Some(v) => {
|
|
|
|
mywrite!(w, "s");
|
2013-12-20 17:36:07 -08:00
|
|
|
enc_f(w, v);
|
2013-10-21 17:11:42 -07:00
|
|
|
}
|
2012-04-01 14:28:30 -07:00
|
|
|
}
|
|
|
|
}
|
2012-04-18 21:26:25 -07:00
|
|
|
|
2014-12-08 20:26:43 -05:00
|
|
|
fn enc_vec_per_param_space<'a, 'tcx, T, F>(w: &mut SeekableMemWriter,
|
|
|
|
cx: &ctxt<'a, 'tcx>,
|
|
|
|
v: &VecPerParamSpace<T>,
|
|
|
|
mut op: F) where
|
|
|
|
F: FnMut(&mut SeekableMemWriter, &ctxt<'a, 'tcx>, &T),
|
|
|
|
{
|
2014-05-31 18:53:13 -04:00
|
|
|
for &space in subst::ParamSpace::all().iter() {
|
|
|
|
mywrite!(w, "[");
|
2014-07-04 16:39:28 +02:00
|
|
|
for t in v.get_slice(space).iter() {
|
2014-05-31 18:53:13 -04:00
|
|
|
op(w, cx, t);
|
|
|
|
}
|
|
|
|
mywrite!(w, "]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn enc_substs<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
|
|
|
substs: &subst::Substs<'tcx>) {
|
2013-07-24 16:52:57 -04:00
|
|
|
enc_region_substs(w, cx, &substs.regions);
|
2014-05-31 18:53:13 -04:00
|
|
|
enc_vec_per_param_space(w, cx, &substs.types,
|
|
|
|
|w, cx, &ty| enc_ty(w, cx, ty));
|
2012-04-18 21:26:25 -07:00
|
|
|
}
|
|
|
|
|
2014-07-29 16:31:39 -07:00
|
|
|
fn enc_region_substs(w: &mut SeekableMemWriter, cx: &ctxt, substs: &subst::RegionSubsts) {
|
2013-07-24 16:52:57 -04:00
|
|
|
match *substs {
|
2014-05-13 11:35:42 -04:00
|
|
|
subst::ErasedRegions => {
|
2013-10-21 17:11:42 -07:00
|
|
|
mywrite!(w, "e");
|
2013-07-24 16:52:57 -04:00
|
|
|
}
|
2014-05-13 11:35:42 -04:00
|
|
|
subst::NonerasedRegions(ref regions) => {
|
2013-10-21 17:11:42 -07:00
|
|
|
mywrite!(w, "n");
|
2014-05-31 18:53:13 -04:00
|
|
|
enc_vec_per_param_space(w, cx, regions,
|
|
|
|
|w, cx, &r| enc_region(w, cx, r));
|
2013-07-24 16:52:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 21:46:52 -04:00
|
|
|
pub fn enc_region(w: &mut SeekableMemWriter, cx: &ctxt, r: ty::Region) {
|
2012-08-06 12:34:08 -07:00
|
|
|
match r {
|
2013-10-29 10:34:11 -04:00
|
|
|
ty::ReLateBound(id, br) => {
|
2014-11-15 16:47:59 -05:00
|
|
|
mywrite!(w, "b[{}|", id.depth);
|
2013-10-21 17:11:42 -07:00
|
|
|
enc_bound_region(w, cx, br);
|
2013-10-29 06:03:32 -04:00
|
|
|
mywrite!(w, "]");
|
|
|
|
}
|
2014-05-31 18:53:13 -04:00
|
|
|
ty::ReEarlyBound(node_id, space, index, name) => {
|
|
|
|
mywrite!(w, "B[{}|{}|{}|{}]",
|
2013-10-29 06:03:32 -04:00
|
|
|
node_id,
|
2014-05-31 18:53:13 -04:00
|
|
|
space.to_uint(),
|
2013-10-29 06:03:32 -04:00
|
|
|
index,
|
2014-03-05 06:59:35 +01:00
|
|
|
token::get_name(name));
|
2013-10-21 17:11:42 -07:00
|
|
|
}
|
2013-10-29 10:34:11 -04:00
|
|
|
ty::ReFree(ref fr) => {
|
2014-11-18 14:22:59 +01:00
|
|
|
mywrite!(w, "f[");
|
|
|
|
enc_scope(w, cx, fr.scope);
|
|
|
|
mywrite!(w, "|");
|
2013-10-21 17:11:42 -07:00
|
|
|
enc_bound_region(w, cx, fr.bound_region);
|
|
|
|
mywrite!(w, "]");
|
|
|
|
}
|
2014-11-18 14:22:59 +01:00
|
|
|
ty::ReScope(scope) => {
|
|
|
|
mywrite!(w, "s");
|
|
|
|
enc_scope(w, cx, scope);
|
|
|
|
mywrite!(w, "|");
|
2013-10-29 06:03:32 -04:00
|
|
|
}
|
2013-10-29 10:34:11 -04:00
|
|
|
ty::ReStatic => {
|
2013-10-29 06:03:32 -04:00
|
|
|
mywrite!(w, "t");
|
|
|
|
}
|
2013-10-29 10:34:11 -04:00
|
|
|
ty::ReEmpty => {
|
2013-10-29 06:03:32 -04:00
|
|
|
mywrite!(w, "e");
|
|
|
|
}
|
2013-10-29 10:34:11 -04:00
|
|
|
ty::ReInfer(_) => {
|
2013-10-21 17:11:42 -07:00
|
|
|
// these should not crop up after typeck
|
2014-02-06 10:38:08 +01:00
|
|
|
cx.diag.handler().bug("cannot encode region variables");
|
2013-10-21 17:11:42 -07:00
|
|
|
}
|
2012-04-18 21:26:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 14:22:59 +01:00
|
|
|
fn enc_scope(w: &mut SeekableMemWriter, _cx: &ctxt, scope: region::CodeExtent) {
|
|
|
|
match scope {
|
|
|
|
region::CodeExtent::Misc(node_id) => mywrite!(w, "M{}", node_id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-29 16:31:39 -07:00
|
|
|
fn enc_bound_region(w: &mut SeekableMemWriter, cx: &ctxt, br: ty::BoundRegion) {
|
2012-08-06 12:34:08 -07:00
|
|
|
match br {
|
2013-10-29 10:34:11 -04:00
|
|
|
ty::BrAnon(idx) => {
|
2013-10-29 06:03:32 -04:00
|
|
|
mywrite!(w, "a{}|", idx);
|
|
|
|
}
|
2014-03-05 06:59:35 +01:00
|
|
|
ty::BrNamed(d, name) => {
|
2013-10-29 06:03:32 -04:00
|
|
|
mywrite!(w, "[{}|{}]",
|
|
|
|
(cx.ds)(d),
|
2014-03-05 06:59:35 +01:00
|
|
|
token::get_name(name));
|
2013-10-29 06:03:32 -04:00
|
|
|
}
|
2013-10-29 10:34:11 -04:00
|
|
|
ty::BrFresh(id) => {
|
2013-10-29 06:03:32 -04:00
|
|
|
mywrite!(w, "f{}|", id);
|
|
|
|
}
|
2014-10-07 20:04:45 -07:00
|
|
|
ty::BrEnv => {
|
|
|
|
mywrite!(w, "e|");
|
|
|
|
}
|
2012-03-08 14:05:16 -08:00
|
|
|
}
|
|
|
|
}
|
2012-04-10 18:32:51 -07:00
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn enc_trait_ref<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
|
|
|
s: &ty::TraitRef<'tcx>) {
|
2013-10-21 17:11:42 -07:00
|
|
|
mywrite!(w, "{}|", (cx.ds)(s.def_id));
|
2014-12-03 16:01:29 -08:00
|
|
|
enc_substs(w, cx, s.substs);
|
2013-03-27 06:16:28 -04:00
|
|
|
}
|
|
|
|
|
2014-12-09 10:36:46 -05:00
|
|
|
fn enc_unsafety(w: &mut SeekableMemWriter, p: ast::Unsafety) {
|
2012-08-06 12:34:08 -07:00
|
|
|
match p {
|
2014-12-09 10:36:46 -05:00
|
|
|
ast::Unsafety::Normal => mywrite!(w, "n"),
|
|
|
|
ast::Unsafety::Unsafe => mywrite!(w, "u"),
|
2012-05-24 23:44:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-29 16:31:39 -07:00
|
|
|
fn enc_abi(w: &mut SeekableMemWriter, abi: Abi) {
|
2013-10-21 17:11:42 -07:00
|
|
|
mywrite!(w, "[");
|
2014-04-02 01:19:41 -07:00
|
|
|
mywrite!(w, "{}", abi.name());
|
2013-10-21 17:11:42 -07:00
|
|
|
mywrite!(w, "]")
|
2013-01-31 17:12:29 -08:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn enc_bare_fn_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
|
|
|
ft: &ty::BareFnTy<'tcx>) {
|
2014-12-09 10:36:46 -05:00
|
|
|
enc_unsafety(w, ft.unsafety);
|
2014-04-02 01:19:41 -07:00
|
|
|
enc_abi(w, ft.abi);
|
2013-01-31 17:12:29 -08:00
|
|
|
enc_fn_sig(w, cx, &ft.sig);
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn enc_closure_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
|
|
|
ft: &ty::ClosureTy<'tcx>) {
|
2014-12-09 10:36:46 -05:00
|
|
|
enc_unsafety(w, ft.unsafety);
|
2013-01-31 17:12:29 -08:00
|
|
|
enc_fn_sig(w, cx, &ft.sig);
|
2014-05-28 22:26:56 -07:00
|
|
|
enc_abi(w, ft.abi);
|
2013-01-31 17:12:29 -08:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
fn enc_fn_sig<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
2014-12-12 11:28:35 -05:00
|
|
|
fsig: &ty::PolyFnSig<'tcx>) {
|
2014-11-15 16:47:59 -05:00
|
|
|
mywrite!(w, "[");
|
2014-12-12 11:28:35 -05:00
|
|
|
for ty in fsig.0.inputs.iter() {
|
2013-04-26 19:13:38 -07:00
|
|
|
enc_ty(w, cx, *ty);
|
2011-06-27 14:37:02 -07:00
|
|
|
}
|
2013-10-21 17:11:42 -07:00
|
|
|
mywrite!(w, "]");
|
2014-12-12 11:28:35 -05:00
|
|
|
if fsig.0.variadic {
|
2013-10-29 06:03:32 -04:00
|
|
|
mywrite!(w, "V");
|
|
|
|
} else {
|
|
|
|
mywrite!(w, "N");
|
2013-10-25 01:56:34 -04:00
|
|
|
}
|
2014-12-12 11:28:35 -05:00
|
|
|
match fsig.0.output {
|
2014-10-24 21:14:37 +02:00
|
|
|
ty::FnConverging(result_type) => {
|
|
|
|
enc_ty(w, cx, result_type);
|
|
|
|
}
|
|
|
|
ty::FnDiverging => {
|
|
|
|
mywrite!(w, "z");
|
|
|
|
}
|
|
|
|
}
|
2011-06-27 14:37:02 -07:00
|
|
|
}
|
2011-07-19 17:52:34 -07:00
|
|
|
|
2014-08-27 21:46:52 -04:00
|
|
|
pub fn enc_builtin_bounds(w: &mut SeekableMemWriter, _cx: &ctxt, bs: &ty::BuiltinBounds) {
|
|
|
|
for bound in bs.iter() {
|
2013-05-07 17:30:21 -04:00
|
|
|
match bound {
|
2013-10-21 17:11:42 -07:00
|
|
|
ty::BoundSend => mywrite!(w, "S"),
|
|
|
|
ty::BoundSized => mywrite!(w, "Z"),
|
2014-03-27 00:01:11 +01:00
|
|
|
ty::BoundCopy => mywrite!(w, "P"),
|
2014-08-05 16:40:04 -07:00
|
|
|
ty::BoundSync => mywrite!(w, "T"),
|
2011-12-28 17:50:12 +01:00
|
|
|
}
|
2013-07-26 13:53:29 +09:00
|
|
|
}
|
2013-05-07 17:30:21 -04:00
|
|
|
|
2014-08-27 21:46:52 -04:00
|
|
|
mywrite!(w, ".");
|
|
|
|
}
|
|
|
|
|
2014-12-26 04:36:04 -05:00
|
|
|
pub fn enc_existential_bounds<'a,'tcx>(w: &mut SeekableMemWriter,
|
|
|
|
cx: &ctxt<'a,'tcx>,
|
|
|
|
bs: &ty::ExistentialBounds<'tcx>) {
|
|
|
|
let param_bounds = ty::ParamBounds { trait_bounds: vec!(),
|
|
|
|
region_bounds: vec!(bs.region_bound),
|
|
|
|
builtin_bounds: bs.builtin_bounds,
|
|
|
|
projection_bounds: bs.projection_bounds.clone() };
|
|
|
|
enc_bounds(w, cx, ¶m_bounds);
|
2014-08-27 21:46:52 -04:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn enc_bounds<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
|
|
|
bs: &ty::ParamBounds<'tcx>) {
|
2014-08-27 21:46:52 -04:00
|
|
|
enc_builtin_bounds(w, cx, &bs.builtin_bounds);
|
|
|
|
|
2014-08-14 18:05:27 -04:00
|
|
|
for &r in bs.region_bounds.iter() {
|
2014-08-27 21:46:52 -04:00
|
|
|
mywrite!(w, "R");
|
|
|
|
enc_region(w, cx, r);
|
|
|
|
}
|
|
|
|
|
2014-04-22 02:21:52 +03:00
|
|
|
for tp in bs.trait_bounds.iter() {
|
2013-10-21 17:11:42 -07:00
|
|
|
mywrite!(w, "I");
|
2014-12-17 14:16:28 -05:00
|
|
|
enc_trait_ref(w, cx, &*tp.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
for tp in bs.projection_bounds.iter() {
|
|
|
|
mywrite!(w, "P");
|
|
|
|
enc_projection_predicate(w, cx, &tp.0);
|
2013-05-07 17:30:21 -04:00
|
|
|
}
|
|
|
|
|
2013-10-21 17:11:42 -07:00
|
|
|
mywrite!(w, ".");
|
2011-12-28 17:50:12 +01:00
|
|
|
}
|
2011-06-27 14:37:02 -07:00
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn enc_type_param_def<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
|
|
|
|
v: &ty::TypeParameterDef<'tcx>) {
|
2014-05-31 18:53:13 -04:00
|
|
|
mywrite!(w, "{}:{}|{}|{}|",
|
2014-09-30 19:11:34 -05:00
|
|
|
token::get_name(v.name), (cx.ds)(v.def_id),
|
2014-05-31 18:53:13 -04:00
|
|
|
v.space.to_uint(), v.index);
|
2014-08-27 21:46:52 -04:00
|
|
|
enc_bounds(w, cx, &v.bounds);
|
2014-01-30 19:28:02 +02: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-08 22:54:49 -07:00
|
|
|
}
|
2014-12-07 11:10:48 -05:00
|
|
|
|
|
|
|
pub fn enc_predicate<'a, 'tcx>(w: &mut SeekableMemWriter,
|
|
|
|
cx: &ctxt<'a, 'tcx>,
|
|
|
|
p: &ty::Predicate<'tcx>)
|
|
|
|
{
|
|
|
|
match *p {
|
|
|
|
ty::Predicate::Trait(ref trait_ref) => {
|
|
|
|
mywrite!(w, "t");
|
2014-12-17 14:16:28 -05:00
|
|
|
enc_trait_ref(w, cx, &*trait_ref.0.trait_ref);
|
2014-12-07 11:10:48 -05:00
|
|
|
}
|
2014-12-13 05:34:34 -05:00
|
|
|
ty::Predicate::Equate(ty::Binder(ty::EquatePredicate(a, b))) => {
|
2014-12-07 11:10:48 -05:00
|
|
|
mywrite!(w, "e");
|
|
|
|
enc_ty(w, cx, a);
|
|
|
|
enc_ty(w, cx, b);
|
|
|
|
}
|
2014-12-13 05:34:34 -05:00
|
|
|
ty::Predicate::RegionOutlives(ty::Binder(ty::OutlivesPredicate(a, b))) => {
|
2014-12-07 11:10:48 -05:00
|
|
|
mywrite!(w, "r");
|
|
|
|
enc_region(w, cx, a);
|
|
|
|
enc_region(w, cx, b);
|
|
|
|
}
|
2014-12-13 05:34:34 -05:00
|
|
|
ty::Predicate::TypeOutlives(ty::Binder(ty::OutlivesPredicate(a, b))) => {
|
2014-12-07 11:10:48 -05:00
|
|
|
mywrite!(w, "o");
|
|
|
|
enc_ty(w, cx, a);
|
|
|
|
enc_region(w, cx, b);
|
|
|
|
}
|
2014-12-17 14:16:28 -05:00
|
|
|
ty::Predicate::Projection(ty::Binder(ref data)) => {
|
|
|
|
mywrite!(w, "p");
|
|
|
|
enc_projection_predicate(w, cx, data)
|
|
|
|
}
|
2014-12-07 11:10:48 -05:00
|
|
|
}
|
|
|
|
}
|
2014-12-17 14:16:28 -05:00
|
|
|
|
|
|
|
fn enc_projection_predicate<'a, 'tcx>(w: &mut SeekableMemWriter,
|
|
|
|
cx: &ctxt<'a, 'tcx>,
|
|
|
|
data: &ty::ProjectionPredicate<'tcx>) {
|
|
|
|
enc_trait_ref(w, cx, &*data.projection_ty.trait_ref);
|
|
|
|
mywrite!(w, "{}|", token::get_name(data.projection_ty.item_name));
|
|
|
|
enc_ty(w, cx, data.ty);
|
|
|
|
}
|