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 7 pull requests #30432

Closed
wants to merge 16 commits into from
Closed
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
42 changes: 22 additions & 20 deletions src/doc/book/the-stack-and-the-heap.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,63 +130,64 @@ on the stack is the first one you retrieve from it.
Let’s try a three-deep example:

```rust
fn bar() {
fn italic() {
let i = 6;
}

fn foo() {
fn bold() {
let a = 5;
let b = 100;
let c = 1;

bar();
italic();
}

fn main() {
let x = 42;

foo();
bold();
}
```

We have some kooky function names to make the diagrams clearer.

Okay, first, we call `main()`:

| Address | Name | Value |
|---------|------|-------|
| 0 | x | 42 |

Next up, `main()` calls `foo()`:
Next up, `main()` calls `bold()`:

| Address | Name | Value |
|---------|------|-------|
| 3 | c | 1 |
| 2 | b | 100 |
| 1 | a | 5 |
| **3** | **c**|**1** |
| **2** | **b**|**100**|
| **1** | **a**| **5** |
| 0 | x | 42 |

And then `foo()` calls `bar()`:
And then `bold()` calls `italic()`:

| Address | Name | Value |
|---------|------|-------|
| 4 | i | 6 |
| 3 | c | 1 |
| 2 | b | 100 |
| 1 | a | 5 |
| *4* | *i* | *6* |
| **3** | **c**|**1** |
| **2** | **b**|**100**|
| **1** | **a**| **5** |
| 0 | x | 42 |

Whew! Our stack is growing tall.

After `bar()` is over, its frame is deallocated, leaving just `foo()` and
After `italic()` is over, its frame is deallocated, leaving just `bold()` and
`main()`:

| Address | Name | Value |
|---------|------|-------|
| 3 | c | 1 |
| 2 | b | 100 |
| 1 | a | 5 |
| 0 | x | 42 |
| **3** | **c**|**1** |
| **2** | **b**|**100**|
| **1** | **a**| **5** |
| 0 | x | 42 |

And then `foo()` ends, leaving just `main()`:
And then `bold()` ends, leaving just `main()`:

| Address | Name | Value |
|---------|------|-------|
Expand Down Expand Up @@ -578,3 +579,4 @@ comes at the cost of either significant runtime support (e.g. in the form of a
garbage collector) or significant programmer effort (in the form of explicit
memory management calls that require verification not provided by the Rust
compiler).

6 changes: 0 additions & 6 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
//! nor does it provide concurrency or I/O. These things require
//! platform integration, and this library is platform-agnostic.
//!
//! *It is not recommended to use the core library*. The stable
//! functionality of libcore is reexported from the
//! [standard library](../std/index.html). The composition of this library is
//! subject to change over time; only the interface exposed through libstd is
//! intended to be stable.
//!
//! # How to use the core library
//!
// FIXME: Fill me in with more detail when the interface settles
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ macro_rules! int_impl {
self.overflowing_shl(rhs).0
}

/// Panic-free bitwise shift-left; yields `self >> mask(rhs)`,
/// Panic-free bitwise shift-right; yields `self >> mask(rhs)`,
/// where `mask` removes any high-order bits of `rhs` that
/// would cause the shift to exceed the bitwidth of the type.
///
Expand Down Expand Up @@ -1446,7 +1446,7 @@ macro_rules! uint_impl {
self.overflowing_shl(rhs).0
}

/// Panic-free bitwise shift-left; yields `self >> mask(rhs)`,
/// Panic-free bitwise shift-right; yields `self >> mask(rhs)`,
/// where `mask` removes any high-order bits of `rhs` that
/// would cause the shift to exceed the bitwidth of the type.
///
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ explanatory comments for the same example:

// `for`-loops use a protocol based on the `Iterator`
// trait. Each item yielded in a `for` loop has the
// type `Iterator::Item` -- that is,I `Item` is the
// type `Iterator::Item` -- that is, `Item` is the
// associated type of the concrete iterator impl.
for v in &vs {
// ~ ~~~
Expand Down
11 changes: 5 additions & 6 deletions src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ use std::cell::{Cell, RefCell};
use std::char::from_u32;
use std::fmt;
use syntax::ast;
use syntax::owned_slice::OwnedSlice;
use syntax::codemap::{self, Pos, Span};
use syntax::parse::token;
use syntax::ptr::P;
Expand Down Expand Up @@ -1154,10 +1153,10 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
}

