Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #30555

Merged
merged 14 commits into from
Dec 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/doc/book/syntax-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

* `!` (`ident!(…)`, `ident!{…}`, `ident![…]`): denotes macro expansion. See [Macros].
* `!` (`!expr`): bitwise or logical complement. Overloadable (`Not`).
* `!=` (`var != expr`): nonequality comparison. Overloadable (`PartialEq`).
* `%` (`expr % expr`): arithmetic remainder. Overloadable (`Rem`).
* `%=` (`var %= expr`): arithmetic remainder & assignment.
* `&` (`expr & expr`): bitwise and. Overloadable (`BitAnd`).
Expand Down Expand Up @@ -75,13 +76,13 @@
* `;` (`[…; len]`): part of fixed-size array syntax. See [Primitive Types (Arrays)].
* `<<` (`expr << expr`): left-shift. Overloadable (`Shl`).
* `<<=` (`var <<= expr`): left-shift & assignment.
* `<` (`expr < expr`): less-than comparison. Overloadable (`Cmp`, `PartialCmp`).
* `<=` (`var <= expr`): less-than or equal-to comparison. Overloadable (`Cmp`, `PartialCmp`).
* `<` (`expr < expr`): less-than comparison. Overloadable (`PartialOrd`).
* `<=` (`var <= expr`): less-than or equal-to comparison. Overloadable (`PartialOrd`).
* `=` (`var = expr`, `ident = type`): assignment/equivalence. See [Variable Bindings], [`type` Aliases], generic parameter defaults.
* `==` (`var == expr`): comparison. Overloadable (`Eq`, `PartialEq`).
* `==` (`var == expr`): equality comparison. Overloadable (`PartialEq`).
* `=>` (`pat => expr`): part of match arm syntax. See [Match].
* `>` (`expr > expr`): greater-than comparison. Overloadable (`Cmp`, `PartialCmp`).
* `>=` (`var >= expr`): greater-than or equal-to comparison. Overloadable (`Cmp`, `PartialCmp`).
* `>` (`expr > expr`): greater-than comparison. Overloadable (`PartialOrd`).
* `>=` (`var >= expr`): greater-than or equal-to comparison. Overloadable (`PartialOrd`).
* `>>` (`expr >> expr`): right-shift. Overloadable (`Shr`).
* `>>=` (`var >>= expr`): right-shift & assignment.
* `@` (`ident @ pat`): pattern binding. See [Patterns (Bindings)].
Expand Down
4 changes: 2 additions & 2 deletions src/grammar/parser-lalr.y
Original file line number Diff line number Diff line change
Expand Up @@ -1822,8 +1822,8 @@ unpaired_token
| LIT_FLOAT { $$ = mk_atom(yytext); }
| LIT_STR { $$ = mk_atom(yytext); }
| LIT_STR_RAW { $$ = mk_atom(yytext); }
| LIT_BYTE_STR { $$ = mk_atom(yytext); }
| LIT_BYTE_STR_RAW { $$ = mk_atom(yytext); }
| LIT_BYTE_STR { $$ = mk_atom(yytext); }
| LIT_BYTE_STR_RAW { $$ = mk_atom(yytext); }
| IDENT { $$ = mk_atom(yytext); }
| UNDERSCORE { $$ = mk_atom(yytext); }
| LIFETIME { $$ = mk_atom(yytext); }
Expand Down
11 changes: 5 additions & 6 deletions src/librustc/front/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,11 +839,10 @@ pub fn map_crate<'ast>(forest: &'ast mut Forest) -> Map<'ast> {
}

/// Used for items loaded from external crate that are being inlined into this
/// crate. The `path` should be the path to the item but should not include
/// the item itself.
/// crate.
pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
path: Vec<PathElem>,
def_path: DefPath,
parent_path: Vec<PathElem>,
parent_def_path: DefPath,
ii: InlinedItem,
fold_ops: F)
-> &'ast InlinedItem {
Expand All @@ -862,7 +861,7 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
};

let ii_parent = map.forest.inlined_items.alloc(InlinedParent {
path: path,
path: parent_path,
ii: ii
});

