Skip to content

Rollup of 8 pull requests #66417

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

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7b9d50d
rename Error::iter_chain() and remove Error::iter_sources()
haraldh Oct 15, 2019
b941034
qualify-const remove cannot mutate statics in initializer of another …
spastorino Nov 11, 2019
695e91a
check-consts remove cannot mutate statics in initializer of another s…
spastorino Nov 12, 2019
139477d
Update mdbook.
ehuss Nov 12, 2019
32d1f47
Fix mdbook-linkcheck license checks.
ehuss Nov 12, 2019
37de933
Fix spurious CI filures due to OOM
wesleywiser Nov 14, 2019
f37f423
Make a test compatible across python versions.
smmalis37 Nov 14, 2019
3fe7cfc
Remove some stack frames from `.async` calls
sfackler Nov 14, 2019
92154d0
[ConstProp] Avoid OOM crashes by not evaluating large Places
wesleywiser Nov 14, 2019
6c9ba97
miri: helper methods for max values of machine's usize/isize
RalfJung Nov 14, 2019
0c52c3e
Respond to review feedback
wesleywiser Nov 14, 2019
6a49b52
TAIT: remove `OpaqueTy` in AST.
Centril Nov 7, 2019
6d8e300
TAIT: feature gate recursive locations
Centril Nov 7, 2019
0e8e176
TAIT: parse recursively instead of hack.
Centril Nov 7, 2019
aa6a72f
TAIT: use hack in ->HIR to avoid more changes
Centril Nov 7, 2019
e31d75c
TAIT: remove redundant check from ast_validation
Centril Nov 7, 2019
89b5907
TAIT: adjust save-analysis
Centril Nov 7, 2019
75aaa85
TAIT: adjust resolve
Centril Nov 7, 2019
8b663ec
TAIT: --bless some span changes for the better
Centril Nov 7, 2019
03cf0d7
TAIT: adjust tests
Centril Nov 7, 2019
5b93d4d
Rollup merge of #65557 - haraldh:error_iter_rename, r=sfackler
tmandry Nov 14, 2019
9876ced
Rollup merge of #66197 - Centril:transparent-ast, r=varkor
tmandry Nov 14, 2019
8b8f7ee
Rollup merge of #66306 - spastorino:remove-error-handled-by-miri, r=o…
tmandry Nov 14, 2019
b375256
Rollup merge of #66338 - ehuss:update-mdbook, r=alexcrichton
tmandry Nov 14, 2019
407968d
Rollup merge of #66394 - wesleywiser:fix_oom, r=oli-obk
tmandry Nov 14, 2019
ab8e0df
Rollup merge of #66396 - smmalis37:pythontest, r=alexcrichton
tmandry Nov 14, 2019
853af77
Rollup merge of #66398 - sfackler:no-async-nesting, r=Centril
tmandry Nov 14, 2019
e3bbc0d
Rollup merge of #66410 - RalfJung:miri-machine-max, r=oli-obk
tmandry Nov 14, 2019
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
347 changes: 172 additions & 175 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ impl<'a> LoweringContext<'a> {
| ItemKind::Union(_, ref generics)
| ItemKind::Enum(_, ref generics)
| ItemKind::TyAlias(_, ref generics)
| ItemKind::OpaqueTy(_, ref generics)
| ItemKind::Trait(_, _, ref generics, ..) => {
let def_id = self.lctx.resolver.definitions().local_def_id(item.id);
let count = generics
Expand Down
62 changes: 35 additions & 27 deletions src/librustc/hir/lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,20 +335,22 @@ impl LoweringContext<'_> {
ItemKind::Mod(ref m) => hir::ItemKind::Mod(self.lower_mod(m)),
ItemKind::ForeignMod(ref nm) => hir::ItemKind::ForeignMod(self.lower_foreign_mod(nm)),
ItemKind::GlobalAsm(ref ga) => hir::ItemKind::GlobalAsm(self.lower_global_asm(ga)),
ItemKind::TyAlias(ref t, ref generics) => hir::ItemKind::TyAlias(
self.lower_ty(t, ImplTraitContext::disallowed()),
self.lower_generics(generics, ImplTraitContext::disallowed()),
),
ItemKind::OpaqueTy(ref b, ref generics) => hir::ItemKind::OpaqueTy(
hir::OpaqueTy {
generics: self.lower_generics(generics,
ImplTraitContext::OpaqueTy(None)),
bounds: self.lower_param_bounds(b,
ImplTraitContext::OpaqueTy(None)),
impl_trait_fn: None,
origin: hir::OpaqueTyOrigin::TypeAlias,
ItemKind::TyAlias(ref ty, ref generics) => match ty.kind.opaque_top_hack() {
None => {
let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
hir::ItemKind::TyAlias(ty, generics)
},
),
Some(bounds) => {
let ty = hir::OpaqueTy {
generics: self.lower_generics(generics, ImplTraitContext::OpaqueTy(None)),
bounds: self.lower_param_bounds(bounds, ImplTraitContext::OpaqueTy(None)),
impl_trait_fn: None,
origin: hir::OpaqueTyOrigin::TypeAlias,
};
hir::ItemKind::OpaqueTy(ty)
}
}
ItemKind::Enum(ref enum_definition, ref generics) => {
hir::ItemKind::Enum(
hir::EnumDef {
Expand Down Expand Up @@ -914,16 +916,20 @@ impl LoweringContext<'_> {

(generics, hir::ImplItemKind::Method(sig, body_id))
}
ImplItemKind::TyAlias(ref ty) => (
self.lower_generics(&i.generics, ImplTraitContext::disallowed()),
hir::ImplItemKind::TyAlias(self.lower_ty(ty, ImplTraitContext::disallowed())),
),
ImplItemKind::OpaqueTy(ref bounds) => (
self.lower_generics(&i.generics, ImplTraitContext::disallowed()),
hir::ImplItemKind::OpaqueTy(
self.lower_param_bounds(bounds, ImplTraitContext::disallowed()),
),
),
ImplItemKind::TyAlias(ref ty) => {
let generics = self.lower_generics(&i.generics, ImplTraitContext::disallowed());
let kind = match ty.kind.opaque_top_hack() {
None => {
let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
hir::ImplItemKind::TyAlias(ty)
}
Some(bs) => {
let bounds = self.lower_param_bounds(bs, ImplTraitContext::disallowed());
hir::ImplItemKind::OpaqueTy(bounds)
}
};
(generics, kind)
},
ImplItemKind::Macro(..) => bug!("`TyMac` should have been expanded by now"),
};

Expand All @@ -948,11 +954,13 @@ impl LoweringContext<'_> {
span: i.span,
vis: self.lower_visibility(&i.vis, Some(i.id)),
defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),
kind: match i.kind {
kind: match &i.kind {
ImplItemKind::Const(..) => hir::AssocItemKind::Const,
ImplItemKind::TyAlias(..) => hir::AssocItemKind::Type,
ImplItemKind::OpaqueTy(..) => hir::AssocItemKind::OpaqueTy,
ImplItemKind::Method(ref sig, _) => hir::AssocItemKind::Method {
ImplItemKind::TyAlias(ty) => match ty.kind.opaque_top_hack() {
None => hir::AssocItemKind::Type,
Some(_) => hir::AssocItemKind::OpaqueTy,
},
ImplItemKind::Method(sig, _) => hir::AssocItemKind::Method {
has_self: sig.decl.has_self(),
},
ImplItemKind::Macro(..) => unimplemented!(),
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
}
ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) |
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) |
ItemKind::OpaqueTy(..) | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) |
ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) |
ItemKind::TyAlias(..) => DefPathData::TypeNs(i.ident.name),
ItemKind::Fn(sig, generics, body) if sig.header.asyncness.node.is_async() => {
return self.visit_async_fn(
Expand Down Expand Up @@ -239,8 +239,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
}
ImplItemKind::Method(..) |
ImplItemKind::Const(..) => DefPathData::ValueNs(ii.ident.name),
ImplItemKind::TyAlias(..) |
ImplItemKind::OpaqueTy(..) => DefPathData::TypeNs(ii.ident.name),
ImplItemKind::TyAlias(..) => DefPathData::TypeNs(ii.ident.name),
ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id),
};

