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.
|
|
|
|
|
2013-01-07 14:16:52 -08:00
|
|
|
|
2011-06-27 15:30:17 -07:00
|
|
|
// Type decoding
|
2011-06-27 16:03:01 -07:00
|
|
|
|
2012-08-22 17:58:05 -07:00
|
|
|
// tjc note: Would be great to have a `match check` macro equivalent
|
|
|
|
// for some of these
|
|
|
|
|
2014-03-21 18:05:05 -07:00
|
|
|
#![allow(non_camel_case_types)]
|
2013-05-17 15:28:44 -07:00
|
|
|
|
2014-11-06 00:05:53 -08:00
|
|
|
pub use self::DefIdSource::*;
|
|
|
|
|
2014-11-18 14:22:59 +01:00
|
|
|
use middle::region;
|
2014-05-13 11:35:42 -04:00
|
|
|
use middle::subst;
|
2014-05-31 18:53:13 -04:00
|
|
|
use middle::subst::VecPerParamSpace;
|
2014-09-13 21:09:25 +03:00
|
|
|
use middle::ty::{mod, Ty};
|
2012-12-13 13:05:22 -08:00
|
|
|
|
2014-04-20 15:11:18 +03:00
|
|
|
use std::rc::Rc;
|
2013-06-28 18:32:26 -04:00
|
|
|
use std::str;
|
2014-05-22 16:57:53 -07:00
|
|
|
use std::string::String;
|
2013-03-13 22:25:28 -04:00
|
|
|
use syntax::abi;
|
2012-09-04 11:54:36 -07:00
|
|
|
use syntax::ast;
|
2014-02-14 07:07:09 +02:00
|
|
|
use syntax::parse::token;
|
2011-06-27 15:30:17 -07:00
|
|
|
|
2014-09-13 21:09:25 +03:00
|
|
|
// Compact string representation for Ty values. API ty_str &
|
2011-07-04 19:07:56 -07:00
|
|
|
// parse_from_str. Extra parameters are for converting to/from def_ids in the
|
|
|
|
// data buffer. Whatever format you choose should not contain pipe characters.
|
2011-06-27 15:30:17 -07:00
|
|
|
|
2013-01-17 06:13:26 -08:00
|
|
|
// Def id conversion: when we encounter def-ids, they have to be translated.
|
|
|
|
// For example, the crate number must be converted from the crate number used
|
|
|
|
// in the library we are reading from into the local crate numbers in use
|
|
|
|
// here. To perform this translation, the type decoder is supplied with a
|
|
|
|
// conversion function of type `conv_did`.
|
|
|
|
//
|
|
|
|
// Sometimes, particularly when inlining, the correct translation of the
|
|
|
|
// def-id will depend on where it originated from. Therefore, the conversion
|
|
|
|
// function is given an indicator of the source of the def-id. See
|
|
|
|
// astencode.rs for more information.
|
2014-10-15 02:25:34 -04:00
|
|
|
#[deriving(Show)]
|
2013-01-29 16:51:16 -08:00
|
|
|
pub enum DefIdSource {
|
2013-01-17 06:13:26 -08:00
|
|
|
// Identifies a struct, trait, enum, etc.
|
|
|
|
NominalType,
|
|
|
|
|
|
|
|
// Identifies a type alias (`type X = ...`).
|
|
|
|
TypeWithId,
|
|
|
|
|
|
|
|
// Identifies a type parameter (`fn foo<X>() { ... }`).
|
2013-10-29 06:03:32 -04:00
|
|
|
TypeParameter,
|
|
|
|
|
|
|
|
// Identifies a region parameter (`fn foo<'X>() { ... }`).
|
|
|
|
RegionParameter,
|
2014-11-02 11:34:18 -08:00
|
|
|
|
|
|
|
// Identifies an unboxed closure
|
|
|
|
UnboxedClosureSource
|
2013-01-17 06:13:26 -08:00
|
|
|
}
|
librustc: Make `Copy` opt-in.
This change makes the compiler no longer infer whether types (structures
and enumerations) implement the `Copy` trait (and thus are implicitly
copyable). Rather, you must implement `Copy` yourself via `impl Copy for
MyType {}`.
A new warning has been added, `missing_copy_implementations`, to warn
you if a non-generic public type has been added that could have
implemented `Copy` but didn't.
For convenience, you may *temporarily* opt out of this behavior by using
`#![feature(opt_out_copy)]`. Note though that this feature gate will never be
accepted and will be removed by the time that 1.0 is released, so you should
transition your code away from using it.
This breaks code like:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
Change this code to:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
impl Copy for Point2D {}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
This is the backwards-incompatible part of #13231.
Part of RFC #3.
[breaking-change]
2014-12-05 17:01:33 -08:00
|
|
|
|
|
|
|
impl Copy for DefIdSource {}
|
2014-03-02 15:26:39 -08:00
|
|
|
pub type conv_did<'a> =
|
2014-04-07 13:30:48 -07:00
|
|
|
|source: DefIdSource, ast::DefId|: 'a -> ast::DefId;
|
2011-06-27 15:30:17 -07:00
|
|
|
|
2014-04-22 15:56:37 +03:00
|
|
|
pub struct PState<'a, 'tcx: 'a> {
|
2013-12-09 23:16:18 -08:00
|
|
|
data: &'a [u8],
|
2014-02-05 22:15:24 +01:00
|
|
|
krate: ast::CrateNum,
|
2013-02-04 14:02:01 -08:00
|
|
|
pos: uint,
|
2014-04-22 15:56:37 +03:00
|
|
|
tcx: &'a ty::ctxt<'tcx>
|
2013-02-04 14:02:01 -08:00
|
|
|
}
|
2011-06-27 15:30:17 -07:00
|
|
|
|
2013-06-08 02:01:30 +02:00
|
|
|
fn peek(st: &PState) -> char {
|
2012-02-13 20:55:23 +01:00
|
|
|
st.data[st.pos] as char
|
2011-12-28 17:50:12 +01:00
|
|
|
}
|
2011-06-27 15:30:17 -07:00
|
|
|
|
2013-06-08 02:01:30 +02:00
|
|
|
fn next(st: &mut PState) -> char {
|
2012-02-13 20:55:23 +01:00
|
|
|
let ch = st.data[st.pos] as char;
|
2011-06-27 15:30:17 -07:00
|
|
|
st.pos = st.pos + 1u;
|
2012-08-01 17:30:05 -07:00
|
|
|
return ch;
|
2011-06-27 15:30:17 -07:00
|
|
|
}
|
|
|
|
|
2013-06-08 02:01:30 +02:00
|
|
|
fn next_byte(st: &mut PState) -> u8 {
|
2012-02-13 20:55:23 +01:00
|
|
|
let b = st.data[st.pos];
|
|
|
|
st.pos = st.pos + 1u;
|
2012-08-01 17:30:05 -07:00
|
|
|
return b;
|
2012-02-13 20:55:23 +01:00
|
|
|
}
|
|
|
|
|
2013-11-19 13:22:03 -08:00
|
|
|
fn scan<R>(st: &mut PState, is_last: |char| -> bool, op: |&[u8]| -> R) -> R {
|
2013-03-13 22:25:28 -04:00
|
|
|
let start_pos = st.pos;
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("scan: '{}' (start)", st.data[st.pos] as char);
|
2013-03-13 22:25:28 -04:00
|
|
|
while !is_last(st.data[st.pos] as char) {
|
|
|
|
st.pos += 1;
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("scan: '{}'", st.data[st.pos] as char);
|
2013-03-13 22:25:28 -04:00
|
|
|
}
|
|
|
|
let end_pos = st.pos;
|
|
|
|
st.pos += 1;
|
2014-09-24 23:41:09 +12:00
|
|
|
return op(st.data[start_pos..end_pos]);
|
2013-03-13 22:25:28 -04:00
|
|
|
}
|
|
|
|
|
2013-09-02 02:50:59 +02:00
|
|
|
pub fn parse_ident(st: &mut PState, last: char) -> ast::Ident {
|
2014-09-30 19:11:34 -05:00
|
|
|
ast::Ident::new(parse_name(st, last))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn parse_name(st: &mut PState, last: char) -> ast::Name {
|
2012-08-01 17:30:05 -07:00
|
|
|
fn is_last(b: char, c: char) -> bool { return c == b; }
|
2014-09-30 19:11:34 -05:00
|
|
|
parse_name_(st, |a| is_last(last, a) )
|
2011-06-27 15:30:17 -07:00
|
|
|
}
|
|
|
|
|
2014-09-30 19:11:34 -05:00
|
|
|
fn parse_name_(st: &mut PState, is_last: |char| -> bool) -> ast::Name {
|
2013-11-28 23:52:11 +11:00
|
|
|
scan(st, is_last, |bytes| {
|
2014-09-30 19:11:34 -05:00
|
|
|
token::intern(str::from_utf8(bytes).unwrap())
|
2014-02-14 07:07:09 +02:00
|
|
|
})
|
2011-06-27 15:30:17 -07:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:56:37 +03:00
|
|
|
pub fn parse_state_from_data<'a, 'tcx>(data: &'a [u8], crate_num: ast::CrateNum,
|
|
|
|
pos: uint, tcx: &'a ty::ctxt<'tcx>)
|
|
|
|
-> PState<'a, 'tcx> {
|
2013-06-08 02:01:30 +02:00
|
|
|
PState {
|
2013-02-04 14:02:01 -08:00
|
|
|
data: data,
|
2014-02-05 22:15:24 +01:00
|
|
|
krate: crate_num,
|
2013-02-04 14:02:01 -08:00
|
|
|
pos: pos,
|
|
|
|
tcx: tcx
|
|
|
|
}
|
2012-09-11 21:25:01 -07:00
|
|
|
}
|
2011-06-27 15:30:17 -07:00
|
|
|
|
2014-05-31 18:53:13 -04:00
|
|
|
fn data_log_string(data: &[u8], pos: uint) -> String {
|
|
|
|
let mut buf = String::new();
|
|
|
|
buf.push_str("<<");
|
|
|
|
for i in range(pos, data.len()) {
|
|
|
|
let c = data[i];
|
|
|
|
if c > 0x20 && c <= 0x7F {
|
2014-10-14 23:05:01 -07:00
|
|
|
buf.push(c as char);
|
2014-05-31 18:53:13 -04:00
|
|
|
} else {
|
2014-10-14 23:05:01 -07:00
|
|
|
buf.push('.');
|
2014-05-31 18:53:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
buf.push_str(">>");
|
|
|
|
buf
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn parse_ty_closure_data<'tcx>(data: &[u8],
|
|
|
|
crate_num: ast::CrateNum,
|
|
|
|
pos: uint,
|
|
|
|
tcx: &ty::ctxt<'tcx>,
|
|
|
|
conv: conv_did)
|
|
|
|
-> ty::ClosureTy<'tcx> {
|
2014-05-28 22:26:56 -07:00
|
|
|
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
|
|
|
|
parse_closure_ty(&mut st, conv)
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn parse_ty_data<'tcx>(data: &[u8], crate_num: ast::CrateNum, pos: uint,
|
|
|
|
tcx: &ty::ctxt<'tcx>, conv: conv_did) -> Ty<'tcx> {
|
2014-05-31 18:53:13 -04:00
|
|
|
debug!("parse_ty_data {}", data_log_string(data, pos));
|
2013-06-08 02:01:30 +02:00
|
|
|
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
|
|
|
|
parse_ty(&mut st, conv)
|
2011-06-27 15:30:17 -07:00
|
|
|
}
|
|
|
|
|
2014-08-27 21:46:52 -04:00
|
|
|
pub fn parse_region_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: &ty::ctxt,
|
|
|
|
conv: conv_did) -> ty::Region {
|
|
|
|
debug!("parse_region_data {}", data_log_string(data, pos));
|
|
|
|
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
|
|
|
|
parse_region(&mut st, conv)
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn parse_bare_fn_ty_data<'tcx>(data: &[u8], crate_num: ast::CrateNum, pos: uint,
|
|
|
|
tcx: &ty::ctxt<'tcx>, conv: conv_did)
|
|
|
|
-> ty::BareFnTy<'tcx> {
|
2014-05-31 18:53:13 -04:00
|
|
|
debug!("parse_bare_fn_ty_data {}", data_log_string(data, pos));
|
2013-06-08 02:01:30 +02:00
|
|
|
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
|
|
|
|
parse_bare_fn_ty(&mut st, conv)
|
2013-03-27 10:26:57 -04:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn parse_trait_ref_data<'tcx>(data: &[u8], crate_num: ast::CrateNum, pos: uint,
|
|
|
|
tcx: &ty::ctxt<'tcx>, conv: conv_did)
|
|
|
|
-> ty::TraitRef<'tcx> {
|
2014-05-31 18:53:13 -04:00
|
|
|
debug!("parse_trait_ref_data {}", data_log_string(data, pos));
|
2013-06-08 02:01:30 +02:00
|
|
|
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
|
|
|
|
parse_trait_ref(&mut st, conv)
|
2013-03-27 06:16:28 -04:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn parse_substs_data<'tcx>(data: &[u8], crate_num: ast::CrateNum, pos: uint,
|
|
|
|
tcx: &ty::ctxt<'tcx>, conv: conv_did) -> subst::Substs<'tcx> {
|
2014-05-31 18:53:13 -04:00
|
|
|
debug!("parse_substs_data {}", data_log_string(data, pos));
|
2013-12-26 13:54:41 -05:00
|
|
|
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
|
|
|
|
parse_substs(&mut st, conv)
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn parse_bounds_data<'tcx>(data: &[u8], crate_num: ast::CrateNum,
|
|
|
|
pos: uint, tcx: &ty::ctxt<'tcx>, conv: conv_did)
|
|
|
|
-> ty::ParamBounds<'tcx> {
|
2014-08-27 21:46:52 -04:00
|
|
|
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
|
|
|
|
parse_bounds(&mut st, conv)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn parse_existential_bounds_data(data: &[u8], crate_num: ast::CrateNum,
|
|
|
|
pos: uint, tcx: &ty::ctxt, conv: conv_did)
|
|
|
|
-> ty::ExistentialBounds {
|
|
|
|
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
|
|
|
|
parse_existential_bounds(&mut st, conv)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn parse_builtin_bounds_data(data: &[u8], crate_num: ast::CrateNum,
|
|
|
|
pos: uint, tcx: &ty::ctxt, conv: conv_did)
|
|
|
|
-> ty::BuiltinBounds {
|
|
|
|
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
|
|
|
|
parse_builtin_bounds(&mut st, conv)
|
|
|
|
}
|
|
|
|
|
2014-04-09 19:15:31 +12:00
|
|
|
fn parse_size(st: &mut PState) -> Option<uint> {
|
|
|
|
assert_eq!(next(st), '/');
|
|
|
|
|
|
|
|
if peek(st) == '|' {
|
|
|
|
assert_eq!(next(st), '|');
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
let n = parse_uint(st);
|
|
|
|
assert_eq!(next(st), '|');
|
|
|
|
Some(n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-29 06:03:32 -04:00
|
|
|
fn parse_trait_store(st: &mut PState, conv: conv_did) -> ty::TraitStore {
|
2013-03-08 21:16:09 -08:00
|
|
|
match next(st) {
|
|
|
|
'~' => ty::UniqTraitStore,
|
2014-04-11 09:01:31 +03:00
|
|
|
'&' => ty::RegionTraitStore(parse_region(st, conv), parse_mutability(st)),
|
2014-05-16 10:45:16 -07:00
|
|
|
c => {
|
|
|
|
st.tcx.sess.bug(format!("parse_trait_store(): bad input '{}'",
|
|
|
|
c).as_slice())
|
|
|
|
}
|
2013-03-08 21:16:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
fn parse_vec_per_param_space<'a, 'tcx, T>(st: &mut PState<'a, 'tcx>,
|
|
|
|
f: |&mut PState<'a, 'tcx>| -> T)
|
|
|
|
-> VecPerParamSpace<T>
|
2014-05-31 18:53:13 -04:00
|
|
|
{
|
|
|
|
let mut r = VecPerParamSpace::empty();
|
|
|
|
for &space in subst::ParamSpace::all().iter() {
|
|
|
|
assert_eq!(next(st), '[');
|
|
|
|
while peek(st) != ']' {
|
|
|
|
r.push(space, f(st));
|
|
|
|
}
|
|
|
|
assert_eq!(next(st), ']');
|
|
|
|
}
|
|
|
|
r
|
|
|
|
}
|
2012-04-18 21:26:25 -07:00
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
fn parse_substs<'a, 'tcx>(st: &mut PState<'a, 'tcx>,
|
|
|
|
conv: conv_did) -> subst::Substs<'tcx> {
|
2014-05-31 18:53:13 -04:00
|
|
|
let regions =
|
|
|
|
parse_region_substs(st, |x,y| conv(x,y));
|
2012-05-09 06:09:58 -07:00
|
|
|
|
2014-05-31 18:53:13 -04:00
|
|
|
let types =
|
|
|
|
parse_vec_per_param_space(st, |st| parse_ty(st, |x,y| conv(x,y)));
|
2012-04-18 21:26:25 -07:00
|
|
|
|
2014-05-31 18:53:13 -04:00
|
|
|
return subst::Substs { types: types,
|
|
|
|
regions: regions };
|
2012-04-18 21:26:25 -07:00
|
|
|
}
|
|
|
|
|
2014-05-13 11:35:42 -04:00
|
|
|
fn parse_region_substs(st: &mut PState, conv: conv_did) -> subst::RegionSubsts {
|
2013-07-24 16:52:57 -04:00
|
|
|
match next(st) {
|
2014-05-13 11:35:42 -04:00
|
|
|
'e' => subst::ErasedRegions,
|
2013-07-24 16:52:57 -04:00
|
|
|
'n' => {
|
2014-05-31 18:53:13 -04:00
|
|
|
subst::NonerasedRegions(
|
|
|
|
parse_vec_per_param_space(
|
|
|
|
st, |st| parse_region(st, |x,y| conv(x,y))))
|
2013-07-24 16:52:57 -04:00
|
|
|
}
|
2014-10-09 15:17:22 -04:00
|
|
|
_ => panic!("parse_bound_region: bad input")
|
2013-07-24 16:52:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-29 10:34:11 -04:00
|
|
|
fn parse_bound_region(st: &mut PState, conv: conv_did) -> ty::BoundRegion {
|
2012-08-22 17:58:05 -07:00
|
|
|
match next(st) {
|
2013-10-29 06:03:32 -04:00
|
|
|
'a' => {
|
|
|
|
let id = parse_uint(st);
|
|
|
|
assert_eq!(next(st), '|');
|
2013-10-29 10:34:11 -04:00
|
|
|
ty::BrAnon(id)
|
2013-10-29 06:03:32 -04:00
|
|
|
}
|
|
|
|
'[' => {
|
|
|
|
let def = parse_def(st, RegionParameter, |x,y| conv(x,y));
|
2014-05-09 18:45:36 -07:00
|
|
|
let ident = token::str_to_ident(parse_str(st, ']').as_slice());
|
2014-02-22 04:04:03 +08:00
|
|
|
ty::BrNamed(def, ident.name)
|
2013-10-29 06:03:32 -04:00
|
|
|
}
|
|
|
|
'f' => {
|
|
|
|
let id = parse_uint(st);
|
|
|
|
assert_eq!(next(st), '|');
|
2013-10-29 10:34:11 -04:00
|
|
|
ty::BrFresh(id)
|
2013-10-29 06:03:32 -04:00
|
|
|
}
|
2014-10-07 20:04:45 -07:00
|
|
|
'e' => ty::BrEnv,
|
2014-10-09 15:17:22 -04:00
|
|
|
_ => panic!("parse_bound_region: bad input")
|
2012-04-18 21:26:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-29 06:03:32 -04:00
|
|
|
fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region {
|
2012-08-22 17:58:05 -07:00
|
|
|
match next(st) {
|
2012-08-03 19:59:04 -07:00
|
|
|
'b' => {
|
2013-10-29 06:03:32 -04:00
|
|
|
assert_eq!(next(st), '[');
|
2014-11-15 16:47:59 -05:00
|
|
|
let id = ty::DebruijnIndex::new(parse_uint(st));
|
2013-10-29 06:03:32 -04:00
|
|
|
assert_eq!(next(st), '|');
|
|
|
|
let br = parse_bound_region(st, |x,y| conv(x,y));
|
|
|
|
assert_eq!(next(st), ']');
|
2013-10-29 10:34:11 -04:00
|
|
|
ty::ReLateBound(id, br)
|
2013-10-29 06:03:32 -04:00
|
|
|
}
|
|
|
|
'B' => {
|
|
|
|
assert_eq!(next(st), '[');
|
2013-11-27 07:02:25 +02:00
|
|
|
let node_id = parse_uint(st) as ast::NodeId;
|
2013-10-29 06:03:32 -04:00
|
|
|
assert_eq!(next(st), '|');
|
2014-05-31 18:53:13 -04:00
|
|
|
let space = parse_param_space(st);
|
|
|
|
assert_eq!(next(st), '|');
|
2013-10-29 06:03:32 -04:00
|
|
|
let index = parse_uint(st);
|
|
|
|
assert_eq!(next(st), '|');
|
2014-05-09 18:45:36 -07:00
|
|
|
let nm = token::str_to_ident(parse_str(st, ']').as_slice());
|
2014-05-31 18:53:13 -04:00
|
|
|
ty::ReEarlyBound(node_id, space, index, nm.name)
|
2012-04-18 21:26:25 -07:00
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
'f' => {
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(next(st), '[');
|
2014-11-18 14:22:59 +01:00
|
|
|
let scope = parse_scope(st);
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(next(st), '|');
|
2013-10-29 06:03:32 -04:00
|
|
|
let br = parse_bound_region(st, |x,y| conv(x,y));
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(next(st), ']');
|
2014-11-18 14:22:59 +01:00
|
|
|
ty::ReFree(ty::FreeRegion { scope: scope,
|
2013-04-01 22:32:37 -07:00
|
|
|
bound_region: br})
|
2012-04-18 21:26:25 -07:00
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
's' => {
|
2014-11-18 14:22:59 +01:00
|
|
|
let scope = parse_scope(st);
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(next(st), '|');
|
2014-11-18 14:22:59 +01:00
|
|
|
ty::ReScope(scope)
|
2012-04-18 21:26:25 -07:00
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
't' => {
|
2013-10-29 10:34:11 -04:00
|
|
|
ty::ReStatic
|
2012-04-18 21:26:25 -07:00
|
|
|
}
|
2013-03-15 15:24:24 -04:00
|
|
|
'e' => {
|
2013-10-29 10:34:11 -04:00
|
|
|
ty::ReStatic
|
2013-03-15 15:24:24 -04:00
|
|
|
}
|
2014-10-09 15:17:22 -04:00
|
|
|
_ => panic!("parse_region: bad input")
|
2012-04-18 21:26:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 14:22:59 +01:00
|
|
|
fn parse_scope(st: &mut PState) -> region::CodeExtent {
|
|
|
|
match next(st) {
|
|
|
|
'M' => {
|
|
|
|
let node_id = parse_uint(st) as ast::NodeId;
|
|
|
|
region::CodeExtent::Misc(node_id)
|
|
|
|
}
|
|
|
|
_ => panic!("parse_scope: bad input")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
fn parse_opt<'a, 'tcx, T>(st: &mut PState<'a, 'tcx>, f: |&mut PState<'a, 'tcx>| -> T)
|
|
|
|
-> Option<T> {
|
2012-08-22 17:58:05 -07:00
|
|
|
match next(st) {
|
2012-08-20 12:23:37 -07:00
|
|
|
'n' => None,
|
2013-06-08 02:01:30 +02:00
|
|
|
's' => Some(f(st)),
|
2014-10-09 15:17:22 -04:00
|
|
|
_ => panic!("parse_opt: bad input")
|
2012-04-18 21:26:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 16:57:53 -07:00
|
|
|
fn parse_str(st: &mut PState, term: char) -> String {
|
|
|
|
let mut result = String::new();
|
2012-04-18 21:26:25 -07:00
|
|
|
while peek(st) != term {
|
2013-06-11 19:13:42 -07:00
|
|
|
unsafe {
|
2014-11-17 21:39:01 +13:00
|
|
|
result.as_mut_vec().push_all(&[next_byte(st)])
|
2013-06-11 19:13:42 -07:00
|
|
|
}
|
2012-04-18 21:26:25 -07:00
|
|
|
}
|
|
|
|
next(st);
|
2014-05-09 18:45:36 -07:00
|
|
|
result
|
2012-04-18 21:26:25 -07:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
fn parse_trait_ref<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did)
|
|
|
|
-> ty::TraitRef<'tcx> {
|
2013-06-21 20:08:35 -04:00
|
|
|
let def = parse_def(st, NominalType, |x,y| conv(x,y));
|
|
|
|
let substs = parse_substs(st, |x,y| conv(x,y));
|
2013-03-27 06:16:28 -04:00
|
|
|
ty::TraitRef {def_id: def, substs: substs}
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> {
|
2012-08-22 17:58:05 -07:00
|
|
|
match next(st) {
|
2013-04-22 20:19:05 -07:00
|
|
|
'b' => return ty::mk_bool(),
|
|
|
|
'i' => return ty::mk_int(),
|
|
|
|
'u' => return ty::mk_uint(),
|
2012-08-03 19:59:04 -07:00
|
|
|
'M' => {
|
2012-08-22 17:58:05 -07:00
|
|
|
match next(st) {
|
2014-01-09 15:05:33 +02:00
|
|
|
'b' => return ty::mk_mach_uint(ast::TyU8),
|
|
|
|
'w' => return ty::mk_mach_uint(ast::TyU16),
|
|
|
|
'l' => return ty::mk_mach_uint(ast::TyU32),
|
|
|
|
'd' => return ty::mk_mach_uint(ast::TyU64),
|
|
|
|
'B' => return ty::mk_mach_int(ast::TyI8),
|
|
|
|
'W' => return ty::mk_mach_int(ast::TyI16),
|
|
|
|
'L' => return ty::mk_mach_int(ast::TyI32),
|
|
|
|
'D' => return ty::mk_mach_int(ast::TyI64),
|
|
|
|
'f' => return ty::mk_mach_float(ast::TyF32),
|
|
|
|
'F' => return ty::mk_mach_float(ast::TyF64),
|
2014-10-09 15:17:22 -04:00
|
|
|
_ => panic!("parse_ty: bad numeric type")
|
2011-06-27 15:30:17 -07:00
|
|
|
}
|
2011-07-27 14:19:39 +02:00
|
|
|
}
|
2013-04-22 20:19:05 -07:00
|
|
|
'c' => return ty::mk_char(),
|
2012-08-03 19:59:04 -07:00
|
|
|
't' => {
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(next(st), '[');
|
2013-06-21 20:08:35 -04:00
|
|
|
let def = parse_def(st, NominalType, |x,y| conv(x,y));
|
|
|
|
let substs = parse_substs(st, |x,y| conv(x,y));
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(next(st), ']');
|
2012-08-01 17:30:05 -07:00
|
|
|
return ty::mk_enum(st.tcx, def, substs);
|
2011-07-27 14:19:39 +02:00
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
'x' => {
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(next(st), '[');
|
2014-11-07 06:16:57 -05:00
|
|
|
let trait_ref = parse_trait_ref(st, |x,y| conv(x,y));
|
2014-08-27 21:46:52 -04:00
|
|
|
let bounds = parse_existential_bounds(st, |x,y| conv(x,y));
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(next(st), ']');
|
2014-11-07 06:16:57 -05:00
|
|
|
return ty::mk_trait(st.tcx, trait_ref, bounds);
|
2011-12-29 11:23:35 +01:00
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
'p' => {
|
2013-10-29 06:03:32 -04:00
|
|
|
let did = parse_def(st, TypeParameter, |x,y| conv(x,y));
|
2014-10-15 02:25:34 -04:00
|
|
|
debug!("parsed ty_param: did={}", did);
|
2014-05-31 18:53:13 -04:00
|
|
|
let index = parse_uint(st);
|
|
|
|
assert_eq!(next(st), '|');
|
|
|
|
let space = parse_param_space(st);
|
|
|
|
assert_eq!(next(st), '|');
|
|
|
|
return ty::mk_param(st.tcx, space, index, did);
|
2012-01-30 11:52:34 +01:00
|
|
|
}
|
2014-01-12 02:25:51 +02:00
|
|
|
'~' => return ty::mk_uniq(st.tcx, parse_ty(st, |x,y| conv(x,y))),
|
2013-10-29 06:14:59 -04:00
|
|
|
'*' => return ty::mk_ptr(st.tcx, parse_mt(st, |x,y| conv(x,y))),
|
2012-08-03 19:59:04 -07:00
|
|
|
'&' => {
|
2013-10-29 06:14:59 -04:00
|
|
|
let r = parse_region(st, |x,y| conv(x,y));
|
|
|
|
let mt = parse_mt(st, |x,y| conv(x,y));
|
2012-08-01 17:30:05 -07:00
|
|
|
return ty::mk_rptr(st.tcx, r, mt);
|
2012-04-23 15:23:20 -07:00
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
'V' => {
|
DST coercions and DST structs
[breaking-change]
1. The internal layout for traits has changed from (vtable, data) to (data, vtable). If you were relying on this in unsafe transmutes, you might get some very weird and apparently unrelated errors. You should not be doing this! Prefer not to do this at all, but if you must, you should use raw::TraitObject rather than hardcoding rustc's internal representation into your code.
2. The minimal type of reference-to-vec-literals (e.g., `&[1, 2, 3]`) is now a fixed size vec (e.g., `&[int, ..3]`) where it used to be an unsized vec (e.g., `&[int]`). If you want the unszied type, you must explicitly give the type (e.g., `let x: &[_] = &[1, 2, 3]`). Note in particular where multiple blocks must have the same type (e.g., if and else clauses, vec elements), the compiler will not coerce to the unsized type without a hint. E.g., `[&[1], &[1, 2]]` used to be a valid expression of type '[&[int]]'. It no longer type checks since the first element now has type `&[int, ..1]` and the second has type &[int, ..2]` which are incompatible.
3. The type of blocks (including functions) must be coercible to the expected type (used to be a subtype). Mostly this makes things more flexible and not less (in particular, in the case of coercing function bodies to the return type). However, in some rare cases, this is less flexible. TBH, I'm not exactly sure of the exact effects. I think the change causes us to resolve inferred type variables slightly earlier which might make us slightly more restrictive. Possibly it only affects blocks with unreachable code. E.g., `if ... { fail!(); "Hello" }` used to type check, it no longer does. The fix is to add a semicolon after the string.
2014-08-04 14:20:11 +02:00
|
|
|
let t = parse_ty(st, |x,y| conv(x,y));
|
2014-04-09 19:15:31 +12:00
|
|
|
let sz = parse_size(st);
|
DST coercions and DST structs
[breaking-change]
1. The internal layout for traits has changed from (vtable, data) to (data, vtable). If you were relying on this in unsafe transmutes, you might get some very weird and apparently unrelated errors. You should not be doing this! Prefer not to do this at all, but if you must, you should use raw::TraitObject rather than hardcoding rustc's internal representation into your code.
2. The minimal type of reference-to-vec-literals (e.g., `&[1, 2, 3]`) is now a fixed size vec (e.g., `&[int, ..3]`) where it used to be an unsized vec (e.g., `&[int]`). If you want the unszied type, you must explicitly give the type (e.g., `let x: &[_] = &[1, 2, 3]`). Note in particular where multiple blocks must have the same type (e.g., if and else clauses, vec elements), the compiler will not coerce to the unsized type without a hint. E.g., `[&[1], &[1, 2]]` used to be a valid expression of type '[&[int]]'. It no longer type checks since the first element now has type `&[int, ..1]` and the second has type &[int, ..2]` which are incompatible.
3. The type of blocks (including functions) must be coercible to the expected type (used to be a subtype). Mostly this makes things more flexible and not less (in particular, in the case of coercing function bodies to the return type). However, in some rare cases, this is less flexible. TBH, I'm not exactly sure of the exact effects. I think the change causes us to resolve inferred type variables slightly earlier which might make us slightly more restrictive. Possibly it only affects blocks with unreachable code. E.g., `if ... { fail!(); "Hello" }` used to type check, it no longer does. The fix is to add a semicolon after the string.
2014-08-04 14:20:11 +02:00
|
|
|
return ty::mk_vec(st.tcx, t, sz);
|
2012-04-10 18:32:51 -07:00
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
'v' => {
|
2014-04-29 13:10:23 +12:00
|
|
|
return ty::mk_str(st.tcx);
|
2012-04-10 18:32:51 -07:00
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
'T' => {
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(next(st), '[');
|
2014-03-04 10:02:49 -08:00
|
|
|
let mut params = Vec::new();
|
2013-06-21 20:08:35 -04:00
|
|
|
while peek(st) != ']' { params.push(parse_ty(st, |x,y| conv(x,y))); }
|
2011-08-15 11:40:26 +02:00
|
|
|
st.pos = st.pos + 1u;
|
2012-08-01 17:30:05 -07:00
|
|
|
return ty::mk_tup(st.tcx, params);
|
2011-08-15 11:40:26 +02:00
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
'f' => {
|
2013-10-29 06:14:59 -04:00
|
|
|
return ty::mk_closure(st.tcx, parse_closure_ty(st, |x,y| conv(x,y)));
|
2013-01-31 17:12:29 -08:00
|
|
|
}
|
|
|
|
'F' => {
|
2013-10-29 06:14:59 -04:00
|
|
|
return ty::mk_bare_fn(st.tcx, parse_bare_fn_ty(st, |x,y| conv(x,y)));
|
2011-07-27 14:19:39 +02:00
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
'#' => {
|
2011-07-27 14:19:39 +02:00
|
|
|
let pos = parse_hex(st);
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(next(st), ':');
|
2011-07-27 14:19:39 +02:00
|
|
|
let len = parse_hex(st);
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(next(st), '#');
|
2014-02-05 22:15:24 +01:00
|
|
|
let key = ty::creader_cache_key {cnum: st.krate,
|
2013-01-31 17:12:29 -08:00
|
|
|
pos: pos,
|
|
|
|
len: len };
|
2013-12-19 19:36:50 -08:00
|
|
|
|
2014-11-07 14:35:18 -05:00
|
|
|
match st.tcx.rcache.borrow().get(&key).cloned() {
|
2013-12-19 19:36:50 -08:00
|
|
|
Some(tt) => return tt,
|
2014-03-20 19:49:20 -07:00
|
|
|
None => {}
|
2011-06-27 15:30:17 -07:00
|
|
|
}
|
2014-03-20 19:49:20 -07:00
|
|
|
let mut ps = PState {
|
|
|
|
pos: pos,
|
|
|
|
.. *st
|
|
|
|
};
|
|
|
|
let tt = parse_ty(&mut ps, |x,y| conv(x,y));
|
|
|
|
st.tcx.rcache.borrow_mut().insert(key, tt);
|
|
|
|
return tt;
|
2011-07-27 14:19:39 +02:00
|
|
|
}
|
2014-12-07 11:10:48 -05:00
|
|
|
'\"' => {
|
2013-06-21 20:08:35 -04:00
|
|
|
let _ = parse_def(st, TypeWithId, |x,y| conv(x,y));
|
|
|
|
let inner = parse_ty(st, |x,y| conv(x,y));
|
2013-04-02 13:41:18 -07:00
|
|
|
inner
|
2012-01-16 11:45:18 +01:00
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
'a' => {
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(next(st), '[');
|
2013-06-21 20:08:35 -04:00
|
|
|
let did = parse_def(st, NominalType, |x,y| conv(x,y));
|
|
|
|
let substs = parse_substs(st, |x,y| conv(x,y));
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(next(st), ']');
|
2012-12-10 13:47:54 -08:00
|
|
|
return ty::mk_struct(st.tcx, did, substs);
|
2012-03-06 08:02:13 -08:00
|
|
|
}
|
2014-05-28 22:26:56 -07:00
|
|
|
'k' => {
|
2014-10-18 10:46:57 -07:00
|
|
|
assert_eq!(next(st), '[');
|
2014-11-02 11:34:18 -08:00
|
|
|
let did = parse_def(st, UnboxedClosureSource, |x,y| conv(x,y));
|
2014-10-18 10:46:57 -07:00
|
|
|
let region = parse_region(st, |x,y| conv(x,y));
|
|
|
|
let substs = parse_substs(st, |x,y| conv(x,y));
|
|
|
|
assert_eq!(next(st), ']');
|
|
|
|
return ty::mk_unboxed_closure(st.tcx, did, region, substs);
|
2014-05-28 22:26:56 -07:00
|
|
|
}
|
2014-05-31 18:53:13 -04:00
|
|
|
'e' => {
|
|
|
|
return ty::mk_err();
|
|
|
|
}
|
2014-10-09 15:17:22 -04:00
|
|
|
c => { panic!("unexpected char in type string: {}", c);}
|
2011-06-27 15:30:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-02 03:45:37 +02:00
|
|
|
fn parse_mutability(st: &mut PState) -> ast::Mutability {
|
2012-08-06 12:34:08 -07:00
|
|
|
match peek(st) {
|
2013-09-02 03:45:37 +02:00
|
|
|
'm' => { next(st); ast::MutMutable }
|
|
|
|
_ => { ast::MutImmutable }
|
2011-06-27 15:30:17 -07:00
|
|
|
}
|
2013-04-02 03:40:57 -04:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
fn parse_mt<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> ty::mt<'tcx> {
|
2013-04-02 03:40:57 -04:00
|
|
|
let m = parse_mutability(st);
|
2013-10-29 06:14:59 -04:00
|
|
|
ty::mt { ty: parse_ty(st, |x,y| conv(x,y)), mutbl: m }
|
2011-06-27 15:30:17 -07:00
|
|
|
}
|
|
|
|
|
2013-06-08 02:01:30 +02:00
|
|
|
fn parse_def(st: &mut PState, source: DefIdSource,
|
2013-09-02 03:45:37 +02:00
|
|
|
conv: conv_did) -> ast::DefId {
|
2013-06-08 02:01:30 +02:00
|
|
|
return conv(source, scan(st, |c| { c == '|' }, parse_def_id));
|
2011-06-27 15:30:17 -07:00
|
|
|
}
|
|
|
|
|
2013-06-08 02:01:30 +02:00
|
|
|
fn parse_uint(st: &mut PState) -> uint {
|
2012-03-15 09:47:03 -04:00
|
|
|
let mut n = 0;
|
2012-03-10 20:34:17 -08:00
|
|
|
loop {
|
2012-02-13 20:55:23 +01:00
|
|
|
let cur = peek(st);
|
2012-08-01 17:30:05 -07:00
|
|
|
if cur < '0' || cur > '9' { return n; }
|
2011-06-27 15:30:17 -07:00
|
|
|
st.pos = st.pos + 1u;
|
|
|
|
n *= 10;
|
2013-04-10 14:45:12 +09:00
|
|
|
n += (cur as uint) - ('0' as uint);
|
2012-03-10 20:34:17 -08:00
|
|
|
};
|
2011-06-27 15:30:17 -07:00
|
|
|
}
|
|
|
|
|
2014-05-31 18:53:13 -04:00
|
|
|
fn parse_param_space(st: &mut PState) -> subst::ParamSpace {
|
|
|
|
subst::ParamSpace::from_uint(parse_uint(st))
|
|
|
|
}
|
|
|
|
|
2013-06-08 02:01:30 +02:00
|
|
|
fn parse_hex(st: &mut PState) -> uint {
|
2012-03-15 09:47:03 -04:00
|
|
|
let mut n = 0u;
|
2012-03-10 20:34:17 -08:00
|
|
|
loop {
|
2012-02-13 20:55:23 +01:00
|
|
|
let cur = peek(st);
|
2012-08-01 17:30:05 -07:00
|
|
|
if (cur < '0' || cur > '9') && (cur < 'a' || cur > 'f') { return n; }
|
2011-06-27 15:30:17 -07:00
|
|
|
st.pos = st.pos + 1u;
|
|
|
|
n *= 16u;
|
2011-07-27 14:19:39 +02:00
|
|
|
if '0' <= cur && cur <= '9' {
|
2011-06-27 15:30:17 -07:00
|
|
|
n += (cur as uint) - ('0' as uint);
|
|
|
|
} else { n += 10u + (cur as uint) - ('a' as uint); }
|
2012-03-10 20:34:17 -08:00
|
|
|
};
|
2011-06-27 15:30:17 -07:00
|
|
|
}
|
|
|
|
|
2014-09-13 20:10:34 +03:00
|
|
|
fn parse_fn_style(c: char) -> ast::FnStyle {
|
2012-08-22 17:58:05 -07:00
|
|
|
match c {
|
2014-09-13 20:10:34 +03:00
|
|
|
'u' => ast::UnsafeFn,
|
|
|
|
'n' => ast::NormalFn,
|
2014-10-09 15:17:22 -04:00
|
|
|
_ => panic!("parse_fn_style: bad fn_style {}", c)
|
2012-05-24 23:44:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-02 01:19:41 -07:00
|
|
|
fn parse_abi_set(st: &mut PState) -> abi::Abi {
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(next(st), '[');
|
2014-04-02 01:19:41 -07:00
|
|
|
scan(st, |c| c == ']', |bytes| {
|
2014-06-02 15:49:42 -07:00
|
|
|
let abi_str = str::from_utf8(bytes).unwrap();
|
2014-05-19 17:23:26 -07:00
|
|
|
abi::lookup(abi_str.as_slice()).expect(abi_str)
|
2014-04-02 01:19:41 -07:00
|
|
|
})
|
2013-01-31 17:12:29 -08:00
|
|
|
}
|
|
|
|
|
2012-11-02 13:33:51 -07:00
|
|
|
fn parse_onceness(c: char) -> ast::Onceness {
|
|
|
|
match c {
|
|
|
|
'o' => ast::Once,
|
|
|
|
'm' => ast::Many,
|
2014-10-09 15:17:22 -04:00
|
|
|
_ => panic!("parse_onceness: bad onceness")
|
2012-11-02 13:33:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
fn parse_closure_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>,
|
|
|
|
conv: conv_did) -> ty::ClosureTy<'tcx> {
|
2014-04-06 18:04:40 -07:00
|
|
|
let fn_style = parse_fn_style(next(st));
|
2012-11-02 13:33:51 -07:00
|
|
|
let onceness = parse_onceness(next(st));
|
2014-04-11 18:03:10 +03:00
|
|
|
let store = parse_trait_store(st, |x,y| conv(x,y));
|
2014-08-27 21:46:52 -04:00
|
|
|
let bounds = parse_existential_bounds(st, |x,y| conv(x,y));
|
2013-06-21 20:08:35 -04:00
|
|
|
let sig = parse_sig(st, |x,y| conv(x,y));
|
2014-05-28 22:26:56 -07:00
|
|
|
let abi = parse_abi_set(st);
|
2013-01-31 17:12:29 -08:00
|
|
|
ty::ClosureTy {
|
2014-04-06 18:04:40 -07:00
|
|
|
fn_style: fn_style,
|
2013-01-31 17:12:29 -08:00
|
|
|
onceness: onceness,
|
2014-04-11 18:03:10 +03:00
|
|
|
store: store,
|
2014-08-27 21:46:52 -04:00
|
|
|
bounds: bounds,
|
2014-05-28 22:26:56 -07:00
|
|
|
sig: sig,
|
|
|
|
abi: abi,
|
2013-01-31 17:12:29 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
fn parse_bare_fn_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>,
|
|
|
|
conv: conv_did) -> ty::BareFnTy<'tcx> {
|
2014-04-06 18:04:40 -07:00
|
|
|
let fn_style = parse_fn_style(next(st));
|
2013-03-13 22:25:28 -04:00
|
|
|
let abi = parse_abi_set(st);
|
2013-10-29 06:03:32 -04:00
|
|
|
let sig = parse_sig(st, |x,y| conv(x,y));
|
2013-01-31 17:12:29 -08:00
|
|
|
ty::BareFnTy {
|
2014-04-06 18:04:40 -07:00
|
|
|
fn_style: fn_style,
|
2014-04-02 01:19:41 -07:00
|
|
|
abi: abi,
|
2013-01-31 17:12:29 -08:00
|
|
|
sig: sig
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
fn parse_sig<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> ty::FnSig<'tcx> {
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(next(st), '[');
|
2014-03-04 10:02:49 -08:00
|
|
|
let mut inputs = Vec::new();
|
2012-02-13 20:55:23 +01:00
|
|
|
while peek(st) != ']' {
|
2013-06-21 20:08:35 -04:00
|
|
|
inputs.push(parse_ty(st, |x,y| conv(x,y)));
|
2011-06-27 15:30:17 -07:00
|
|
|
}
|
|
|
|
st.pos += 1u; // eat the ']'
|
2013-10-29 06:03:32 -04:00
|
|
|
let variadic = match next(st) {
|
|
|
|
'V' => true,
|
|
|
|
'N' => false,
|
2014-10-09 15:17:22 -04:00
|
|
|
r => panic!(format!("bad variadic: {}", r)),
|
2013-10-29 06:03:32 -04:00
|
|
|
};
|
2014-10-24 21:14:37 +02:00
|
|
|
let output = match peek(st) {
|
|
|
|
'z' => {
|
|
|
|
st.pos += 1u;
|
|
|
|
ty::FnDiverging
|
|
|
|
}
|
|
|
|
_ => ty::FnConverging(parse_ty(st, |x,y| conv(x,y)))
|
|
|
|
};
|
2014-11-15 16:47:59 -05:00
|
|
|
ty::FnSig {inputs: inputs,
|
2014-10-24 21:14:37 +02:00
|
|
|
output: output,
|
2013-10-29 06:03:32 -04:00
|
|
|
variadic: variadic}
|
2011-06-27 15:30:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Rust metadata parsing
|
2013-09-02 03:45:37 +02:00
|
|
|
pub fn parse_def_id(buf: &[u8]) -> ast::DefId {
|
2012-03-15 09:47:03 -04:00
|
|
|
let mut colon_idx = 0u;
|
2013-05-14 18:52:12 +09:00
|
|
|
let len = buf.len();
|
2011-08-19 15:16:48 -07:00
|
|
|
while colon_idx < len && buf[colon_idx] != ':' as u8 { colon_idx += 1u; }
|
2011-07-27 14:19:39 +02:00
|
|
|
if colon_idx == len {
|
2013-10-21 13:08:31 -07:00
|
|
|
error!("didn't find ':' when parsing def id");
|
2014-10-09 15:17:22 -04:00
|
|
|
panic!();
|
2011-06-27 15:30:17 -07:00
|
|
|
}
|
2012-08-17 15:54:18 -07:00
|
|
|
|
2014-09-24 23:41:09 +12:00
|
|
|
let crate_part = buf[0u..colon_idx];
|
|
|
|
let def_part = buf[colon_idx + 1u..len];
|
2011-07-12 10:59:18 -07:00
|
|
|
|
2014-11-02 17:27:11 +11:00
|
|
|
let crate_num = match str::from_utf8(crate_part).and_then(from_str::<uint>) {
|
2013-11-27 07:02:25 +02:00
|
|
|
Some(cn) => cn as ast::CrateNum,
|
2014-10-09 15:17:22 -04:00
|
|
|
None => panic!("internal error: parse_def_id: crate number expected, found {}",
|
2013-05-09 13:52:07 +02:00
|
|
|
crate_part)
|
2012-03-06 08:02:13 -08:00
|
|
|
};
|
2014-11-02 17:27:11 +11:00
|
|
|
let def_num = match str::from_utf8(def_part).and_then(from_str::<uint>) {
|
2013-11-27 07:02:25 +02:00
|
|
|
Some(dn) => dn as ast::NodeId,
|
2014-10-09 15:17:22 -04:00
|
|
|
None => panic!("internal error: parse_def_id: id expected, found {}",
|
2013-05-09 13:52:07 +02:00
|
|
|
def_part)
|
2012-03-06 08:02:13 -08:00
|
|
|
};
|
2014-02-05 22:15:24 +01:00
|
|
|
ast::DefId { krate: crate_num, node: def_num }
|
2011-06-27 15:30:17 -07:00
|
|
|
}
|
2011-07-19 17:52:34 -07:00
|
|
|
|
2014-12-07 11:10:48 -05:00
|
|
|
pub fn parse_predicate_data<'tcx>(data: &[u8],
|
|
|
|
start: uint,
|
|
|
|
crate_num: ast::CrateNum,
|
|
|
|
tcx: &ty::ctxt<'tcx>,
|
|
|
|
conv: conv_did)
|
|
|
|
-> ty::Predicate<'tcx>
|
|
|
|
{
|
|
|
|
let mut st = parse_state_from_data(data, crate_num, start, tcx);
|
|
|
|
parse_predicate(&mut st, conv)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn parse_predicate<'a,'tcx>(st: &mut PState<'a, 'tcx>,
|
|
|
|
conv: conv_did)
|
|
|
|
-> ty::Predicate<'tcx>
|
|
|
|
{
|
|
|
|
match next(st) {
|
|
|
|
't' => ty::Predicate::Trait(Rc::new(parse_trait_ref(st, conv))),
|
|
|
|
'e' => ty::Predicate::Equate(parse_ty(st, |x,y| conv(x,y)),
|
|
|
|
parse_ty(st, |x,y| conv(x,y))),
|
|
|
|
'r' => ty::Predicate::RegionOutlives(parse_region(st, |x,y| conv(x,y)),
|
|
|
|
parse_region(st, |x,y| conv(x,y))),
|
|
|
|
'o' => ty::Predicate::TypeOutlives(parse_ty(st, |x,y| conv(x,y)),
|
|
|
|
parse_region(st, |x,y| conv(x,y))),
|
|
|
|
c => panic!("Encountered invalid character in metadata: {}", c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn parse_type_param_def_data<'tcx>(data: &[u8], start: uint,
|
|
|
|
crate_num: ast::CrateNum, tcx: &ty::ctxt<'tcx>,
|
|
|
|
conv: conv_did) -> ty::TypeParameterDef<'tcx>
|
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
|
|
|
{
|
2013-06-08 02:01:30 +02:00
|
|
|
let mut st = parse_state_from_data(data, crate_num, start, tcx);
|
|
|
|
parse_type_param_def(&mut st, conv)
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-08 22:54:49 -07:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
fn parse_type_param_def<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did)
|
|
|
|
-> ty::TypeParameterDef<'tcx> {
|
2014-09-30 19:11:34 -05:00
|
|
|
let name = parse_name(st, ':');
|
2014-05-31 18:53:13 -04:00
|
|
|
let def_id = parse_def(st, NominalType, |x,y| conv(x,y));
|
|
|
|
let space = parse_param_space(st);
|
|
|
|
assert_eq!(next(st), '|');
|
|
|
|
let index = parse_uint(st);
|
|
|
|
assert_eq!(next(st), '|');
|
2014-08-05 19:44:21 -07:00
|
|
|
let associated_with = parse_opt(st, |st| {
|
|
|
|
parse_def(st, NominalType, |x,y| conv(x,y))
|
|
|
|
});
|
|
|
|
assert_eq!(next(st), '|');
|
2014-08-27 21:46:52 -04:00
|
|
|
let bounds = parse_bounds(st, |x,y| conv(x,y));
|
2014-05-31 18:53:13 -04:00
|
|
|
let default = parse_opt(st, |st| parse_ty(st, |x,y| conv(x,y)));
|
|
|
|
|
2014-01-30 19:28:02 +02:00
|
|
|
ty::TypeParameterDef {
|
2014-09-30 19:11:34 -05:00
|
|
|
name: name,
|
2014-05-31 18:53:13 -04:00
|
|
|
def_id: def_id,
|
|
|
|
space: space,
|
|
|
|
index: index,
|
2014-08-05 19:44:21 -07:00
|
|
|
associated_with: associated_with,
|
2014-05-31 18:53:13 -04:00
|
|
|
bounds: bounds,
|
|
|
|
default: default
|
2014-01-30 19:28:02 +02:00
|
|
|
}
|
2011-12-28 17:50:12 +01:00
|
|
|
}
|
|
|
|
|
2014-08-27 21:46:52 -04:00
|
|
|
fn parse_existential_bounds(st: &mut PState, conv: conv_did) -> ty::ExistentialBounds {
|
|
|
|
let r = parse_region(st, |x,y| conv(x,y));
|
|
|
|
let bb = parse_builtin_bounds(st, conv);
|
|
|
|
return ty::ExistentialBounds { region_bound: r, builtin_bounds: bb };
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parse_builtin_bounds(st: &mut PState, _conv: conv_did) -> ty::BuiltinBounds {
|
|
|
|
let mut builtin_bounds = ty::empty_builtin_bounds();
|
|
|
|
|
2012-03-10 20:34:17 -08:00
|
|
|
loop {
|
2013-05-07 17:30:21 -04:00
|
|
|
match next(st) {
|
|
|
|
'S' => {
|
2014-11-06 12:25:16 -05:00
|
|
|
builtin_bounds.insert(ty::BoundSend);
|
2013-05-07 17:30:21 -04:00
|
|
|
}
|
2013-05-30 20:03:01 -04:00
|
|
|
'Z' => {
|
2014-11-06 12:25:16 -05:00
|
|
|
builtin_bounds.insert(ty::BoundSized);
|
2013-05-30 20:03:01 -04:00
|
|
|
}
|
2013-12-18 15:03:32 -08:00
|
|
|
'P' => {
|
2014-11-06 12:25:16 -05:00
|
|
|
builtin_bounds.insert(ty::BoundCopy);
|
2013-12-18 15:03:32 -08:00
|
|
|
}
|
2014-03-03 23:27:46 +01:00
|
|
|
'T' => {
|
2014-11-06 12:25:16 -05:00
|
|
|
builtin_bounds.insert(ty::BoundSync);
|
2014-08-27 21:46:52 -04:00
|
|
|
}
|
|
|
|
'.' => {
|
|
|
|
return builtin_bounds;
|
|
|
|
}
|
|
|
|
c => {
|
2014-10-09 15:17:22 -04:00
|
|
|
panic!("parse_bounds: bad builtin bounds ('{}')", c)
|
2014-08-27 21:46:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
fn parse_bounds<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did)
|
|
|
|
-> ty::ParamBounds<'tcx> {
|
2014-08-27 21:46:52 -04:00
|
|
|
let builtin_bounds = parse_builtin_bounds(st, |x,y| conv(x,y));
|
|
|
|
|
|
|
|
let mut param_bounds = ty::ParamBounds {
|
2014-08-14 18:05:27 -04:00
|
|
|
region_bounds: Vec::new(),
|
2014-08-27 21:46:52 -04:00
|
|
|
builtin_bounds: builtin_bounds,
|
|
|
|
trait_bounds: Vec::new()
|
|
|
|
};
|
|
|
|
loop {
|
|
|
|
match next(st) {
|
|
|
|
'R' => {
|
2014-08-14 18:05:27 -04:00
|
|
|
param_bounds.region_bounds.push(parse_region(st, |x, y| conv (x, y)));
|
2014-03-03 23:27:46 +01:00
|
|
|
}
|
2013-05-07 17:30:21 -04:00
|
|
|
'I' => {
|
2014-04-22 02:21:52 +03:00
|
|
|
param_bounds.trait_bounds.push(Rc::new(parse_trait_ref(st, |x,y| conv(x,y))));
|
2013-05-07 17:30:21 -04:00
|
|
|
}
|
|
|
|
'.' => {
|
2013-05-10 15:57:27 -04:00
|
|
|
return param_bounds;
|
2013-05-07 17:30:21 -04:00
|
|
|
}
|
2013-12-18 15:03:32 -08:00
|
|
|
c => {
|
2014-10-09 15:17:22 -04:00
|
|
|
panic!("parse_bounds: bad bounds ('{}')", c)
|
2013-05-07 17:30:21 -04:00
|
|
|
}
|
|
|
|
}
|
2011-12-28 17:50:12 +01:00
|
|
|
}
|
|
|
|
}
|