Expand All @@ -872,7 +871,7 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
map.krate(),
ii_parent,
ii_parent_id,
def_path,
parent_def_path,
mem::replace(&mut *map.map.borrow_mut(), vec![]),
mem::replace(&mut *map.definitions.borrow_mut(), Definitions::new()));
ii_parent.ii.visit(&mut collector);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,9 @@ pub struct Constant<'tcx> {
#[derive(Clone, Copy, Debug, PartialEq, RustcEncodable, RustcDecodable)]
pub enum ItemKind {
Constant,
/// This is any sort of callable (usually those that have a type of `fn(…) -> …`). This
/// includes functions, constructors, but not methods which have their own ItemKind.
Function,
Struct,
Variant,
Method,
}

Expand Down
15 changes: 9 additions & 6 deletions src/librustc_metadata/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,20 @@ impl<'a, 'b, 'c, 'tcx> ast_map::FoldOps for &'a DecodeContext<'b, 'c, 'tcx> {
/// ast-map.
pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata,
tcx: &ty::ctxt<'tcx>,
path: Vec<ast_map::PathElem>,
def_path: ast_map::DefPath,
parent_path: Vec<ast_map::PathElem>,
parent_def_path: ast_map::DefPath,
par_doc: rbml::Doc,
orig_did: DefId)
-> Result<&'tcx InlinedItem, (Vec<ast_map::PathElem>,
ast_map::DefPath)> {
match par_doc.opt_child(c::tag_ast) {
None => Err((path, def_path)),
None => Err((parent_path, parent_def_path)),
Some(ast_doc) => {
let mut path_as_str = None;
debug!("> Decoding inlined fn: {:?}::?",
{
// Do an Option dance to use the path after it is moved below.
let s = ast_map::path_to_string(path.iter().cloned());
let s = ast_map::path_to_string(parent_path.iter().cloned());
path_as_str = Some(s);
path_as_str.as_ref().map(|x| &x[..])
});
Expand All @@ -152,8 +152,11 @@ pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata,
last_filemap_index: Cell::new(0)
};
let raw_ii = decode_ast(ast_doc);
let ii = ast_map::map_decoded_item(&dcx.tcx.map, path, def_path, raw_ii, dcx);

let ii = ast_map::map_decoded_item(&dcx.tcx.map,
parent_path,
parent_def_path,
raw_ii,
dcx);
let name = match *ii {
InlinedItem::Item(ref i) => i.name,
InlinedItem::Foreign(ref i) => i.name,
Expand Down
47 changes: 36 additions & 11 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,29 +763,54 @@ pub fn get_item_name(intr: &IdentInterner, cdata: Cmd, id: DefIndex) -> ast::Nam
pub type DecodeInlinedItem<'a> =
Box<for<'tcx> FnMut(Cmd,
&ty::ctxt<'tcx>,
Vec<hir_map::PathElem>,
hir_map::DefPath,
Vec<hir_map::PathElem>, // parent_path
hir_map::DefPath, // parent_def_path
rbml::Doc,
DefId)
-> Result<&'tcx InlinedItem, (Vec<hir_map::PathElem>,
hir_map::DefPath)> + 'a>;

pub fn maybe_get_item_ast<'tcx>(cdata: Cmd, tcx: &ty::ctxt<'tcx>, id: DefIndex,
pub fn maybe_get_item_ast<'tcx>(cdata: Cmd,
tcx: &ty::ctxt<'tcx>,
id: DefIndex,
mut decode_inlined_item: DecodeInlinedItem)
-> FoundAst<'tcx> {
debug!("Looking up item: {:?}", id);
let item_doc = cdata.lookup_item(id);
let item_did = item_def_id(item_doc, cdata);
let path = item_path(item_doc).split_last().unwrap().1.to_vec();
let def_path = def_path(cdata, id);
match decode_inlined_item(cdata, tcx, path, def_path, item_doc, item_did) {
let parent_path = {
let mut path = item_path(item_doc);
path.pop();
path
};
let parent_def_path = {
let mut def_path = def_path(cdata, id);
def_path.pop();
def_path
};
match decode_inlined_item(cdata,
tcx,
parent_path,
parent_def_path,
item_doc,
item_did) {
Ok(ii) => FoundAst::Found(ii),
Err((path, def_path)) => {
Err((mut parent_path, mut parent_def_path)) => {
match item_parent_item(cdata, item_doc) {
Some(did) => {
let parent_item = cdata.lookup_item(did.index);
match decode_inlined_item(cdata, tcx, path, def_path, parent_item, did) {
Ok(ii) => FoundAst::FoundParent(did, ii),
Some(parent_did) => {
// Remove the last element from the paths, since we are now
// trying to inline the parent.
parent_path.pop();
parent_def_path.pop();

let parent_item = cdata.lookup_item(parent_did.index);
match decode_inlined_item(cdata,
tcx,
parent_path,
parent_def_path,
parent_item,
parent_did) {
Ok(ii) => FoundAst::FoundParent(parent_did, ii),
Err(_) => FoundAst::NotFound
}
}
Expand Down
58 changes: 29 additions & 29 deletions src/librustc_mir/hair/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,51 +519,51 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
let substs = cx.tcx.mk_substs(cx.tcx.node_id_item_substs(expr.id).substs);
// Otherwise there may be def_map borrow conflicts
let def = cx.tcx.def_map.borrow()[&expr.id].full_def();
match def {
def::DefVariant(_, def_id, false) |
def::DefStruct(def_id) |
def::DefFn(def_id, _) |
def::DefMethod(def_id) => {
let kind = match def {
def::DefVariant(..) => ItemKind::Variant,
def::DefStruct(..) => ItemKind::Struct,
def::DefFn(..) => ItemKind::Function,
def::DefMethod(..) => ItemKind::Method,
_ => panic!()
};
ExprKind::Literal {
literal: Literal::Item { def_id: def_id, kind: kind, substs: substs }
let (def_id, kind) = match def {
// A variant constructor.
def::DefVariant(_, def_id, false) => (def_id, ItemKind::Function),
// A regular function.
def::DefFn(def_id, _) => (def_id, ItemKind::Function),
def::DefMethod(def_id) => (def_id, ItemKind::Method),
def::DefStruct(def_id) => {
match cx.tcx.node_id_to_type(expr.id).sty {
// A tuple-struct constructor.
ty::TyBareFn(..) => (def_id, ItemKind::Function),
// This is a special case: a unit struct which is used as a value. We return a
// completely different ExprKind here to account for this special case.
ty::TyStruct(adt_def, substs) => return ExprKind::Adt {
adt_def: adt_def,
variant_index: 0,
substs: substs,
fields: vec![],
base: None
},
ref sty => panic!("unexpected sty: {:?}", sty)
}
},
def::DefConst(def_id) |
def::DefAssociatedConst(def_id) => {
if let Some(v) = cx.try_const_eval_literal(expr) {
ExprKind::Literal { literal: v }
return ExprKind::Literal { literal: v };
} else {
ExprKind::Literal {
literal: Literal::Item {
def_id: def_id,
kind: ItemKind::Constant,
substs: substs
}
}
(def_id, ItemKind::Constant)
}
}


def::DefStatic(node_id, _) =>
ExprKind::StaticRef {
id: node_id,
},
def::DefStatic(node_id, _) => return ExprKind::StaticRef {
id: node_id,
},

def @ def::DefLocal(..) |
def @ def::DefUpvar(..) =>
convert_var(cx, expr, def),
def @ def::DefUpvar(..) => return convert_var(cx, expr, def),

def =>
cx.tcx.sess.span_bug(
expr.span,
&format!("def `{:?}` not yet implemented", def)),
};
ExprKind::Literal {
literal: Literal::Item { def_id: def_id, kind: kind, substs: substs }
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/librustc_trans/trans/mir/did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
did: DefId)
-> OperandRef<'tcx> {
match kind {
ItemKind::Function |
ItemKind::Struct |
ItemKind::Variant => self.trans_fn_ref(bcx, ty, substs, did),
ItemKind::Function => self.trans_fn_ref(bcx, ty, substs, did),
ItemKind::Method => match bcx.tcx().impl_or_trait_item(did).container() {
ty::ImplContainer(_) => self.trans_fn_ref(bcx, ty, substs, did),
ty::TraitContainer(tdid) => self.trans_static_method(bcx, ty, did, tdid, substs)
Expand Down
49 changes: 31 additions & 18 deletions src/librustc_trans/trans/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,30 @@ use trans::common::{self, Block, Result};
use trans::debuginfo::DebugLoc;
use trans::declare;
use trans::expr;
use trans::adt;
use trans::machine;
use trans::type_::Type;
use trans::type_of;
use trans::tvec;

use super::MirContext;
use super::operand::{OperandRef, OperandValue};
use super::lvalue::LvalueRef;

impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
pub fn trans_rvalue(&mut self,
bcx: Block<'bcx, 'tcx>,
lldest: ValueRef,
dest: LvalueRef<'tcx>,
rvalue: &mir::Rvalue<'tcx>)
-> Block<'bcx, 'tcx>
{
debug!("trans_rvalue(lldest={}, rvalue={:?})",
bcx.val_to_string(lldest),
debug!("trans_rvalue(dest.llval={}, rvalue={:?})",
bcx.val_to_string(dest.llval),
rvalue);

match *rvalue {
mir::Rvalue::Use(ref operand) => {
self.trans_operand_into(bcx, lldest, operand);
self.trans_operand_into(bcx, dest.llval, operand);
bcx
}

Expand All @@ -49,7 +51,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
// into-coerce of a thin pointer to a fat pointer - just
// use the operand path.
let (bcx, temp) = self.trans_rvalue_operand(bcx, rvalue);
self.store_operand(bcx, lldest, temp);
self.store_operand(bcx, dest.llval, temp);
return bcx;
}

Expand All @@ -72,12 +74,12 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
base::store_ty(bcx, llval, lltemp, operand.ty);
base::coerce_unsized_into(bcx,
lltemp, operand.ty,
lldest, cast_ty);
dest.llval, cast_ty);
}
OperandValue::Ref(llref) => {
base::coerce_unsized_into(bcx,
llref, operand.ty,
lldest, cast_ty);
dest.llval, cast_ty);
}
}
bcx
Expand All @@ -86,20 +88,31 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
mir::Rvalue::Repeat(ref elem, ref count) => {
let elem = self.trans_operand(bcx, elem);
let size = self.trans_constant(bcx, count).immediate();
let base = expr::get_dataptr(bcx, lldest);
let base = expr::get_dataptr(bcx, dest.llval);
tvec::iter_vec_raw(bcx, base, elem.ty, size, |bcx, llslot, _| {
self.store_operand(bcx, llslot, elem);
bcx
})
}

mir::Rvalue::Aggregate(_, ref operands) => {
for (i, operand) in operands.iter().enumerate() {
// Note: perhaps this should be StructGep, but
// note that in some cases the values here will
// not be structs but arrays.
let lldest_i = build::GEPi(bcx, lldest, &[0, i]);
self.trans_operand_into(bcx, lldest_i, operand);
mir::Rvalue::Aggregate(ref kind, ref operands) => {
match *kind {
// Unit struct, which is translated very differently compared to any other
// aggregate
mir::AggregateKind::Adt(adt_def, 0, _)
if adt_def.struct_variant().kind() == ty::VariantKind::Unit => {
let repr = adt::represent_type(bcx.ccx(), dest.ty.to_ty(bcx.tcx()));
adt::trans_set_discr(bcx, &*repr, dest.llval, 0);
},
_ => {
for (i, operand) in operands.iter().enumerate() {
// Note: perhaps this should be StructGep, but
// note that in some cases the values here will
// not be structs but arrays.
let lldest_i = build::GEPi(bcx, dest.llval, &[0, i]);
self.trans_operand_into(bcx, lldest_i, operand);
}
}
}
bcx
}
Expand All @@ -113,9 +126,9 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
let llbase1 = build::GEPi(bcx, llbase, &[from_start]);
let adj = common::C_uint(ccx, from_start + from_end);
let lllen1 = build::Sub(bcx, lllen, adj, DebugLoc::None);
let lladdrdest = expr::get_dataptr(bcx, lldest);
let lladdrdest = expr::get_dataptr(bcx, dest.llval);
build::Store(bcx, llbase1, lladdrdest);
let llmetadest = expr::get_meta(bcx, lldest);
let llmetadest = expr::get_meta(bcx, dest.llval);
build::Store(bcx, lllen1, llmetadest);
bcx
}
Expand All @@ -127,7 +140,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
_ => {
assert!(rvalue_creates_operand(rvalue));
let (bcx, temp) = self.trans_rvalue_operand(bcx, rvalue);
self.store_operand(bcx, lldest, temp);
self.store_operand(bcx, dest.llval, temp);
bcx
}
}
Expand Down
Loading