fn rebuild_ty_params(&self,
ty_params: OwnedSlice<hir::TyParam>,
ty_params: P<[hir::TyParam]>,
lifetime: hir::Lifetime,
region_names: &HashSet<ast::Name>)
-> OwnedSlice<hir::TyParam> {
-> P<[hir::TyParam]> {
ty_params.map(|ty_param| {
let bounds = self.rebuild_ty_param_bounds(ty_param.bounds.clone(),
lifetime,
Expand All @@ -1173,10 +1172,10 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
}

fn rebuild_ty_param_bounds(&self,
ty_param_bounds: OwnedSlice<hir::TyParamBound>,
ty_param_bounds: hir::TyParamBounds,
lifetime: hir::Lifetime,
region_names: &HashSet<ast::Name>)
-> OwnedSlice<hir::TyParamBound> {
-> hir::TyParamBounds {
ty_param_bounds.map(|tpb| {
match tpb {
&hir::RegionTyParamBound(lt) => {
Expand Down Expand Up @@ -1249,7 +1248,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
add: &Vec<hir::Lifetime>,
keep: &HashSet<ast::Name>,
remove: &HashSet<ast::Name>,
ty_params: OwnedSlice<hir::TyParam>,
ty_params: P<[hir::TyParam]>,
where_clause: hir::WhereClause)
-> hir::Generics {
let mut lifetimes = Vec::new();
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use middle::ty::fold::{TypeFoldable, TypeFolder};

use std::rc::Rc;
use syntax::abi;
use syntax::owned_slice::OwnedSlice;
use syntax::ptr::P;

use rustc_front::hir;

Expand Down Expand Up @@ -555,8 +555,8 @@ impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
}
}

impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for OwnedSlice<T> {
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> OwnedSlice<T> {
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for P<[T]> {
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> P<[T]> {
self.iter().map(|t| t.fold_with(folder)).collect()
}
}
Expand Down
17 changes: 8 additions & 9 deletions src/librustc_front/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use syntax::ast::{MetaWord, MetaList, MetaNameValue};
use syntax::attr::ThinAttributesExt;
use hir;
use syntax::codemap::{respan, Span, Spanned};
use syntax::owned_slice::OwnedSlice;
use syntax::ptr::P;
use syntax::parse::token;
use syntax::util::move_map::MoveMap;
Expand Down Expand Up @@ -211,7 +210,7 @@ pub trait Folder : Sized {
noop_fold_ty_param(tp, self)
}

fn fold_ty_params(&mut self, tps: OwnedSlice<TyParam>) -> OwnedSlice<TyParam> {
fn fold_ty_params(&mut self, tps: P<[TyParam]>) -> P<[TyParam]> {
noop_fold_ty_params(tps, self)
}

Expand All @@ -220,12 +219,12 @@ pub trait Folder : Sized {
}

fn fold_opt_bounds(&mut self,
b: Option<OwnedSlice<TyParamBound>>)
-> Option<OwnedSlice<TyParamBound>> {
b: Option<TyParamBounds>)
-> Option<TyParamBounds> {
noop_fold_opt_bounds(b, self)
}

fn fold_bounds(&mut self, b: OwnedSlice<TyParamBound>) -> OwnedSlice<TyParamBound> {
fn fold_bounds(&mut self, b: TyParamBounds) -> TyParamBounds {
noop_fold_bounds(b, self)
}

Expand Down Expand Up @@ -576,9 +575,9 @@ pub fn noop_fold_ty_param<T: Folder>(tp: TyParam, fld: &mut T) -> TyParam {
}
}

pub fn noop_fold_ty_params<T: Folder>(tps: OwnedSlice<TyParam>,
pub fn noop_fold_ty_params<T: Folder>(tps: P<[TyParam]>,
fld: &mut T)
-> OwnedSlice<TyParam> {
-> P<[TyParam]> {
tps.move_map(|tp| fld.fold_ty_param(tp))
}

Expand Down Expand Up @@ -726,9 +725,9 @@ pub fn noop_fold_mt<T: Folder>(MutTy { ty, mutbl }: MutTy, folder: &mut T) -> Mu
}
}

pub fn noop_fold_opt_bounds<T: Folder>(b: Option<OwnedSlice<TyParamBound>>,
pub fn noop_fold_opt_bounds<T: Folder>(b: Option<TyParamBounds>,
folder: &mut T)
-> Option<OwnedSlice<TyParamBound>> {
-> Option<TyParamBounds> {
b.map(|bounds| folder.fold_bounds(bounds))
}

Expand Down
15 changes: 7 additions & 8 deletions src/librustc_front/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ use syntax::abi::Abi;
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect};
use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, CrateConfig};
use syntax::attr::ThinAttributes;
use syntax::owned_slice::OwnedSlice;
use syntax::parse::token::InternedString;
use syntax::ptr::P;

Expand Down Expand Up @@ -193,8 +192,8 @@ impl PathParameters {
pub fn none() -> PathParameters {
AngleBracketedParameters(AngleBracketedParameterData {
lifetimes: Vec::new(),
types: OwnedSlice::empty(),
bindings: OwnedSlice::empty(),
types: P::empty(),
bindings: P::empty(),
})
}

Expand Down Expand Up @@ -267,10 +266,10 @@ pub struct AngleBracketedParameterData {
/// The lifetime parameters for this path segment.
pub lifetimes: Vec<Lifetime>,
/// The type parameters for this path segment, if present.
pub types: OwnedSlice<P<Ty>>,
pub types: P<[P<Ty>]>,
/// Bindings (equality constraints) on associated types, if present.
/// E.g., `Foo<A=Bar>`.
pub bindings: OwnedSlice<TypeBinding>,
pub bindings: P<[TypeBinding]>,
}

impl AngleBracketedParameterData {
Expand Down Expand Up @@ -310,7 +309,7 @@ pub enum TraitBoundModifier {
Maybe,
}

pub type TyParamBounds = OwnedSlice<TyParamBound>;
pub type TyParamBounds = P<[TyParamBound]>;

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct TyParam {
Expand All @@ -326,7 +325,7 @@ pub struct TyParam {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct Generics {
pub lifetimes: Vec<LifetimeDef>,
pub ty_params: OwnedSlice<TyParam>,
pub ty_params: P<[TyParam]>,
pub where_clause: WhereClause,
}

Expand Down Expand Up @@ -369,7 +368,7 @@ pub struct WhereBoundPredicate {
/// The type being bounded
pub bounded_ty: P<Ty>,
/// Trait and lifetime bounds (`Clone+Send+'static`)
pub bounds: OwnedSlice<TyParamBound>,
pub bounds: TyParamBounds,
}

/// A lifetime predicate, e.g. `'a: 'b+'c`
Expand Down
13 changes: 6 additions & 7 deletions src/librustc_front/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ use syntax::attr::{ThinAttributes, ThinAttributesExt};
use syntax::ext::mtwt;
use syntax::ptr::P;
use syntax::codemap::{respan, Spanned, Span};
use syntax::owned_slice::OwnedSlice;
use syntax::parse::token;
use syntax::std_inject;
use syntax::visit::{self, Visitor};
Expand Down Expand Up @@ -430,8 +429,8 @@ pub fn lower_ty_param(lctx: &LoweringContext, tp: &TyParam) -> hir::TyParam {
}

pub fn lower_ty_params(lctx: &LoweringContext,
tps: &OwnedSlice<TyParam>)
-> OwnedSlice<hir::TyParam> {
tps: &P<[TyParam]>)
-> P<[hir::TyParam]> {
tps.iter().map(|tp| lower_ty_param(lctx, tp)).collect()
}

Expand Down Expand Up @@ -583,8 +582,8 @@ pub fn lower_mt(lctx: &LoweringContext, mt: &MutTy) -> hir::MutTy {
}

pub fn lower_opt_bounds(lctx: &LoweringContext,
b: &Option<OwnedSlice<TyParamBound>>)
-> Option<OwnedSlice<hir::TyParamBound>> {
b: &Option<TyParamBounds>)
-> Option<hir::TyParamBounds> {
b.as_ref().map(|ref bounds| lower_bounds(lctx, bounds))
}

Expand Down Expand Up @@ -1795,8 +1794,8 @@ fn path_all(sp: Span,
identifier: last_identifier,
parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
lifetimes: lifetimes,
types: OwnedSlice::from_vec(types),
bindings: OwnedSlice::from_vec(bindings),
types: P::from_vec(types),
bindings: P::from_vec(bindings),
}),
});
hir::Path {
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_front/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub use self::AnnNode::*;

use syntax::abi;
use syntax::ast;
use syntax::owned_slice::OwnedSlice;
use syntax::codemap::{self, CodeMap, BytePos, Spanned};
use syntax::diagnostic;
use syntax::parse::token::{self, BinOpToken};
Expand Down Expand Up @@ -519,7 +518,7 @@ impl<'a> State<'a> {
hir::TyBareFn(ref f) => {
let generics = hir::Generics {
lifetimes: f.lifetimes.clone(),
ty_params: OwnedSlice::empty(),
ty_params: P::empty(),
where_clause: hir::WhereClause {
id: ast::DUMMY_NODE_ID,
predicates: Vec::new(),
Expand Down Expand Up @@ -2258,7 +2257,7 @@ impl<'a> State<'a> {
}
let generics = hir::Generics {
lifetimes: Vec::new(),
ty_params: OwnedSlice::empty(),
ty_params: P::empty(),
where_clause: hir::WhereClause {
id: ast::DUMMY_NODE_ID,
predicates: Vec::new(),
Expand Down
Loading