Expand Down
13 changes: 13 additions & 0 deletions src/librustc/mir/interpret/pointer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fmt::{self, Display};
use std::convert::TryFrom;

use crate::mir;
use crate::ty::layout::{self, HasDataLayout, Size};
Expand Down Expand Up @@ -40,6 +41,18 @@ pub trait PointerArithmetic: layout::HasDataLayout {
self.data_layout().pointer_size
}

#[inline]
fn usize_max(&self) -> u64 {
let max_usize_plus_1 = 1u128 << self.pointer_size().bits();
u64::try_from(max_usize_plus_1-1).unwrap()
}

#[inline]
fn isize_max(&self) -> i64 {
let max_isize_plus_1 = 1u128 << (self.pointer_size().bits()-1);
i64::try_from(max_isize_plus_1-1).unwrap()
}

/// Helper function: truncate given value-"overflowed flag" pair to pointer size and
/// update "overflowed flag" if there was an overflow.
/// This should be called by all the other methods before returning!
Expand Down
12 changes: 1 addition & 11 deletions src/librustc_mir/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
let is_thread_local = self.tcx.has_attr(*def_id, sym::thread_local);
if is_thread_local {
self.check_op(ops::ThreadLocalAccess);
} else if self.const_kind() == ConstKind::Static && context.is_mutating_use() {
// this is not strictly necessary as miri will also bail out
// For interior mutability we can't really catch this statically as that
// goes through raw pointers and intermediate temporaries, so miri has
// to catch this anyway

self.tcx.sess.span_err(
self.span,
"cannot mutate statics in the initializer of another static",
);
} else {
} else if self.const_kind() != ConstKind::Static || !context.is_mutating_use() {
self.check_op(ops::StaticAccess);
}
}
Expand Down
16 changes: 13 additions & 3 deletions src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use rustc::ty::subst::InternalSubsts;
use rustc_data_structures::fx::FxHashMap;
use rustc_index::vec::IndexVec;
use rustc::ty::layout::{
LayoutOf, TyLayout, LayoutError, HasTyCtxt, TargetDataLayout, HasDataLayout,
LayoutOf, TyLayout, LayoutError, HasTyCtxt, TargetDataLayout, HasDataLayout, Size,
};

