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.
|
|
|
|
|
2014-03-21 18:05:05 -07:00
|
|
|
#![allow(non_camel_case_types)]
|
2014-03-18 10:58:26 -07:00
|
|
|
// FIXME: remove this after snapshot, and Results are handled
|
2014-03-21 18:05:05 -07:00
|
|
|
#![allow(unused_must_use)]
|
2013-05-17 15:28:44 -07:00
|
|
|
|
2012-12-13 13:05:22 -08:00
|
|
|
use c = metadata::common;
|
|
|
|
use cstore = metadata::cstore;
|
|
|
|
use driver::session::Session;
|
|
|
|
use metadata::decoder;
|
2014-05-14 15:31:30 -04:00
|
|
|
use middle::def;
|
2014-01-15 14:39:08 -05:00
|
|
|
use e = metadata::encoder;
|
2014-07-23 12:43:29 -07:00
|
|
|
use middle::freevars::{CaptureMode, freevar_entry};
|
2014-08-04 18:58:48 -07:00
|
|
|
use middle::freevars;
|
2014-01-15 14:39:08 -05:00
|
|
|
use middle::region;
|
2012-12-13 13:05:22 -08:00
|
|
|
use metadata::tydecode;
|
2013-10-29 06:03:32 -04:00
|
|
|
use metadata::tydecode::{DefIdSource, NominalType, TypeWithId, TypeParameter,
|
|
|
|
RegionParameter};
|
2012-12-13 13:05:22 -08:00
|
|
|
use metadata::tyencode;
|
2014-05-13 11:35:42 -04:00
|
|
|
use middle::subst;
|
2014-05-31 18:53:13 -04:00
|
|
|
use middle::subst::VecPerParamSpace;
|
2014-03-06 19:24:11 +02:00
|
|
|
use middle::typeck::{MethodCall, MethodCallee, MethodOrigin};
|
2014-04-21 19:21:53 -04:00
|
|
|
use middle::{ty, typeck};
|
2014-06-21 03:39:03 -07:00
|
|
|
use util::ppaux::ty_to_string;
|
2012-04-10 10:52:06 -07:00
|
|
|
|
2014-01-06 14:00:46 +02:00
|
|
|
use syntax::{ast, ast_map, ast_util, codemap, fold};
|
2014-07-14 16:31:52 -07:00
|
|
|
use syntax::ast_util::PostExpansionMethod;
|
2013-08-31 18:13:04 +02:00
|
|
|
use syntax::codemap::Span;
|
2014-01-09 15:05:33 +02:00
|
|
|
use syntax::fold::Folder;
|
2013-05-14 17:27:27 -07:00
|
|
|
use syntax::parse::token;
|
2012-12-23 17:41:37 -05:00
|
|
|
use syntax;
|
2012-02-14 15:21:53 -08:00
|
|
|
|
2014-02-26 12:58:41 -05:00
|
|
|
use libc;
|
2013-11-10 22:46:32 -08:00
|
|
|
use std::io::Seek;
|
core: Remove the cast module
This commit revisits the `cast` module in libcore and libstd, and scrutinizes
all functions inside of it. The result was to remove the `cast` module entirely,
folding all functionality into the `mem` module. Specifically, this is the fate
of each function in the `cast` module.
* transmute - This function was moved to `mem`, but it is now marked as
#[unstable]. This is due to planned changes to the `transmute`
function and how it can be invoked (see the #[unstable] comment).
For more information, see RFC 5 and #12898
* transmute_copy - This function was moved to `mem`, with clarification that is
is not an error to invoke it with T/U that are different
sizes, but rather that it is strongly discouraged. This
function is now #[stable]
* forget - This function was moved to `mem` and marked #[stable]
* bump_box_refcount - This function was removed due to the deprecation of
managed boxes as well as its questionable utility.
* transmute_mut - This function was previously deprecated, and removed as part
of this commit.
* transmute_mut_unsafe - This function doesn't serve much of a purpose when it
can be achieved with an `as` in safe code, so it was
removed.
* transmute_lifetime - This function was removed because it is likely a strong
indication that code is incorrect in the first place.
* transmute_mut_lifetime - This function was removed for the same reasons as
`transmute_lifetime`
* copy_lifetime - This function was moved to `mem`, but it is marked
`#[unstable]` now due to the likelihood of being removed in
the future if it is found to not be very useful.
* copy_mut_lifetime - This function was also moved to `mem`, but had the same
treatment as `copy_lifetime`.
* copy_lifetime_vec - This function was removed because it is not used today,
and its existence is not necessary with DST
(copy_lifetime will suffice).
In summary, the cast module was stripped down to these functions, and then the
functions were moved to the `mem` module.
transmute - #[unstable]
transmute_copy - #[stable]
forget - #[stable]
copy_lifetime - #[unstable]
copy_mut_lifetime - #[unstable]
[breaking-change]
2014-05-09 10:34:51 -07:00
|
|
|
use std::mem;
|
2014-06-11 19:33:52 -07:00
|
|
|
use std::gc::GC;
|
2013-10-21 17:11:42 -07:00
|
|
|
|
2014-07-29 18:27:28 -07:00
|
|
|
use rbml::io::SeekableMemWriter;
|
2014-07-29 17:06:37 -07:00
|
|
|
use rbml::{reader, writer};
|
|
|
|
use rbml;
|
2014-02-05 08:52:54 -08:00
|
|
|
use serialize;
|
2014-08-12 20:31:30 -07:00
|
|
|
use serialize::{Decodable, Decoder, DecoderHelpers, Encodable};
|
|
|
|
use serialize::{EncoderHelpers};
|
2013-06-13 19:19:50 +12:00
|
|
|
|
2013-02-28 11:57:33 -05:00
|
|
|
#[cfg(test)] use syntax::parse;
|
|
|
|
#[cfg(test)] use syntax::print::pprust;
|
2014-05-16 10:15:33 -07:00
|
|
|
#[cfg(test)] use std::gc::Gc;
|
2013-02-28 11:57:33 -05:00
|
|
|
|
2014-03-06 05:07:47 +02:00
|
|
|
struct DecodeContext<'a> {
|
2014-04-17 15:06:25 +03:00
|
|
|
cdata: &'a cstore::crate_metadata,
|
2014-03-06 05:07:47 +02:00
|
|
|
tcx: &'a ty::ctxt,
|
2013-02-19 02:40:42 -05:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-03-06 05:07:47 +02:00
|
|
|
struct ExtendedDecodeContext<'a> {
|
2014-03-06 05:28:28 +02:00
|
|
|
dcx: &'a DecodeContext<'a>,
|
2014-01-09 15:05:33 +02:00
|
|
|
from_id_range: ast_util::IdRange,
|
|
|
|
to_id_range: ast_util::IdRange
|
2012-07-11 15:00:40 -07:00
|
|
|
}
|
|
|
|
|
2012-07-31 10:27:51 -07:00
|
|
|
trait tr {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn tr(&self, xcx: &ExtendedDecodeContext) -> Self;
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2012-11-29 18:37:33 -08:00
|
|
|
trait tr_intern {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn tr_intern(&self, xcx: &ExtendedDecodeContext) -> ast::DefId;
|
2012-11-29 18:37:33 -08:00
|
|
|
}
|
|
|
|
|
2014-07-29 16:31:39 -07:00
|
|
|
pub type Encoder<'a> = writer::Encoder<'a, SeekableMemWriter>;
|
2014-03-18 10:58:26 -07:00
|
|
|
|
2012-02-14 15:21:53 -08:00
|
|
|
// ______________________________________________________________________
|
2012-03-01 10:36:22 -08:00
|
|
|
// Top-level methods.
|
|
|
|
|
2013-06-13 19:19:50 +12:00
|
|
|
pub fn encode_inlined_item(ecx: &e::EncodeContext,
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w: &mut Encoder,
|
2014-04-21 19:21:53 -04:00
|
|
|
ii: e::InlinedItemRef) {
|
2014-02-14 07:07:09 +02:00
|
|
|
let id = match ii {
|
|
|
|
e::IIItemRef(i) => i.id,
|
|
|
|
e::IIForeignRef(i) => i.id,
|
2014-08-04 13:56:56 -07:00
|
|
|
e::IITraitItemRef(_, e::ProvidedInlinedTraitItemRef(m)) => m.id,
|
|
|
|
e::IITraitItemRef(_, e::RequiredInlinedTraitItemRef(m)) => m.id,
|
2014-01-06 14:00:46 +02:00
|
|
|
};
|
2014-02-14 07:07:09 +02:00
|
|
|
debug!("> Encoding inlined item: {} ({})",
|
2014-06-21 03:39:03 -07:00
|
|
|
ecx.tcx.map.path_to_string(id),
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.writer.tell());
|
2012-03-01 10:36:22 -08:00
|
|
|
|
2014-01-06 14:00:46 +02:00
|
|
|
let ii = simplify_ast(ii);
|
2013-04-17 12:15:37 -04:00
|
|
|
let id_range = ast_util::compute_id_range_for_inlined_item(&ii);
|
2013-05-01 17:54:54 -07:00
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.start_tag(c::tag_ast as uint);
|
|
|
|
id_range.encode(rbml_w);
|
|
|
|
encode_ast(rbml_w, ii);
|
|
|
|
encode_side_tables_for_ii(ecx, rbml_w, &ii);
|
|
|
|
rbml_w.end_tag();
|
2012-03-01 10:36:22 -08:00
|
|
|
|
2014-02-14 07:07:09 +02:00
|
|
|
debug!("< Encoded inlined fn: {} ({})",
|
2014-06-21 03:39:03 -07:00
|
|
|
ecx.tcx.map.path_to_string(id),
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.writer.tell());
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-04-17 15:06:25 +03:00
|
|
|
pub fn decode_inlined_item(cdata: &cstore::crate_metadata,
|
2014-03-06 05:07:47 +02:00
|
|
|
tcx: &ty::ctxt,
|
2014-03-06 05:28:28 +02:00
|
|
|
path: Vec<ast_map::PathElem>,
|
2014-07-29 17:06:37 -07:00
|
|
|
par_doc: rbml::Doc)
|
2014-03-06 05:28:28 +02:00
|
|
|
-> Result<ast::InlinedItem, Vec<ast_map::PathElem>> {
|
|
|
|
let dcx = &DecodeContext {
|
2013-02-19 02:40:42 -05:00
|
|
|
cdata: cdata,
|
|
|
|
tcx: tcx,
|
|
|
|
};
|
2012-08-06 12:34:08 -07:00
|
|
|
match par_doc.opt_child(c::tag_ast) {
|
2014-02-14 07:07:09 +02:00
|
|
|
None => Err(path),
|
2012-08-20 12:23:37 -07:00
|
|
|
Some(ast_doc) => {
|
2014-02-14 07:07:09 +02:00
|
|
|
let mut path_as_str = None;
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("> Decoding inlined fn: {}::?",
|
2014-02-14 07:07:09 +02:00
|
|
|
{
|
|
|
|
// Do an Option dance to use the path after it is moved below.
|
2014-06-21 03:39:03 -07:00
|
|
|
let s = ast_map::path_to_string(ast_map::Values(path.iter()));
|
2014-02-14 07:07:09 +02:00
|
|
|
path_as_str = Some(s);
|
|
|
|
path_as_str.as_ref().map(|x| x.as_slice())
|
|
|
|
});
|
2014-05-28 20:36:05 +01:00
|
|
|
let mut ast_dsr = reader::Decoder::new(ast_doc);
|
2014-03-29 01:05:46 +01:00
|
|
|
let from_id_range = Decodable::decode(&mut ast_dsr).unwrap();
|
2014-03-05 16:36:01 +02:00
|
|
|
let to_id_range = reserve_id_range(&dcx.tcx.sess, from_id_range);
|
2014-03-06 05:28:28 +02:00
|
|
|
let xcx = &ExtendedDecodeContext {
|
2013-02-19 02:40:42 -05:00
|
|
|
dcx: dcx,
|
|
|
|
from_id_range: from_id_range,
|
|
|
|
to_id_range: to_id_range
|
|
|
|
};
|
2012-03-01 19:37:52 -08:00
|
|
|
let raw_ii = decode_ast(ast_doc);
|
2014-02-14 07:07:09 +02:00
|
|
|
let ii = renumber_and_map_ast(xcx, &dcx.tcx.map, path, raw_ii);
|
2014-01-06 14:00:46 +02:00
|
|
|
let ident = match ii {
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::IIItem(i) => i.ident,
|
|
|
|
ast::IIForeign(i) => i.ident,
|
2014-08-04 13:56:56 -07:00
|
|
|
ast::IITraitItem(_, iti) => {
|
|
|
|
match iti {
|
|
|
|
ast::ProvidedInlinedTraitItem(m) => m.pe_ident(),
|
|
|
|
ast::RequiredInlinedTraitItem(m) => m.pe_ident(),
|
|
|
|
}
|
|
|
|
}
|
2014-01-06 14:00:46 +02:00
|
|
|
};
|
2014-02-14 07:07:09 +02:00
|
|
|
debug!("Fn named: {}", token::get_ident(ident));
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("< Decoded inlined fn: {}::{}",
|
2014-02-14 07:07:09 +02:00
|
|
|
path_as_str.unwrap(),
|
|
|
|
token::get_ident(ident));
|
2014-03-05 16:36:01 +02:00
|
|
|
region::resolve_inlined_item(&tcx.sess, &tcx.region_maps, &ii);
|
2013-01-24 16:45:20 -08:00
|
|
|
decode_side_tables(xcx, ast_doc);
|
2012-08-06 12:34:08 -07:00
|
|
|
match ii {
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::IIItem(i) => {
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!(">>> DECODED ITEM >>>\n{}\n<<< DECODED ITEM <<<",
|
2014-06-21 03:39:03 -07:00
|
|
|
syntax::print::pprust::item_to_string(&*i));
|
2012-04-20 16:56:51 -07:00
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
_ => { }
|
2012-04-20 16:56:51 -07:00
|
|
|
}
|
2014-02-14 07:07:09 +02:00
|
|
|
Ok(ii)
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
}
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2012-02-14 15:21:53 -08:00
|
|
|
// ______________________________________________________________________
|
|
|
|
// Enumerating the IDs which appear in an AST
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-03-05 16:36:01 +02:00
|
|
|
fn reserve_id_range(sess: &Session,
|
2014-01-09 15:05:33 +02:00
|
|
|
from_id_range: ast_util::IdRange) -> ast_util::IdRange {
|
2012-02-14 15:21:53 -08:00
|
|
|
// Handle the case of an empty range:
|
2013-03-15 15:24:24 -04:00
|
|
|
if from_id_range.empty() { return from_id_range; }
|
2012-02-14 15:21:53 -08:00
|
|
|
let cnt = from_id_range.max - from_id_range.min;
|
2013-11-27 07:02:25 +02:00
|
|
|
let to_id_min = sess.reserve_node_ids(cnt);
|
2013-09-06 22:11:55 -04:00
|
|
|
let to_id_max = to_id_min + cnt;
|
2014-01-09 15:05:33 +02:00
|
|
|
ast_util::IdRange { min: to_id_min, max: to_id_max }
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-03-06 05:07:47 +02:00
|
|
|
impl<'a> ExtendedDecodeContext<'a> {
|
2013-07-27 10:25:59 +02:00
|
|
|
pub fn tr_id(&self, id: ast::NodeId) -> ast::NodeId {
|
2013-01-17 06:13:26 -08:00
|
|
|
/*!
|
|
|
|
* Translates an internal id, meaning a node id that is known
|
|
|
|
* to refer to some part of the item currently being inlined,
|
|
|
|
* such as a local variable or argument. All naked node-ids
|
|
|
|
* that appear in types have this property, since if something
|
|
|
|
* might refer to an external item we would use a def-id to
|
|
|
|
* allow for the possibility that the item resides in another
|
|
|
|
* crate.
|
|
|
|
*/
|
|
|
|
|
2012-02-14 15:21:53 -08:00
|
|
|
// from_id_range should be non-empty
|
2013-03-15 15:24:24 -04:00
|
|
|
assert!(!self.from_id_range.empty());
|
2012-02-14 15:21:53 -08:00
|
|
|
(id - self.from_id_range.min + self.to_id_range.min)
|
|
|
|
}
|
2013-09-02 03:45:37 +02:00
|
|
|
pub fn tr_def_id(&self, did: ast::DefId) -> ast::DefId {
|
2013-01-17 06:13:26 -08:00
|
|
|
/*!
|
|
|
|
* Translates an EXTERNAL def-id, converting the crate number
|
|
|
|
* from the one used in the encoded data to the current crate
|
|
|
|
* numbers.. By external, I mean that it be translated to a
|
|
|
|
* reference to the item in its original crate, as opposed to
|
|
|
|
* being translated to a reference to the inlined version of
|
|
|
|
* the item. This is typically, but not always, what you
|
|
|
|
* want, because most def-ids refer to external things like
|
|
|
|
* types or other fns that may or may not be inlined. Note
|
|
|
|
* that even when the inlined function is referencing itself
|
|
|
|
* recursively, we would want `tr_def_id` for that
|
|
|
|
* reference--- conceptually the function calls the original,
|
|
|
|
* non-inlined version, and trans deals with linking that
|
|
|
|
* recursive call to the inlined copy.
|
|
|
|
*
|
|
|
|
* However, there are a *few* cases where def-ids are used but
|
|
|
|
* we know that the thing being referenced is in fact *internal*
|
|
|
|
* to the item being inlined. In those cases, you should use
|
|
|
|
* `tr_intern_def_id()` below.
|
|
|
|
*/
|
|
|
|
|
2012-02-14 15:21:53 -08:00
|
|
|
decoder::translate_def_id(self.dcx.cdata, did)
|
|
|
|
}
|
2013-09-02 03:45:37 +02:00
|
|
|
pub fn tr_intern_def_id(&self, did: ast::DefId) -> ast::DefId {
|
2013-01-17 06:13:26 -08:00
|
|
|
/*!
|
|
|
|
* Translates an INTERNAL def-id, meaning a def-id that is
|
|
|
|
* known to refer to some part of the item currently being
|
|
|
|
* inlined. In that case, we want to convert the def-id to
|
|
|
|
* refer to the current crate and to the new, inlined node-id.
|
|
|
|
*/
|
|
|
|
|
2014-02-05 22:15:24 +01:00
|
|
|
assert_eq!(did.krate, ast::LOCAL_CRATE);
|
|
|
|
ast::DefId { krate: ast::LOCAL_CRATE, node: self.tr_id(did.node) }
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2013-08-31 18:13:04 +02:00
|
|
|
pub fn tr_span(&self, _span: Span) -> Span {
|
2014-01-01 15:53:22 +09:00
|
|
|
codemap::DUMMY_SP // FIXME (#1972): handle span properly
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2013-09-02 03:45:37 +02:00
|
|
|
impl tr_intern for ast::DefId {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn tr_intern(&self, xcx: &ExtendedDecodeContext) -> ast::DefId {
|
2013-02-22 01:41:37 -05:00
|
|
|
xcx.tr_intern_def_id(*self)
|
2012-11-29 18:37:33 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-02 03:45:37 +02:00
|
|
|
impl tr for ast::DefId {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn tr(&self, xcx: &ExtendedDecodeContext) -> ast::DefId {
|
2013-02-22 01:41:37 -05:00
|
|
|
xcx.tr_def_id(*self)
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2013-10-29 06:03:32 -04:00
|
|
|
impl tr for Option<ast::DefId> {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn tr(&self, xcx: &ExtendedDecodeContext) -> Option<ast::DefId> {
|
2013-10-29 06:03:32 -04:00
|
|
|
self.map(|d| xcx.tr_def_id(d))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-31 18:13:04 +02:00
|
|
|
impl tr for Span {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn tr(&self, xcx: &ExtendedDecodeContext) -> Span {
|
2013-02-22 01:41:37 -05:00
|
|
|
xcx.tr_span(*self)
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2012-12-17 19:31:04 -08:00
|
|
|
trait def_id_encoder_helpers {
|
2013-09-02 03:45:37 +02:00
|
|
|
fn emit_def_id(&mut self, did: ast::DefId);
|
2012-07-11 15:00:40 -07:00
|
|
|
}
|
|
|
|
|
2014-03-18 10:58:26 -07:00
|
|
|
impl<S:serialize::Encoder<E>, E> def_id_encoder_helpers for S {
|
|
|
|
fn emit_def_id(&mut self, did: ast::DefId) {
|
2014-04-11 20:59:18 -07:00
|
|
|
did.encode(self).ok().unwrap()
|
2014-03-18 10:58:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-17 19:31:04 -08:00
|
|
|
trait def_id_decoder_helpers {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn read_def_id(&mut self, xcx: &ExtendedDecodeContext) -> ast::DefId;
|
2013-07-22 16:40:31 -07:00
|
|
|
fn read_def_id_noxcx(&mut self,
|
2014-04-17 15:06:25 +03:00
|
|
|
cdata: &cstore::crate_metadata) -> ast::DefId;
|
2012-07-11 15:00:40 -07:00
|
|
|
}
|
|
|
|
|
2014-03-18 10:58:26 -07:00
|
|
|
impl<D:serialize::Decoder<E>, E> def_id_decoder_helpers for D {
|
|
|
|
fn read_def_id(&mut self, xcx: &ExtendedDecodeContext) -> ast::DefId {
|
2014-04-11 20:59:18 -07:00
|
|
|
let did: ast::DefId = Decodable::decode(self).ok().unwrap();
|
2014-03-18 10:58:26 -07:00
|
|
|
did.tr(xcx)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn read_def_id_noxcx(&mut self,
|
2014-04-17 15:06:25 +03:00
|
|
|
cdata: &cstore::crate_metadata) -> ast::DefId {
|
2014-04-11 20:59:18 -07:00
|
|
|
let did: ast::DefId = Decodable::decode(self).ok().unwrap();
|
2013-07-22 16:40:31 -07:00
|
|
|
decoder::translate_def_id(cdata, did)
|
|
|
|
}
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2012-02-14 15:21:53 -08:00
|
|
|
// ______________________________________________________________________
|
|
|
|
// Encoding and decoding the AST itself
|
|
|
|
//
|
|
|
|
// The hard work is done by an autogenerated module astencode_gen. To
|
|
|
|
// regenerate astencode_gen, run src/etc/gen-astencode. It will
|
|
|
|
// replace astencode_gen with a dummy file and regenerate its
|
|
|
|
// contents. If you get compile errors, the dummy file
|
|
|
|
// remains---resolve the errors and then rerun astencode_gen.
|
|
|
|
// Annoying, I know, but hopefully only temporary.
|
|
|
|
//
|
|
|
|
// When decoding, we have to renumber the AST so that the node ids that
|
|
|
|
// appear within are disjoint from the node ids in our existing ASTs.
|
|
|
|
// We also have to adjust the spans: for now we just insert a dummy span,
|
|
|
|
// but eventually we should add entries to the local codemap as required.
|
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
fn encode_ast(rbml_w: &mut Encoder, item: ast::InlinedItem) {
|
|
|
|
rbml_w.start_tag(c::tag_tree as uint);
|
|
|
|
item.encode(rbml_w);
|
|
|
|
rbml_w.end_tag();
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-01-06 14:00:46 +02:00
|
|
|
struct NestedItemsDropper;
|
2013-08-29 12:10:02 -07:00
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Folder for NestedItemsDropper {
|
2013-12-27 20:34:51 -07:00
|
|
|
fn fold_block(&mut self, blk: ast::P<ast::Block>) -> ast::P<ast::Block> {
|
2013-11-21 15:42:55 -08:00
|
|
|
let stmts_sans_items = blk.stmts.iter().filter_map(|stmt| {
|
2012-08-06 12:34:08 -07:00
|
|
|
match stmt.node {
|
2014-01-03 15:08:48 -08:00
|
|
|
ast::StmtExpr(_, _) | ast::StmtSemi(_, _) => Some(*stmt),
|
|
|
|
ast::StmtDecl(decl, _) => {
|
|
|
|
match decl.node {
|
|
|
|
ast::DeclLocal(_) => Some(*stmt),
|
|
|
|
ast::DeclItem(_) => None,
|
|
|
|
}
|
|
|
|
}
|
2013-11-28 12:22:53 -08:00
|
|
|
ast::StmtMac(..) => fail!("unexpanded macro in astencode")
|
2012-03-07 15:13:31 -08:00
|
|
|
}
|
2013-11-21 15:42:55 -08:00
|
|
|
}).collect();
|
2013-12-01 00:00:39 +02:00
|
|
|
let blk_sans_items = ast::P(ast::Block {
|
2014-02-28 15:25:15 -08:00
|
|
|
view_items: Vec::new(), // I don't know if we need the view_items
|
|
|
|
// here, but it doesn't break tests!
|
2013-01-14 20:52:28 -08:00
|
|
|
stmts: stmts_sans_items,
|
2013-01-24 16:45:20 -08:00
|
|
|
expr: blk.expr,
|
|
|
|
id: blk.id,
|
2013-07-16 20:08:35 +02:00
|
|
|
rules: blk.rules,
|
|
|
|
span: blk.span,
|
2013-12-01 00:00:39 +02:00
|
|
|
});
|
|
|
|
fold::noop_fold_block(blk_sans_items, self)
|
2012-03-07 15:13:31 -08:00
|
|
|
}
|
2013-08-29 12:10:02 -07:00
|
|
|
}
|
2012-03-07 15:13:31 -08:00
|
|
|
|
2013-08-29 12:10:02 -07:00
|
|
|
// Produces a simplified copy of the AST which does not include things
|
|
|
|
// that we do not need to or do not want to export. For example, we
|
|
|
|
// do not include any nested items: if these nested items are to be
|
|
|
|
// inlined, their AST will be exported separately (this only makes
|
|
|
|
// sense because, in Rust, nested items are independent except for
|
|
|
|
// their visibility).
|
|
|
|
//
|
|
|
|
// As it happens, trans relies on the fact that we do not export
|
|
|
|
// nested items, as otherwise it would get confused when translating
|
|
|
|
// inlined items.
|
2014-01-09 15:05:33 +02:00
|
|
|
fn simplify_ast(ii: e::InlinedItemRef) -> ast::InlinedItem {
|
2014-01-06 14:00:46 +02:00
|
|
|
let mut fld = NestedItemsDropper;
|
2012-03-07 15:13:31 -08:00
|
|
|
|
2014-01-06 14:00:46 +02:00
|
|
|
match ii {
|
|
|
|
// HACK we're not dropping items.
|
2014-08-04 13:56:56 -07:00
|
|
|
e::IIItemRef(i) => {
|
|
|
|
ast::IIItem(fold::noop_fold_item(i, &mut fld)
|
|
|
|
.expect_one("expected one item"))
|
|
|
|
}
|
|
|
|
e::IITraitItemRef(d, iti) => {
|
|
|
|
ast::IITraitItem(d, match iti {
|
|
|
|
e::ProvidedInlinedTraitItemRef(m) => {
|
|
|
|
ast::ProvidedInlinedTraitItem(
|
|
|
|
fold::noop_fold_method(m, &mut fld)
|
|
|
|
.expect_one("noop_fold_method must produce \
|
|
|
|
exactly one method"))
|
|
|
|
}
|
|
|
|
e::RequiredInlinedTraitItemRef(m) => {
|
|
|
|
ast::RequiredInlinedTraitItem(
|
|
|
|
fold::noop_fold_method(m, &mut fld)
|
|
|
|
.expect_one("noop_fold_method must produce \
|
|
|
|
exactly one method"))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
e::IIForeignRef(i) => {
|
|
|
|
ast::IIForeign(fold::noop_fold_foreign_item(i, &mut fld))
|
|
|
|
}
|
2012-03-07 15:13:31 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
fn decode_ast(par_doc: rbml::Doc) -> ast::InlinedItem {
|
2013-03-26 15:04:30 -04:00
|
|
|
let chi_doc = par_doc.get(c::tag_tree as uint);
|
2014-05-28 20:36:05 +01:00
|
|
|
let mut d = reader::Decoder::new(chi_doc);
|
2014-03-29 01:05:46 +01:00
|
|
|
Decodable::decode(&mut d).unwrap()
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-03-06 05:07:47 +02:00
|
|
|
struct AstRenumberer<'a> {
|
2014-03-06 05:28:28 +02:00
|
|
|
xcx: &'a ExtendedDecodeContext<'a>,
|
2013-08-29 12:10:02 -07:00
|
|
|
}
|
|
|
|
|
2014-03-06 05:07:47 +02:00
|
|
|
impl<'a> ast_map::FoldOps for AstRenumberer<'a> {
|
2014-01-06 14:00:46 +02:00
|
|
|
fn new_id(&self, id: ast::NodeId) -> ast::NodeId {
|
2014-02-14 07:07:09 +02:00
|
|
|
if id == ast::DUMMY_NODE_ID {
|
|
|
|
// Used by ast_map to map the NodeInlinedParent.
|
|
|
|
self.xcx.dcx.tcx.sess.next_node_id()
|
|
|
|
} else {
|
|
|
|
self.xcx.tr_id(id)
|
|
|
|
}
|
2013-08-29 12:10:02 -07:00
|
|
|
}
|
2014-01-06 14:00:46 +02:00
|
|
|
fn new_span(&self, span: Span) -> Span {
|
2013-08-29 12:10:02 -07:00
|
|
|
self.xcx.tr_span(span)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-06 05:28:28 +02:00
|
|
|
fn renumber_and_map_ast(xcx: &ExtendedDecodeContext,
|
2014-02-14 07:07:09 +02:00
|
|
|
map: &ast_map::Map,
|
2014-03-04 10:02:49 -08:00
|
|
|
path: Vec<ast_map::PathElem> ,
|
2014-01-09 15:05:33 +02:00
|
|
|
ii: ast::InlinedItem) -> ast::InlinedItem {
|
2014-02-28 15:25:15 -08:00
|
|
|
ast_map::map_decoded_item(map,
|
|
|
|
path.move_iter().collect(),
|
|
|
|
AstRenumberer { xcx: xcx },
|
|
|
|
|fld| {
|
2014-01-06 14:00:46 +02:00
|
|
|
match ii {
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::IIItem(i) => {
|
|
|
|
ast::IIItem(fld.fold_item(i).expect_one("expected one item"))
|
2014-01-06 14:00:46 +02:00
|
|
|
}
|
2014-08-04 13:56:56 -07:00
|
|
|
ast::IITraitItem(d, iti) => {
|
|
|
|
match iti {
|
|
|
|
ast::ProvidedInlinedTraitItem(m) => {
|
|
|
|
ast::IITraitItem(
|
|
|
|
xcx.tr_def_id(d),
|
|
|
|
ast::ProvidedInlinedTraitItem(
|
|
|
|
fld.fold_method(m)
|
|
|
|
.expect_one("expected one method")))
|
|
|
|
}
|
|
|
|
ast::RequiredInlinedTraitItem(m) => {
|
|
|
|
ast::IITraitItem(
|
|
|
|
xcx.tr_def_id(d),
|
|
|
|
ast::RequiredInlinedTraitItem(
|
|
|
|
fld.fold_method(m)
|
|
|
|
.expect_one("expected one method")))
|
|
|
|
}
|
|
|
|
}
|
2014-01-06 14:00:46 +02:00
|
|
|
}
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::IIForeign(i) => ast::IIForeign(fld.fold_foreign_item(i))
|
2014-01-06 14:00:46 +02:00
|
|
|
}
|
|
|
|
})
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2012-02-14 15:21:53 -08:00
|
|
|
// ______________________________________________________________________
|
|
|
|
// Encoding and decoding of ast::def
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
fn decode_def(xcx: &ExtendedDecodeContext, doc: rbml::Doc) -> def::Def {
|
2014-05-28 20:36:05 +01:00
|
|
|
let mut dsr = reader::Decoder::new(doc);
|
2014-05-14 15:31:30 -04:00
|
|
|
let def: def::Def = Decodable::decode(&mut dsr).unwrap();
|
2012-02-14 15:21:53 -08:00
|
|
|
def.tr(xcx)
|
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-05-14 15:31:30 -04:00
|
|
|
impl tr for def::Def {
|
|
|
|
fn tr(&self, xcx: &ExtendedDecodeContext) -> def::Def {
|
2013-02-22 01:41:37 -05:00
|
|
|
match *self {
|
2014-05-14 15:31:30 -04:00
|
|
|
def::DefFn(did, p) => def::DefFn(did.tr(xcx), p),
|
|
|
|
def::DefStaticMethod(did, wrapped_did2, p) => {
|
|
|
|
def::DefStaticMethod(did.tr(xcx),
|
2013-08-08 11:38:10 -07:00
|
|
|
match wrapped_did2 {
|
2014-05-14 15:31:30 -04:00
|
|
|
def::FromTrait(did2) => {
|
|
|
|
def::FromTrait(did2.tr(xcx))
|
2013-08-08 11:38:10 -07:00
|
|
|
}
|
2014-05-14 15:31:30 -04:00
|
|
|
def::FromImpl(did2) => {
|
|
|
|
def::FromImpl(did2.tr(xcx))
|
2013-08-08 11:38:10 -07:00
|
|
|
}
|
|
|
|
},
|
2012-10-18 13:29:34 -07:00
|
|
|
p)
|
2013-06-14 18:21:47 -07:00
|
|
|
}
|
2014-05-14 15:31:30 -04:00
|
|
|
def::DefMethod(did0, did1) => {
|
|
|
|
def::DefMethod(did0.tr(xcx), did1.map(|did1| did1.tr(xcx)))
|
2013-06-14 18:21:47 -07:00
|
|
|
}
|
2014-05-14 15:31:30 -04:00
|
|
|
def::DefSelfTy(nid) => { def::DefSelfTy(xcx.tr_id(nid)) }
|
|
|
|
def::DefMod(did) => { def::DefMod(did.tr(xcx)) }
|
|
|
|
def::DefForeignMod(did) => { def::DefForeignMod(did.tr(xcx)) }
|
|
|
|
def::DefStatic(did, m) => { def::DefStatic(did.tr(xcx), m) }
|
|
|
|
def::DefArg(nid, b) => { def::DefArg(xcx.tr_id(nid), b) }
|
|
|
|
def::DefLocal(nid, b) => { def::DefLocal(xcx.tr_id(nid), b) }
|
|
|
|
def::DefVariant(e_did, v_did, is_s) => {
|
|
|
|
def::DefVariant(e_did.tr(xcx), v_did.tr(xcx), is_s)
|
2013-06-22 18:58:41 -07:00
|
|
|
},
|
2014-05-14 15:31:30 -04:00
|
|
|
def::DefTrait(did) => def::DefTrait(did.tr(xcx)),
|
|
|
|
def::DefTy(did) => def::DefTy(did.tr(xcx)),
|
|
|
|
def::DefPrimTy(p) => def::DefPrimTy(p),
|
2014-05-31 18:53:13 -04:00
|
|
|
def::DefTyParam(s, did, v) => def::DefTyParam(s, did.tr(xcx), v),
|
2014-05-14 15:31:30 -04:00
|
|
|
def::DefBinding(nid, bm) => def::DefBinding(xcx.tr_id(nid), bm),
|
|
|
|
def::DefUse(did) => def::DefUse(did.tr(xcx)),
|
|
|
|
def::DefUpvar(nid1, def, nid2, nid3) => {
|
|
|
|
def::DefUpvar(xcx.tr_id(nid1),
|
2014-05-16 10:15:33 -07:00
|
|
|
box(GC) (*def).tr(xcx),
|
2012-08-20 16:53:33 -07:00
|
|
|
xcx.tr_id(nid2),
|
|
|
|
xcx.tr_id(nid3))
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2014-05-14 15:31:30 -04:00
|
|
|
def::DefStruct(did) => def::DefStruct(did.tr(xcx)),
|
|
|
|
def::DefRegion(nid) => def::DefRegion(xcx.tr_id(nid)),
|
|
|
|
def::DefTyParamBinder(nid) => {
|
|
|
|
def::DefTyParamBinder(xcx.tr_id(nid))
|
2012-07-26 14:04:03 -07:00
|
|
|
}
|
2014-05-14 15:31:30 -04:00
|
|
|
def::DefLabel(nid) => def::DefLabel(xcx.tr_id(nid))
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2012-09-11 21:25:01 -07:00
|
|
|
// ______________________________________________________________________
|
|
|
|
// Encoding and decoding of adjustment information
|
|
|
|
|
2013-12-26 13:54:41 -05:00
|
|
|
impl tr for ty::AutoDerefRef {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn tr(&self, xcx: &ExtendedDecodeContext) -> ty::AutoDerefRef {
|
2013-12-26 13:54:41 -05:00
|
|
|
ty::AutoDerefRef {
|
|
|
|
autoderefs: self.autoderefs,
|
|
|
|
autoref: match self.autoref {
|
|
|
|
Some(ref autoref) => Some(autoref.tr(xcx)),
|
|
|
|
None => None
|
2013-02-27 19:28:37 -05:00
|
|
|
}
|
2013-01-16 19:24:10 -08:00
|
|
|
}
|
2012-09-11 21:25:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 11:47:00 -08:00
|
|
|
impl tr for ty::AutoRef {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn tr(&self, xcx: &ExtendedDecodeContext) -> ty::AutoRef {
|
2013-03-15 15:24:24 -04:00
|
|
|
self.map_region(|r| r.tr(xcx))
|
2012-09-11 21:25:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 11:47:00 -08:00
|
|
|
impl tr for ty::Region {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn tr(&self, xcx: &ExtendedDecodeContext) -> ty::Region {
|
2013-02-22 01:41:37 -05:00
|
|
|
match *self {
|
2014-05-31 18:53:13 -04:00
|
|
|
ty::ReLateBound(id, br) => {
|
|
|
|
ty::ReLateBound(xcx.tr_id(id), br.tr(xcx))
|
|
|
|
}
|
|
|
|
ty::ReEarlyBound(id, space, index, ident) => {
|
|
|
|
ty::ReEarlyBound(xcx.tr_id(id), space, index, ident)
|
|
|
|
}
|
|
|
|
ty::ReScope(id) => {
|
|
|
|
ty::ReScope(xcx.tr_id(id))
|
|
|
|
}
|
|
|
|
ty::ReEmpty | ty::ReStatic | ty::ReInfer(..) => {
|
|
|
|
*self
|
|
|
|
}
|
2013-10-29 10:34:11 -04:00
|
|
|
ty::ReFree(ref fr) => {
|
|
|
|
ty::ReFree(ty::FreeRegion {scope_id: xcx.tr_id(fr.scope_id),
|
2013-04-01 22:32:37 -07:00
|
|
|
bound_region: fr.bound_region.tr(xcx)})
|
|
|
|
}
|
2012-09-11 21:25:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-29 10:34:11 -04:00
|
|
|
impl tr for ty::BoundRegion {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn tr(&self, xcx: &ExtendedDecodeContext) -> ty::BoundRegion {
|
2013-02-22 01:41:37 -05:00
|
|
|
match *self {
|
2013-10-29 10:34:11 -04:00
|
|
|
ty::BrAnon(_) |
|
|
|
|
ty::BrFresh(_) => *self,
|
|
|
|
ty::BrNamed(id, ident) => ty::BrNamed(xcx.tr_def_id(id),
|
2013-10-29 06:03:32 -04:00
|
|
|
ident),
|
2012-09-11 21:25:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-11 09:01:31 +03:00
|
|
|
impl tr for ty::TraitStore {
|
|
|
|
fn tr(&self, xcx: &ExtendedDecodeContext) -> ty::TraitStore {
|
|
|
|
match *self {
|
|
|
|
ty::RegionTraitStore(r, m) => {
|
|
|
|
ty::RegionTraitStore(r.tr(xcx), m)
|
|
|
|
}
|
|
|
|
ty::UniqTraitStore => ty::UniqTraitStore
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-14 15:21:53 -08:00
|
|
|
// ______________________________________________________________________
|
|
|
|
// Encoding and decoding of freevar information
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
fn encode_freevar_entry(rbml_w: &mut Encoder, fv: &freevar_entry) {
|
|
|
|
(*fv).encode(rbml_w).unwrap();
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-07-23 12:43:29 -07:00
|
|
|
fn encode_capture_mode(rbml_w: &mut Encoder, cm: CaptureMode) {
|
|
|
|
cm.encode(rbml_w).unwrap();
|
|
|
|
}
|
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
trait rbml_decoder_helper {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn read_freevar_entry(&mut self, xcx: &ExtendedDecodeContext)
|
2013-05-01 17:54:54 -07:00
|
|
|
-> freevar_entry;
|
2014-07-23 12:43:29 -07:00
|
|
|
fn read_capture_mode(&mut self) -> CaptureMode;
|
2012-07-11 15:00:40 -07:00
|
|
|
}
|
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
impl<'a> rbml_decoder_helper for reader::Decoder<'a> {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn read_freevar_entry(&mut self, xcx: &ExtendedDecodeContext)
|
2013-05-01 17:54:54 -07:00
|
|
|
-> freevar_entry {
|
2014-03-29 01:05:46 +01:00
|
|
|
let fv: freevar_entry = Decodable::decode(self).unwrap();
|
2012-02-14 15:21:53 -08:00
|
|
|
fv.tr(xcx)
|
|
|
|
}
|
2014-07-23 12:43:29 -07:00
|
|
|
|
|
|
|
fn read_capture_mode(&mut self) -> CaptureMode {
|
|
|
|
let cm: CaptureMode = Decodable::decode(self).unwrap();
|
|
|
|
cm
|
|
|
|
}
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2013-02-14 11:47:00 -08:00
|
|
|
impl tr for freevar_entry {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn tr(&self, xcx: &ExtendedDecodeContext) -> freevar_entry {
|
2013-01-16 19:24:10 -08:00
|
|
|
freevar_entry {
|
|
|
|
def: self.def.tr(xcx),
|
|
|
|
span: self.span.tr(xcx),
|
|
|
|
}
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-08-04 18:58:48 -07:00
|
|
|
impl tr for ty::UpvarBorrow {
|
|
|
|
fn tr(&self, xcx: &ExtendedDecodeContext) -> ty::UpvarBorrow {
|
|
|
|
ty::UpvarBorrow {
|
|
|
|
kind: self.kind,
|
|
|
|
region: self.region.tr(xcx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-14 15:21:53 -08:00
|
|
|
// ______________________________________________________________________
|
2014-02-26 16:06:45 +02:00
|
|
|
// Encoding and decoding of MethodCallee
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-02-26 16:06:45 +02:00
|
|
|
trait read_method_callee_helper {
|
2014-06-11 18:01:48 -04:00
|
|
|
fn read_method_callee(&mut self, xcx: &ExtendedDecodeContext)
|
|
|
|
-> (typeck::ExprAdjustment, MethodCallee);
|
2014-02-26 16:06:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn encode_method_callee(ecx: &e::EncodeContext,
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w: &mut Encoder,
|
2014-06-11 18:01:48 -04:00
|
|
|
adjustment: typeck::ExprAdjustment,
|
2014-02-26 16:06:45 +02:00
|
|
|
method: &MethodCallee) {
|
2014-08-12 20:31:30 -07:00
|
|
|
use serialize::Encoder;
|
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.emit_struct("MethodCallee", 4, |rbml_w| {
|
|
|
|
rbml_w.emit_struct_field("adjustment", 0u, |rbml_w| {
|
|
|
|
adjustment.encode(rbml_w)
|
2014-03-23 01:11:39 +02:00
|
|
|
});
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.emit_struct_field("origin", 1u, |rbml_w| {
|
|
|
|
method.origin.encode(rbml_w)
|
2014-02-26 16:06:45 +02:00
|
|
|
});
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.emit_struct_field("ty", 2u, |rbml_w| {
|
|
|
|
Ok(rbml_w.emit_ty(ecx, method.ty))
|
2014-02-26 16:06:45 +02:00
|
|
|
});
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.emit_struct_field("substs", 3u, |rbml_w| {
|
|
|
|
Ok(rbml_w.emit_substs(ecx, &method.substs))
|
2014-03-18 10:58:26 -07:00
|
|
|
})
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap();
|
2014-02-26 16:06:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> read_method_callee_helper for reader::Decoder<'a> {
|
2014-06-11 18:01:48 -04:00
|
|
|
fn read_method_callee(&mut self, xcx: &ExtendedDecodeContext)
|
|
|
|
-> (typeck::ExprAdjustment, MethodCallee) {
|
|
|
|
|
2014-03-29 01:05:46 +01:00
|
|
|
self.read_struct("MethodCallee", 4, |this| {
|
2014-06-11 18:01:48 -04:00
|
|
|
let adjustment = this.read_struct_field("adjustment", 0, |this| {
|
2014-03-23 01:11:39 +02:00
|
|
|
Decodable::decode(this)
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap();
|
2014-06-11 18:01:48 -04:00
|
|
|
Ok((adjustment, MethodCallee {
|
2014-03-29 01:05:46 +01:00
|
|
|
origin: this.read_struct_field("origin", 1, |this| {
|
2014-02-26 16:06:45 +02:00
|
|
|
let method_origin: MethodOrigin =
|
2014-03-29 01:05:46 +01:00
|
|
|
Decodable::decode(this).unwrap();
|
|
|
|
Ok(method_origin.tr(xcx))
|
|
|
|
}).unwrap(),
|
|
|
|
ty: this.read_struct_field("ty", 2, |this| {
|
|
|
|
Ok(this.read_ty(xcx))
|
|
|
|
}).unwrap(),
|
|
|
|
substs: this.read_struct_field("substs", 3, |this| {
|
|
|
|
Ok(this.read_substs(xcx))
|
|
|
|
}).unwrap()
|
2014-03-18 10:58:26 -07:00
|
|
|
}))
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap()
|
2014-02-26 16:06:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl tr for MethodOrigin {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn tr(&self, xcx: &ExtendedDecodeContext) -> MethodOrigin {
|
2013-02-22 01:41:37 -05:00
|
|
|
match *self {
|
2014-02-26 16:01:36 +02:00
|
|
|
typeck::MethodStatic(did) => typeck::MethodStatic(did.tr(xcx)),
|
2014-05-28 22:26:56 -07:00
|
|
|
typeck::MethodStaticUnboxedClosure(did) => {
|
|
|
|
typeck::MethodStaticUnboxedClosure(did.tr(xcx))
|
|
|
|
}
|
2014-02-26 16:01:36 +02:00
|
|
|
typeck::MethodParam(ref mp) => {
|
|
|
|
typeck::MethodParam(
|
|
|
|
typeck::MethodParam {
|
|
|
|
trait_id: mp.trait_id.tr(xcx),
|
|
|
|
.. *mp
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
typeck::MethodObject(ref mo) => {
|
|
|
|
typeck::MethodObject(
|
|
|
|
typeck::MethodObject {
|
|
|
|
trait_id: mo.trait_id.tr(xcx),
|
|
|
|
.. *mo
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2012-02-14 15:21:53 -08:00
|
|
|
// ______________________________________________________________________
|
2012-03-08 16:17:59 +01:00
|
|
|
// Encoding and decoding vtable_res
|
2012-02-14 15:21:53 -08:00
|
|
|
|
2014-03-23 01:11:39 +02:00
|
|
|
fn encode_vtable_res_with_key(ecx: &e::EncodeContext,
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w: &mut Encoder,
|
2014-06-11 18:01:48 -04:00
|
|
|
adjustment: typeck::ExprAdjustment,
|
2014-04-10 14:04:45 +03:00
|
|
|
dr: &typeck::vtable_res) {
|
2014-08-12 20:31:30 -07:00
|
|
|
use serialize::Encoder;
|
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.emit_struct("VtableWithKey", 2, |rbml_w| {
|
|
|
|
rbml_w.emit_struct_field("adjustment", 0u, |rbml_w| {
|
|
|
|
adjustment.encode(rbml_w)
|
2014-03-23 01:11:39 +02:00
|
|
|
});
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.emit_struct_field("vtable_res", 1u, |rbml_w| {
|
|
|
|
Ok(encode_vtable_res(ecx, rbml_w, dr))
|
2014-03-18 10:58:26 -07:00
|
|
|
})
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap()
|
2014-03-23 01:11:39 +02:00
|
|
|
}
|
|
|
|
|
2013-07-22 16:40:31 -07:00
|
|
|
pub fn encode_vtable_res(ecx: &e::EncodeContext,
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w: &mut Encoder,
|
2014-05-31 18:53:13 -04:00
|
|
|
dr: &typeck::vtable_res) {
|
2012-12-17 19:31:04 -08:00
|
|
|
// can't autogenerate this code because automatic code of
|
2012-02-14 15:21:53 -08:00
|
|
|
// ty::t doesn't work, and there is no way (atm) to have
|
2012-12-17 19:31:04 -08:00
|
|
|
// hand-written encoding routines combine with auto-generated
|
2014-05-31 18:53:13 -04:00
|
|
|
// ones. perhaps we should fix this.
|
|
|
|
encode_vec_per_param_space(
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w, dr,
|
|
|
|
|rbml_w, param_tables| encode_vtable_param_res(ecx, rbml_w,
|
2014-05-31 18:53:13 -04:00
|
|
|
param_tables))
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2013-07-22 16:40:31 -07:00
|
|
|
pub fn encode_vtable_param_res(ecx: &e::EncodeContext,
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w: &mut Encoder,
|
2014-04-10 14:04:45 +03:00
|
|
|
param_tables: &typeck::vtable_param_res) {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.emit_from_vec(param_tables.as_slice(), |rbml_w, vtable_origin| {
|
|
|
|
Ok(encode_vtable_origin(ecx, rbml_w, vtable_origin))
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap()
|
2013-07-22 16:40:31 -07:00
|
|
|
}
|
|
|
|
|
2014-07-29 22:08:39 -07:00
|
|
|
pub fn encode_unboxed_closure_kind(ebml_w: &mut Encoder,
|
|
|
|
kind: ty::UnboxedClosureKind) {
|
2014-08-12 20:31:30 -07:00
|
|
|
use serialize::Encoder;
|
|
|
|
|
2014-07-29 22:08:39 -07:00
|
|
|
ebml_w.emit_enum("UnboxedClosureKind", |ebml_w| {
|
|
|
|
match kind {
|
|
|
|
ty::FnUnboxedClosureKind => {
|
|
|
|
ebml_w.emit_enum_variant("FnUnboxedClosureKind", 0, 3, |_| {
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
ty::FnMutUnboxedClosureKind => {
|
|
|
|
ebml_w.emit_enum_variant("FnMutUnboxedClosureKind", 1, 3, |_| {
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
ty::FnOnceUnboxedClosureKind => {
|
|
|
|
ebml_w.emit_enum_variant("FnOnceUnboxedClosureKind",
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
|_| {
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).unwrap()
|
|
|
|
}
|
2013-07-22 16:40:31 -07:00
|
|
|
|
|
|
|
pub fn encode_vtable_origin(ecx: &e::EncodeContext,
|
2014-07-29 22:08:39 -07:00
|
|
|
rbml_w: &mut Encoder,
|
|
|
|
vtable_origin: &typeck::vtable_origin) {
|
2014-08-12 20:31:30 -07:00
|
|
|
use serialize::Encoder;
|
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.emit_enum("vtable_origin", |rbml_w| {
|
2013-04-17 12:15:37 -04:00
|
|
|
match *vtable_origin {
|
2014-05-07 07:20:15 -04:00
|
|
|
typeck::vtable_static(def_id, ref substs, ref vtable_res) => {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.emit_enum_variant("vtable_static", 0u, 3u, |rbml_w| {
|
|
|
|
rbml_w.emit_enum_variant_arg(0u, |rbml_w| {
|
|
|
|
Ok(rbml_w.emit_def_id(def_id))
|
2013-11-21 15:42:55 -08:00
|
|
|
});
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.emit_enum_variant_arg(1u, |rbml_w| {
|
|
|
|
Ok(rbml_w.emit_substs(ecx, substs))
|
2013-11-21 15:42:55 -08:00
|
|
|
});
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.emit_enum_variant_arg(2u, |rbml_w| {
|
|
|
|
Ok(encode_vtable_res(ecx, rbml_w, vtable_res))
|
2013-11-21 15:42:55 -08:00
|
|
|
})
|
|
|
|
})
|
2012-02-07 21:19:53 -08:00
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
typeck::vtable_param(pn, bn) => {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.emit_enum_variant("vtable_param", 1u, 3u, |rbml_w| {
|
|
|
|
rbml_w.emit_enum_variant_arg(0u, |rbml_w| {
|
|
|
|
pn.encode(rbml_w)
|
2013-11-21 15:42:55 -08:00
|
|
|
});
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.emit_enum_variant_arg(1u, |rbml_w| {
|
|
|
|
rbml_w.emit_uint(bn)
|
2013-11-21 15:42:55 -08:00
|
|
|
})
|
|
|
|
})
|
2012-02-07 21:19:53 -08:00
|
|
|
}
|
2014-05-28 22:26:56 -07:00
|
|
|
typeck::vtable_unboxed_closure(def_id) => {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.emit_enum_variant("vtable_unboxed_closure",
|
2014-05-28 22:26:56 -07:00
|
|
|
2u,
|
|
|
|
1u,
|
2014-07-29 17:06:37 -07:00
|
|
|
|rbml_w| {
|
|
|
|
rbml_w.emit_enum_variant_arg(0u, |rbml_w| {
|
|
|
|
Ok(rbml_w.emit_def_id(def_id))
|
2014-05-28 22:26:56 -07:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2014-05-31 18:53:13 -04:00
|
|
|
typeck::vtable_error => {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.emit_enum_variant("vtable_error", 3u, 3u, |_rbml_w| {
|
2014-05-31 18:53:13 -04:00
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
}
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap()
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2013-07-22 16:40:31 -07:00
|
|
|
pub trait vtable_decoder_helpers {
|
2014-05-31 18:53:13 -04:00
|
|
|
fn read_vec_per_param_space<T>(&mut self,
|
|
|
|
f: |&mut Self| -> T)
|
|
|
|
-> VecPerParamSpace<T>;
|
2014-03-23 01:11:39 +02:00
|
|
|
fn read_vtable_res_with_key(&mut self,
|
|
|
|
tcx: &ty::ctxt,
|
2014-04-17 15:06:25 +03:00
|
|
|
cdata: &cstore::crate_metadata)
|
2014-06-11 18:01:48 -04:00
|
|
|
-> (typeck::ExprAdjustment, typeck::vtable_res);
|
2013-07-22 16:40:31 -07:00
|
|
|
fn read_vtable_res(&mut self,
|
2014-04-17 15:06:25 +03:00
|
|
|
tcx: &ty::ctxt, cdata: &cstore::crate_metadata)
|
2013-02-22 01:41:37 -05:00
|
|
|
-> typeck::vtable_res;
|
2013-07-22 16:40:31 -07:00
|
|
|
fn read_vtable_param_res(&mut self,
|
2014-04-17 15:06:25 +03:00
|
|
|
tcx: &ty::ctxt, cdata: &cstore::crate_metadata)
|
2013-07-22 16:40:31 -07:00
|
|
|
-> typeck::vtable_param_res;
|
|
|
|
fn read_vtable_origin(&mut self,
|
2014-04-17 15:06:25 +03:00
|
|
|
tcx: &ty::ctxt, cdata: &cstore::crate_metadata)
|
2013-05-01 17:54:54 -07:00
|
|
|
-> typeck::vtable_origin;
|
2012-07-11 15:00:40 -07:00
|
|
|
}
|
|
|
|
|
2013-12-18 14:10:28 -08:00
|
|
|
impl<'a> vtable_decoder_helpers for reader::Decoder<'a> {
|
2014-05-31 18:53:13 -04:00
|
|
|
fn read_vec_per_param_space<T>(&mut self,
|
|
|
|
f: |&mut reader::Decoder<'a>| -> T)
|
|
|
|
-> VecPerParamSpace<T>
|
|
|
|
{
|
|
|
|
let types = self.read_to_vec(|this| Ok(f(this))).unwrap();
|
|
|
|
let selfs = self.read_to_vec(|this| Ok(f(this))).unwrap();
|
|
|
|
let fns = self.read_to_vec(|this| Ok(f(this))).unwrap();
|
|
|
|
VecPerParamSpace::new(types, selfs, fns)
|
|
|
|
}
|
|
|
|
|
2014-03-23 01:11:39 +02:00
|
|
|
fn read_vtable_res_with_key(&mut self,
|
|
|
|
tcx: &ty::ctxt,
|
2014-04-17 15:06:25 +03:00
|
|
|
cdata: &cstore::crate_metadata)
|
2014-06-11 18:01:48 -04:00
|
|
|
-> (typeck::ExprAdjustment, typeck::vtable_res) {
|
2014-03-29 01:05:46 +01:00
|
|
|
self.read_struct("VtableWithKey", 2, |this| {
|
2014-06-11 18:01:48 -04:00
|
|
|
let adjustment = this.read_struct_field("adjustment", 0, |this| {
|
2014-03-23 01:11:39 +02:00
|
|
|
Decodable::decode(this)
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap();
|
2014-06-11 18:01:48 -04:00
|
|
|
Ok((adjustment, this.read_struct_field("vtable_res", 1, |this| {
|
2014-03-29 01:05:46 +01:00
|
|
|
Ok(this.read_vtable_res(tcx, cdata))
|
|
|
|
}).unwrap()))
|
|
|
|
}).unwrap()
|
2014-03-23 01:11:39 +02:00
|
|
|
}
|
|
|
|
|
2013-07-22 16:40:31 -07:00
|
|
|
fn read_vtable_res(&mut self,
|
2014-05-31 18:53:13 -04:00
|
|
|
tcx: &ty::ctxt,
|
|
|
|
cdata: &cstore::crate_metadata)
|
|
|
|
-> typeck::vtable_res
|
|
|
|
{
|
|
|
|
self.read_vec_per_param_space(
|
|
|
|
|this| this.read_vtable_param_res(tcx, cdata))
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2013-07-22 16:40:31 -07:00
|
|
|
fn read_vtable_param_res(&mut self,
|
2014-04-17 15:06:25 +03:00
|
|
|
tcx: &ty::ctxt, cdata: &cstore::crate_metadata)
|
2013-07-22 16:40:31 -07:00
|
|
|
-> typeck::vtable_param_res {
|
2014-04-10 14:04:45 +03:00
|
|
|
self.read_to_vec(|this| Ok(this.read_vtable_origin(tcx, cdata)))
|
|
|
|
.unwrap().move_iter().collect()
|
2013-07-22 16:40:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn read_vtable_origin(&mut self,
|
2014-04-17 15:06:25 +03:00
|
|
|
tcx: &ty::ctxt, cdata: &cstore::crate_metadata)
|
2013-03-26 18:46:48 -07:00
|
|
|
-> typeck::vtable_origin {
|
2014-03-29 01:05:46 +01:00
|
|
|
self.read_enum("vtable_origin", |this| {
|
2013-11-21 15:42:55 -08:00
|
|
|
this.read_enum_variant(["vtable_static",
|
|
|
|
"vtable_param",
|
2014-05-28 22:26:56 -07:00
|
|
|
"vtable_error",
|
|
|
|
"vtable_unboxed_closure"],
|
2013-11-21 15:42:55 -08:00
|
|
|
|this, i| {
|
2014-03-29 01:05:46 +01:00
|
|
|
Ok(match i {
|
2013-03-26 18:46:48 -07:00
|
|
|
0 => {
|
|
|
|
typeck::vtable_static(
|
2014-03-29 01:05:46 +01:00
|
|
|
this.read_enum_variant_arg(0u, |this| {
|
|
|
|
Ok(this.read_def_id_noxcx(cdata))
|
|
|
|
}).unwrap(),
|
|
|
|
this.read_enum_variant_arg(1u, |this| {
|
2014-05-07 07:20:15 -04:00
|
|
|
Ok(this.read_substs_noxcx(tcx, cdata))
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap(),
|
|
|
|
this.read_enum_variant_arg(2u, |this| {
|
|
|
|
Ok(this.read_vtable_res(tcx, cdata))
|
|
|
|
}).unwrap()
|
2012-02-14 15:21:53 -08:00
|
|
|
)
|
|
|
|
}
|
2012-08-21 17:22:45 -07:00
|
|
|
1 => {
|
2012-03-08 16:17:59 +01:00
|
|
|
typeck::vtable_param(
|
2014-03-29 01:05:46 +01:00
|
|
|
this.read_enum_variant_arg(0u, |this| {
|
2013-07-22 17:42:45 -07:00
|
|
|
Decodable::decode(this)
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap(),
|
|
|
|
this.read_enum_variant_arg(1u, |this| {
|
2013-05-01 17:54:54 -07:00
|
|
|
this.read_uint()
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap()
|
2012-02-14 15:21:53 -08:00
|
|
|
)
|
|
|
|
}
|
2014-05-31 18:53:13 -04:00
|
|
|
2 => {
|
2014-05-28 22:26:56 -07:00
|
|
|
typeck::vtable_unboxed_closure(
|
|
|
|
this.read_enum_variant_arg(0u, |this| {
|
|
|
|
Ok(this.read_def_id_noxcx(cdata))
|
|
|
|
}).unwrap()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
3 => {
|
2014-05-31 18:53:13 -04:00
|
|
|
typeck::vtable_error
|
|
|
|
}
|
2013-10-21 13:08:31 -07:00
|
|
|
_ => fail!("bad enum variant")
|
2014-03-18 10:58:26 -07:00
|
|
|
})
|
2013-11-21 15:42:55 -08:00
|
|
|
})
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap()
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-05-31 18:53:13 -04:00
|
|
|
// ___________________________________________________________________________
|
|
|
|
//
|
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
fn encode_vec_per_param_space<T>(rbml_w: &mut Encoder,
|
2014-05-31 18:53:13 -04:00
|
|
|
v: &subst::VecPerParamSpace<T>,
|
|
|
|
f: |&mut Encoder, &T|) {
|
|
|
|
for &space in subst::ParamSpace::all().iter() {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.emit_from_vec(v.get_slice(space),
|
|
|
|
|rbml_w, n| Ok(f(rbml_w, n))).unwrap();
|
2014-05-31 18:53:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-14 15:21:53 -08:00
|
|
|
// ______________________________________________________________________
|
|
|
|
// Encoding and decoding the side tables
|
|
|
|
|
2012-07-11 15:00:40 -07:00
|
|
|
trait get_ty_str_ctxt {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn ty_str_ctxt<'a>(&'a self) -> tyencode::ctxt<'a>;
|
2012-07-11 15:00:40 -07:00
|
|
|
}
|
|
|
|
|
2013-12-09 23:16:18 -08:00
|
|
|
impl<'a> get_ty_str_ctxt for e::EncodeContext<'a> {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn ty_str_ctxt<'a>(&'a self) -> tyencode::ctxt<'a> {
|
|
|
|
tyencode::ctxt {
|
2013-06-14 18:21:47 -07:00
|
|
|
diag: self.tcx.sess.diagnostic(),
|
2014-06-21 03:39:03 -07:00
|
|
|
ds: e::def_to_string,
|
2013-06-14 18:21:47 -07:00
|
|
|
tcx: self.tcx,
|
2014-04-22 19:06:43 +03:00
|
|
|
abbrevs: &self.type_abbrevs
|
2013-06-14 18:21:47 -07:00
|
|
|
}
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
trait rbml_writer_helpers {
|
2014-05-28 22:26:56 -07:00
|
|
|
fn emit_closure_type(&mut self,
|
|
|
|
ecx: &e::EncodeContext,
|
|
|
|
closure_type: &ty::ClosureTy);
|
2013-06-13 19:19:50 +12:00
|
|
|
fn emit_ty(&mut self, ecx: &e::EncodeContext, ty: ty::t);
|
|
|
|
fn emit_tys(&mut self, ecx: &e::EncodeContext, tys: &[ty::t]);
|
2013-05-01 17:54:54 -07:00
|
|
|
fn emit_type_param_def(&mut self,
|
2013-06-13 19:19:50 +12:00
|
|
|
ecx: &e::EncodeContext,
|
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
|
|
|
type_param_def: &ty::TypeParameterDef);
|
2014-05-06 15:59:45 -04:00
|
|
|
fn emit_polytype(&mut self,
|
|
|
|
ecx: &e::EncodeContext,
|
|
|
|
pty: ty::Polytype);
|
2014-05-13 11:35:42 -04:00
|
|
|
fn emit_substs(&mut self, ecx: &e::EncodeContext, substs: &subst::Substs);
|
2013-12-26 13:54:41 -05:00
|
|
|
fn emit_auto_adjustment(&mut self, ecx: &e::EncodeContext, adj: &ty::AutoAdjustment);
|
2012-07-11 15:00:40 -07:00
|
|
|
}
|
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
impl<'a> rbml_writer_helpers for Encoder<'a> {
|
2014-05-28 22:26:56 -07:00
|
|
|
fn emit_closure_type(&mut self,
|
|
|
|
ecx: &e::EncodeContext,
|
|
|
|
closure_type: &ty::ClosureTy) {
|
|
|
|
self.emit_opaque(|this| {
|
|
|
|
Ok(e::write_closure_type(ecx, this, closure_type))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-06-13 19:19:50 +12:00
|
|
|
fn emit_ty(&mut self, ecx: &e::EncodeContext, ty: ty::t) {
|
2014-03-29 01:05:46 +01:00
|
|
|
self.emit_opaque(|this| Ok(e::write_type(ecx, this, ty)));
|
2012-09-11 21:25:01 -07:00
|
|
|
}
|
|
|
|
|
2013-06-13 19:19:50 +12:00
|
|
|
fn emit_tys(&mut self, ecx: &e::EncodeContext, tys: &[ty::t]) {
|
2014-03-29 01:05:46 +01:00
|
|
|
self.emit_from_vec(tys, |this, ty| Ok(this.emit_ty(ecx, *ty)));
|
2012-02-07 21:19:53 -08:00
|
|
|
}
|
|
|
|
|
2013-05-01 17:54:54 -07:00
|
|
|
fn emit_type_param_def(&mut self,
|
2013-06-13 19:19:50 +12:00
|
|
|
ecx: &e::EncodeContext,
|
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
|
|
|
type_param_def: &ty::TypeParameterDef) {
|
2013-11-21 15:42:55 -08:00
|
|
|
self.emit_opaque(|this| {
|
2014-03-29 01:05:46 +01:00
|
|
|
Ok(tyencode::enc_type_param_def(this.writer,
|
2014-03-06 05:28:28 +02:00
|
|
|
&ecx.ty_str_ctxt(),
|
2014-03-18 10:58:26 -07:00
|
|
|
type_param_def))
|
|
|
|
});
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
|
|
|
|
2014-05-06 15:59:45 -04:00
|
|
|
fn emit_polytype(&mut self,
|
2013-06-13 19:19:50 +12:00
|
|
|
ecx: &e::EncodeContext,
|
2014-05-06 15:59:45 -04:00
|
|
|
pty: ty::Polytype) {
|
2014-08-12 20:31:30 -07:00
|
|
|
use serialize::Encoder;
|
|
|
|
|
2014-05-06 15:59:45 -04:00
|
|
|
self.emit_struct("Polytype", 2, |this| {
|
2013-11-21 15:42:55 -08:00
|
|
|
this.emit_struct_field("generics", 0, |this| {
|
|
|
|
this.emit_struct("Generics", 2, |this| {
|
2014-05-31 18:53:13 -04:00
|
|
|
this.emit_struct_field("types", 0, |this| {
|
|
|
|
Ok(encode_vec_per_param_space(
|
2014-05-06 15:59:45 -04:00
|
|
|
this, &pty.generics.types,
|
2014-05-31 18:53:13 -04:00
|
|
|
|this, def| this.emit_type_param_def(ecx, def)))
|
2013-11-21 15:42:55 -08:00
|
|
|
});
|
2014-05-31 18:53:13 -04:00
|
|
|
this.emit_struct_field("regions", 1, |this| {
|
|
|
|
Ok(encode_vec_per_param_space(
|
2014-05-06 15:59:45 -04:00
|
|
|
this, &pty.generics.regions,
|
2014-05-31 18:53:13 -04:00
|
|
|
|this, def| def.encode(this).unwrap()))
|
2013-11-21 15:42:55 -08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
this.emit_struct_field("ty", 1, |this| {
|
2014-05-06 15:59:45 -04:00
|
|
|
Ok(this.emit_ty(ecx, pty.ty))
|
2013-11-21 15:42:55 -08:00
|
|
|
})
|
2014-03-18 10:58:26 -07:00
|
|
|
});
|
2013-04-09 19:41:20 -07:00
|
|
|
}
|
2013-12-26 13:54:41 -05:00
|
|
|
|
2014-05-13 11:35:42 -04:00
|
|
|
fn emit_substs(&mut self, ecx: &e::EncodeContext, substs: &subst::Substs) {
|
2014-03-29 01:05:46 +01:00
|
|
|
self.emit_opaque(|this| Ok(tyencode::enc_substs(this.writer,
|
2014-03-18 10:58:26 -07:00
|
|
|
&ecx.ty_str_ctxt(),
|
|
|
|
substs)));
|
2013-12-26 13:54:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn emit_auto_adjustment(&mut self, ecx: &e::EncodeContext, adj: &ty::AutoAdjustment) {
|
2014-08-12 20:31:30 -07:00
|
|
|
use serialize::Encoder;
|
|
|
|
|
2013-12-26 13:54:41 -05:00
|
|
|
self.emit_enum("AutoAdjustment", |this| {
|
|
|
|
match *adj {
|
2014-04-11 18:03:10 +03:00
|
|
|
ty::AutoAddEnv(store) => {
|
|
|
|
this.emit_enum_variant("AutoAddEnv", 0, 1, |this| {
|
|
|
|
this.emit_enum_variant_arg(0, |this| store.encode(this))
|
2014-03-18 10:58:26 -07:00
|
|
|
})
|
2013-12-26 13:54:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ty::AutoDerefRef(ref auto_deref_ref) => {
|
|
|
|
this.emit_enum_variant("AutoDerefRef", 1, 1, |this| {
|
2014-03-18 10:58:26 -07:00
|
|
|
this.emit_enum_variant_arg(0, |this| auto_deref_ref.encode(this))
|
|
|
|
})
|
2013-12-26 13:54:41 -05:00
|
|
|
}
|
|
|
|
|
2014-04-11 09:01:31 +03:00
|
|
|
ty::AutoObject(store, b, def_id, ref substs) => {
|
|
|
|
this.emit_enum_variant("AutoObject", 2, 4, |this| {
|
|
|
|
this.emit_enum_variant_arg(0, |this| store.encode(this));
|
|
|
|
this.emit_enum_variant_arg(1, |this| b.encode(this));
|
|
|
|
this.emit_enum_variant_arg(2, |this| def_id.encode(this));
|
|
|
|
this.emit_enum_variant_arg(3, |this| Ok(this.emit_substs(ecx, substs)))
|
2014-03-18 10:58:26 -07:00
|
|
|
})
|
2013-12-26 13:54:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2012-07-11 15:00:40 -07:00
|
|
|
trait write_tag_and_id {
|
2013-11-19 13:22:03 -08:00
|
|
|
fn tag(&mut self, tag_id: c::astencode_tag, f: |&mut Self|);
|
2013-07-27 10:25:59 +02:00
|
|
|
fn id(&mut self, id: ast::NodeId);
|
2012-07-11 15:00:40 -07:00
|
|
|
}
|
|
|
|
|
2014-03-18 10:58:26 -07:00
|
|
|
impl<'a> write_tag_and_id for Encoder<'a> {
|
2013-12-20 17:36:07 -08:00
|
|
|
fn tag(&mut self,
|
|
|
|
tag_id: c::astencode_tag,
|
2014-03-18 10:58:26 -07:00
|
|
|
f: |&mut Encoder<'a>|) {
|
2013-05-01 17:54:54 -07:00
|
|
|
self.start_tag(tag_id as uint);
|
|
|
|
f(self);
|
|
|
|
self.end_tag();
|
2012-02-07 21:19:53 -08:00
|
|
|
}
|
|
|
|
|
2013-07-27 10:25:59 +02:00
|
|
|
fn id(&mut self, id: ast::NodeId) {
|
2014-03-18 10:58:26 -07:00
|
|
|
self.wr_tagged_u64(c::tag_table_id as uint, id as u64);
|
2012-02-07 21:19:53 -08:00
|
|
|
}
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2013-12-20 17:36:07 -08:00
|
|
|
struct SideTableEncodingIdVisitor<'a,'b> {
|
2014-06-25 12:47:34 -07:00
|
|
|
ecx_ptr: *const libc::c_void,
|
2014-07-29 17:06:37 -07:00
|
|
|
new_rbml_w: &'a mut Encoder<'b>,
|
2013-08-29 19:01:19 -07:00
|
|
|
}
|
|
|
|
|
2013-12-20 17:36:07 -08:00
|
|
|
impl<'a,'b> ast_util::IdVisitingOperation for
|
|
|
|
SideTableEncodingIdVisitor<'a,'b> {
|
2013-08-29 19:01:19 -07:00
|
|
|
fn visit_id(&self, id: ast::NodeId) {
|
2014-07-29 17:06:37 -07:00
|
|
|
// Note: this will cause a copy of rbml_w, which is bad as
|
2013-08-29 19:01:19 -07:00
|
|
|
// it is mutable. But I believe it's harmless since we generate
|
|
|
|
// balanced EBML.
|
2013-12-20 17:36:07 -08:00
|
|
|
//
|
2014-01-26 03:43:42 -05:00
|
|
|
// FIXME(pcwalton): Don't copy this way.
|
2014-07-29 17:06:37 -07:00
|
|
|
let mut new_rbml_w = unsafe {
|
|
|
|
self.new_rbml_w.unsafe_clone()
|
2013-12-20 17:36:07 -08:00
|
|
|
};
|
2013-08-29 19:01:19 -07:00
|
|
|
// See above
|
|
|
|
let ecx: &e::EncodeContext = unsafe {
|
core: Remove the cast module
This commit revisits the `cast` module in libcore and libstd, and scrutinizes
all functions inside of it. The result was to remove the `cast` module entirely,
folding all functionality into the `mem` module. Specifically, this is the fate
of each function in the `cast` module.
* transmute - This function was moved to `mem`, but it is now marked as
#[unstable]. This is due to planned changes to the `transmute`
function and how it can be invoked (see the #[unstable] comment).
For more information, see RFC 5 and #12898
* transmute_copy - This function was moved to `mem`, with clarification that is
is not an error to invoke it with T/U that are different
sizes, but rather that it is strongly discouraged. This
function is now #[stable]
* forget - This function was moved to `mem` and marked #[stable]
* bump_box_refcount - This function was removed due to the deprecation of
managed boxes as well as its questionable utility.
* transmute_mut - This function was previously deprecated, and removed as part
of this commit.
* transmute_mut_unsafe - This function doesn't serve much of a purpose when it
can be achieved with an `as` in safe code, so it was
removed.
* transmute_lifetime - This function was removed because it is likely a strong
indication that code is incorrect in the first place.
* transmute_mut_lifetime - This function was removed for the same reasons as
`transmute_lifetime`
* copy_lifetime - This function was moved to `mem`, but it is marked
`#[unstable]` now due to the likelihood of being removed in
the future if it is found to not be very useful.
* copy_mut_lifetime - This function was also moved to `mem`, but had the same
treatment as `copy_lifetime`.
* copy_lifetime_vec - This function was removed because it is not used today,
and its existence is not necessary with DST
(copy_lifetime will suffice).
In summary, the cast module was stripped down to these functions, and then the
functions were moved to the `mem` module.
transmute - #[unstable]
transmute_copy - #[stable]
forget - #[stable]
copy_lifetime - #[unstable]
copy_mut_lifetime - #[unstable]
[breaking-change]
2014-05-09 10:34:51 -07:00
|
|
|
mem::transmute(self.ecx_ptr)
|
2013-08-29 19:01:19 -07:00
|
|
|
};
|
2014-07-29 17:06:37 -07:00
|
|
|
encode_side_tables_for_id(ecx, &mut new_rbml_w, id)
|
2013-08-29 19:01:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 19:19:50 +12:00
|
|
|
fn encode_side_tables_for_ii(ecx: &e::EncodeContext,
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w: &mut Encoder,
|
2014-01-09 15:05:33 +02:00
|
|
|
ii: &ast::InlinedItem) {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.start_tag(c::tag_table as uint);
|
|
|
|
let mut new_rbml_w = unsafe {
|
|
|
|
rbml_w.unsafe_clone()
|
2013-12-20 17:36:07 -08:00
|
|
|
};
|
2013-06-13 19:19:50 +12:00
|
|
|
|
2013-08-29 19:01:19 -07:00
|
|
|
// Because the ast visitor uses @IdVisitingOperation, I can't pass in
|
|
|
|
// ecx directly, but /I/ know that it'll be fine since the lifetime is
|
|
|
|
// tied to the CrateContext that lives throughout this entire section.
|
2013-10-02 11:29:29 -07:00
|
|
|
ast_util::visit_ids_for_inlined_item(ii, &SideTableEncodingIdVisitor {
|
2013-08-29 19:01:19 -07:00
|
|
|
ecx_ptr: unsafe {
|
core: Remove the cast module
This commit revisits the `cast` module in libcore and libstd, and scrutinizes
all functions inside of it. The result was to remove the `cast` module entirely,
folding all functionality into the `mem` module. Specifically, this is the fate
of each function in the `cast` module.
* transmute - This function was moved to `mem`, but it is now marked as
#[unstable]. This is due to planned changes to the `transmute`
function and how it can be invoked (see the #[unstable] comment).
For more information, see RFC 5 and #12898
* transmute_copy - This function was moved to `mem`, with clarification that is
is not an error to invoke it with T/U that are different
sizes, but rather that it is strongly discouraged. This
function is now #[stable]
* forget - This function was moved to `mem` and marked #[stable]
* bump_box_refcount - This function was removed due to the deprecation of
managed boxes as well as its questionable utility.
* transmute_mut - This function was previously deprecated, and removed as part
of this commit.
* transmute_mut_unsafe - This function doesn't serve much of a purpose when it
can be achieved with an `as` in safe code, so it was
removed.
* transmute_lifetime - This function was removed because it is likely a strong
indication that code is incorrect in the first place.
* transmute_mut_lifetime - This function was removed for the same reasons as
`transmute_lifetime`
* copy_lifetime - This function was moved to `mem`, but it is marked
`#[unstable]` now due to the likelihood of being removed in
the future if it is found to not be very useful.
* copy_mut_lifetime - This function was also moved to `mem`, but had the same
treatment as `copy_lifetime`.
* copy_lifetime_vec - This function was removed because it is not used today,
and its existence is not necessary with DST
(copy_lifetime will suffice).
In summary, the cast module was stripped down to these functions, and then the
functions were moved to the `mem` module.
transmute - #[unstable]
transmute_copy - #[stable]
forget - #[stable]
copy_lifetime - #[unstable]
copy_mut_lifetime - #[unstable]
[breaking-change]
2014-05-09 10:34:51 -07:00
|
|
|
mem::transmute(ecx)
|
2013-08-29 19:01:19 -07:00
|
|
|
},
|
2014-07-29 17:06:37 -07:00
|
|
|
new_rbml_w: &mut new_rbml_w,
|
2013-10-02 11:29:29 -07:00
|
|
|
});
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.end_tag();
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2013-06-13 19:19:50 +12:00
|
|
|
fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w: &mut Encoder,
|
2013-07-27 10:25:59 +02:00
|
|
|
id: ast::NodeId) {
|
2012-05-13 17:01:52 -07:00
|
|
|
let tcx = ecx.tcx;
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("Encoding side tables for id {}", id);
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-03-20 19:49:20 -07:00
|
|
|
for def in tcx.def_map.borrow().find(&id).iter() {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.tag(c::tag_table_def, |rbml_w| {
|
|
|
|
rbml_w.id(id);
|
|
|
|
rbml_w.tag(c::tag_table_val, |rbml_w| (*def).encode(rbml_w).unwrap());
|
2014-03-20 19:49:20 -07:00
|
|
|
})
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2013-03-03 07:33:39 -05:00
|
|
|
|
2014-03-20 19:49:20 -07:00
|
|
|
for &ty in tcx.node_types.borrow().find(&(id as uint)).iter() {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.tag(c::tag_table_node_type, |rbml_w| {
|
|
|
|
rbml_w.id(id);
|
|
|
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
|
|
|
rbml_w.emit_ty(ecx, *ty);
|
2013-11-21 15:42:55 -08:00
|
|
|
})
|
2014-03-20 19:49:20 -07:00
|
|
|
})
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-05-07 07:20:15 -04:00
|
|
|
for &item_substs in tcx.item_substs.borrow().find(&id).iter() {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.tag(c::tag_table_item_subst, |rbml_w| {
|
|
|
|
rbml_w.id(id);
|
|
|
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
|
|
|
rbml_w.emit_substs(ecx, &item_substs.substs);
|
2013-11-21 15:42:55 -08:00
|
|
|
})
|
2014-03-20 19:49:20 -07:00
|
|
|
})
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-03-20 19:49:20 -07:00
|
|
|
for &fv in tcx.freevars.borrow().find(&id).iter() {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.tag(c::tag_table_freevars, |rbml_w| {
|
|
|
|
rbml_w.id(id);
|
|
|
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
|
|
|
rbml_w.emit_from_vec(fv.as_slice(), |rbml_w, fv_entry| {
|
|
|
|
Ok(encode_freevar_entry(rbml_w, fv_entry))
|
2014-03-18 10:58:26 -07:00
|
|
|
});
|
2013-11-21 15:42:55 -08:00
|
|
|
})
|
2014-08-04 18:58:48 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
for freevar in fv.iter() {
|
|
|
|
match freevars::get_capture_mode(tcx, id) {
|
|
|
|
freevars::CaptureByRef => {
|
|
|
|
rbml_w.tag(c::tag_table_upvar_borrow_map, |rbml_w| {
|
|
|
|
rbml_w.id(id);
|
|
|
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
|
|
|
let var_id = freevar.def.def_id().node;
|
|
|
|
let upvar_id = ty::UpvarId {
|
|
|
|
var_id: var_id,
|
|
|
|
closure_expr_id: id
|
|
|
|
};
|
|
|
|
let upvar_borrow = tcx.upvar_borrow_map.borrow()
|
|
|
|
.get_copy(&upvar_id);
|
|
|
|
var_id.encode(rbml_w);
|
|
|
|
upvar_borrow.encode(rbml_w);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-07-23 12:43:29 -07:00
|
|
|
for &cm in tcx.capture_modes.borrow().find(&id).iter() {
|
|
|
|
rbml_w.tag(c::tag_table_capture_modes, |rbml_w| {
|
|
|
|
rbml_w.id(id);
|
|
|
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
|
|
|
encode_capture_mode(rbml_w, *cm);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-02-05 22:15:24 +01:00
|
|
|
let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
|
2014-05-06 15:59:45 -04:00
|
|
|
for &pty in tcx.tcache.borrow().find(&lid).iter() {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.tag(c::tag_table_tcache, |rbml_w| {
|
|
|
|
rbml_w.id(id);
|
|
|
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
|
|
|
rbml_w.emit_polytype(ecx, pty.clone());
|
2013-11-21 15:42:55 -08:00
|
|
|
})
|
2014-03-20 19:49:20 -07:00
|
|
|
})
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-03-20 19:49:20 -07:00
|
|
|
for &type_param_def in tcx.ty_param_defs.borrow().find(&id).iter() {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.tag(c::tag_table_param_defs, |rbml_w| {
|
|
|
|
rbml_w.id(id);
|
|
|
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
|
|
|
rbml_w.emit_type_param_def(ecx, type_param_def)
|
2013-11-21 15:42:55 -08:00
|
|
|
})
|
2014-03-20 19:49:20 -07:00
|
|
|
})
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-03-06 19:24:11 +02:00
|
|
|
let method_call = MethodCall::expr(id);
|
2014-04-09 18:18:40 +03:00
|
|
|
for &method in tcx.method_map.borrow().find(&method_call).iter() {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
|
|
|
|
rbml_w.id(id);
|
|
|
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
|
|
|
encode_method_callee(ecx, rbml_w, method_call.adjustment, method)
|
2013-11-21 15:42:55 -08:00
|
|
|
})
|
2014-02-26 16:06:45 +02:00
|
|
|
})
|
2012-02-07 21:19:53 -08:00
|
|
|
}
|
|
|
|
|
2014-04-09 18:18:40 +03:00
|
|
|
for &dr in tcx.vtable_map.borrow().find(&method_call).iter() {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.tag(c::tag_table_vtable_map, |rbml_w| {
|
|
|
|
rbml_w.id(id);
|
|
|
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
|
|
|
encode_vtable_res_with_key(ecx, rbml_w, method_call.adjustment, dr);
|
2013-11-21 15:42:55 -08:00
|
|
|
})
|
2014-03-20 19:49:20 -07:00
|
|
|
})
|
2012-02-07 21:19:53 -08:00
|
|
|
}
|
2012-04-23 15:23:20 -07:00
|
|
|
|
2014-04-10 16:26:26 +03:00
|
|
|
for &adj in tcx.adjustments.borrow().find(&id).iter() {
|
|
|
|
match *adj {
|
2014-03-23 01:11:39 +02:00
|
|
|
ty::AutoDerefRef(adj) => {
|
|
|
|
for autoderef in range(0, adj.autoderefs) {
|
2014-06-11 18:01:48 -04:00
|
|
|
let method_call = MethodCall::autoderef(id, autoderef);
|
2014-04-09 18:18:40 +03:00
|
|
|
for &method in tcx.method_map.borrow().find(&method_call).iter() {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
|
|
|
|
rbml_w.id(id);
|
|
|
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
|
|
|
encode_method_callee(ecx, rbml_w,
|
2014-06-11 18:01:48 -04:00
|
|
|
method_call.adjustment, method)
|
2014-03-23 01:11:39 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-04-09 18:18:40 +03:00
|
|
|
for &dr in tcx.vtable_map.borrow().find(&method_call).iter() {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.tag(c::tag_table_vtable_map, |rbml_w| {
|
|
|
|
rbml_w.id(id);
|
|
|
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
|
|
|
encode_vtable_res_with_key(ecx, rbml_w,
|
2014-06-11 18:01:48 -04:00
|
|
|
method_call.adjustment, dr);
|
2014-03-23 01:11:39 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-11 18:01:48 -04:00
|
|
|
ty::AutoObject(..) => {
|
|
|
|
let method_call = MethodCall::autoobject(id);
|
|
|
|
for &method in tcx.method_map.borrow().find(&method_call).iter() {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
|
|
|
|
rbml_w.id(id);
|
|
|
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
|
|
|
encode_method_callee(ecx, rbml_w, method_call.adjustment, method)
|
2014-06-11 18:01:48 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
for &dr in tcx.vtable_map.borrow().find(&method_call).iter() {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.tag(c::tag_table_vtable_map, |rbml_w| {
|
|
|
|
rbml_w.id(id);
|
|
|
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
|
|
|
encode_vtable_res_with_key(ecx, rbml_w, method_call.adjustment, dr);
|
2014-06-11 18:01:48 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2014-03-23 01:11:39 +02:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.tag(c::tag_table_adjustments, |rbml_w| {
|
|
|
|
rbml_w.id(id);
|
|
|
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
|
|
|
rbml_w.emit_auto_adjustment(ecx, adj);
|
2013-11-21 15:42:55 -08:00
|
|
|
})
|
2014-03-20 19:49:20 -07:00
|
|
|
})
|
2012-04-23 15:23:20 -07:00
|
|
|
}
|
2014-05-28 22:26:56 -07:00
|
|
|
|
2014-07-29 22:08:39 -07:00
|
|
|
for unboxed_closure in tcx.unboxed_closures
|
|
|
|
.borrow()
|
|
|
|
.find(&ast_util::local_def(id))
|
|
|
|
.iter() {
|
|
|
|
rbml_w.tag(c::tag_table_unboxed_closures, |rbml_w| {
|
2014-07-29 17:06:37 -07:00
|
|
|
rbml_w.id(id);
|
|
|
|
rbml_w.tag(c::tag_table_val, |rbml_w| {
|
2014-07-29 22:08:39 -07:00
|
|
|
rbml_w.emit_closure_type(ecx, &unboxed_closure.closure_type);
|
|
|
|
encode_unboxed_closure_kind(rbml_w, unboxed_closure.kind)
|
2014-05-28 22:26:56 -07:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2012-07-11 15:00:40 -07:00
|
|
|
trait doc_decoder_helpers {
|
2013-02-22 01:41:37 -05:00
|
|
|
fn as_int(&self) -> int;
|
2013-12-18 14:10:28 -08:00
|
|
|
fn opt_child(&self, tag: c::astencode_tag) -> Option<Self>;
|
2012-07-11 15:00:40 -07:00
|
|
|
}
|
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
impl<'a> doc_decoder_helpers for rbml::Doc<'a> {
|
2013-02-22 01:41:37 -05:00
|
|
|
fn as_int(&self) -> int { reader::doc_as_u64(*self) as int }
|
2014-07-29 17:06:37 -07:00
|
|
|
fn opt_child(&self, tag: c::astencode_tag) -> Option<rbml::Doc<'a>> {
|
2013-02-22 01:41:37 -05:00
|
|
|
reader::maybe_get_doc(*self, tag as uint)
|
2012-02-07 21:19:53 -08:00
|
|
|
}
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
trait rbml_decoder_decoder_helpers {
|
2014-03-06 05:28:28 +02:00
|
|
|
fn read_ty(&mut self, xcx: &ExtendedDecodeContext) -> ty::t;
|
|
|
|
fn read_tys(&mut self, xcx: &ExtendedDecodeContext) -> Vec<ty::t>;
|
|
|
|
fn read_type_param_def(&mut self, xcx: &ExtendedDecodeContext)
|
2013-05-01 17:54:54 -07:00
|
|
|
-> ty::TypeParameterDef;
|
2014-05-06 15:59:45 -04:00
|
|
|
fn read_polytype(&mut self, xcx: &ExtendedDecodeContext)
|
|
|
|
-> ty::Polytype;
|
2014-05-13 11:35:42 -04:00
|
|
|
fn read_substs(&mut self, xcx: &ExtendedDecodeContext) -> subst::Substs;
|
2014-03-06 05:28:28 +02:00
|
|
|
fn read_auto_adjustment(&mut self, xcx: &ExtendedDecodeContext) -> ty::AutoAdjustment;
|
2014-07-29 22:08:39 -07:00
|
|
|
fn read_unboxed_closure(&mut self, xcx: &ExtendedDecodeContext)
|
|
|
|
-> ty::UnboxedClosure;
|
2013-05-01 17:54:54 -07:00
|
|
|
fn convert_def_id(&mut self,
|
2014-03-06 05:28:28 +02:00
|
|
|
xcx: &ExtendedDecodeContext,
|
2013-01-17 06:13:26 -08:00
|
|
|
source: DefIdSource,
|
2013-09-02 03:45:37 +02:00
|
|
|
did: ast::DefId)
|
|
|
|
-> ast::DefId;
|
2013-07-22 16:40:31 -07:00
|
|
|
|
|
|
|
// Versions of the type reading functions that don't need the full
|
|
|
|
// ExtendedDecodeContext.
|
|
|
|
fn read_ty_noxcx(&mut self,
|
2014-04-17 15:06:25 +03:00
|
|
|
tcx: &ty::ctxt, cdata: &cstore::crate_metadata) -> ty::t;
|
2013-07-22 16:40:31 -07:00
|
|
|
fn read_tys_noxcx(&mut self,
|
2014-03-06 05:07:47 +02:00
|
|
|
tcx: &ty::ctxt,
|
2014-04-17 15:06:25 +03:00
|
|
|
cdata: &cstore::crate_metadata) -> Vec<ty::t>;
|
2014-05-07 07:20:15 -04:00
|
|
|
fn read_substs_noxcx(&mut self, tcx: &ty::ctxt,
|
|
|
|
cdata: &cstore::crate_metadata)
|
2014-05-13 11:35:42 -04:00
|
|
|
-> subst::Substs;
|
2012-07-11 15:00:40 -07:00
|
|
|
}
|
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
impl<'a> rbml_decoder_decoder_helpers for reader::Decoder<'a> {
|
2013-07-22 16:40:31 -07:00
|
|
|
fn read_ty_noxcx(&mut self,
|
2014-04-17 15:06:25 +03:00
|
|
|
tcx: &ty::ctxt, cdata: &cstore::crate_metadata) -> ty::t {
|
2014-03-29 01:05:46 +01:00
|
|
|
self.read_opaque(|_, doc| {
|
|
|
|
Ok(tydecode::parse_ty_data(
|
2013-12-18 14:10:28 -08:00
|
|
|
doc.data,
|
2013-07-22 16:40:31 -07:00
|
|
|
cdata.cnum,
|
|
|
|
doc.start,
|
|
|
|
tcx,
|
2014-03-18 10:58:26 -07:00
|
|
|
|_, id| decoder::translate_def_id(cdata, id)))
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap()
|
2013-07-22 16:40:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn read_tys_noxcx(&mut self,
|
2014-03-06 05:07:47 +02:00
|
|
|
tcx: &ty::ctxt,
|
2014-04-17 15:06:25 +03:00
|
|
|
cdata: &cstore::crate_metadata) -> Vec<ty::t> {
|
2014-03-29 01:05:46 +01:00
|
|
|
self.read_to_vec(|this| Ok(this.read_ty_noxcx(tcx, cdata)) )
|
|
|
|
.unwrap()
|
2014-03-08 21:36:22 +01:00
|
|
|
.move_iter()
|
|
|
|
.collect()
|
2013-07-22 16:40:31 -07:00
|
|
|
}
|
|
|
|
|
2014-05-07 07:20:15 -04:00
|
|
|
fn read_substs_noxcx(&mut self,
|
|
|
|
tcx: &ty::ctxt,
|
|
|
|
cdata: &cstore::crate_metadata)
|
2014-05-13 11:35:42 -04:00
|
|
|
-> subst::Substs
|
2014-05-07 07:20:15 -04:00
|
|
|
{
|
|
|
|
self.read_opaque(|_, doc| {
|
|
|
|
Ok(tydecode::parse_substs_data(
|
|
|
|
doc.data,
|
|
|
|
cdata.cnum,
|
|
|
|
doc.start,
|
|
|
|
tcx,
|
|
|
|
|_, id| decoder::translate_def_id(cdata, id)))
|
|
|
|
}).unwrap()
|
|
|
|
}
|
|
|
|
|
2014-03-06 05:28:28 +02:00
|
|
|
fn read_ty(&mut self, xcx: &ExtendedDecodeContext) -> ty::t {
|
2012-04-18 21:26:25 -07:00
|
|
|
// Note: regions types embed local node ids. In principle, we
|
|
|
|
// should translate these node ids into the new decode
|
|
|
|
// context. However, we do not bother, because region types
|
|
|
|
// are not used during trans.
|
|
|
|
|
2014-03-29 01:05:46 +01:00
|
|
|
return self.read_opaque(|this, doc| {
|
2013-10-29 06:03:32 -04:00
|
|
|
debug!("read_ty({})", type_string(doc));
|
|
|
|
|
2013-01-10 10:59:58 -08:00
|
|
|
let ty = tydecode::parse_ty_data(
|
2013-12-18 14:10:28 -08:00
|
|
|
doc.data,
|
2013-05-01 17:54:54 -07:00
|
|
|
xcx.dcx.cdata.cnum,
|
|
|
|
doc.start,
|
|
|
|
xcx.dcx.tcx,
|
|
|
|
|s, a| this.convert_def_id(xcx, s, a));
|
2013-01-10 10:59:58 -08:00
|
|
|
|
2014-03-29 01:05:46 +01:00
|
|
|
Ok(ty)
|
|
|
|
}).unwrap();
|
2013-01-10 10:59:58 -08:00
|
|
|
|
2014-07-29 17:06:37 -07:00
|
|
|
fn type_string(doc: rbml::Doc) -> String {
|
2014-05-22 16:57:53 -07:00
|
|
|
let mut str = String::new();
|
2013-08-03 12:45:23 -04:00
|
|
|
for i in range(doc.start, doc.end) {
|
2013-08-25 20:21:13 -07:00
|
|
|
str.push_char(doc.data[i] as char);
|
2013-01-10 10:59:58 -08:00
|
|
|
}
|
2014-05-09 18:45:36 -07:00
|
|
|
str
|
2012-09-11 21:25:01 -07:00
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
}
|
|
|
|
|
2014-03-06 05:28:28 +02:00
|
|
|
fn read_tys(&mut self, xcx: &ExtendedDecodeContext) -> Vec<ty::t> {
|
2014-03-29 01:05:46 +01:00
|
|
|
self.read_to_vec(|this| Ok(this.read_ty(xcx))).unwrap().move_iter().collect()
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
|
|
|
|
2014-03-06 05:28:28 +02:00
|
|
|
fn read_type_param_def(&mut self, xcx: &ExtendedDecodeContext)
|
2013-05-01 17:54:54 -07:00
|
|
|
-> ty::TypeParameterDef {
|
2014-03-29 01:05:46 +01:00
|
|
|
self.read_opaque(|this, doc| {
|
|
|
|
Ok(tydecode::parse_type_param_def_data(
|
2013-12-18 14:10:28 -08:00
|
|
|
doc.data,
|
2013-05-01 17:54:54 -07:00
|
|
|
doc.start,
|
|
|
|
xcx.dcx.cdata.cnum,
|
|
|
|
xcx.dcx.tcx,
|
2014-03-18 10:58:26 -07:00
|
|
|
|s, a| this.convert_def_id(xcx, s, a)))
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap()
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
|
|
|
|
2014-05-06 15:59:45 -04:00
|
|
|
fn read_polytype(&mut self, xcx: &ExtendedDecodeContext)
|
|
|
|
-> ty::Polytype {
|
|
|
|
self.read_struct("Polytype", 2, |this| {
|
|
|
|
Ok(ty::Polytype {
|
2014-03-29 01:05:46 +01:00
|
|
|
generics: this.read_struct_field("generics", 0, |this| {
|
2013-11-21 15:42:55 -08:00
|
|
|
this.read_struct("Generics", 2, |this| {
|
2014-03-29 01:05:46 +01:00
|
|
|
Ok(ty::Generics {
|
2014-05-31 18:53:13 -04:00
|
|
|
types:
|
|
|
|
this.read_struct_field("types", 0, |this| {
|
|
|
|
Ok(this.read_vec_per_param_space(
|
|
|
|
|this| this.read_type_param_def(xcx)))
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap(),
|
2014-05-31 18:53:13 -04:00
|
|
|
|
|
|
|
regions:
|
|
|
|
this.read_struct_field("regions", 1, |this| {
|
|
|
|
Ok(this.read_vec_per_param_space(
|
|
|
|
|this| Decodable::decode(this).unwrap()))
|
|
|
|
}).unwrap()
|
2014-03-18 10:58:26 -07:00
|
|
|
})
|
2013-11-21 15:42:55 -08:00
|
|
|
})
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap(),
|
|
|
|
ty: this.read_struct_field("ty", 1, |this| {
|
|
|
|
Ok(this.read_ty(xcx))
|
|
|
|
}).unwrap()
|
2014-03-18 10:58:26 -07:00
|
|
|
})
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap()
|
2013-04-09 19:41:20 -07:00
|
|
|
}
|
|
|
|
|
2014-05-13 11:35:42 -04:00
|
|
|
fn read_substs(&mut self, xcx: &ExtendedDecodeContext) -> subst::Substs {
|
2014-03-29 01:05:46 +01:00
|
|
|
self.read_opaque(|this, doc| {
|
|
|
|
Ok(tydecode::parse_substs_data(doc.data,
|
2013-12-26 13:54:41 -05:00
|
|
|
xcx.dcx.cdata.cnum,
|
|
|
|
doc.start,
|
|
|
|
xcx.dcx.tcx,
|
2014-03-18 10:58:26 -07:00
|
|
|
|s, a| this.convert_def_id(xcx, s, a)))
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap()
|
2013-12-26 13:54:41 -05:00
|
|
|
}
|
|
|
|
|
2014-03-06 05:28:28 +02:00
|
|
|
fn read_auto_adjustment(&mut self, xcx: &ExtendedDecodeContext) -> ty::AutoAdjustment {
|
2014-03-29 01:05:46 +01:00
|
|
|
self.read_enum("AutoAdjustment", |this| {
|
2013-12-26 13:54:41 -05:00
|
|
|
let variants = ["AutoAddEnv", "AutoDerefRef", "AutoObject"];
|
|
|
|
this.read_enum_variant(variants, |this, i| {
|
2014-03-29 01:05:46 +01:00
|
|
|
Ok(match i {
|
2013-12-26 13:54:41 -05:00
|
|
|
0 => {
|
2014-04-11 18:03:10 +03:00
|
|
|
let store: ty::TraitStore =
|
2014-03-29 01:05:46 +01:00
|
|
|
this.read_enum_variant_arg(0, |this| Decodable::decode(this)).unwrap();
|
2013-12-26 13:54:41 -05:00
|
|
|
|
2014-04-11 18:03:10 +03:00
|
|
|
ty:: AutoAddEnv(store.tr(xcx))
|
2013-12-26 13:54:41 -05:00
|
|
|
}
|
|
|
|
1 => {
|
|
|
|
let auto_deref_ref: ty::AutoDerefRef =
|
2014-03-29 01:05:46 +01:00
|
|
|
this.read_enum_variant_arg(0, |this| Decodable::decode(this)).unwrap();
|
2013-12-26 13:54:41 -05:00
|
|
|
|
|
|
|
ty::AutoDerefRef(auto_deref_ref.tr(xcx))
|
|
|
|
}
|
|
|
|
2 => {
|
2014-04-11 09:01:31 +03:00
|
|
|
let store: ty::TraitStore =
|
2014-03-29 01:05:46 +01:00
|
|
|
this.read_enum_variant_arg(0, |this| Decodable::decode(this)).unwrap();
|
2013-12-26 13:54:41 -05:00
|
|
|
let b: ty::BuiltinBounds =
|
2014-04-11 09:01:31 +03:00
|
|
|
this.read_enum_variant_arg(1, |this| Decodable::decode(this)).unwrap();
|
2013-12-26 13:54:41 -05:00
|
|
|
let def_id: ast::DefId =
|
2014-04-11 09:01:31 +03:00
|
|
|
this.read_enum_variant_arg(2, |this| Decodable::decode(this)).unwrap();
|
|
|
|
let substs = this.read_enum_variant_arg(3, |this| Ok(this.read_substs(xcx)))
|
2014-03-29 01:05:46 +01:00
|
|
|
.unwrap();
|
2013-12-26 13:54:41 -05:00
|
|
|
|
2014-04-11 09:01:31 +03:00
|
|
|
ty::AutoObject(store.tr(xcx), b, def_id.tr(xcx), substs)
|
2013-12-26 13:54:41 -05:00
|
|
|
}
|
|
|
|
_ => fail!("bad enum variant for ty::AutoAdjustment")
|
2014-03-18 10:58:26 -07:00
|
|
|
})
|
2013-12-26 13:54:41 -05:00
|
|
|
})
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap()
|
2013-12-26 13:54:41 -05:00
|
|
|
}
|
|
|
|
|
2014-07-29 22:08:39 -07:00
|
|
|
fn read_unboxed_closure(&mut self, xcx: &ExtendedDecodeContext)
|
|
|
|
-> ty::UnboxedClosure {
|
|
|
|
let closure_type = self.read_opaque(|this, doc| {
|
2014-05-28 22:26:56 -07:00
|
|
|
Ok(tydecode::parse_ty_closure_data(
|
|
|
|
doc.data,
|
|
|
|
xcx.dcx.cdata.cnum,
|
|
|
|
doc.start,
|
|
|
|
xcx.dcx.tcx,
|
|
|
|
|s, a| this.convert_def_id(xcx, s, a)))
|
2014-07-29 22:08:39 -07:00
|
|
|
}).unwrap();
|
|
|
|
let variants = [
|
|
|
|
"FnUnboxedClosureKind",
|
|
|
|
"FnMutUnboxedClosureKind",
|
|
|
|
"FnOnceUnboxedClosureKind"
|
|
|
|
];
|
|
|
|
let kind = self.read_enum_variant(variants, |_, i| {
|
|
|
|
Ok(match i {
|
|
|
|
0 => ty::FnUnboxedClosureKind,
|
|
|
|
1 => ty::FnMutUnboxedClosureKind,
|
|
|
|
2 => ty::FnOnceUnboxedClosureKind,
|
|
|
|
_ => fail!("bad enum variant for ty::UnboxedClosureKind"),
|
|
|
|
})
|
|
|
|
}).unwrap();
|
|
|
|
ty::UnboxedClosure {
|
|
|
|
closure_type: closure_type,
|
|
|
|
kind: kind,
|
|
|
|
}
|
2014-05-28 22:26:56 -07:00
|
|
|
}
|
|
|
|
|
2013-05-01 17:54:54 -07:00
|
|
|
fn convert_def_id(&mut self,
|
2014-03-06 05:28:28 +02:00
|
|
|
xcx: &ExtendedDecodeContext,
|
2013-01-17 06:13:26 -08:00
|
|
|
source: tydecode::DefIdSource,
|
2013-09-02 03:45:37 +02:00
|
|
|
did: ast::DefId)
|
|
|
|
-> ast::DefId {
|
2013-01-17 06:13:26 -08:00
|
|
|
/*!
|
|
|
|
* Converts a def-id that appears in a type. The correct
|
|
|
|
* translation will depend on what kind of def-id this is.
|
|
|
|
* This is a subtle point: type definitions are not
|
|
|
|
* inlined into the current crate, so if the def-id names
|
|
|
|
* a nominal type or type alias, then it should be
|
|
|
|
* translated to refer to the source crate.
|
|
|
|
*
|
|
|
|
* However, *type parameters* are cloned along with the function
|
|
|
|
* they are attached to. So we should translate those def-ids
|
|
|
|
* to refer to the new, cloned copy of the type parameter.
|
2013-10-29 06:03:32 -04:00
|
|
|
* We only see references to free type parameters in the body of
|
|
|
|
* an inlined function. In such cases, we need the def-id to
|
|
|
|
* be a local id so that the TypeContents code is able to lookup
|
|
|
|
* the relevant info in the ty_param_defs table.
|
|
|
|
*
|
|
|
|
* *Region parameters*, unfortunately, are another kettle of fish.
|
|
|
|
* In such cases, def_id's can appear in types to distinguish
|
|
|
|
* shadowed bound regions and so forth. It doesn't actually
|
|
|
|
* matter so much what we do to these, since regions are erased
|
|
|
|
* at trans time, but it's good to keep them consistent just in
|
|
|
|
* case. We translate them with `tr_def_id()` which will map
|
|
|
|
* the crate numbers back to the original source crate.
|
|
|
|
*
|
|
|
|
* It'd be really nice to refactor the type repr to not include
|
|
|
|
* def-ids so that all these distinctions were unnecessary.
|
2013-01-17 06:13:26 -08:00
|
|
|
*/
|
|
|
|
|
2013-01-10 10:59:58 -08:00
|
|
|
let r = match source {
|
2013-10-29 06:03:32 -04:00
|
|
|
NominalType | TypeWithId | RegionParameter => xcx.tr_def_id(did),
|
2013-01-17 06:13:26 -08:00
|
|
|
TypeParameter => xcx.tr_intern_def_id(did)
|
2013-01-10 10:59:58 -08:00
|
|
|
};
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("convert_def_id(source={:?}, did={:?})={:?}", source, did, r);
|
2013-01-10 10:59:58 -08:00
|
|
|
return r;
|
2013-01-17 06:13:26 -08:00
|
|
|
}
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
|
|
|
|
2014-03-06 05:28:28 +02:00
|
|
|
fn decode_side_tables(xcx: &ExtendedDecodeContext,
|
2014-07-29 17:06:37 -07:00
|
|
|
ast_doc: rbml::Doc) {
|
2012-02-14 15:21:53 -08:00
|
|
|
let dcx = xcx.dcx;
|
2013-03-26 15:04:30 -04:00
|
|
|
let tbl_doc = ast_doc.get(c::tag_table as uint);
|
2013-11-21 15:42:55 -08:00
|
|
|
reader::docs(tbl_doc, |tag, entry_doc| {
|
2013-03-26 15:04:30 -04:00
|
|
|
let id0 = entry_doc.get(c::tag_table_id as uint).as_int();
|
2013-11-27 07:02:25 +02:00
|
|
|
let id = xcx.tr_id(id0 as ast::NodeId);
|
2012-02-14 15:21:53 -08:00
|
|
|
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!(">> Side table document with tag 0x{:x} \
|
2013-09-27 22:38:08 -07:00
|
|
|
found for id {} (orig {})",
|
2012-08-22 17:24:52 -07:00
|
|
|
tag, id, id0);
|
2012-02-14 15:21:53 -08:00
|
|
|
|
2013-06-22 18:58:41 -07:00
|
|
|
match c::astencode_tag::from_uint(tag) {
|
|
|
|
None => {
|
2012-02-14 15:21:53 -08:00
|
|
|
xcx.dcx.tcx.sess.bug(
|
2014-05-16 10:45:16 -07:00
|
|
|
format!("unknown tag found in side tables: {:x}",
|
|
|
|
tag).as_slice());
|
2012-02-14 15:21:53 -08:00
|
|
|
}
|
2013-06-20 15:23:52 -04:00
|
|
|
Some(value) => {
|
2013-06-22 18:58:41 -07:00
|
|
|
let val_doc = entry_doc.get(c::tag_table_val as uint);
|
2014-05-28 20:36:05 +01:00
|
|
|
let mut val_dsr = reader::Decoder::new(val_doc);
|
2013-06-22 18:58:41 -07:00
|
|
|
let val_dsr = &mut val_dsr;
|
|
|
|
|
|
|
|
match value {
|
|
|
|
c::tag_table_def => {
|
|
|
|
let def = decode_def(xcx, val_doc);
|
2014-03-20 19:49:20 -07:00
|
|
|
dcx.tcx.def_map.borrow_mut().insert(id, def);
|
2013-06-22 18:58:41 -07:00
|
|
|
}
|
|
|
|
c::tag_table_node_type => {
|
|
|
|
let ty = val_dsr.read_ty(xcx);
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("inserting ty for node {:?}: {}",
|
2014-06-21 03:39:03 -07:00
|
|
|
id, ty_to_string(dcx.tcx, ty));
|
2014-03-20 19:49:20 -07:00
|
|
|
dcx.tcx.node_types.borrow_mut().insert(id as uint, ty);
|
2013-06-22 18:58:41 -07:00
|
|
|
}
|
2014-05-07 07:20:15 -04:00
|
|
|
c::tag_table_item_subst => {
|
|
|
|
let item_substs = ty::ItemSubsts {
|
|
|
|
substs: val_dsr.read_substs(xcx)
|
|
|
|
};
|
|
|
|
dcx.tcx.item_substs.borrow_mut().insert(
|
|
|
|
id, item_substs);
|
2013-06-22 18:58:41 -07:00
|
|
|
}
|
|
|
|
c::tag_table_freevars => {
|
2014-04-14 17:43:57 +03:00
|
|
|
let fv_info = val_dsr.read_to_vec(|val_dsr| {
|
|
|
|
Ok(val_dsr.read_freevar_entry(xcx))
|
2014-03-29 01:05:46 +01:00
|
|
|
}).unwrap().move_iter().collect();
|
2014-03-20 19:49:20 -07:00
|
|
|
dcx.tcx.freevars.borrow_mut().insert(id, fv_info);
|
2013-06-22 18:58:41 -07:00
|
|
|
}
|
2014-08-04 18:58:48 -07:00
|
|
|
c::tag_table_upvar_borrow_map => {
|
|
|
|
let var_id: ast::NodeId = Decodable::decode(val_dsr).unwrap();
|
|
|
|
let upvar_id = ty::UpvarId {
|
|
|
|
var_id: xcx.tr_id(var_id),
|
|
|
|
closure_expr_id: id
|
|
|
|
};
|
|
|
|
let ub: ty::UpvarBorrow = Decodable::decode(val_dsr).unwrap();
|
|
|
|
dcx.tcx.upvar_borrow_map.borrow_mut().insert(upvar_id, ub.tr(xcx));
|
|
|
|
}
|
2014-07-23 12:43:29 -07:00
|
|
|
c::tag_table_capture_modes => {
|
|
|
|
let capture_mode = val_dsr.read_capture_mode();
|
|
|
|
dcx.tcx
|
|
|
|
.capture_modes
|
|
|
|
.borrow_mut()
|
|
|
|
.insert(id, capture_mode);
|
|
|
|
}
|
2013-06-22 18:58:41 -07:00
|
|
|
c::tag_table_tcache => {
|
2014-05-06 15:59:45 -04:00
|
|
|
let pty = val_dsr.read_polytype(xcx);
|
2014-02-05 22:15:24 +01:00
|
|
|
let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
|
2014-05-06 15:59:45 -04:00
|
|
|
dcx.tcx.tcache.borrow_mut().insert(lid, pty);
|
2013-06-22 18:58:41 -07:00
|
|
|
}
|
|
|
|
c::tag_table_param_defs => {
|
|
|
|
let bounds = val_dsr.read_type_param_def(xcx);
|
2014-03-20 19:49:20 -07:00
|
|
|
dcx.tcx.ty_param_defs.borrow_mut().insert(id, bounds);
|
2013-06-22 18:58:41 -07:00
|
|
|
}
|
|
|
|
c::tag_table_method_map => {
|
2014-06-11 18:01:48 -04:00
|
|
|
let (adjustment, method) = val_dsr.read_method_callee(xcx);
|
2014-03-23 01:11:39 +02:00
|
|
|
let method_call = MethodCall {
|
|
|
|
expr_id: id,
|
2014-06-11 18:01:48 -04:00
|
|
|
adjustment: adjustment
|
2014-03-23 01:11:39 +02:00
|
|
|
};
|
2014-04-09 18:18:40 +03:00
|
|
|
dcx.tcx.method_map.borrow_mut().insert(method_call, method);
|
2013-06-22 18:58:41 -07:00
|
|
|
}
|
|
|
|
c::tag_table_vtable_map => {
|
2014-06-11 18:01:48 -04:00
|
|
|
let (adjustment, vtable_res) =
|
2014-03-23 01:11:39 +02:00
|
|
|
val_dsr.read_vtable_res_with_key(xcx.dcx.tcx,
|
|
|
|
xcx.dcx.cdata);
|
|
|
|
let vtable_key = MethodCall {
|
|
|
|
expr_id: id,
|
2014-06-11 18:01:48 -04:00
|
|
|
adjustment: adjustment
|
2014-03-23 01:11:39 +02:00
|
|
|
};
|
2014-04-09 18:18:40 +03:00
|
|
|
dcx.tcx.vtable_map.borrow_mut().insert(vtable_key, vtable_res);
|
2013-06-22 18:58:41 -07:00
|
|
|
}
|
|
|
|
c::tag_table_adjustments => {
|
2014-04-10 16:26:26 +03:00
|
|
|
let adj: ty::AutoAdjustment = val_dsr.read_auto_adjustment(xcx);
|
2014-03-20 19:49:20 -07:00
|
|
|
dcx.tcx.adjustments.borrow_mut().insert(id, adj);
|
2013-06-22 18:58:41 -07:00
|
|
|
}
|
2014-07-29 22:08:39 -07:00
|
|
|
c::tag_table_unboxed_closures => {
|
|
|
|
let unboxed_closure =
|
|
|
|
val_dsr.read_unboxed_closure(xcx);
|
2014-05-28 22:26:56 -07:00
|
|
|
dcx.tcx
|
2014-07-29 22:08:39 -07:00
|
|
|
.unboxed_closures
|
2014-05-28 22:26:56 -07:00
|
|
|
.borrow_mut()
|
|
|
|
.insert(ast_util::local_def(id),
|
2014-07-29 22:08:39 -07:00
|
|
|
unboxed_closure);
|
2014-05-28 22:26:56 -07:00
|
|
|
}
|
2013-06-22 18:58:41 -07:00
|
|
|
_ => {
|
|
|
|
xcx.dcx.tcx.sess.bug(
|
2014-05-16 10:45:16 -07:00
|
|
|
format!("unknown tag found in side tables: {:x}",
|
|
|
|
tag).as_slice());
|
2013-06-22 18:58:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 21:19:53 -08:00
|
|
|
}
|
2012-02-27 14:06:44 -08:00
|
|
|
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!(">< Side table doc loaded");
|
2013-08-02 02:17:20 -04:00
|
|
|
true
|
2013-11-21 15:42:55 -08:00
|
|
|
});
|
2012-02-07 21:19:53 -08:00
|
|
|
}
|
2012-03-15 10:15:49 -04:00
|
|
|
|
|
|
|
// ______________________________________________________________________
|
|
|
|
// Testing of astencode_gen
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2014-07-29 17:06:37 -07:00
|
|
|
fn encode_item_ast(rbml_w: &mut Encoder, item: Gc<ast::Item>) {
|
|
|
|
rbml_w.start_tag(c::tag_tree as uint);
|
|
|
|
(*item).encode(rbml_w);
|
|
|
|
rbml_w.end_tag();
|
2012-03-15 10:15:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2014-07-29 17:06:37 -07:00
|
|
|
fn decode_item_ast(par_doc: rbml::Doc) -> Gc<ast::Item> {
|
2013-03-26 15:04:30 -04:00
|
|
|
let chi_doc = par_doc.get(c::tag_tree as uint);
|
2014-05-28 20:36:05 +01:00
|
|
|
let mut d = reader::Decoder::new(chi_doc);
|
2014-05-16 10:15:33 -07:00
|
|
|
box(GC) Decodable::decode(&mut d).unwrap()
|
2012-03-15 10:15:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2012-07-31 10:27:51 -07:00
|
|
|
trait fake_ext_ctxt {
|
2013-07-19 07:38:55 +02:00
|
|
|
fn cfg(&self) -> ast::CrateConfig;
|
2014-03-09 16:54:34 +02:00
|
|
|
fn parse_sess<'a>(&'a self) -> &'a parse::ParseSess;
|
2013-08-31 18:13:04 +02:00
|
|
|
fn call_site(&self) -> Span;
|
2013-09-02 02:50:59 +02:00
|
|
|
fn ident_of(&self, st: &str) -> ast::Ident;
|
2012-03-15 10:15:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2014-03-09 16:54:34 +02:00
|
|
|
impl fake_ext_ctxt for parse::ParseSess {
|
2014-02-28 15:25:15 -08:00
|
|
|
fn cfg(&self) -> ast::CrateConfig {
|
|
|
|
Vec::new()
|
|
|
|
}
|
2014-03-09 16:54:34 +02:00
|
|
|
fn parse_sess<'a>(&'a self) -> &'a parse::ParseSess { self }
|
2013-08-31 18:13:04 +02:00
|
|
|
fn call_site(&self) -> Span {
|
|
|
|
codemap::Span {
|
2012-12-12 10:44:01 -08:00
|
|
|
lo: codemap::BytePos(0),
|
|
|
|
hi: codemap::BytePos(0),
|
|
|
|
expn_info: None
|
|
|
|
}
|
|
|
|
}
|
2013-09-02 02:50:59 +02:00
|
|
|
fn ident_of(&self, st: &str) -> ast::Ident {
|
2013-06-04 12:34:25 -07:00
|
|
|
token::str_to_ident(st)
|
2012-12-12 10:44:01 -08:00
|
|
|
}
|
2012-03-15 10:15:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2014-03-09 16:54:34 +02:00
|
|
|
fn mk_ctxt() -> parse::ParseSess {
|
2014-02-07 00:38:33 +02:00
|
|
|
parse::new_parse_sess()
|
2012-03-15 10:15:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2014-05-16 10:15:33 -07:00
|
|
|
fn roundtrip(in_item: Option<Gc<ast::Item>>) {
|
2013-08-04 01:59:24 +02:00
|
|
|
let in_item = in_item.unwrap();
|
2014-07-29 16:31:39 -07:00
|
|
|
let mut wr = SeekableMemWriter::new();
|
2013-12-20 17:36:07 -08:00
|
|
|
{
|
2014-07-29 17:06:37 -07:00
|
|
|
let mut rbml_w = writer::Encoder::new(&mut wr);
|
|
|
|
encode_item_ast(&mut rbml_w, in_item);
|
2013-12-20 17:36:07 -08:00
|
|
|
}
|
2014-07-29 17:06:37 -07:00
|
|
|
let rbml_doc = rbml::Doc::new(wr.get_ref());
|
|
|
|
let out_item = decode_item_ast(rbml_doc);
|
2012-03-15 10:15:49 -04:00
|
|
|
|
2014-02-28 01:23:06 -08:00
|
|
|
assert!(in_item == out_item);
|
2012-03-15 10:15:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_basic() {
|
2013-08-15 02:06:33 -04:00
|
|
|
let cx = mk_ctxt();
|
|
|
|
roundtrip(quote_item!(cx,
|
2012-03-15 10:15:49 -04:00
|
|
|
fn foo() {}
|
2012-12-12 10:44:01 -08:00
|
|
|
));
|
2012-03-15 10:15:49 -04:00
|
|
|
}
|
2014-07-08 22:28:52 -07:00
|
|
|
/* NOTE: When there's a snapshot, update this (yay quasiquoter!)
|
2012-03-15 10:15:49 -04:00
|
|
|
#[test]
|
|
|
|
fn test_smalltalk() {
|
2013-08-15 02:06:33 -04:00
|
|
|
let cx = mk_ctxt();
|
|
|
|
roundtrip(quote_item!(cx,
|
2012-03-15 10:15:49 -04:00
|
|
|
fn foo() -> int { 3 + 4 } // first smalltalk program ever executed.
|
2012-12-12 10:44:01 -08:00
|
|
|
));
|
2012-03-15 10:15:49 -04:00
|
|
|
}
|
2014-07-08 22:28:52 -07:00
|
|
|
*/
|
2012-03-15 10:15:49 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_more() {
|
2013-08-15 02:06:33 -04:00
|
|
|
let cx = mk_ctxt();
|
|
|
|
roundtrip(quote_item!(cx,
|
2012-03-15 10:15:49 -04:00
|
|
|
fn foo(x: uint, y: uint) -> uint {
|
|
|
|
let z = x + y;
|
2012-08-01 17:30:05 -07:00
|
|
|
return z;
|
2012-03-15 10:15:49 -04:00
|
|
|
}
|
2012-12-12 10:44:01 -08:00
|
|
|
));
|
2012-03-15 10:15:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_simplification() {
|
2013-08-15 02:06:33 -04:00
|
|
|
let cx = mk_ctxt();
|
2014-03-17 09:55:41 +02:00
|
|
|
let item = quote_item!(&cx,
|
2013-07-10 14:43:25 -07:00
|
|
|
fn new_int_alist<B>() -> alist<int, B> {
|
2013-05-07 17:57:58 -07:00
|
|
|
fn eq_int(a: int, b: int) -> bool { a == b }
|
2014-03-04 10:02:49 -08:00
|
|
|
return alist {eq_fn: eq_int, data: Vec::new()};
|
2012-03-15 10:15:49 -04:00
|
|
|
}
|
2014-01-06 14:00:46 +02:00
|
|
|
).unwrap();
|
2014-07-07 16:35:15 -07:00
|
|
|
let item_in = e::IIItemRef(&*item);
|
2014-01-06 14:00:46 +02:00
|
|
|
let item_out = simplify_ast(item_in);
|
2014-01-09 15:05:33 +02:00
|
|
|
let item_exp = ast::IIItem(quote_item!(cx,
|
2013-07-10 14:43:25 -07:00
|
|
|
fn new_int_alist<B>() -> alist<int, B> {
|
2014-03-04 10:02:49 -08:00
|
|
|
return alist {eq_fn: eq_int, data: Vec::new()};
|
2012-03-15 10:15:49 -04:00
|
|
|
}
|
2013-08-04 01:59:24 +02:00
|
|
|
).unwrap());
|
2012-08-06 12:34:08 -07:00
|
|
|
match (item_out, item_exp) {
|
2014-01-09 15:05:33 +02:00
|
|
|
(ast::IIItem(item_out), ast::IIItem(item_exp)) => {
|
2014-07-07 16:35:15 -07:00
|
|
|
assert!(pprust::item_to_string(&*item_out) ==
|
|
|
|
pprust::item_to_string(&*item_exp));
|
2012-03-15 10:15:49 -04:00
|
|
|
}
|
2013-10-21 13:08:31 -07:00
|
|
|
_ => fail!()
|
2012-03-15 10:15:49 -04:00
|
|
|
}
|
|
|
|
}
|