use crate::rustc::ty::subst::Subst;
Expand All @@ -35,6 +35,9 @@ use crate::interpret::{
use crate::const_eval::error_to_const_error;
use crate::transform::{MirPass, MirSource};

/// The maximum number of bytes that we'll allocate space for a return value.
const MAX_ALLOC_LIMIT: u64 = 1024;

pub struct ConstProp;

impl<'tcx> MirPass<'tcx> for ConstProp {
Expand Down Expand Up @@ -313,8 +316,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
ecx
.layout_of(body.return_ty().subst(tcx, substs))
.ok()
// Don't bother allocating memory for ZST types which have no values.
.filter(|ret_layout| !ret_layout.is_zst())
// Don't bother allocating memory for ZST types which have no values
// or for large values.
.filter(|ret_layout| !ret_layout.is_zst() &&
ret_layout.size < Size::from_bytes(MAX_ALLOC_LIMIT))
.map(|ret_layout| ecx.allocate(ret_layout, MemoryKind::Stack));

ecx.push_stack_frame(
Expand Down Expand Up @@ -453,6 +458,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
) -> Option<()> {
let span = source_info.span;

// #66397: Don't try to eval into large places as that can cause an OOM
if place_layout.size >= Size::from_bytes(MAX_ALLOC_LIMIT) {
return None;
}

let overflow_check = self.tcx.sess.overflow_checks();

// Perform any special handling for specific Rvalue types.
Expand Down
13 changes: 0 additions & 13 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,19 +785,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {

// Only allow statics (not consts) to refer to other statics.
if self.mode == Mode::Static || self.mode == Mode::StaticMut {
if self.mode == Mode::Static
&& context.is_mutating_use()
&& !self.suppress_errors
{
// this is not strictly necessary as miri will also bail out
// For interior mutability we can't really catch this statically as that
// goes through raw pointers and intermediate temporaries, so miri has
// to catch this anyway
self.tcx.sess.span_err(
self.span,
"cannot mutate statics in the initializer of another static",
);
}
return;
}
unleash_miri!(self);
Expand Down
61 changes: 13 additions & 48 deletions src/librustc_parse/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use syntax::ast::{self, Abi, DUMMY_NODE_ID, Ident, Attribute, AttrKind, AttrStyl
use syntax::ast::{ItemKind, ImplItem, ImplItemKind, TraitItem, TraitItemKind, UseTree, UseTreeKind};
use syntax::ast::{PathSegment, IsAuto, Constness, IsAsync, Unsafety, Defaultness};
use syntax::ast::{Visibility, VisibilityKind, Mutability, FnHeader, ForeignItem, ForeignItemKind};
use syntax::ast::{Ty, TyKind, Generics, GenericBounds, TraitRef, EnumDef, VariantData, StructField};
use syntax::ast::{Ty, TyKind, Generics, TraitRef, EnumDef, VariantData, StructField};
use syntax::ast::{Mac, MacDelimiter, Block, BindingMode, FnDecl, FnSig, SelfKind, Param};
use syntax::ptr::P;
use syntax::ThinVec;
Expand All @@ -21,15 +21,6 @@ use log::debug;
use std::mem;
use errors::{PResult, Applicability, DiagnosticBuilder, DiagnosticId, StashKey};

/// Whether the type alias or associated type is a concrete type or an opaque type.
#[derive(Debug)]
pub(super) enum AliasKind {
/// Just a new name for the same type.
Weak(P<Ty>),
/// Only trait impls of the type will be usable, not the actual type itself.
OpaqueTy(GenericBounds),
}

pub(super) type ItemInfo = (Ident, ItemKind, Option<Vec<Attribute>>);

impl<'a> Parser<'a> {
Expand Down Expand Up @@ -266,15 +257,11 @@ impl<'a> Parser<'a> {
return self.mk_item_with_info(attrs, lo, vis, info);
}

if let Some(type_) = self.eat_type() {
let (ident, alias, generics) = type_?;
if self.eat_keyword(kw::Type) {
// TYPE ITEM
let item_ = match alias {
AliasKind::Weak(ty) => ItemKind::TyAlias(ty, generics),
AliasKind::OpaqueTy(bounds) => ItemKind::OpaqueTy(bounds, generics),
};
let span = lo.to(self.prev_span);
return Ok(Some(self.mk_item(span, ident, item_, vis, attrs)));
let (ident, ty, generics) = self.parse_type_alias()?;
let kind = ItemKind::TyAlias(ty, generics);
return self.mk_item_with_info(attrs, lo, vis, (ident, kind, None));
}

if self.eat_keyword(kw::Enum) {
Expand Down Expand Up @@ -708,13 +695,9 @@ impl<'a> Parser<'a> {
let lo = self.token.span;
let vis = self.parse_visibility(false)?;
let defaultness = self.parse_defaultness();
let (name, kind, generics) = if let Some(type_) = self.eat_type() {
let (name, alias, generics) = type_?;
let kind = match alias {
AliasKind::Weak(typ) => ast::ImplItemKind::TyAlias(typ),
AliasKind::OpaqueTy(bounds) => ast::ImplItemKind::OpaqueTy(bounds),
};
(name, kind, generics)
let (name, kind, generics) = if self.eat_keyword(kw::Type) {
let (name, ty, generics) = self.parse_type_alias()?;
(name, ast::ImplItemKind::TyAlias(ty), generics)
} else if self.is_const_item() {
self.parse_impl_const()?
} else if let Some(mac) = self.parse_assoc_macro_invoc("impl", Some(&vis), at_end)? {
Expand Down Expand Up @@ -1318,34 +1301,16 @@ impl<'a> Parser<'a> {
})
}

/// Parses `type Foo = Bar;` or returns `None`
/// without modifying the parser state.
fn eat_type(&mut self) -> Option<PResult<'a, (Ident, AliasKind, Generics)>> {
// This parses the grammar:
// Ident ["<"...">"] ["where" ...] ("=" | ":") Ty ";"
if self.eat_keyword(kw::Type) {
Some(self.parse_type_alias())
} else {
None
}
}

/// Parses a type alias or opaque type.
fn parse_type_alias(&mut self) -> PResult<'a, (Ident, AliasKind, Generics)> {
/// Parses the grammar:
/// Ident ["<"...">"] ["where" ...] ("=" | ":") Ty ";"
fn parse_type_alias(&mut self) -> PResult<'a, (Ident, P<Ty>, Generics)> {
let ident = self.parse_ident()?;
let mut tps = self.parse_generics()?;
tps.where_clause = self.parse_where_clause()?;
self.expect(&token::Eq)?;
let alias = if self.check_keyword(kw::Impl) {
self.bump();
let bounds = self.parse_generic_bounds(Some(self.prev_span))?;
AliasKind::OpaqueTy(bounds)
} else {
let ty = self.parse_ty()?;
AliasKind::Weak(ty)
};
let ty = self.parse_ty()?;
self.expect_semi()?;
Ok((ident, alias, tps))
Ok((ident, ty, tps))
}

/// Parses an enum declaration.
Expand Down
10 changes: 1 addition & 9 deletions src/librustc_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use syntax::source_map::Spanned;
use syntax::symbol::{kw, sym};
use syntax::visit::{self, Visitor};
use syntax::{span_err, struct_span_err, walk_list};
use syntax_pos::{Span, MultiSpan};
use syntax_pos::Span;
use errors::{Applicability, FatalError};

struct AstValidator<'a> {
Expand Down Expand Up @@ -584,14 +584,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
"unions cannot have zero fields");
}
}
ItemKind::OpaqueTy(ref bounds, _) => {
if !bounds.iter()
.any(|b| if let GenericBound::Trait(..) = *b { true } else { false }) {
let msp = MultiSpan::from_spans(bounds.iter()
.map(|bound| bound.span()).collect());
self.err_handler().span_err(msp, "at least one trait must be specified");
}
}
_ => {}
}

Expand Down
13 changes: 6 additions & 7 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,13 +699,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
}

// These items live in the type namespace.
ItemKind::TyAlias(..) => {
let res = Res::Def(DefKind::TyAlias, self.r.definitions.local_def_id(item.id));
self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion));
}

ItemKind::OpaqueTy(_, _) => {
let res = Res::Def(DefKind::OpaqueTy, self.r.definitions.local_def_id(item.id));
ItemKind::TyAlias(ref ty, _) => {
let def_kind = match ty.kind.opaque_top_hack() {
None => DefKind::TyAlias,
Some(_) => DefKind::OpaqueTy,
};
let res = Res::Def(def_kind, self.r.definitions.local_def_id(item.id));
self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion));
}

Expand Down
13 changes: 0 additions & 13 deletions src/librustc_resolve/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,6 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {

match item.kind {
ItemKind::TyAlias(_, ref generics) |
ItemKind::OpaqueTy(_, ref generics) |
ItemKind::Fn(_, ref generics, _) => {
self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes),
|this| visit::walk_item(this, item));
Expand Down Expand Up @@ -1085,18 +1084,6 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {

this.visit_ty(ty);
}
ImplItemKind::OpaqueTy(ref bounds) => {
// If this is a trait impl, ensure the type
// exists in trait
this.check_trait_item(impl_item.ident,
TypeNS,
impl_item.span,
|n, s| TypeNotMemberOfTrait(n, s));

for bound in bounds {
this.visit_param_bound(bound);
}
}
ImplItemKind::Macro(_) =>
panic!("unexpanded macro in resolve!"),
}
Expand Down
Loading